Muhammad Akmal Nazir
Muhammad Akmal Nazir

Reputation: 51

Retrieve rdf labels in an OWL/RDF ontology using Owlready2

I'm working on a project in which i need to retrieve rdf:label values of human/mouse ontologies and run a matcher on those labels. However, I can't seem to find a built-in Owlready2 method that can return all labels from all classes in the ontology. I can get all class names using onto.classes() but that doesn't help me because i can't get labels from class names. Class names only have IRIs in the dataset in the format of human.NCIXXXXX.

I am using OAEI 2012 dataset which is in OWL/RDF format: http://oaei.ontologymatching.org/2012/anatomy/index.html (download link for dataset is under dataset heading)

Here's a snippet of the human owl ontology file:

<owl:Class rdf:about="http://human.owl#NCI_C33648">
    <rdfs:label rdf:datatype="http://www.w3.org/2001/XMLSchema#string">Subiculum</rdfs:label>
    <rdfs:subClassOf rdf:resource="http://human.owl#NCI_C13031"/>
    <rdfs:subClassOf>
        <owl:Restriction>
            <owl:onProperty rdf:resource="http://human.owl#UNDEFINED_part_of"/>
            <owl:someValuesFrom rdf:resource="http://human.owl#NCI_C12353"/>
        </owl:Restriction>
    </rdfs:subClassOf>
    <oboInOwl:hasRelatedSynonym rdf:resource="http://human.owl#genid6200"/>
</owl:Class>

onto.classes() return human.NCI_C13031. I want the LABEL value of "subiculum" in a Python list.

The owlready2 documentation says that one can retrieve an entity object based on a specified label by calling the onto.search(label = "XXXXXX") (X = labelname). However, I want the reverse of this. I need to retrive the labels. I can't seem to find a way to do this using owlready2. is there a way to do this with/without owlready2? I do know that there IS an OWL/RDF parser in owlready2 (wasn't there for owlready) and i can successfully read the file. I just need a certain label query to work.

Please consider that I need to do this in Python and I am also very much new to Python. I tried ontospy but it doesn't seem to have the ontology querying potential and is just for ontology documentation (correct me if I'm wrong).

Thanks!

EDIT: Solved it by myself. To get labels, you set the set render function to a custom defined function which takes an entity and returns its label. Its all in the owlready documentation: https://pythonhosted.org/Owlready2/annotations.html#custom-rendering-of-entities` `

Upvotes: 4

Views: 1767

Answers (1)

Nafis Tanveer Islam
Nafis Tanveer Islam

Reputation: 21

If you have an instance of a protege entity <class 'owlready2.entity.ThingClass'> you can use the following:entity.label to get the value of label.

Upvotes: 0

Related Questions