Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.hp.hpl.jena.query.Query;
- import com.hp.hpl.jena.query.QueryExecution;
- import com.hp.hpl.jena.query.QueryExecutionFactory;
- import com.hp.hpl.jena.query.QueryFactory;
- import com.hp.hpl.jena.query.QuerySolution;
- import com.hp.hpl.jena.query.ResultSet;
- import com.hp.hpl.jena.rdf.model.Literal;
- import com.hp.hpl.jena.rdf.model.Model;
- import com.hp.hpl.jena.rdf.model.ModelFactory;
- public class java_test {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Model model = ModelFactory.createDefaultModel();
- String sparqlQueryString = "PREFIX mdb: <http://data.linkedmdb.org/resource/movie/>"
- + "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> "
- +
- "select ?label "
- +
- "where "
- +
- "{ ?film mdb:director_name ?dir ."+
- "?film rdfs:label ?label . }"
- + "LIMIT 20";
- Query query = QueryFactory.create(sparqlQueryString);
- QueryExecution qexec = QueryExecutionFactory.sparqlService("http://linkedmdb.org/sparql",query);
- ResultSet results = qexec.execSelect();
- while (results.hasNext()) {
- QuerySolution soln = results.nextSolution();
- Literal value = soln.getLiteral("label");
- System.out.println(value);
- System.out.println( soln.getResource("label").getURI());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement