2

我正在学习 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:someValuesFrom中存在的 URI ,具体取决于owl:onProperty中存在的 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 查询关于 protégé 中限制列表(等效于)的帖子的建议。但是这篇文章中给出的2个答案不起作用。

您对我的查询有什么问题有任何想法吗?感谢您的帮助 !

4

1 回答 1

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

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

?主题:http
://snomed.info/id/187903000 ?x:http ://snomed.info/id/13881006

于 2018-10-05T12:23:49.860 回答