2

I'm trying to create a SPARQL query with Jena to query DBpedia. The query is working when I use Virtuoso but when I plug it into the following Java code, it returns an empty set.

String sr="Christopher_Nolan";
String sparqlQueryString1 = "PREFIX dbont: <http://dbpedia.org/ontology/> "+            
        "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>"+ 
        "PREFIX foaf: <http://xmlns.com/foaf/0.1/> "+
        "   SELECT distinct   ?s"+        
        "   WHERE {  "+       
        "?s foaf:name ?label  ."  +
        "filter(?label=\"Christpher_Nolan\"@en)." +             
        "        }";
          Query query = QueryFactory.create(sparqlQueryString1);
          QueryExecution qexec = QueryExecutionFactory.sparqlService("http://dbpedia.org/sparql", query);

          ResultSet results = qexec.execSelect();
          ResultSetFormatter.out(System.out,results, query);       

         qexec.close() ;    
Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
fadox
  • 29
  • 2

1 Answers1

2

I don't think this is a problem with Jena, but with your particular query. Your query, when run on the DBpedia SPARQL endpoint, produces no results

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT distinct ?s      
WHERE {
  ?s foaf:name ?label .
  filter(?label="Christpher_Nolan"@en)
}

SPARQL results (no results)

no results

However, if you add an o to the name Christopher, and change the underscore to a space, you get three results:

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT distinct ?s      
WHERE {
  ?s foaf:name ?label .
  filter(?label="Christopher Nolan"@en)
}

SPARQL results (3 results)

s
http://dbpedia.org/resource/Christopher_Nolan_(author)
http://dbpedia.org/resource/Christopher_Nolan
http://dbpedia.org/resource/Chris_Nolan_(musician)

three results

I'd also point out that this is a rather unusual use of filter. If you want to select triples that use a certain value, just put that value into the triple pattern:

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT distinct ?s      
WHERE {
  ?s foaf:name "Christopher Nolan"@en 
}

SPARQL results (same 3 results)

Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
  • I tried to copy and paste your queries into the DBpedia. I got no result, it showed just the head of table. – lvarayut Feb 10 '14 at 21:43
  • @LVarayut DBpedia's endpoing can be a bit flaky at times, but I'm still able to copy and paste those queries to http://dbpedia.org/sparql and get the expected results. Note that the expected results are: no results for the first query, and three results for the second and third query. I've added screenshots as evidence. :) – Joshua Taylor Feb 10 '14 at 21:45
  • Thanks for you respond. I was using [fr.dbpedia.org/sparql](http://fr.dbpedia.org/sparql) and it doesn't work. I just tried with [dbpedia.org/sparql](http://dbpedia.org/sparql). It worked like a charm. Could you explain a little bit `what is Default Data Set Name (Graph IRI)` and what should I put in there? – lvarayut Feb 10 '14 at 21:51
  • @LVarayut Yes, as I recall, the localized DBpedias don't have all the multi-lingual data, so the French DBpedia very well might not have the English data. – Joshua Taylor Feb 10 '14 at 21:53