0
import java.io.*;
import com.hp.hpl.jena.datatypes.xsd.XSDDatatype.*;
import com.hp.hpl.jena.rdf.model.*;
import com.hp.hpl.jena.db.*;
import com.hp.hpl.jena.db.impl.*;
import com.hp.hpl.jena.graph.compose.*;
import com.hp.hpl.jena.graph.query.*;
import com.hp.hpl.jena.graph.*;
import com.hp.hpl.jena.vocabulary.*;
import com.hp.hpl.jena.rdf.model.*;
import com.hp.hpl.jena.rdf.model.ModelMaker.*;
import com.hp.hpl.jena.mem.*;
import com.hp.hpl.jena.mem.faster.*;

class Firstsparql{

    public static void main(String[] args){
        // Open the bloggers RDF graph from the filesystem
        InputStream in = new FileInputStream(new File("foaf.rdf"));

        // Create an empty in-memory model and populate it from the graph
        Model model = ModelFactory.createMemModelMaker().createModel();
        model.read(in,null); // null base URI, since model URIs are absolute
        in.close();

        // Create a new query
        String queryString =
        "PREFIX foaf: <http://xmlns.com/foaf/0.1/> " +
        "SELECT ?url " +
        "WHERE {" +
        "      ?contributor foaf:name \"Jon Foobar\" . " +
        "      ?contributor foaf:weblog ?url . " +
        "      }";

        Query query = QueryFactory.create(queryString);

        // Execute the query and obtain results
        QueryExecution qe = QueryExecutionFactory.create(query, model);
        ResultSet results = qe.execSelect();

        // Output query results
        ResultSetFormatter.out(System.out, results, query);

        // Important – free up resources used running the query
        qe.close();
        }
}

嗨,我已经在我的类路径中包含了 jena.jar 文件,但仍然无法识别一些变量和方法。我希望它们没有在jena api中定义..还有其他我需要包含的api吗。请让我..知道。谢谢。

4

2 回答 2

0

除了上述建议外,您还可以在https://jena.apache.org/documentation上阅读有关 jena 架构的信息

特别是,Jena 用于处理 SPARQL 查询的部分称为 ARQ。ARQ.jar 涉及到 QueryFactory。

于 2011-03-27T12:11:00.437 回答
0

CLASSPATH需要包含.jarJena lib 目录中的所有文件,而不仅仅是jena.jar.

于 2011-03-26T11:36:09.527 回答