SSE, = SPARQL S-Expressions, is not SPARQL syntax. It is used intrernally for read/write all sorts of datastructures in its own unifying syntax.

http://jena.apache.org/documentation/notes/sse.html

You need to invoke the SPARQL parser if you want to write in SPARQL syntax.

This happens to be wrapped up for convenience (internal API) in 'PathParser':

Illustration of the formats:

    org.apache.jena.sparql.core.Prologue prologue
          = new Prologue(SSE.defaultPrefixMapWrite) ;
    Path path = PathParser.parse("^:r|:p*/:q",
                                 SSE.defaultPrefixMapRead) ;
    System.out.println(path) ;
    String x = WriterPath.asString(path, prologue) ;
    System.out.println(x) ;
    Path path2 = SSE.parsePath(x) ;
    System.out.println(path2) ;


^<http://example/r>|((<http://example/p>)*/<http://example/q>)

in SSE is:

(alt
   (reverse <http://example/r>)
   (seq (path* <http://example/p>) <http://example/q>))

     Andy

On 02/03/16 14:13, Andreas Kahl wrote:
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;
     }

Reply via email to