我知道Query SPARQL resulting level 1 hierarchy和SPARQL Query - get top-level classes of a dataset有一些答案
但这对我想做的事还不够。我有类类别,owl:Thing的子类和查询
SELECT DISTINCT ?cls
WHERE {
?cls a owl:Class .
FILTER NOT EXISTS {
?cls rdfs:subClassOf ?sup .
FILTER(?sup != owl:Thing)
}
}对于没有限制的其他类,它可以很好地工作,但是它不返回类别,因为类别有限制,这个查询将它们看作是单独的类。我的类别类如下所示:
:Category rdf:type owl:Class ;
rdfs:subClassOf owl:Thing ,
[ rdf:type owl:Restriction ;
owl:onProperty :hasConfidence ;
owl:minCardinality "0"^^xsd:nonNegativeInteger
] ,
[ rdf:type owl:Restriction ;
owl:onProperty :hasIntensity ;
owl:minCardinality "0"^^xsd:nonNegativeInteger
] ,
[ rdf:type owl:Restriction ;
owl:onProperty :hasConfidence ;
owl:maxCardinality "1"^^xsd:nonNegativeInteger
] ,
[ rdf:type owl:Restriction ;
owl:onProperty :hasIntensity ;
owl:maxCardinality "1"^^xsd:nonNegativeInteger
] ;
rdfs:comment """Category refers to the classification used to annotate the emotion.
This can be further expanded to add support to new categories."""@en ;
rdfs:label "Category"@en .如何修改查询以添加这些顶级类,这些类是某些限制的“子类”?我需要一个过滤器对这些限制,但我不知道如何进入这个。我试着做
SELECT DISTINCT ?cls
WHERE
{
{
?cls a owl:Class .
FILTER NOT EXISTS {
?cls rdfs:subClassOf ?sup .
FILTER(?sup != owl:Thing)
}
}
UNION
{ ?cls rdfs:subClassOf owl:Thing }
}它起作用了,但这意味着分类必须是owl:Thing的明确子类,这在许多本体论中并不总是如此。
发布于 2022-07-12 01:03:29
我想通了。以下是对像我这样有问题的人的查询:
SELECT DISTINCT ?cls
WHERE
{
?cls a owl:Class .
FILTER NOT EXISTS {
?cls rdfs:subClassOf ?sup .
FILTER(?sup != owl:Thing) .
FILTER NOT EXISTS {
?sup a owl:Restriction .
}
}
FILTER(?cls != owl:Thing) # We get rid of the root class from the query results
}基本上,我所需要的只是一个用于owl:限制类类型的过滤器。我还添加了一个过滤器来去除查询结果中的owl:Thing。通过这个查询,我能够从本体中获得类别类,它是顶层/级别1层次结构的一部分。
https://stackoverflow.com/questions/72944628
复制相似问题