SPARQL property path in reified rdf triples

You can use intermediate queries, first to dereify the statements:

CONSTRUCT {
  ?s a rdfs:Class .
  ?o a rdfs:Class .
  ?s rdfs:subClassOf ?o .
}
WHERE {
  ?t a rdf:Statement .
  ?t rdf:object ?o .
  ?t rdf:predicate rdfs:subClassOf .
  ?t rdf:subject ?s .
}

Then to obtain all of the subclass relations:

SELECT ?s ?o
WHERE {
  ?s a rdfs:Class .
  ?s rdfs:subClassOf* ?o .
}

If you know that classes are not interlinked by other predicates, you may use paths:

SELECT ?s ?o
WHERE {
  ?s a rdfs:Class .
  ?o a rdfs:Class .
  ?s (^rdf:subject/rdf:object)* ?o .
}

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top