简体   繁体   English

SPARQL:如果类层次结构的深度未知,如何获得本体的概念?

[英]SPARQL: How to get an insance of an ontology, if depth of the class hierarchy is unknown?

I have a question about SPARQL. 我有一个关于SPARQL的问题。 I have an ontology of animals: 我有动物的本体论:

Animals  (is a superclass with object property <hasColor>)
------ Mammals (subclass of Animals)
------------- Dog (subclass of Mammals)
---------------- dog1 (a instance with property <hasColor>="white")
---------------- dog2 (a instance with property <hasColor>="red"   )
------ Bird (subclass of Animals)

Is it possible to find with SPARQL "all Animals, that are 'white' " or "all instances of Animals"? 是否有可能找到SPARQL“所有动物,'白''或”所有动物实例“? And backwards: How can I know, if a instance (dog1) belongs to Animals? 倒退:我怎么知道,如果一个实例(dog1)属于动物?

NOTE : The depth and breadth of the class hierarchy is unknown in advance. 注意 :类层次结构的深度和广度是事先未知的。

Also the query below will not work 此外,下面的查询将无法正常工作

SELECT ?x WHERE  {?x rdfs:subClassOf  :Animals .  ?x :hasСolor "white"}

And the next query (find all Animals, that are 'white') works only if the depth of class hierarchy is known. 并且下一个查询(查找所有动物,即'白色')仅在已知类层次结构的深度时才起作用。 (So if the hierarchy is known, can I make the specified steps (from top of hierarchy to bottom) to reach the goal: in this case 2 steps. (因此,如果已知层次结构,我可以制定指定的步骤(从层次结构的顶部到底部)以达到目标:在这种情况下是2个步骤。

SELECT ?z WHERE  {
?x  rdfs:subClassOf :Animals .
?y  rdfs:subClassOf ?x .
?z  rdf:type ?y .
?z :hasColor "white"
}

The same is true for the next example - "find all instances of Animals" 下一个例子也是如此 - “查找动物的所有实例”

SELECT ?z WHERE  {
?x  rdfs:subClassOf :Animals .
?y  rdfs:subClassOf ?x .
?z  rdf:type ?y .
}

What to do, if the hierarchie is unknown? 怎么办,如果不知道的是什么?

The query will be processed with SDB (is a component of Jena ). 查询将使用SDB处理(是Jena的一个组件)。

I want something like : select ?x where {?x rdfs:subClassOf :Animals . ?x :hasСolor "white"}) 我想要这样的东西: select ?x where {?x rdfs:subClassOf :Animals . ?x :hasСolor "white"}) select ?x where {?x rdfs:subClassOf :Animals . ?x :hasСolor "white"})

UPD. UPD。 Solution for "find all Animals (instances), that are 'white'" might look like this: “查找所有动物(实例),即'白色'”的解决方案可能如下所示:

SELECT ?y WHERE { ?x rdfs:subClassOf* :Animals . SELECT?y WHERE {?x rdfs:subClassOf *:动物。 ?y rdf:type ?x . ?rdf:输入?x。 ?y :hasColor "white"} ?y:hasColor“white”}

You can use transitivity in your SPARQL query (using *) : 您可以在SPARQL查询中使用传递性(使用*):

SELECT ?y WHERE { ?x rdfs:subClassOf* :Animals . 
                  ?y rdf:type ?x . 
                  ?y :hasColor "white" }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM