implementing paths for SHACL

I had thought that implementing paths for SHACL would be hard, with lots of
changes required.   It turned out to be not nearly as hard as I expected in my
implementation.

The core of the implementation of paths is a function that converts a path
(however the syntax is defined) into a string that can be used as a SPARQL
path.  Then instead of using an IRI as the predicate in triple patterns just
use the result of this function.  I ended up with nine places where this was
needed, two each in sh:equals, sh:notEquals, sh:lessThan, and
sh:lessThanOrEquals and one in sh:propValues.

There is a little bit more that has to be done if a path is used elsewhere.

My conversion function ended up being roughly

def parttoSPARQL(g,part) :
    result =  ("^"+g.value(part,SH.inverse).n3()) \
              if (part,SH.inverse,None) in g else part.n3()
    return result

def pathtoSPARQL(g,value) :
    if (value,RDF.rest,None) in g :
        path = [ parttoSPARQL(g,part) for part in listElements(g,value) ]
        return Literal("/".join(path))
    else : return parttoSPARQL(g,value)


peter

Received on Wednesday, 23 March 2016 16:00:52 UTC