retrieving Class restrictions from ontology

9 views
Skip to first unread message

Boris Metodiev

unread,
Dec 4, 2017, 11:31:50 AM12/4/17
to rdflib-dev
I'm trying to perform an ontology matching task using two anatomy ontologies in rdf format (using rdflib). All of the organs in the ontology have their own classes, and they are grouped with superclasses such as "reproductive system part", for example. What I want is to run a query that retrieves all of the nodes connected to a certain class, both inbound and outbound connections. I tried the following: 

querytrial1=graph.query("""SELECT ?node ?nodeLabel ?othernodes ?othernodesLabel where { 
    bind (<http://human.owl#NCI_C12308> as ?node )
    ?node ?y ?othernodes .
    ?node rdfs:label ?nodeLabel .
    ?othernodes rdfs:label ?othernodesLabel 
LIMIT 100""")

and then this for the inbound connections: 

querytrial2=graph.query("""SELECT ?node ?nodeLabel ?othernode2 ?othernodeLabel2 where { 
    bind (<http://human.owl#NCI_C12308> as ?node )
    ?othernodes2 ?z ?node .
    ?node rdfs:label ?nodeLabel .
    ?othernodes2 rdfs:label ?othernodes2Label
LIMIT 100""") 

The first one only returns some of the desired connections. It doesn't return the node listed in the class restriction: 

<owl:Class rdf:about="http://human.owl#NCI_C12308"><rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Clitoris</rdfs:label><rdfs:subClassOf rdf:resource="http://human.owl#NCI_C13039"/><rdfs:subClassOf><owl:Restriction><owl:onProperty rdf:resource="http://human.owl#UNDEFINED_part_of"/><owl:someValuesFrom rdf:resource="http://human.owl#NCI_C12408"/></owl:Restriction></rdfs:subClassOf><oboInOwl:hasRelatedSynonym rdf:resource="http://human.owl#genid2595"/></owl:Class>

It returns the subClassOf, but not the property restriction and the someValuesFrom: class. 

Is there a way to run a query and get the node cited in the property restriction? 

Any advice would be much appreciated. I've attached the ontology in case anyone would like to look at it. 


human.owl

Jörn Hees

unread,
Dec 5, 2017, 2:31:09 AM12/5/17
to rdfli...@googlegroups.com

> On 4 Dec 2017, at 17:31, Boris Metodiev <boris...@gmail.com> wrote:
>
> <owl:Class rdf:about="http://human.owl#NCI_C12308"><rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Clitoris</rdfs:label><rdfs:subClassOf rdf:resource="http://human.owl#NCI_C13039"/><rdfs:subClassOf><owl:Restriction><owl:onProperty rdf:resource="http://human.owl#UNDEFINED_part_of"/><owl:someValuesFrom rdf:resource="http://human.owl#NCI_C12408"/></owl:Restriction></rdfs:subClassOf><oboInOwl:hasRelatedSynonym rdf:resource="http://human.owl#genid2595"/></owl:Class>

As very often with RDF+XML it helps to just rewrite as N-Triples:

<http://human.owl#NCI_C12308> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Class> .
<http://human.owl#NCI_C12308> <http://www.w3.org/2000/01/rdf-schema#label> "Clitoris" .
<http://human.owl#NCI_C12308> <http://www.w3.org/2000/01/rdf-schema#subClassOf> <http://human.owl#NCI_C13039> .
<http://human.owl#NCI_C12308> <http://www.w3.org/2000/01/rdf-schema#subClassOf> _:b1 .
<http://human.owl#NCI_C12308> <http://ex.com/hasRelatedSynonym> <http://human.owl#genid2595> .
_:b1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Restriction> .
_:b1 <http://www.w3.org/2002/07/owl#onProperty> <http://human.owl#UNDEFINED_part_of> .
_:b1 <http://www.w3.org/2002/07/owl#someValuesFrom> <http://human.owl#NCI_C12408> .

The restriction doesn't have an rdfs:label as you're querying for!

The following will also return the BNode...

querytrial1=graph.query("""SELECT ?node ?nodeLabel ?othernodes ?othernodesLabel where {
bind (<http://human.owl#NCI_C12308> as ?node )
?node ?y ?othernodes .
?node rdfs:label ?nodeLabel .
OPTIONAL { ?othernodes rdfs:label ?othernodesLabel }
}
LIMIT 100""")

Best,
Jörn

Boris Metodiev

unread,
Dec 12, 2017, 12:56:43 PM12/12/17
to rdflib-dev
Thanks for clearing that up !
Reply all
Reply to author
Forward
0 new messages