0

I want to retrieve all the URLs of a term in an RDF, but I receive none. Thanks for the help.

The SPARQL query is:

String queryString = "PREFIX j.0:<http://myURLList#>" +
                     "PREFIX j.1:<http://purl.org/dc/terms/>" +
                       "SELECT ?url" +
                         "WHERE {" +
                             "?term j.0:linkTerm \"respiratory\" ." +
                              "?term j.0:termURL ?url ." +
                         "}";

Query query = QueryFactory.create(queryString);
QueryExecution qe =QueryExecutionFactory.create(query, model);
ResultSet results = qe.execSelect();
// Output query results 
ResultSetFormatter.out(System.out, results, query);
qe.close();
Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
Jan Beeck
  • 303
  • 8
  • 24
  • 3
    You need to show your data. What do you expect this to return? Without seeing your data, we can't say what it should return. – Joshua Taylor Sep 17 '14 at 02:08
  • 1
    This is a duplicate of [DBpedia Jena Query returning null](http://stackoverflow.com/q/15663510/1281433). – Joshua Taylor Sep 17 '14 at 11:57
  • I called the wrong PREFIX j.0: when the right one is PREFIX j.0:. Thank you guys for make me realize that the query was fine. – Jan Beeck Sep 18 '14 at 19:53
  • `prefix j.0: ` isn't quite "fine" though, as you won't be constructing absolute URIs, and that means that your results could be rather unpredictable. (An RDF graph only contains absolute URIs.) – Joshua Taylor Sep 18 '14 at 20:14
  • I am not sure if I have to open a new thread. How could I bind a variable into the query?, I have this line "?term j.0:linkTerm \"respiratory\" ." + ; I would like to replace \"respiratory\" with a String variable obtained before the query. Thanks. – Jan Beeck Sep 18 '14 at 21:28
  • You might have a look at [parameterized sparql strings](http://stackoverflow.com/a/16739846/1281433). – Joshua Taylor Sep 18 '14 at 22:56
  • The function ParameterizedSparqlString returns a String like: PREFIX j.0:....... .}, I have created a function that returns a String with PREFIX j.0:.... /"respiratory/" ... .} The latter is the format that works in my case. – Jan Beeck Sep 19 '14 at 02:45
  • ParameterizedSparqlString isn't a function, it's a class. If you make an instance from, e.g., `select ?x where { ?x rdfs:label ?label }`, and use [setLiteral(String var,String param)](http://jena.apache.org/documentation/javadoc/arq/com/hp/hpl/jena/query/ParameterizedSparqlString.html), to set label `"respiratory"`, then you'll get back `select ?x where { ?x rdfs:label "respiratory" }`. Jena is documented pretty well, and you'll have much better results if you read the documentation and use the appropriate methods. – Joshua Taylor Sep 19 '14 at 03:46

1 Answers1

3

Your java code concatenation is missing new line marks '\n'. This leads to a malformed query in the first case. e.g. instead of "?url WHERE {" your query string contains "?urlWHERE {".

Jerven
  • 582
  • 3
  • 7
  • 3
    good catch. This is a duplicate, actually, of [DBpedia Jena Query returning null](http://stackoverflow.com/q/15663510/1281433). – Joshua Taylor Sep 17 '14 at 11:56