views:

584

answers:

1

Im trying to create a Sqarql query using Jena to query dbpedia.

The query is working when I use it with standalone tools (Twinkle) but when I plug it in this java code it returns an empty set.

    String sparqlQueryString1= "PREFIX dbont: <http://dbpedia.org/ontology/&gt; "+
    "PREFIX dbp: <http://dbpedia.org/property/&gt;"+
        "PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#&gt;"+
    "   SELECT ?musician  ?place"+
    "   FROM<http://dbpedia.org/resource/Daphne_Oram&gt;"+
    "   WHERE {  "+
    "       ?musician dbont:birthPlace ?place ."+
    "        }";


      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() ;

Any ideas what im doing wrong?

+4  A: 

The problem is your FROM <...> clause. Remove it and all is well. With that clause in place I suspect the endpoint is limiting the query to the graph with that name, but no such graph exists and thus there is no result.

The confusing thing is that it seems like the query works on the form at http://dbpedia.org/sparql. However there a default graph URI is set, so the query goes over that graph too. Clear it and the query doesn't work. As an alternative you can set it to retrieve remote data. That pulls in the named rdf which mentions three birthplaces.

If you're trying to find the birth place of that musician use:

{ <http://dbpedia.org/resource/Daphne_Oram&gt; dbont:birthPlace ?place . }
that worked nicely.thanks!
Marcom