Reputation: 31
This is my first question here on StackOverflow. I'm using Apache Jena in order to query DBPedia and the results i got are pretty strange. Here's my code, with a simple query :
String sparqlQuery = "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> select ?o where { <http://dbpedia.org/ontology/Agent> rdfs:subClassOf ?o}";
System.out.println("Query : " + sparqlQuery);
Query query = QueryFactory.create(sparqlQuery);
QueryExecution qexec = QueryExecutionFactory.sparqlService("http://dbpedia.org/sparql", query);
ResultSet results = qexec.execSelect();
ResultSetFormatter.out(System.out, results, query);
qexec.close();
And this is what i got in response :
<http://www.w3.org/2002/07/owl#Thing>
<http://www.w3.org/2002/07/owl#Thing>
<http://www.w3.org/2002/07/owl#Thing>
Any idea why i don't get a single Resource ? I tried with other Resources, same problem.
Thanks for your help and have a nice day !
Upvotes: 3
Views: 78
Reputation: 5140
That's pretty strange, when I test your query on http://dbpedia.org/sparql, I got only one resource.
Can you check that there are three result in your ResultSet
?
int count = 0;
while( results.hasNext() ){
results.next();
count++;
}
System.out.println("I see "+count+" rows !");
As workaround, you could use the DISTINCT
keyword:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT DISTINCT ?o
WHERE {
<http://dbpedia.org/ontology/Agent> rdfs:subClassOf ?o
}
Upvotes: 2
Reputation: 16700
The query is sent to dbpedia so it is that giving three answers. Jena only formats the results.
It might be because there are 3 triples in different named graphs - the default dbpedia graph is the union of all named graphs.
Try:
select *{ GRAPH ?g { <http://dbpedia.org/ontology/Agent> rdfs:subClassOf ?o} }
Also check the results returns : issue the query with wget or curl and see the bytes sent back.
(The response you show does not correspond the ResultSetFormatter output)
Upvotes: 2