2

I need to show the tree structure of a data stored in a triple store (Stardog). I can get all sub-classes of a specific class via rdfs:subClassOf+, but it does not tell me the level/depth of each sub-class. Also I can get parent of each sub-class, but still I need to process the result to get the tree. This is the SPARQL query that I use:

SELECT DISTINCT subClass ?parent
WHERE {
  ?subClass rdfs:subClassOf+ <A Class URI> .
  ?subClass rdfs:subClassOf ?parent
}

Does anybody know a better way of doing this by SPARQL query?

Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
Amin
  • 111
  • 9
  • The property in that duplicate is not rdfs:subClassOf, but it's an isomorphic problem, and the same approach will work for your problem, although you may need to take into consideration whether `X rdfs:subClassOf X` or not. – Joshua Taylor Sep 04 '14 at 23:19
  • @JoshuaTaylor Does [your solution](http://stackoverflow.com/questions/5198889/calculate-length-of-path-between-nodes) work when my data is split among named graphs, considering that [A property path does not span multiple graphs](http://www.google.com/url?q=http%3A%2F%2Fwww.w3.org%2FTR%2Fsparql11-query%2F%23sparqlPropertyPaths&sa=D&sntz=1&usg=AFQjCNGbgU8dnEDEhfbRiT_jqbzH6Q2HXA)? Please take a look at my post [here](https://groups.google.com/a/clarkparsia.com/forum/#!topic/stardog/sfX1Iolvh2M) – Amin Sep 13 '14 at 15:55
  • I don't think it would work in that case. (Though you didn't mention multiple graphs in the question.) This is a case where it would be *very helpful* to be able to run a query against `construct`ed data. (Since you could construct a graph containing just the subclass properties, and then query against it.) Unfortunately, that's not part of SPARQL 1.1, and I've only heard of one triple store (and it's not Stardog) that's implemented something like it. – Joshua Taylor Sep 13 '14 at 16:09

0 Answers0