../../_images/ontologies_with_python.png
Jean-Baptiste Lamy
Apress Editions, 350 pages

../../_images/python_et_les_ontologies.jpeg
Jean-Baptiste Lamy
ENI Éditions, 310 pages

Owlready2 is a module for ontology-oriented programming in Python 3.

documentation download stats

Owlready2 can:

  • Import OWL 2.0 ontologies in NTriples, RDF/XML or OWL/XML format.

  • Export OWL 2.0 ontologies to NTriples or RDF/XML.

  • Manipulates ontology classes, instances and properties transparently, as if they were normal Python objects.

  • Add Python methods to ontology classes.

  • Perform automatic classification of classes and instances, using the HermiT or Pellet reasoner (included)

  • Load DBpedia or UMLS (for medical terminology, using the integrated PyMedTermino2 submodule)

  • Tested up to 1 billion of RDF triples (but can potentially support more).

  • In addition, the quadstore is compatible with the RDFlib Pyton module, which can be used to perform SPARQL queries.

  • Finally, Owlready2 can also be used as an ORM (Object-Relational mapper) -- as a graph/object database, it beats Neo4J, MongoDB, SQLObject and SQLAlchemy in terms of performances (see Benchmark)

Owlready2 has been created by Jean-Baptiste Lamy (my email is on the left) at the LIMICS reseach lab, INSERM UMRS 1142, Université Sorbonne Paris Nord, Sorbonne Université. It is available under the GNU LGPL licence v3.

If you use Owlready2, please cite the following article:

Lamy JB. Owlready: Ontology-oriented programming in Python with automatic classification and high level constructs for biomedical ontologies. Artificial Intelligence In Medicine 2017;80:11-28

Owlready2 0.45 has been released!

Owlready is a Python module for ontology-oriented programming. It can load OWL 2.0 ontologies and manipulate them transparently in Python.

Here are the changes:

  • The PREDEFINED_ONTOLOGIES global dictionary can now be used to map ontology IRI to arbitrary local pathes or URL.

  • The new FTSSqlite3Phrase() string type can be used to perform FTS search using Sqlite3 special syntax, e.g. default_world.search(label = FTSSqlite3Phrase("Electrocardiographic OR ECG"))

  • Add support for RDF plain literals, via the plainliteral Python datatype.

  • Bugfixes: * Fix set_name() on property when python_name is the same as name * Fix some special characters (e.g. :) and keyword (e.g. OR) in FTS search * Fix literal with no datatype (should be considered as string, see https://www.w3.org/TR/rdf11-concepts/#section-Graph-Literal * Fix wrong inheritance of TransitiveProperty, ReflexiveProperty and SymmetricProperty * Fix 'DeprecationWarning: invalid escape sequence' in regexp * Raise an error when creating a new ontology inside a with ontology:... block * Use rdf:langString for locstr (was rdf:plainLiteral)

The new version be downloaded from PyPI (Python Package Index): https://pypi.python.org/pypi/Owlready2

Owlready2 0.44 has been released!

Owlready is a Python module for ontology-oriented programming. It can load OWL 2.0 ontologies and manipulate them transparently in Python.

This version includes an observation framework allowing to register a listener to any entity, in order to be notified when the entity relations are modified.

It also introduces a new syntax for annotating relations: AnnotatedRelation(s,p,o).comment = ["abc"] (NB the old syntax remains supported).

Here are the changes:

  • New syntax for annotations on relation, e.g. AnnotatedRelation(s,p,o).comment = "abc" (the old syntax remains supported)

  • Optimize annotations on relations

  • Support GRAPH clauses in SPARQL INSERT queries

  • Observation framework (see owlready2.observe and doc on the observation framework)

  • Bugfixes: - Fix the update of equivalent_to after destroying a class - Fix the update of annotations on class when modified with SPARQL queries - Fix SPARQL GRAPH clause in SELECT queries when querying the graph as a variable and all triples are not inside the GRAPH clause - Fix LANGMATCHES SPARQL function - Prevent multiprocessing loading of large ontologies when fork is not available (i.e. on Mac) - Fix subproperties parent classes when destroying a property - Fix loading of TransitiveProperty, SymmetricProperty, AsymmetricProperty, ReflexiveProperty, IrreflexiveProperty

The new version be downloaded from PyPI (Python Package Index): https://pypi.python.org/pypi/Owlready2

Owlready2 0.43 has been released!

Owlready is a Python module for ontology-oriented programming. It can load OWL 2.0 ontologies and manipulate them transparently in Python.

This version includes a backward incompatible change: literal with different languages are now considered as different. For instance:

  • locstr("Test", "en") != "Test"

  • locstr("Test", "en") != locstr("Test", "fr")

This was not the case in previous releases, and it caused some weird bugs and confusion between literals.

I also would like to introduce a new projet: FullPy is Python module for designing web applications entirely in Python. It uses Owlready for data semantics and persistance. More information on FullPy can be found here:

Finally, due to a last minute bug, there is no 0.42 version.

Here are the changes:

  • INCOMPATIBLE CHANGE: Consider literal with different language as different

  • Support GRAPH clauses in SPARQL queries

  • World now supports custom lock (e.g. World(lock = ...))

  • Bugfixes: - Fix World(enable_thread_parallelism = True) (was named enable_gevent) - Fix blank nodes in rdflib_store - Fix FILTER in SPARQL when the filter was just after a recursive query - Fix recursive query in SPARQL involving variables in their right part - Fix SPARQL query with annotations containing entities - Fix property creation when using a Union in the '>>' syntax (e.g. class Prop((MyClass | MyOtherClass) >> str): pass) - Fix UMLS extraction in PyMedTermino2 - Fix Class IRI with brackets (or other special characters) when writing RDF/XML file

The new version be downloaded from PyPI (Python Package Index): https://pypi.python.org/pypi/Owlready2

Owlready2 0.41 has been released!

Owlready is a Python module for ontology-oriented programming. It can load OWL 2.0 ontologies and manipulate them transparently in Python.

This version introduces some works on thread-based parallelization. The parsing of huge OWL file is now faster (about 25% faster on GO), and Owlready can execute SPARQL queries in parallel. Please refer to the doc for more info (https://owlready2.readthedocs.io/en/latest/sync.html).

Here are the changes:

  • Parallelized huge OWL file parsing (about 25% faster on GO)

  • Parallelized SPARQL queries (see owlready2.sparql.execute_many() and execute(spawn = True))

  • Bugfixes: - Fix Class.INDIRECT_get_class_properties() with restriction on Inverse(Prop) - Fix Restriction of type HasSelf - Fix delattr in destroy_entity() - Fix blank nodes importation from RDFlib - Fix ', + and - in FTS search

The new version be downloaded from PyPI (Python Package Index): https://pypi.python.org/pypi/Owlready2

Owlready2 0.40 has been released!

Owlready is a Python module for ontology-oriented programming. It can load OWL 2.0 ontologies and manipulate them transparently in Python.

Here are the changes:

  • General class axiom support

  • Update Log4J in Pellet for security purpose

  • Add get_lang_first() for annotations.

  • Bugfixes: - Add trailing / to ontology URL if missing - Fix Individual.is_a when loading ontologies with individuals belonging to two classes, one being the descendant of the other - Fix datetime to make them XSD-compatible (thanks Lukas Müller) - Ensure that Things are properly initialized so that the __init__ method can be safely overwritten (thanks Lukas Müller) - Fix destroy_entity()

The new version be downloaded from PyPI (Python Package Index): https://pypi.python.org/pypi/Owlready2

Owlready2 0.39 has been released!

Owlready is a Python module for ontology-oriented programming. It can load OWL 2.0 ontologies and manipulate them transparently in Python.

Here are the changes:

  • Make RDF triple deletion non-ontology-specific

  • Faster creation of individual with property value (e.g. MyClass(prop = [value]))

  • Bugfixes: - Fix entity.prop.remove(x) and entity.prop = x when existing values are defined in another ontology than the entity - Fix inverse property update when referenced entity is destroyed (thanks Franzlst) - Prevent reasoners from reparenting OWL base entities such as Thing - Fix the reloading of an ontology that has been destroyed, when a local filename is provided as the ontology base IRI - Fix destroying object property involved in a property chain - Fix reloading of ontologies when the IRI of the ontology was a local filename - Fix SELECT * in SPARQL coumpound queries - Fix Class.get_class_properties() when some properties are defined as restriction on an Inverse property - Fix for RDFlib 0.6.2 (supports bind() override optional argument)

The new version be downloaded from PyPI (Python Package Index): https://pypi.python.org/pypi/Owlready2

Owlready2 0.38 has been released!

Owlready is a Python module for ontology-oriented programming. It can load OWL 2.0 ontologies and manipulate them transparently in Python.

Here are the changes:

  • Accepts localized language codes, such as fr_FR or fr_BE, and wildcard fr_any

  • Add 'update_is_a' optional args to Ontology.destroy()

  • Bugfixes: - Fix individual.INVERSE_prop update when prop is functional - Fix performance regression on complex SPARQL queries with OPTIONAL - Fix declare_datatype after a World has been closed - Fix Pellet reasoning on blank nodes (ignoring them) - Fix Pellet reasoning on strings data property that include comma "," - Fix boolean constant 'true' and 'false' in SPARQL engine - Fix INSERT SPARQL queries with UNION that insert RDF triples without variables - Fix SPARQL queries with only a FILTER NOT EXISTS in the WHERE part - Accept empty lines at the beginning of NTriple files - Support non-ASCII characters when parsing SWRL rules

The new version be downloaded from PyPI (Python Package Index): https://pypi.python.org/pypi/Owlready2

Owlready2 0.37 has been released!

Owlready is a Python module for ontology-oriented programming. It can load OWL 2.0 ontologies and manipulate them transparently in Python.

Here are the changes:

  • Add World.forget_reference(entity)

  • Add NamedIndividual (for SPARQL results on rdf:type)

  • Add 'update_relation' optional args to Ontology.destroy()

  • Add Ontology.set_base_iri() and Ontology.base_iri = "new_base_iri"

  • Bugfixes: - Fix SPARQL queries having a UNION but using no variable from the UNION - Fix SPARQL queries on read only quadstores - Fix SPARQL queries mixing OPTIONAL and VALUES / STATIC - Fix property defined as a subproperty of TransitiveProperty (and the like), but not of type ObjectProperty - Fix importlib.reload(owlready2) - Fix RDF/XML serialization of individuals whose class name start by a digit - Fix RDF/XML serialization when ontology base IRI ends with / - Fix Or.Classes = ... and And.Classes = ... - Fix ONLY class properties with more than two values

The new version be downloaded from PyPI (Python Package Index): https://pypi.python.org/pypi/Owlready2

Owlready2 0.36 has been released!

Owlready is a Python module for ontology-oriented programming. It can load OWL 2.0 ontologies and manipulate them transparently in Python.

Here are the changes:

  • Support xsd:duration, including DATETIME_DIFF(), DATETIME_ADD(), DATETIME_SUB() SPARQL non-standard functions

  • Faster ontology operation (e.g. ontology deletion) on big quadstores

  • Automatically add .owl, .rdf or .xml to ontology IRI if the IRI itself does not yield an OWL file

  • Bugfixes: - Fix FusionClasses (= individuals belonging to several classes, i.e. multiple instanciation) when using several worlds - Fix OPTIONAL SPARQL clause when guessing variable types - Fix typo in undo entity destruction (thanks Lukas Westhofen) - Fix IRI from OWL namespace in SWRL rules - Fix Pellet explanation on inconsistent ontology - Fix MEDDRA parent-child relation of LLT in PyMedTermino2 - Make sure the filename is a file before returning (Thanks Nicolas Rouquette)

The new version be downloaded from PyPI (Python Package Index): https://pypi.python.org/pypi/Owlready2

Owlready2 0.35 has been released!

Owlready is a Python module for ontology-oriented programming. It can load OWL 2.0 ontologies and manipulate them transparently in Python.

Here are the changes:

  • SPARQL optimizations

  • Support for VALUES in SPARQL

  • Add STATIC optimization keyword extension to SPARQL

  • Accept GROUP BY, HAVING, LIMIT in INSERT and DELETE SPARQL query

  • Add the STORID(iri), DATE(), TIME() and DATETIME() SPARQL function

  • UMLS CUI are now hierarchized by Semnatic Types (TUI)

  • Improved parallelism

  • Bugfixes: - Fix 'sqlite3.OperationalError: circular reference: prelim1_objs' in .instances(), caused by a bug in old versions of SQLite3 - Fix SPARQL INSERT query with data parameters in the INSERT clause - Fix RDF list parsing when the list includes the integer number 5 - Fix nb_parameter in SPARQL query when numbered parameters are used - Fix ObjectProperty.subclasses(), ObjectProperty.descendants(), Property.subclasses(), DataProperty.descendants(), AnnotationProperty.subclasses(), AnnotationProperty.descendants() - Fix declare_datatype() for datatype already used in Owlready, such as AnyURI - Fix Pellet on properties having annotations that are not declared in the loaded ontologies

The new version be downloaded from PyPI (Python Package Index): https://pypi.python.org/pypi/Owlready2

Owlready2 0.34 has been released!

Owlready is a Python module for ontology-oriented programming. It can load OWL 2.0 ontologies and manipulate them transparently in Python.

Here are the changes:

  • NEW FORUM ADDRESS: http://owlready.306.s1.nabble.com

  • Support SPARQL property path expressions with parentheses without sequences, repeats or negative property set nested inside repeats

  • Add define_datatype_in_ontology() global function for defining a new user-defined datatype in an ontology

  • Class.instances() now takes into account equivalent classes (like other class methods such as .descendants())

  • Add the LOADED(iri) SPARQL function

  • Support Thing.is_a.append(...)

  • Faster loading of very large quadstores

  • list(onto.metadata) now lists the annotations present on the ontology

  • Add OntologyClass and NamespaceClass argument to get_ontology() and get_namespace(), allowing the use of custom classes

  • Bugfixes: - Accept UTF8 and latin encoding from reasoners (thanks Francesco Compagno) - Fix SPARQL query with a UNION without variables - Fix semantic type support in UMLS

The new version be downloaded from PyPI (Python Package Index): https://pypi.python.org/pypi/Owlready2

Owlready2 0.33 has been released!

Owlready is a Python module for ontology-oriented programming. It can load OWL 2.0 ontologies and manipulate them transparently in Python.

Here are the changes:

  • Bugfixes: - Fix 'sqlite3.OperationalError: no such table: sqlite_schema' with SQLite3 < 0.33

The new version be downloaded from PyPI (Python Package Index): https://pypi.python.org/pypi/Owlready2

Owlready2 0.32 has been released!

Owlready is a Python module for ontology-oriented programming. It can load OWL 2.0 ontologies and manipulate them transparently in Python.

Here are the changes:

  • Add scripts to import OMOP-CDM as an ontology (see directory pymedtermino2/omop_cdm/)

  • SPARQL engine optimization

  • Bugfixes: - Fix name clash when creating individuals from classes whose names end with a number, e.g. "c1" + "1" vs "c" + "11" - Fix block with only a FILTER in SPARQL

The new version be downloaded from PyPI (Python Package Index): https://pypi.python.org/pypi/Owlready2

Owlready2 0.31 has been released!

Owlready is a Python module for ontology-oriented programming. It can load OWL 2.0 ontologies and manipulate them transparently in Python.

This version can open SPARQL endpoints, with the new SPARQL engine, and fixes several bogues, in particular in the SPARQL engine.

Here are the changes:

  • Can open SPARQL endpoints (see module owlready2.sparql.endpoint and doc)

  • Support ClaML file format in PyMedTermino2 for French ICD10

  • Bugfixes: - Fix prefix in SPARQL that does not correspond to an existing ontology - Fix ! in SPARQL FILTER - Fix Thing.subclasses() so as it now returns classes that have parent constructs but no parent named classes - Fix metaclass of FusionClass when creating individuals belonging to several classes, including one from PyMedTermino - Fix Prop[individual] for functional properties with no relation for the given individual

The new version be downloaded from PyPI (Python Package Index): https://pypi.python.org/pypi/Owlready2