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:

<?xml version="1.0"?>
<!DOCTYPE rdf:RDF [
    <!ENTITY terms "http://purl.org/dc/terms/" >
    <!ENTITY foaf "http://xmlns.com/foaf/0.1/" >
    <!ENTITY owl "http://www.w3.org/2002/07/owl#" >
    <!ENTITY obo "http://purl.obolibrary.org/obo/" >
    <!ENTITY patterns "http://www.co-ode.org/patterns#" >
    <!ENTITY dc "http://purl.org/dc/elements/1.1/" >
    <!ENTITY xsd "http://www.w3.org/2001/XMLSchema#" >
    <!ENTITY xml "http://www.w3.org/XML/1998/namespace" >
    <!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#" >
    <!ENTITY NCBITaxon "http://purl.obolibrary.org/obo/NCBITaxon#" >
    <!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
    <!ENTITY oboInOwl "http://www.geneontology.org/formats/oboInOwl#" >
]>

<rdf:RDF
     xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
     xmlns:terms="http://purl.org/dc/terms/"
     xmlns:owl="http://www.w3.org/2002/07/owl#"
     xmlns:oboInOwl="http://www.geneontology.org/formats/oboInOwl#"
     xmlns:xml="http://www.w3.org/XML/1998/namespace"
     xmlns:patterns="http://www.co-ode.org/patterns#"
     xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
     xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
     xmlns:NCBITaxon="&obo;NCBITaxon#"
     xmlns:obo="http://purl.obolibrary.org/obo/"
     xmlns:foaf="http://xmlns.com/foaf/0.1/"
     xmlns:dc="http://purl.org/dc/elements/1.1/">

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

 
Thanks again for any help!