Hello,
I would like to create a SPARQL query using a property path:
SELECT * WHERE {
<http://exampleUri> dct:creator/gndo:preferredNameForThePerson ?o
}
I am trying to create that query via the Jena API, but parsing the
PropertyPath with SSE.parsePath(String,PrefixMapping) fails.
This is my call:
String propertyPath = "dct:creator/gndo:preferredNameForThePerson";
Path parsedPropertyPath = SSE.parsePath(propertyPath, PREFIXMAPPING);
The parsing fails with
org.apache.jena.sparql.ARQException: Not a list:
dct:creator/gndo:preferredNameForThePerson
I cannot find any working examples. Is my PropertyPath wrong, or does
Jena require a special syntax? Should I use another method to obtain a
Path object?
As a context I have appended my complete methods for creating the SPARQL
query.
Thanks for your advice.
Regards
Andreas
P.S. Here are my SPARQL creator methods
private Query buildQuery(final String propertyPath) {
// dct:creator/gndo:preferredNameForThePerson
ElementTriplesBlock triplesBlock = new ElementTriplesBlock();
Path parsedPropertyPath = SSE.parsePath(propertyPath,
PREFIXMAPPING);
triplesBlock.addTriplePath(
new
TriplePath(NodeFactory.createURI(this.titleUri.toString()),
parsedPropertyPath,
NodeFactory.createVariable("preferredName"))
);
final Query query = buildSelectQuery(triplesBlock);
System.out.println(query.serialize());
return query;
}
private Query buildSelectQuery(final ElementTriplesBlock queryBlock)
{
final Query query = new Query();
query.setPrefixMapping(PREFIXMAPPING);
query.setQuerySelectType();
query.setQueryResultStar(true);
query.setDistinct(true);
query.setQueryPattern(queryBlock);
return query;
}