限制列表上的SPARQL查询

时间:2018-10-05 09:58:54

标签: sparql restriction snomed-ct

我正在学习SPARQL,需要有关查询的一些建议。

本体示例:

<owl:Class rdf:about="http://snomed.info/id/187903000">
    <owl:equivalentClass>
        <owl:Class>
            <owl:intersectionOf rdf:parseType="Collection">
                <rdf:Description rdf:about="http://snomed.info/id/187900002"/>
                <owl:Restriction>
                    <owl:onProperty rdf:resource="http://snomed.info/id/609096000"/>
                    <owl:someValuesFrom>
                        <owl:Class>
                            <owl:intersectionOf rdf:parseType="Collection">
                                <owl:Restriction>
                                    <owl:onProperty rdf:resource="http://snomed.info/id/116676008"/>
                                    <owl:someValuesFrom rdf:resource="http://snomed.info/id/367651003"/>
                                </owl:Restriction>
                                <owl:Restriction>
                                    <owl:onProperty rdf:resource="http://snomed.info/id/363698007"/>
                                    <owl:someValuesFrom rdf:resource="http://snomed.info/id/13881006"/>
                                </owl:Restriction>
                            </owl:intersectionOf>
                        </owl:Class>
                    </owl:someValuesFrom>
                </owl:Restriction>
            </owl:intersectionOf>
        </owl:Class>
    </owl:equivalentClass>
    <rdfs:subClassOf rdf:resource="http://snomed.info/id/126546006"/>
    <rdfs:subClassOf rdf:resource="http://snomed.info/id/363501002"/>
    <rdfs:subClassOf rdf:resource="http://snomed.info/id/448558006"/>
    <field:Description.term.en-us.preferred xml:lang="en">Malignant neoplasm of malar bone</field:Description.term.en-us.preferred>
    <rdfs:label xml:lang="en">Malignant neoplasm of malar bone (disorder)</rdfs:label>
</owl:Class>

我试图根据 owl:onProperty 中存在的URI检索 owl:someValuesFrom 中存在的URI。

我尝试了此查询:

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT ?subject ?fsn ?rs WHERE {
  ?subject rdfs:label ?fsn ;
  <http://snomed.info/id/116676008> ?rs .
}

遵循本文Sparql query on restriction list (Equivalent To) in protégé的建议。但是这篇文章给出的两个答案没有用。

您是否对我的查询有任何疑问? 谢谢您的帮助!

1 个答案:

答案 0 :(得分:1)

对于可能有相同问题的人,AKSW的答案确实很有帮助并且有效!

所以我使用Turtle格式表示本体:

@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix ns0: <http://snomed.info/field/Description.term.en-us.> .

<http://snomed.info/id/187903000>
  a owl:Class ;
  owl:equivalentClass [
    a owl:Class ;
    owl:intersectionOf (
      <http://snomed.info/id/187900002>
      _:genid3
    )
  ] ;
  rdfs:subClassOf <http://snomed.info/id/126546006>, <http://snomed.info/id/363501002>, <http://snomed.info/id/448558006> ;
  ns0:preferred "Malignant neoplasm of malar bone"@en ;
  rdfs:label "Malignant neoplasm of malar bone (disorder)"@en .

_:genid3
  a owl:Restriction ;
  owl:onProperty <http://snomed.info/id/609096000> ;
  owl:someValuesFrom [
    a owl:Class ;
    owl:intersectionOf (
      _:genid6
      _:genid8
    )
  ] .

_:genid6
  a owl:Restriction ;
  owl:onProperty <http://snomed.info/id/116676008> ;
  owl:someValuesFrom <http://snomed.info/id/367651003> .

_:genid8
  a owl:Restriction ;
  owl:onProperty <http://snomed.info/id/363698007> ;
  owl:someValuesFrom <http://snomed.info/id/13881006> .

使用这种格式,查询方式显得更简单。因此,如果我想检索属性 http://snomed.info/id/363698007 的值,则需要使用以下查询:

PREFIX  rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

SELECT ?subject ?x WHERE {
  ?subject owl:equivalentClass/(owl:intersectionOf/rdf:rest+/rdf:first)*/owl:someValuesFrom/(owl:intersectionOf/rdf:rest*/rdf:first)* ?rs .
  ?rs owl:onProperty <http://snomed.info/id/363698007> ;
      owl:someValuesFrom ?x .
}

此查询将为您提供以下结果:

  

?subject:http://snomed.info/id/187903000
  ?x:http://snomed.info/id/13881006