Sparql 查询以获取属于 "property class" 的所有 类
Sparql query to get all classes that are subclass of a "property class"
我需要 "annotate" 给一些 class 添加一个 属性。我需要这样做才能让我的应用程序的视图层提取正确的 classes.
我所做的是:
创建一个名为 uiProperty 的对象 属性 并编辑这些 class 使其成为此 class 的子class :
uiProperty some
所以我的 classes 的最终 OWL 代码是这样的:
rdfs:subClassOf owebs:RealEstate ,
[ rdf:type owl:Restriction ;
owl:onProperty owebs:uiProperty ;
owl:someValuesFrom owl:Thing
] ;
现在我想构建一个 sparql 查询来获取这些 classes。我做了以下事情:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owbes: <http://www.isep.org/desco/2015/>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
SELECT $uri $label WHERE {
$uri rdfs:subClassOf owbes:RealEstate.
$uri rdfs:subClassOf $x.
$x owl:onProperty owbes:uiProperty.
$uri rdfs:label $label
}
问题
该查询的结果太多 class。相同的 class 被重复多次。例如:
我的问题
为什么会这样?
以及如何解决?
I need to "annotate" some classes by adding a property to them. I need
to do that in order to let the view layer of my application extract
the correct classes.
这实际上就是 注释属性 ,例如 rdfs:label 的用途。您可以定义自己的注释属性,然后通过查询这些属性更直接地使用 SPARQL 检索 类。例如,这里有一个 ontology 和三个特殊的 类:
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:j.0="urn:ex:"
xmlns:owl="http://www.w3.org/2002/07/owl#">
<owl:Ontology rdf:about="http://www.semanticweb.org/taylorj/ontologies/2015/5/untitled-ontology-45"/>
<owl:Class rdf:about="urn:ex:C">
<j.0:isSpecialClass rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">true</j.0:isSpecialClass>
</owl:Class>
<owl:Class rdf:about="urn:ex:A">
<j.0:isSpecialClass rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">true</j.0:isSpecialClass>
</owl:Class>
<owl:Class rdf:about="urn:ex:B"/>
<owl:AnnotationProperty rdf:about="urn:ex:isSpecialClass"/>
</rdf:RDF>
我需要 "annotate" 给一些 class 添加一个 属性。我需要这样做才能让我的应用程序的视图层提取正确的 classes.
我所做的是:
创建一个名为 uiProperty 的对象 属性 并编辑这些 class 使其成为此 class 的子class :
uiProperty some
所以我的 classes 的最终 OWL 代码是这样的:
rdfs:subClassOf owebs:RealEstate ,
[ rdf:type owl:Restriction ;
owl:onProperty owebs:uiProperty ;
owl:someValuesFrom owl:Thing
] ;
现在我想构建一个 sparql 查询来获取这些 classes。我做了以下事情:
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owbes: <http://www.isep.org/desco/2015/>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
SELECT $uri $label WHERE {
$uri rdfs:subClassOf owbes:RealEstate.
$uri rdfs:subClassOf $x.
$x owl:onProperty owbes:uiProperty.
$uri rdfs:label $label
}
问题
该查询的结果太多 class。相同的 class 被重复多次。例如:
我的问题
为什么会这样? 以及如何解决?
I need to "annotate" some classes by adding a property to them. I need to do that in order to let the view layer of my application extract the correct classes.
这实际上就是 注释属性 ,例如 rdfs:label 的用途。您可以定义自己的注释属性,然后通过查询这些属性更直接地使用 SPARQL 检索 类。例如,这里有一个 ontology 和三个特殊的 类:
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:j.0="urn:ex:"
xmlns:owl="http://www.w3.org/2002/07/owl#">
<owl:Ontology rdf:about="http://www.semanticweb.org/taylorj/ontologies/2015/5/untitled-ontology-45"/>
<owl:Class rdf:about="urn:ex:C">
<j.0:isSpecialClass rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">true</j.0:isSpecialClass>
</owl:Class>
<owl:Class rdf:about="urn:ex:A">
<j.0:isSpecialClass rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">true</j.0:isSpecialClass>
</owl:Class>
<owl:Class rdf:about="urn:ex:B"/>
<owl:AnnotationProperty rdf:about="urn:ex:isSpecialClass"/>
</rdf:RDF>