On Thu, Dec 12, 2013 at 5:55 AM, Aidan Delaney <[email protected]> wrote: > ?leaf (rdfs:subClassOf)+ ?root > > In my case I'm trying to match trees within an RDF graph. The internal nodes > of > the trees are either unary or binary. This could be described by the > (nearly) BNF > grammar > > root ::= root bOp root | uOp root | leaf > leaf ::= (?leaf rdf:type my:leaf)
Since your query variable is ?leaf, I assume you don't want the intermediate nodes. If you have data like this: @prefix : <http://example.org/> . # a # / \ # / \ # b c # / \ # d e :b :sub :a . :c :sub :a . :d :sub :b . :e :sub :b . then you can use a query like this: prefix : <http://example.org/> select ?leaf where { ?leaf :sub* :a . filter not exists { ?subLeaf :sub ?leaf } } to get results like this: -------- | leaf | ======== | :c | | :e | | :d | -------- -- Joshua Taylor, http://www.cs.rpi.edu/~tayloj/
