簡體   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