Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SPARQL property path in reified rdf triples

Is it possible, to use property path with reified rdf triples?

I like to get all superclasses of a specified class (stored in ?class).

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT ?class ?superclass ?supersuperclass ?supersupersuperclass
WHERE{
  {
    ?s rdf:subject ?class .
    ?s rdf:predicate rdfs:subClassOf .
    ?s rdf:object ?superclass .
    
    OPTIONAL {
    ?s1 rdf:subject ?superclass .
    ?s1 rdf:predicate rdfs:subClassOf .
    ?s1 rdf:object ?supersuperclass .
    }
    
    OPTIONAL {
    ?s2 rdf:subject ?supersuperclass .
    ?s2 rdf:predicate rdfs:subClassOf .
    ?s2 rdf:object ?supersupersuperclass .
    }
    
  }

}
like image 920
Helpy Avatar asked Feb 03 '26 10:02

Helpy


1 Answers

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 .
}
like image 131
IS4 Avatar answered Feb 06 '26 02:02

IS4



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!