首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用SPARQL从本体中获取顶级类并过滤出查询中的类限制?

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

Stack Overflow用户
提问于 2022-07-11 21:00:14
回答 1查看 44关注 0票数 0

我知道Query SPARQL resulting level 1 hierarchySPARQL Query - get top-level classes of a dataset有一些答案

但这对我想做的事还不够。我有类类别,owl:Thing的子类和查询

代码语言:javascript
复制
SELECT DISTINCT ?cls 
WHERE {
  ?cls a owl:Class .
  FILTER NOT EXISTS { 
    ?cls rdfs:subClassOf ?sup .
    FILTER(?sup != owl:Thing) 
  } 
}

对于没有限制的其他类,它可以很好地工作,但是它不返回类别,因为类别有限制,这个查询将它们看作是单独的类。我的类别类如下所示:

代码语言:javascript
复制
: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 .

如何修改查询以添加这些顶级类,这些类是某些限制的“子类”?我需要一个过滤器对这些限制,但我不知道如何进入这个。我试着做

代码语言:javascript
复制
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的明确子类,这在许多本体论中并不总是如此。

EN

Stack Overflow用户

发布于 2022-07-12 01:03:29

我想通了。以下是对像我这样有问题的人的查询:

代码语言:javascript
复制
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层次结构的一部分。

票数 0
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72944628

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档