2014-10-06 47 views
0

我有一个从根到叶的长度不同的结构。我希望将它们输出到列表中。我也希望所有的父母和父母都在市场领域。最大深度为5级,我如何将结果限制在Market_segment而不转到Market_segment的父母。 currenly此查询将返回MARKET_SEGMENT的父母,如果路径短于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. 
        }}}}} 
} 
+1

不要为[计算的深度子类在OWL本体](http://stackoverflow.com/q/26115488/1281433)或[Sparql查询为儿童,孙辈,..一类](http://stackoverflow.com/q/23094361/1281433 ) 帮帮我?他们是类似的问题。你不会很容易得到不同的变量(?parent,?gparent等),但是你可以得到每个节点的深度。 – 2014-10-06 21:49:23

回答

0

使用逆属性路径:

PREFIX mdy: <http://www.owl-ontologies.com/mdys.owl#> 
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> 
SELECT ?node ?parent 
    WHERE { 
      ?node ^rdfs:subClassOf* mdy:Market_Segment . 
      ?node ^rdfs:subClassOf ?parent   
} 

参见 http://www.w3.org/TR/sparql11-query/#propertypaths

相关问题