Skip to main content

A module for ontology-oriented programming in Python: load OWL 2.0 ontologies as Python objects, modify them, save them, and perform reasoning via HermiT. Includes an optimized RDF quadstore.

Project description

Owlready2 is a module for ontology-oriented programming in Python 3, including an optimized RDF quadstore.

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 reasoner.

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

Owlready has been created by Jean-Baptiste Lamy at the LIMICS reseach lab. It is available under the GNU LGPL licence v3. In case of trouble, please contact Jean-Baptiste Lamy <jean-baptiste.lamy @ univ-paris13 . fr>

LIMICS
University Paris 13, Sorbonne Paris Cité
Bureau 149
74 rue Marcel Cachin
93017 BOBIGNY
FRANCE

What can I do with Owlready2?

Load an ontology from a local repository, or from Internet:

>>> from owlready2 import *
>>> onto_path.append("/path/to/your/local/ontology/repository")
>>> onto = get_ontology("http://www.lesfleursdunormal.fr/static/_downloads/pizza_onto.owl")
>>> onto.load()

Create new classes in the ontology, possibly mixing OWL constructs and Python methods:

>>> class NonVegetarianPizza(onto.Pizza):
...   equivalent_to = [
...     onto.Pizza
...   & ( onto.has_topping.some(onto.MeatTopping)
...     | onto.has_topping.some(onto.FishTopping)
...     ) ]
...   def eat(self): print("Beurk! I'm vegetarian!")

Access ontology class, and create new instances / individuals:

>>> onto.Pizza
pizza_onto.Pizza
>>> test_pizza = onto.Pizza("test_pizza_owl_identifier")
>>> test_pizza.has_topping = [ onto.CheeseTopping(),
...                            onto.TomatoTopping(),
...                            onto.MeatTopping  () ]

Export to RDF/XML file:

>>> test_onto.save()

Perform reasoning, and classify instances and classes:

>>> test_pizza.__class__
onto.Pizza

>>> # Execute HermiT and reparent instances and classes
>>> sync_reasoner()

>>> test_pizza.__class__
onto.NonVegetarianPizza
>>> test_pizza.eat()
Beurk! I'm vegetarian !

For more documentation, look at the doc/ directories in the source.

Changelog

version 1 - 0.2

  • Fix sync_reasonner and Hermit call under windows (thanks Clare Grasso)

version 1 - 0.3

  • Add warnings

  • Accepts ontologies files that do not ends with ‘.owl’

  • Fix a bug when loading ontologies including concept without a ‘#’ in their IRI

version 2 - 0.1

  • Full rewrite, including an optimized quadstore

version 2 - 0.2

  • Implement RDFXML parser and generator in Python (no longer use rapper or rdflib)

  • Property chain support

  • Add ntriples_diff.py utility

  • Bugfixes: * Fix breaklines in literal when exporting to NTriples

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Owlready2-0.2.tar.gz (6.7 MB view details)

Uploaded Source

File details

Details for the file Owlready2-0.2.tar.gz.

File metadata

  • Download URL: Owlready2-0.2.tar.gz
  • Upload date:
  • Size: 6.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for Owlready2-0.2.tar.gz
Algorithm Hash digest
SHA256 0ed582740a7389b2ea19151cb91c549198072f123576628b76d658614b739d3d
MD5 c4fd36eab9fa881394e53b837c541966
BLAKE2b-256 a839064ceb21eb5cb8837d5d5b9b33bfca07b7a621d27daa3e4bf9c699099ae6

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page