0

I reported an issue in the execution of a SPARQL query in Java code using Jena. The ontology is avalaible here (please correct a extra white space at line 798545). After loading an ontology from a N-Triples file on a Jena Model, using

Model model=ModelFactory.createDefaultModel();
model.read("minerva-dataset.nt");

I tried to make a query on the model, using SPARQL:

String queryString = "PREFIX owl: <http://www.w3.org/2002/07/owl#> \n"
            + "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n"
            + "PREFIX dcterms:<http://purl.org/dc/terms/>\n"
            + "SELECT  ?title WHERE { \n" + "?book rdf:type owl:Thing .\n" + "?book dcterms:title ?title.\n"+"}";

    System.out.println(queryString);  //I used this to see if the query was correctly parsed

    Query query = QueryFactory.create(queryString);
    QueryExecution qe = QueryExecutionFactory.create(query, model);
    ResultSet rs = qe.execSelect();
    ResultSetFormatter.out(System.out, rs);

but, even trying another query, the ResultSet results empty. I'm sure that the query HAS results because I also ran it on Protegé on the same ontology I loaded in the Jena Model. Then I searched an error in the loading process, but using

FileOutputStream test=new FileOutputStream("test.txt");
model.write(test,"N-TRIPLES");

I saw that in the output file the number of axioms was the same of the original file of the ontology (even if the order wasn't the same).

So I think the error is in the execution of the query(also considering that in the Eclipse console doesn't appear any parsing error), but I can't understand from what it's caused.

Jul10
  • 503
  • 7
  • 19
  • 4
    Are there any rdf:type owl:Thing declarations in minerva-dataset.nt? Jena does not add inference by default. Try `{ ?book dcterms:title ?title . } ` - does this have results? if not, there are no titles in the data. if there are, it was the `rdf:type owl:Thing` blocking a match. – AndyS Jun 15 '17 at 16:48
  • Thanks, now it works. It was exactly what you said. – Jul10 Jun 15 '17 at 16:57

0 Answers0