Skip to main content

A python implementation of the OWL 2 standard. See https://www.w3.org/TR/owl2-syntax/ and https://www.w3.org/TR/owl2-mapping-to-rdf/

Project description

PyOWL2

A python implementation of the OWL 2 standard. See https://www.w3.org/TR/owl2-syntax/ and https://www.w3.org/TR/owl2-mapping-to-rdf/

PyOWL2

A lightweight Python implementation of OWL 2 constructs, designed for mapping and interacting with OWL 2 ontology elements such as Class, ObjectProperty, Datatype, AnnotationProperty, and more.

Features:

  • Object-oriented representation of OWL 2 elements
  • Getter access for ontology elements
  • Clean, extensible Python API
  • Ideal for RDF/OWL-based modeling and semantic reasoning tools

Installation

pip install pyowl2

Examples of supported OWL 2 Constructs

OWL Construct Python Class
owl:Class OWLClass
owl:Datatype OWLDatatype
owl:ObjectProperty OWLObjectProperty

Basic Usage

from rdfxml import Namespace, URIRef, XSD
from pyowl2 import (
    IRI,
    OWLOntology,
    OWLDeclaration,
    OWLClass,
    OWLObjectProperty,
    OWLDatatype,
    OWLObjectPropertyDomain,
    OWLObjectPropertyRange,
    OWLEquivalentClasses
)

# Define the namespace
reference = URIRef("https://example.org#")
namespace = Namespace(reference)

# Define the ontology
ontology = OWLOntology(reference)

# Define a class
person = OWLClass(IRI(namespace, "Person"))

# Define an object property
has_spouse = OWLObjectProperty(IRI(namespace, "hasSpouse")

# Define a datatype
birthdate = OWLDatatype(IRI(namespace, "birthDate"))

## Save axioms in the ontology
ontology.add_axioms([
    OWLDeclaration(person),
    OWLDeclaration(has_spouse),
    OWLObjectPropertyDomain(has_spouse, person),
    OWLObjectPropertyRange(has_spouse, person),
    OWLEquivalentClasses(birtdate, OWLDatatype(XSD.date)),
])
ontology.save(OUTPUT_PATH)

Access to the ontology elements

from rdfxml import Namespace, URIRef
from pyowl2 import OWLOntology, AxiomsType

reference = URIRef("https://example.org#")
namespace = Namespace(reference)
ontology = OWLOntology(reference, PATH_TO_ONTOLOGY)

# print the list of all classes in the ontology
print(ontology.get_axioms(AxiomsType.CLASSES))

Advanced usage

from rdfxml import Namespace, URIRef, XSD
from pyowl2 import (
    IRI,
    OWLOntology,
    OWLFullClass,
    OWLFullObjectProperty,
    OWLFullDataRange
)

# Define the namespace
reference = URIRef("https://example.org#")
namespace = Namespace(reference)

# Define the ontology
ontology = OWLOntology(reference)

# Define a class
person = OWLFullClass(IRI(namespace, "Person"))

# Define an object property
has_spouse = OWLFullObjectProperty(
    IRI(namespace, "hasSpouse"),
    range=person.class_,
    domain=person.class_
)

# Define a datatype
birthdate = OWLFullDataRange(IRI(namespace, "birthDate"))
birthdate.is_equivalent_to([OWLDatatype(XSD.date)])

# Save axioms in the ontology
ontology.add_axioms([
    person,
    has_spouse,
    birtdate,
])
ontology.save(OUTPUT_PATH)

Project Structure

pyowl
├── __init__.py
├── abstracts
│   ├── __init__.py
│   ├── annotation_axiom.py
│   ├── annotation_subject.py
│   ├── annotation_value.py
│   ├── assertion.py
│   ├── axiom.py
│   ├── class_axiom.py
│   ├── class_expression.py
│   ├── data_property_axiom.py
│   ├── data_property_expression.py
│   ├── data_range.py
│   ├── entity.py
│   ├── individual.py
│   ├── object_property_axiom.py
│   ├── object_property_expression.py
│   ├── object.py
│   └── property_range.py
├── axioms
│   ├── __init__.py
│   ├── annotations
│   │   ├── __init__.py
│   │   ├── annotation_assertion.py
│   │   ├── annotation_property_domain.py
│   │   ├── annotation_property_range.py
│   │   └── sub_annotation_property_of.py
│   ├── assertion
│   │   ├── __init__.py
│   │   ├── class_assertion.py
│   │   ├── data_property_assertion.py
│   │   ├── different_individuals.py
│   │   ├── negative_data_property_assertion.py
│   │   ├── negative_object_property_assertion.py
│   │   ├── object_property_assertion.py
│   │   └── same_individual.py
│   ├── class_axiom
│   │   ├── __init__.py
│   │   ├── disjoint_classes.py
│   │   ├── disjoint_union.py
│   │   ├── equivalent_classes.py
│   │   └── sub_class_of.py
│   ├── data_property_axiom
│   │   ├── __init__.py
│   │   ├── data_property_domain.py
│   │   ├── data_property_range.py
│   │   ├── disjoint_data_properties.py
│   │   ├── equivalent_data_properties.py
│   │   ├── functional_data_property.py
│   │   └── sub_data_property_of.py
│   ├── datatype_definition.py
│   ├── declaration.py
│   ├── general.py
│   ├── has_key.py
│   └── object_property_axiom
│       ├── __init__.py
│       ├── asymmetric_object_property.py
│       ├── disjoint_object_properties.py
│       ├── equivalent_object_properties.py
│       ├── functional_object_property.py
│       ├── inverse_functional_object_property.py
│       ├── inverse_object_properties.py
│       ├── irreflexive_object_property.py
│       ├── object_property_chain.py
│       ├── object_property_domain.py
│       ├── object_property_range.py
│       ├── reflexive_object_property.py
│       ├── sub_object_property_of.py
│       ├── symmetric_object_property.py
│       └── transitive_object_property.py
├── base
│   ├── __init__.py
│   ├── annotation_property.py
│   ├── annotation.py
│   ├── datatype.py
│   ├── iri.py
│   └── owl_class.py
├── class_expression
│   ├── __init__.py
│   ├── data_all_values_from.py
│   ├── data_exact_cardinality.py
│   ├── data_has_value.py
│   ├── data_max_cardinality.py
│   ├── data_min_cardinality.py
│   ├── data_some_values_from.py
│   ├── object_all_values_from.py
│   ├── object_complement_of.py
│   ├── object_exact_cardinality.py
│   ├── object_has_self.py
│   ├── object_has_value.py
│   ├── object_intersection_of.py
│   ├── object_max_cardinality.py
│   ├── object_min_cardinality.py
│   ├── object_one_of.py
│   ├── object_some_values_from.py
│   └── object_union_of.py
├── data_range
│   ├── __init__.py
│   ├── data_complement_of.py
│   ├── data_intersection_of.py
│   ├── data_one_of.py
│   ├── data_union_of.py
│   └── datatype_restriction.py
├── expressions
│   ├── __init__.py
│   ├── data_property.py
│   ├── inverse_object_property.py
│   └── object_property.py
├── getter
│   ├── __init__.py
│   ├── rdf_xml_clear.py
│   └── rdf_xml_getter.py
├── individual
│   ├── __init__.py
│   ├── anonymous_individual.py
│   └── named_individual.py
├── literal
│   ├── __init__.py
│   └── literal.py
├── mapper
│   ├── __init__.py
│   └── rdf_xml_mapper.py
├── ontology.py
├── setup.cfg
├── setup.py
└── utils
    ├── __init__.py
    ├── datatype.py
    ├── individual.py
    ├── object_property.py
    ├── thing.py
    └── utils.py

License

This project is licensed under the Creative Commons Attribution-ShareAlike 4.0 International.

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

pyowl2-1.0.2.tar.gz (61.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyowl2-1.0.2-py3-none-any.whl (113.8 kB view details)

Uploaded Python 3

File details

Details for the file pyowl2-1.0.2.tar.gz.

File metadata

  • Download URL: pyowl2-1.0.2.tar.gz
  • Upload date:
  • Size: 61.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pyowl2-1.0.2.tar.gz
Algorithm Hash digest
SHA256 09d333481691f562b86ad06fb696b9dbb972eed5e8bd863c0ae4411a14149a72
MD5 957193777a9f87f6ae2aa5be99cb7ed6
BLAKE2b-256 ab66904147d0344bebf40e37b6084edf97b649c93b6a56757aa136d0c14777c3

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyowl2-1.0.2.tar.gz:

Publisher: publish.yml on giuseppefilippone/pyowl2

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyowl2-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: pyowl2-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 113.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pyowl2-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 eb74842f43c724be7a2d3141c1e566188bed11a42fef25aa6ad5b3e1ea6a65d4
MD5 2c93805c60b65601bf5713f5c7fda2ff
BLAKE2b-256 69a77463a9743aa8d67abb2e22edc2ae723c7d82ffab0f5e3b63731abc467a0b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyowl2-1.0.2-py3-none-any.whl:

Publisher: publish.yml on giuseppefilippone/pyowl2

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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