1

I am trying to run a query using D2RQ. When I run the query using the browser from http://localhost:2020/sparql as described in Using the D2RQ Engine with Jena, everything works fine, but with the Jena API it does not produce any results. The query is

PREFIX vocab: <http://localhost:2020/resource/vocab/>
SELECT ?personName WHERE {
  ?person vocab:people_Name ?personName .
}

Here the is Java code that constructs the query and runs it against a Model:

ModelD2RQ m = new ModelD2RQ( "file:///C:/Users/sabse/Downloads/d2rq-0.8.1/d2rq-0.8.1/mapping-ontology.ttl");
String sparql =
  "PREFIX vocab: <http://localhost:2020/resource/vocab/>" +
  "SELECT ?personName WHERE {" +
  "  ?person vocab:people_Name ?personName . " +
  "}";
Query q = QueryFactory.create(sparql);
ResultSet rs = QueryExecutionFactory.create(q, m).execSelect();
ResultSetFormatter.out(System.out, rs, q);
m.close();

The data begins with the following prefix declarations:

@prefix vocab: <vocab/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix d2rq: <http://www.wiwiss.fu-berlin.de/suhl/bizer/D2RQ/0.1#> .
@prefix jdbc: <http://d2rq.org/terms/jdbc/> .
Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
Keks
  • 77
  • 7
  • What sort of results do you get from the working query? The prefix `http://localhost:2020/resource/vocab/` is surprising to me; does the data not actually use a more meaningful IRI prefix? – Joshua Taylor Jan 11 '14 at 18:47
  • I get the names of all the people in the database. The prefix is the same one as in the browser. – Keks Jan 11 '14 at 22:24
  • Can you show some of the contents of the `.ttl` file? Is the prefix `http://localhost:2020/resource/vocab/` what's used there, too? – Joshua Taylor Jan 11 '14 at 22:26
  • when I change the prefix in the .ttl file, it gets even worse, I get exceptions. – Keks Jan 11 '14 at 22:31
  • I'm not sure what you mean by "change the prefix", and you didn't show any exceptions, so I can't speak to those. However, the prefix `` is a relative URL, so SPARQL engines are going to do something a bit unpredictable with it. If I had to guess, I'm guessing that when you load the data from file, you're getting IRIs in such a way that `vocab:People_name` expands to something ilke `file:///C:/Users/sabse/Downloads/d2rq-0.8.1/d2rq-0.8.1/mapping-ontology.ttl/vocab/People_name`, which would explain why your SPARQL query isn't working. – Joshua Taylor Jan 11 '14 at 22:34
  • If you try a SPARQL query like `select * where { ?s ?p ?o } limit 10` on the model loaded from a file, what sorts of IRIs do you see in it? – Joshua Taylor Jan 11 '14 at 22:35
  • 1
    For comparison, have a look at this question, [tbloader vs SPARQL INSERT - Why different Behaviour with named graphs?](http://stackoverflow.com/q/18891690/1281433), where someone ran into the same kind of issue because of relative IRIs. – Joshua Taylor Jan 11 '14 at 22:37
  • Thanks a lot! I solved it now with the help of your tips. – Keks Jan 11 '14 at 22:45

0 Answers0