Search code examples
scalasparqlrdfjena

Querying RDF Properties Made by Jena with SPARQL


So, I've been playing around with Jena in Scala to try and get a feel for it, and I've come across a simple problem. Suppose you create a property with some code like var myProperty = model.createProperty("myProperty"), and then add it to your model with something like model.createLiteralStatement(model.createResource(), myProperty, "test") and you simply wish to retrieve this statement with a SPARQL query how would you go about it?

I have tried the following:

var sparqlQuery = "SELECT ?value " +
  "WHERE " +
  "{?subject " + "<myProperty>" +  " ?value." +
  "}"
val query = QueryFactory.create(sparqlQuery)
var queryExec: QueryExecution = QueryExecutionFactory.create(query, model) 
val results = queryExec.execSelect

But sadly, the results are empty. What am I doing wrong here?


Solution

  • In the query, <myProperty> is a relative URI. The parser will expand this to a full (absolute) URI, probably adding the current directory as the base of resolution.

    It will not match createProperty("myProperty").

    The data should have an absolute URI (e.g. createProperty("http://example/myProperty") and the query should agree <http://example/myProperty>.

    You can use prefixes in the query.