How to return all Properties for a Class

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

How to return all Properties for a Class

fengbozheng
Hi Jiba,

I'm trying to use Owlready to process the OWL file of a biomedical ontology NCI thesaurus. Is there a way for me to get all properties (i.e., all relations with other concepts) for a given class? I found an example for SNOMED CT by using PyMedTermino, in which given a concept, the “get_class_properties” method returns the set of relations available for a given concept. Is there a way so that I could do the same thing for NCI thesaurus?

Thanks,
Fengbo
Reply | Threaded
Open this post in threaded view
|

Re: How to return all Properties for a Class

Jiba
Administrator
Hi,

get_class_properties() is available for all classes; it is not limited to SNOMED CT so you should be able to use it with NCI thesaurus, or any other ontologies.

Jiba
Reply | Threaded
Open this post in threaded view
|

Re: How to return all Properties for a Class

fengbozheng
Thanks for your reply.
I have a further question. Suppose we have a class A and it has many properties and their corresponding values. Is it possible for me to retrieve all the properties and their corresponding values automatically and systematically? (I know I could use class.method() to retrieve the value one by one. )
However, my concern is that when I use method get_class_properties(), the result I got (stored in a list) are objects (or classes?, but not method). Then I do not know how to call the relevant method (for object's in the list) directly in the code. Could you help me with this?

Thanks,
Fengbo
Reply | Threaded
Open this post in threaded view
|

Re: How to return all Properties for a Class

Jiba
Administrator
Hi,

You can use prop[Class] or getattr(Class, prop.python_name), where prop is one of the objects in the list returned by get_class_properties().

Jiba
Reply | Threaded
Open this post in threaded view
|

Re: How to return all Properties for a Class

fengbozheng
Thanks, it worked.
I'm currently trying to use owlready to process the OWL file for NCIt. And I found that for those defined (not primitive) classes, the IS-A relations are not complete. An example is for class C21212. I found that in the OWL file, this class should be a subclass of another concept C20184, however, I couldn't get it by either querying list(C20184.is_a) or querying its properties and their value. Could you help me with this?
 
Here is the part of code in OWL file related to this class. The potential part corresponding to the IS-A relation is bolded.



    <owl:Class rdf:about="http://ncicb.nci.nih.gov/xml/owl/EVS/Thesaurus.owl#C21212">
        <owl:equivalentClass>
            <owl:Class>
                <owl:intersectionOf rdf:parseType="Collection">
                    <rdf:Description rdf:about="http://ncicb.nci.nih.gov/xml/owl/EVS/Thesaurus.owl#C20184"/>
                    <owl:Restriction>
                        <owl:onProperty rdf:resource="http://ncicb.nci.nih.gov/xml/owl/EVS/Thesaurus.owl#R52"/>
                        <owl:someValuesFrom rdf:resource="http://ncicb.nci.nih.gov/xml/owl/EVS/Thesaurus.owl#C17101"/>
                    </owl:Restriction>
                    <owl:Restriction>
                        <owl:onProperty rdf:resource="http://ncicb.nci.nih.gov/xml/owl/EVS/Thesaurus.owl#R53"/>
                        <owl:someValuesFrom rdf:resource="http://ncicb.nci.nih.gov/xml/owl/EVS/Thesaurus.owl#C16514"/>
                    </owl:Restriction>
                    <owl:Restriction>
                        <owl:onProperty rdf:resource="http://ncicb.nci.nih.gov/xml/owl/EVS/Thesaurus.owl#R53"/>
                        <owl:someValuesFrom rdf:resource="http://ncicb.nci.nih.gov/xml/owl/EVS/Thesaurus.owl#C18081"/>
                    </owl:Restriction>
                    <owl:Restriction>
                        <owl:onProperty rdf:resource="http://ncicb.nci.nih.gov/xml/owl/EVS/Thesaurus.owl#R53"/>
                        <owl:someValuesFrom rdf:resource="http://ncicb.nci.nih.gov/xml/owl/EVS/Thesaurus.owl#C18125"/>
                    </owl:Restriction>
                    <owl:Restriction>
                        <owl:onProperty rdf:resource="http://ncicb.nci.nih.gov/xml/owl/EVS/Thesaurus.owl#R54"/>
                        <owl:someValuesFrom rdf:resource="http://ncicb.nci.nih.gov/xml/owl/EVS/Thesaurus.owl#C20847"/>
                    </owl:Restriction>
                </owl:intersectionOf>
            </owl:Class>
        </owl:equivalentClass>
        <rdfs:subClassOf>
            <owl:Restriction>
                <owl:onProperty rdf:resource="http://ncicb.nci.nih.gov/xml/owl/EVS/Thesaurus.owl#R51"/>
                <owl:someValuesFrom rdf:resource="http://ncicb.nci.nih.gov/xml/owl/EVS/Thesaurus.owl#C21176"/>
            </owl:Restriction>
        </rdfs:subClassOf>
        <NHC0>C21212</NHC0>
        <P106>Amino Acid, Peptide, or Protein</P106>
        <P108>Ribonucleotide Reductase Subunit</P108>
        <P207>C1335783</P207>
        <P366>Ribonucleotide_Reductase_Subunit</P366>
        <P90>Ribonucleotide Reductase Subunit</P90>
        <P97>Encoded by Ribonucleotide Reductase Subunit Genes (RRM1 and RRM2), the M1 Chain and M2 Chain subunits compose Ribonucleoside-Diphosphate Reductase, a heterodimeric cytoplasmic enzyme essential in dividing cells that reduces ribonucleotides to deoxyribonucleotide precursors for DNA synthesis in S phase. Enzyme activity closely correlates with the cellular rate of growth and appears to vary with the cell cycle. A substrate site and catalytic site regulate enzyme activity. Allosteric control by deoxynucleoside triphosphates and by ATP bound to M1 prevents DNA replication and cell proliferation. An M1 catalytic site only forms in the presence of M2. M2 synthesis is cell-cycle dependent. p53 regulates ribonucleotide reductase by interaction with p53R2 as well as the M2 subunit. (NCI)</P97>
        <rdfs:label>Ribonucleotide Reductase Subunit</rdfs:label>
    </owl:Class>

 

Thanks,
Fengbo
Reply | Threaded
Open this post in threaded view
|

Re: How to return all Properties for a Class

fengbozheng
This post was updated on .
I found that for those defined classes, I could use method .equivalent_to to get all the definition (I'm not sure if this is the correct solution to my previous question).

And the returned object type is <owlready2.class_construct.And> 
(e.g. [ThesaurusInferred.C20184 & ThesaurusInferred.R52.some(ThesaurusInferred.C17101) & ThesaurusInferred.R53.some(ThesaurusInferred.C16514) & ThesaurusInferred.R53.some(ThesaurusInferred.C18081) & ThesaurusInferred.R53.some(ThesaurusInferred.C18125) & ThesaurusInferred.R54.some(ThesaurusInferred.C20847)])

Is there a way for me to handle this object and get the restrictions (or relations) separately so that I could interpret them? (handle the <owlready2.class_construct.And> object as well as the restrictions (Property.some(Range_Class)) ) It will be the best if I could get them separately as object so that I could directly get the label. For example, in this case, I want to get:
ThesaurusInferred.C20184;
ThesaurusInferred.R52, ThesaurusInferred.C17101; (Property, RangeClass)
ThesaurusInferred.R53, ThesaurusInferred.C16514;
...
If I could get them as object of type <owlready2.entity.ThingClass>, then I could further call method .label to get its label easily.

I know I could convert the <owlready2.class_construct.And> to string and split them by " & ", however, in that case, I don't know how to convert splited string back to <owlready2.entity.ThingClass> in order to call method .label.

Could you help me with this?


Thanks,
Fengbo
Reply | Threaded
Open this post in threaded view
|

Re: How to return all Properties for a Class

Jiba
Administrator
Hi,

Yes, for defined classes, the definition is not in is_a but in equivalent_to (similarly to Protégé).

The object you get here is a "And". You can use its .Classes attributes to get the list of operands. Each operand is either a class, e.g. ThesaurusInferred.C20184, or another construct, e.g. a SOME restriction. Restrictions also have attributes, such as type (using constants such as SOME), property, value and cardinality.

Jiba
Reply | Threaded
Open this post in threaded view
|

Re: How to return all Properties for a Class

fengbozheng
Hi Jiba,

I'm really appreciated for your patient tutoring. I think it should work now.

Thanks,
Fengbo