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)