Question

I'm constantly having the following problem. When I write queries into Jena they don't work.

Take for example this good query from other sites:

PREFIX dbpedia: <http://dbpedia.org/resource/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX mo: <http://purl.org/ontology/mo/>

SELECT *
WHERE {dbpedia:The_Beatles mo:member ?member .
       ?member foaf:name ?name
      }

when I translate it into Java's Jena it should look like this:

public static String beatlesMembers = 
        "PREFIX dbpedia: <http://dbpedia.org/resource/> "+
        "PREFIX foaf: <http://xmlns.com/foaf/0.1/> "+
        "PREFIX mo: <http://purl.org/ontology/mo/> "+
        "SELECT * " +
        "WHERE {dbpedia:The_Beatles mo:member ?member . "+
        "?member foaf:name ?name "+
        "}";

and then I query DBPEDIA

Query query = QueryFactory.create(Requests.beatlesMembers);

QueryExecution qexec = QueryExecutionFactory.sparqlService("http://dbpedia.org/sparql", query);

try {
    ResultSet results = qexec.execSelect();
    for (; results.hasNext();) {
        QuerySolution s = results.nextSolution();
        System.out.println(s.toString());
    }
}
finally {
   qexec.close();
}

And it returns nothing...

Any idea why? I can't figure out how to correctly write these queries in Java. Hope you can help.

Thank you very much for your help

Was it helpful?

Solution

Did you try the query at dbpedia.org?

When I run it there, through the web form interface, I get zero rows.

{ dbpedia:The_Beatles mo:member ?member } has zero matches. There are no http://purl.org/ontology/mo/ triples.

Try { dbpedia:The_Beatles ?pred ?obj} and look at the details.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top