Welcome to Owlready2’s documentation! — Owlready2 0.49 documentation

# Welcome to Owlready2’s documentation!

Owlready2 is a package for ontology-oriented programming in Python. It can load OWL 2.0 ontologies as Python objects, modify them, save them, and perform reasoning via HermiT (included). Owlready2 allows a transparent access to OWL ontologies (contrary to usual Java-based API).

Owlready version 2 includes an optimized triplestore / quadstore, based on SQLite3. This quadstore is optimized both for performance and memory consumption. Contrary to version 1, Owlready2 can deal with big ontologies. Owlready2 can also access to UMLS and medical terminology (using the integrated PyMedTermino2 submodule).

Owlready2 has been created at the LIMICS reseach lab, University Paris 13, Sorbonne Paris Cité, INSERM UMRS 1142, Paris 6 University, by Jean-Baptiste Lamy. It was initially developed during the VIIIP research project funded by ANSM, the French Drug Agency; this is why some examples in this documentation relate to drug ;).

Owlready2 is available under the GNU LGPL licence v3. If you use Owlready2 in scientific works, 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

In case of troubles, questions or comments, please use this Forum/Mailing list: http://owlready.306.s1.nabble.com

## Table of content

- Introduction
  - Short example: What can I do with Owlready?
  - Architecture
- Owlready2 Installation
  - Installation from terminal (Bash under Linux or DOS under Windows)
  - Installation in Spyder / IDLE (or any other Python console)
  - Manual installation
- Managing ontologies
  - Creating an ontology
  - Loading an ontology from OWL files
  - Accessing the content of an ontology
  - Simple queries
  - Ontology metadata
  - Importing other ontologies
  - Saving an ontology to an OWL file
  - Changing the ontology base IRI
  - Destroying an ontology
- Classes and Individuals (Instances)
  - Creating a Class
  - Creating and managing subclasses
  - Creating classes dynamically
  - Creating equivalent classes
  - Creating Individuals
  - Querying Individual relations
  - Introspecting Individuals
  - Mutli-Class Individuals
  - Equivalent (identical, SameAs) individuals
  - Destroying entities
- Properties
  - Creating a new class of property
  - Getting domain and range
  - Creating a relation
  - Data Property
  - Inverse Properties
  - Functional and Inverse Functional properties
  - Creating a subproperty
  - Obtaining indirect relations (considering subproperty, transitivity, etc)
  - Associating Python alias name to Properties
  - Getting relation instances
- Datatypes
  - Creating enumerated datatypes
  - Creating custom datatypes
- Class constructs, restrictions and logical operators
  - Restrictions on a Property
  - Restrictions as class properties
  - Restrictions as class properties in defined classes
  - Logical operators (intersection, union and complement)
  - One-Of constructs
  - Inverse-of constructs
  - ConstrainedDatatype
  - Property chain
- Disjointness, open and local closed world reasoning
  - Disjoint Classes
  - Disjoint Properties
  - Different Individuals
  - Querying and modifying disjoints
  - Closing Individuals
  - Closing Classes
  - Closing an ontology
- Mixing Python and OWL
  - Adding Python methods to an OWL Class
  - Forward declarations
  - Associating a Python module to an OWL ontology
- Reasoning
  - Configuration
  - Setting up everything
  - Running the reasoner
  - Results of the automatic classification
  - Inconsistent classes and ontologies
  - Querying inferred classification
- Annotations
  - Adding an annotation
  - Querying annotations
  - Deleting annotations
  - Nested annotated relations
  - Custom rendering of entities
  - Language-specific annotations
  - Plain literal
  - Creating new classes of annotation
  - Full-text search (FTS)
- Namespaces
  - Accessing entities defined in another namespace
  - Creating classes in a specific namespace
  - Modifying a class defined in another ontology
  - Renaming entities defined in a namespace
- SPARQL queries
  - Native SPARQL engine
    - SPARQL elements supported
    - SPARQL elements not supported
    - Performing SPARQL queries
    - INSERT queries
    - DELETE queries
    - Parameters in SPARQL queries
    - Prepare SPARQL queries
    - Define additional SPARQL functions in Python
    - Performance tips
    - Non-standard additions to SPARQL
    - Open a SPARQL endpoint
  - Using RDFlib for executing SPARQL queries
- Worlds
  - Persistent world: storing the quadstore in an SQLite3 file database
  - Using several isolated Worlds
  - Working with RDFlib
- Parallelism, multiprocessing and synchronization
  - Parallelized file parsing
  - Thread-based parallel execution of SPARQL queries
    - Executing many SPARQL queries in parallel
    - Executing a single SPARQL query in parallel
  - Cooperative microthreads (e.g. GEvent)
    - Synchronization
  - Multiprocessing
    - Synchronization
    - Server example
  - Combining multiprocessing with cooperative microthreads
- SWRL rules
  - Creating SWRL rules
  - Displaying rules
  - Modifying rules manually
- General class axioms
  - Creating a general class axiom
  - Accessing general class axioms
- PyMedTermino2
  - Introduction
  - Installation
  - SNOMED CT
    - Loading
    - Concepts
    - Full-text search
    - Is-a relations: parent and child concepts
    - Part-of relations
    - Other relations
    - Relation groups
    - Iterating over SNOMED CT
    - French translation
  - ICD10
    - Loading modules
    - Concepts
  - UMLS
    - Loading modules
    - UMLS concepts (CUI)
    - Relation with source terminologies
    - Mapping between terminologies
  - Set of concepts
  - Pruning terminologies
- Observation framework
  - Adding and removing listeners
  - Coalescing events
  - Stopping observation
- Development
  - Development installation
- Differences between Owlready version 1 and 2
  - Creation of Classes, Properties and Individuals
  - Generated Individual names
  - Functional properties
  - Creation of restrictions
  - Logical operators and ‘One of’ constructs
  - Reasoning
  - Annotations
- Contact and links