SPARQL query on restriction list

978 views Asked by At

I'm learning SPARQL and need some advices about a query.

Exemple of the ontology :

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

I'm trying to retrieve the URI present in owl:someValuesFrom depending of which URI present in owl:onProperty.

I tried this query :

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

following the advice of this post Sparql query on restriction list (Equivalent To) in protégé. But the 2 answers given in this post didn't work.

Have you got any ideas of what's wrong with my query ? Thank you for your help !

1

There are 1 answers

1
M. Le Gall On BEST ANSWER

For people which may have the same question, the answer of AKSW is really helpfull and worked !

So I use the Turtle format to represent my ontology :

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

With this format the way to query appear simplier. So if I want to retrieve the value of the property http://snomed.info/id/363698007 I need to use the following query :

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

This query will give you the following result :

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