Theo Stefou
Theo Stefou

Reputation: 645

SPARQL inference: How to count the number of steps?

Is there a way to know in my query how many steps were followed by the inferencer to connect a subclass to a super class?

Upvotes: 1

Views: 287

Answers (1)

Damyan Ognyanov
Damyan Ognyanov

Reputation: 786

You could use the length of the rdfs:subClass path between the classes.

Try to adapt the answer from Calculate length of path between nodes?

e.g. something like:

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
select ?sub ?super (count(?mid) as ?distance) { 
  ?sub rdfs:subClassOf* ?mid .
  filter(!sameTerm(?sub, ?mid))
  ?mid rdfs:subClassOf+ ?super .
}
group by ?sub ?super 
order by ?sub ?super

Upvotes: 1

Related Questions