Reputation: 55
I'm trying to write a SPARQL query that, given a node, returns the connected nodes up to the root.
I've tried using property paths:
SELECT ?subproperty WHERE { <leaf node URI> <http://www.w3.org/2000/01/rdf-schema#subPropertyOf>+ ?subproperty . }
but I want to also traverse subclasses if possible in the same query. Basically, I'd like to find all parent nodes up to the root from any given node.
So my model currently has:
Class A
Class B and Class C (subclasses of A)
Property D (property of B)
Property E (subproperty of D)
I want to make a query that if given E, returns something like:
Property E, Property D, Class B, Class A
The model may change in the future, so I'd like the query to be able to handle any length between the leaf and root node. Thanks for any help or pointers! (also sorry for the simplified representation of the model, very new to ontologies)
Upvotes: 1
Views: 759
Reputation: 55
I ended up using a wildcarding trick from SPARQL: is there any path between two nodes? to traverse the nodes. I just edited the wildcard so that it only looks at parent nodes.
Upvotes: 1