繁体   English   中英

如何使用 SPARQL 从本体中获取顶级类并过滤查询中的类限制?

[英]How to get the top level classes from an ontology with SPARQL and filter out classes restrictions in the query?

我知道Query SPARQL 结果级别 1 层次结构SPARQL Query 有一些答案 - 获取数据集的顶级类

但这对于我正在尝试做的事情来说还不够。 我有类别类别、owl:Thing 的子类和查询

SELECT DISTINCT ?cls 
WHERE {
  ?cls a owl:Class .
  FILTER NOT EXISTS { 
    ?cls rdfs:subClassOf ?sup .
    FILTER(?sup != owl:Thing) 
  } 
}

对于其他没有限制的类也可以正常工作,但它不会返回 Category 因为 Category 有限制,此查询将它们视为单独的类。 我的类别类如下所示:

: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 }
}

它有效,但这意味着 Category 必须是 owl:Thing 的明确子类,这在许多本体中并不总是如此。

我想到了。 以下是对像我这样遇到问题的任何人的查询:

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:Restriction 类类型的过滤器。 我还添加了一个过滤器以从查询结果中删除 owl:Thing。 通过这个查询,我可以从我的本体中获取 Category 类,它是顶层/级别 1 层次结构的一部分。

暂无
暂无

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

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