【发布时间】:2014-10-06 19:22:29
【问题描述】:
我有一个从根到叶长度不同的结构。我希望将它们输出到列表中。我也希望所有的父母和祖父母都在 market_segment 之下。最大深度为 5 级,如何将结果绑定到仅 Market_segment 而不转到 Market_segment 的父级。如果路径短于 5,则当前此查询将返回 Market_Segment 的父级。
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.
}}}}}
}
【问题讨论】:
-
请Calculate the depth of subclass in the OWL ontology 或Sparql query for children, grandchildren, .. of a class 帮忙?他们是类似的问题。您不会那么容易获得不同的变量(?parent、?gparent 等),但您可以获得每个节点的深度。
标签: rdf sparql semantic-web owl