So, im doing a simple query. I want all uri/property/object of a certain dbpedia uri, ex: http://dbpedia.org/resource/Roger_Federer. The problem is, it returns just the property of it, as we can see on the resultset.
Class:
public class SemanticCrawlerImpl implements SemanticCrawler {
public void search(Model graph, String resourceURI) {
graph.read(resourceURI);
// Create a new query
String queryString =
"SELECT ?url ?property ?object" +
"WHERE {" +
" <"+resourceURI+"> ?property ?object ." +
"}";
Query query = QueryFactory.create(queryString);
System.out.println("----------------------");
System.out.println("Query Result Sheet");
System.out.println("----------------------");
// Execute the query and obtain results
QueryExecution qe = QueryExecutionFactory.create(query, graph);
com.hp.hpl.jena.query.ResultSet results = qe.execSelect();
// Output query results
ResultSetFormatter.out(System.out, results, query);
qe.close();
}
}
Resultset
| url | property | objectWHERE |
=================================================================================
| | <http://dbpedia.org/property/medaltemplatesTitle> | |
| | <http://dbpedia.org/ontology/thumbnail> | |
| | <http://www.w3.org/2002/07/owl#sameAs> | |
| | <http://www.w3.org/2002/07/owl#sameAs> | |
| | <http://www.w3.org/2002/07/owl#sameAs> | |
| | <http://www.w3.org/2002/07/owl#sameAs> | |
| | <http://dbpedia.org/property/name> | |
| | <http://dbpedia.org/property/daviscupresult> | |
| | <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> | |
| | <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> | |
| | <http://dbpedia.org/property/hopmancupresult> | |
| | <http://dbpedia.org/ontology/wikiPageExternalLink> | |
| | <http://purl.org/dc/terms/subject> | |
| | <http://www.w3.org/2002/07/owl#sameAs> | |
| | <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> | |
| | <http://purl.org/dc/terms/subject> | |
| | <http://www.w3.org/2002/07/owl#sameAs> | |
| | <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> | |
| | <http://dbpedia.org/ontology/height> | |
| | <http://purl.org/dc/terms/subject> | |
| | <http://www.w3.org/2002/07/owl#sameAs> | |
| | <http://dbpedia.org/ontology/birthYear> | |
There is a typo in your query, a missing space. Note that the output should be "object", not "objectWHERE". Also, there is no need for your ?url variable, since you are not using it in your query. Replace this fragment in your code and it will work:
// Create a new query
String queryString =
"SELECT ?property ?object " +
"WHERE {" +
" <"+resourceURI+"> ?property ?object ." +
"}";
Query query = QueryFactory.create(queryString);
Also, I don't get why you first read the resource locally and then issue the sparql query against the local graph. Why not doing it directly against the dbpedia endpoint? Something like this:
String resourceURI = "http://dbpedia.org/resource/Roger_Federer";
String queryString =
"SELECT ?property ?object " +
"WHERE {" +
" <"+resourceURI+"> ?property ?object ." +
"}";
Query query = QueryFactory.create(queryString);
//System.out.println(queryIn);
QueryExecution qe = QueryExecutionFactory.sparqlService("http://dbpedia.org/sparql", query);
ResultSet results = qe.execSelect();
ResultSetFormatter.out(System.out, results, query);
qe.close();
I think it is cleaner.