1 year ago

#235629

test-img

Robert Alexander

Using RDFLIB to fetch elements for every class

I have an OWL RDF data file that contains several data such as the following example:

<!-- http://purl.obolibrary.org/obo/OGMS_0000014 -->

    <owl:Class rdf:about="http://purl.obolibrary.org/obo/OGMS_0000014">
        <rdfs:subClassOf rdf:resource="http://purl.obolibrary.org/obo/OGMS_0000123"/>
        <obo:IAO_0000115 xml:lang="en">A representation that is either the output of a clinical history taking or a physical examination or an image finding, or some combination thereof.</obo:IAO_0000115>
        <obo:IAO_0000117>Albert Goldfain</obo:IAO_0000117>
        <obo:IAO_0000119>http://ontology.buffalo.edu/medo/Disease_and_Diagnosis.pdf</obo:IAO_0000119>
        <obo:IAO_0000232>creation date: 2010-07-19T10:18:02Z</obo:IAO_0000232>
        <rdfs:label>clinical finding</rdfs:label>
    </owl:Class>

and need to extract only the strings following the rdfs:label and the <obo:IAO_0000115 xml:lang="en"> tags for each class.

I am successfully reading the RDF file as follows:

from rdflib import Graph, URIRef
g = Graph()
g.parse("ogms_20210819.owl")

and then loop through it as usual:

# Loop through each triple in the graph (subj, pred, obj)
for subj, pred, obj in g:
    print(subj, pred, obj)

but I'm not understanding how to fetch only the text from the two tags I need for each class.

Thanks a lot for any help.

python

rdf

owl

rdflib

0 Answers

Your Answer

Accepted video resources