© Lamy Jean-Baptiste 2021
L. Jean-BaptisteOntologies with Pythonhttps://doi.org/10.1007/978-1-4842-6552-9_10

10. Mixing Python and OWL

Lamy Jean-Baptiste1  
(1)
Université Sorbonne Paris Nord, LIMICS, Sorbonne Université INSERM, UMR 1142, Bobigny, France
 

In this chapter, we will see how to mix Python methods and OWL logical constructors within the same class.

10.1 Adding Python methods to OWL classes

With Owlready, OWL classes are Python classes (almost) like the others. It is therefore possible to include Python methods in these classes. Here is a simple example to calculate the price per tablet of a drug from its unit price (per box) and the number of tablets in the box:
>>> from owlready2 import *
>>> onto = get_ontology("http://test.org/drug.owl#") ...

Get Ontologies with Python: Programming OWL 2.0 Ontologies with Python and Owlready2 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.