I have a structure that have different length from the root to leaf. I wish to output them into a list. I also wish all parents and grand parents are under market_segment. the maximum depth is 5 level, How do I bound the result to only Market_segment without going over to the parents of Market_segment. currenly this query will return parents of Market_Segment, if the path is shorter than 5.
PREFIX mdy: <http://www.owl-ontologies.com/mdys.owl#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?node ?parent ?gparent ?ggparent ?gggparent ?ggggparent
WHERE {
?node rdfs:subClassOf* mdy:Market_Segment
OPTIONAL {?node rdfs:subClassOf ?parent.
OPTIONAL {?parent rdfs:subClassOf ?gparent.
OPTIONAL {?gparent rdfs:subClassOf ?ggparent.
OPTIONAL {?ggparent rdfs:subClassOf ?gggparent.
OPTIONAL {?gggparent rdfs:subClassOf ?ggggparent.
}}}}}
}