Search code examples
javardfsparqljena

SPARQL query to find the URL of a term in an RDF


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

Solution

  • 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 {".