3

Imagine you do something crazy and store your object-oriented model as an RDF graph.

RDF Graph

shows a simplified example of the inheritance hierarchy and the associated attributes.

In practice, you get such graph structure if you translate some UML class diagram into RDFS.

The question is: what SPARQL query can deliver all the predicate-object pairs necessary to instantiate a particular resource of "Class C". In other words: how do you get all the predicate-object pairs along the whole inheritance chain (only single inheritance).

dbugger
  • 15,868
  • 9
  • 31
  • 33

2 Answers2

4

Given this diagram, the predicate-object pairs of all members of the class:ClassC is simply:

SELECT ?inst ?p ?o
WHERE {
   ?inst a :ClassC .
   Inst ?p ?o .

Keep in mind that there is not property inheritance in RDF/RDFS. If you want to find all of property/values pairs for ClassA with entailments for subclasses then useL

SELECT ?inst ?p ?o
WHERE {
   ?cls rdfs:subClassOf* :ClassA .
   ?inst a ?cls .
   ?inst ?p ?o
}

In this respect, RDFS works a bit backwards of one's expectations of OO inheritance.

scotthenninger
  • 3,921
  • 1
  • 15
  • 24
4

With the info from @scotthenninger the following query did the job:

SELECT ?p ?o
WHERE {
   :ClassC rdfs:subClassOf* ?anySuperClass .
   ?anySuperClass ?p ?o .   
}

edit: Similar query gets all the self-defined properties and their range along the inheritance chain:

SELECT ?prop ?obj
    WHERE {
       :ClassC rdfs:subClassOf* ?anySuperClass .
       ?prop rdfs:domain ?anySuperClass .   
       ?prop rdfs:range ?obj .
}

End results combined:

foo:ID         xsd:string
foo:name       xsd:string
rdfs:comment   xsd:string
foo:similarTo  :ClassD