开发者

cannot find symbol for QueryFactory - jena API

开发者 https://www.devze.com 2023-02-20 07:53 出处:网络
import java.io.*; import com.hp.hpl.jena.datatypes.xsd.XSDDatatype.*; import com.hp.hpl.jena.rdf.model.*;
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.createMemM开发者_开发百科odelMaker().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();
        }
}

Hi, i have included jena.jar file in my classpath but still some of variables and methods are not recognised. ihope they are not defined in jena api..is there any other api i need to include.pls..let me..know. thanks.


Your CLASSPATH needs to include all of the .jar files in the Jena lib directory, not just jena.jar.


Apart from advise above, you can read about jena's architecture on https://jena.apache.org/documentation

Particularly, Jena's part for process SPARQL query called ARQ. ARQ.jar involves QueryFactory.

0

精彩评论

暂无评论...
验证码 换一张
取 消