Extending ThingClass

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

Extending ThingClass

jesper-friis
Hi,
I have an upper ontology that uses parthood as one of its basic concepts. To work with that, and all ontologies that are based on it in a natural way using owlready2, I would like to add some extra methods to ThingClass. Can I do that without modifying the code base of owlready2, by monkey patching or some other techniques?


Regards
/Jesper
Reply | Threaded
Open this post in threaded view
|

Re: Extending ThingClass

Jiba
Administrator
Hi,

Modifying ThingClass is probably not the easiest way to solve your problem.

Maybe you could just add classmethod in your Part classes?

The example below (quoted from the Artificial Intelligence in Medicine paper describing Owlready) adds a subparts() method to the Cellular_component class in Gene Ontology. Similar methods may be added for superparts, etc


with obo:
      class GO_0005575(Thing): # Redefines Cellular_component class
            @classmethod
            def subparts(self):
                  results = []
                  for construct in self.constructs():
                        if isinstance(construct, Restriction) and (construct.property is obo.BFO_0000050):
                              results.extend(construct.subclasses())
                  return results

(see full example on page 12 of :
http://www.lesfleursdunormal.fr/_downloads/article_owlready_aim_2017.pdf )

Best regards,
Jiba