1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
String queryString = "SELECT ?label ?comment " + " WHERE { " +
"<"+uri+"> <http://www.w3.org/2000/01/rdf-schema#label> ?label." +
"<"+uri+"> <http://www.w3.org/2000/01/rdf-schema#comment> ?comment." +
" FILTER langMatches(lang(?label), 'en') " +
" FILTER langMatches(lang(?comment), 'en')}";
Query query = QueryFactory.create(queryString);
// initializing queryExecution factory with remote service.
// **this actually was the main problem I couldn't figure out.**
QueryExecution qexec = QueryExecutionFactory.sparqlService("http://dbpedia.org/sparql", query);
try {
ResultSet results = qexec.execSelect();
for (; results.hasNext();) {
QuerySolution sol = results.next();
System.out.println(sol.get("?label") + "\n" + sol.get("?comment"));
}
}catch(Exception e){
e.printStackTrace();
}
finally {
qexec.close();
}
}catch(Exception e){
e.printStackTrace();
} |
Partager