Re: Extracting properties with different namespaces
Posted by June27 on URL: http://owlready.306.s1.nabble.com/Extracting-properties-with-different-namespaces-tp963p972.html
Hi,
Thanks very much for your reply. My ontology doesn't import any other ontologies, and I've actually been using a really subset subset of my overall ontology, to try and isolate the problem. Here's the test ontology I've been working with:
<owl:Class rdf:about="&obo;CHEBI_28260"> <rdfs:subClassOf rdf:resource="&obo;CHEBI_33917"/> <rdfs:subClassOf rdf:resource="&obo;FOODON_03420108"/> <obo:IAO_0000115 rdf:datatype="&xsd;string">An aldohexose that is the C-4 epimer of glucose.</obo:IAO_0000115> <obo:IAO_0000118>galactose</obo:IAO_0000118> <obo:IAO_0000412 rdf:resource="&obo;chebi.owl"/> <obo:IAO_0000412>http://langual.org</obo:IAO_0000412> <oboInOwl:hasDbXref>http://www.langual.org/langual_thesaurus.asp?termid=C0254</oboInOwl:hasDbXref> <oboInOwl:hasRelatedSynonym>galactose, d-</oboInOwl:hasRelatedSynonym> <rdfs:label rdf:datatype="&xsd;string">galactose</rdfs:label> </owl:Class>
<owl:Class rdf:about="&obo;CHEBI_28757"> <rdfs:subClassOf rdf:resource="&obo;CHEBI_24973"/> <rdfs:subClassOf rdf:resource="&obo;FOODON_03420108"/> <obo:IAO_0000115 rdf:datatype="&xsd;string">A ketohexose that is an isomer of glucose.</obo:IAO_0000115> <obo:IAO_0000118>fructose</obo:IAO_0000118> <obo:IAO_0000412 rdf:resource="&obo;chebi.owl"/> <obo:IAO_0000412>http://langual.org</obo:IAO_0000412> <oboInOwl:hasDbXref>http://www.langual.org/langual_thesaurus.asp?termid=C0223</oboInOwl:hasDbXref> <oboInOwl:hasRelatedSynonym>levulose</oboInOwl:hasRelatedSynonym> <rdfs:comment>LanguaL curation note: Used when pure fructose is the major ingredient. If *HIGH FRUCTOSE SYRUP* is the major ingredient, use that term for indexing.</rdfs:comment> <rdfs:label rdf:datatype="&xsd;string">fructose</rdfs:label> </owl:Class>
</rdf:RDF>
So from the above, I'm just trying to iterate through all classes and extract "label" and "hasRelatedSynonym" using the code:
allLabels=[]
for i in onto.classes():
label1 = i.label[0]
synonyms1 ='; '.join(i.hasRelatedSynonym)
attributes = '; '.join(filter(None, [label1, synonyms1]))
allLabels.append(attributes)