Skip to content

Commit

Permalink
Merge pull request #107 from dice-group/develop
Browse files Browse the repository at this point in the history
1.3.3 patch
  • Loading branch information
alkidbaci authored Nov 11, 2024
2 parents 291ea43 + d77a483 commit d3cf32e
Show file tree
Hide file tree
Showing 21 changed files with 374 additions and 196 deletions.
8 changes: 0 additions & 8 deletions .github/workflows/ruff.yml

This file was deleted.

4 changes: 3 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install -e .
- name: Lint with ruff
run: |
ruff check owlapy --line-length=200
- name: Test with pytest
run: |
wget https://files.dice-research.org/projects/Ontolearn/KGs.zip
Expand Down
52 changes: 50 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# OWLAPY
[![Coverage](https://img.shields.io/badge/coverage-78%25-green)](https://dice-group.github.io/owlapy/usage/further_resources.html#coverage-report)
[![Pypi](https://img.shields.io/badge/pypi-1.3.2-blue)](https://pypi.org/project/owlapy/1.3.2/)
[![Docs](https://img.shields.io/badge/documentation-1.3.2-yellow)](https://dice-group.github.io/owlapy/usage/main.html)
[![Pypi](https://img.shields.io/badge/pypi-1.3.3-blue)](https://pypi.org/project/owlapy/1.3.3/)
[![Docs](https://img.shields.io/badge/documentation-1.3.3-yellow)](https://dice-group.github.io/owlapy/usage/main.html)

![OWLAPY](docs/_static/images/owlapy_logo.png)

Expand Down Expand Up @@ -30,6 +30,54 @@ pytest -p no:warnings -x # Running 142 tests ~ 30 secs

## Examples

### Exploring OWL Ontology

<details><summary> Click me! </summary>

```python
from owlapy.owl_ontology_manager import SyncOntologyManager

ontology_path = "KGs/Family/father.owl"
onto = SyncOntologyManager().load_ontology(ontology_path)

print({owl_class.reminder for owl_class in onto.classes_in_signature()})
# {'Thing', 'female', 'male', 'person'}

print({individual.reminder for individual in onto.individuals_in_signature()})
# {'michelle', 'stefan', 'martin', 'anna', 'heinz', 'markus'}

print({object_property.reminder for object_property in onto.object_properties_in_signature()})
# {'hasChild'}

for owl_subclass_of_axiom in onto.get_tbox_axioms():
print(owl_subclass_of_axiom)

# OWLEquivalentClassesAxiom([OWLClass(IRI('http://example.com/father#', 'male')), OWLObjectComplementOf(OWLClass(IRI('http://example.com/father#', 'female')))],[])
# OWLSubClassOfAxiom(sub_class=OWLClass(IRI('http://example.com/father#', 'female')),super_class=OWLClass(IRI('http://example.com/father#', 'person')),annotations=[])
# OWLSubClassOfAxiom(sub_class=OWLClass(IRI('http://example.com/father#', 'male')),super_class=OWLClass(IRI('http://example.com/father#', 'person')),annotations=[])
# OWLSubClassOfAxiom(sub_class=OWLClass(IRI('http://example.com/father#', 'person')),super_class=OWLClass(IRI('http://www.w3.org/2002/07/owl#', 'Thing')),annotations=[])
# OWLObjectPropertyRangeAxiom(OWLObjectProperty(IRI('http://example.com/father#', 'hasChild')),OWLClass(IRI('http://example.com/father#', 'person')),[])
# OWLObjectPropertyDomainAxiom(OWLObjectProperty(IRI('http://example.com/father#', 'hasChild')),OWLClass(IRI('http://example.com/father#', 'person')),[])


for axiom in onto.get_abox_axioms():
print(axiom)

# OWLClassAssertionAxiom(individual=OWLNamedIndividual(IRI('http://example.com/father#', 'anna')),class_expression=OWLClass(IRI('http://example.com/father#', 'female')),annotations=[])
# OWLClassAssertionAxiom(individual=OWLNamedIndividual(IRI('http://example.com/father#', 'michelle')),class_expression=OWLClass(IRI('http://example.com/father#', 'female')),annotations=[])
# OWLClassAssertionAxiom(individual=OWLNamedIndividual(IRI('http://example.com/father#', 'martin')),class_expression=OWLClass(IRI('http://example.com/father#', 'male')),annotations=[])
# OWLClassAssertionAxiom(individual=OWLNamedIndividual(IRI('http://example.com/father#', 'markus')),class_expression=OWLClass(IRI('http://example.com/father#', 'male')),annotations=[])
# OWLClassAssertionAxiom(individual=OWLNamedIndividual(IRI('http://example.com/father#', 'heinz')),class_expression=OWLClass(IRI('http://example.com/father#', 'male')),annotations=[])
# OWLClassAssertionAxiom(individual=OWLNamedIndividual(IRI('http://example.com/father#', 'stefan')),class_expression=OWLClass(IRI('http://example.com/father#', 'male')),annotations=[])
# OWLObjectPropertyAssertionAxiom(subject=OWLNamedIndividual(IRI('http://example.com/father#', 'markus')),property_=OWLObjectProperty(IRI('http://example.com/father#', 'hasChild')),object_=OWLNamedIndividual(IRI('http://example.com/father#', 'anna')),annotations=[])
# OWLObjectPropertyAssertionAxiom(subject=OWLNamedIndividual(IRI('http://example.com/father#', 'martin')),property_=OWLObjectProperty(IRI('http://example.com/father#', 'hasChild')),object_=OWLNamedIndividual(IRI('http://example.com/father#', 'heinz')),annotations=[])
# OWLObjectPropertyAssertionAxiom(subject=OWLNamedIndividual(IRI('http://example.com/father#', 'stefan')),property_=OWLObjectProperty(IRI('http://example.com/father#', 'hasChild')),object_=OWLNamedIndividual(IRI('http://example.com/father#', 'markus')),annotations=[])
# OWLObjectPropertyAssertionAxiom(subject=OWLNamedIndividual(IRI('http://example.com/father#', 'anna')),property_=OWLObjectProperty(IRI('http://example.com/father#', 'hasChild')),object_=OWLNamedIndividual(IRI('http://example.com/father#', 'heinz')),annotations=[])

```

</details>

### Creating OWL Class Expressions
<details><summary> Click me! </summary>

Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

project = 'OWLAPY'
author = 'Ontolearn Team'
release = '1.3.2'
release = '1.3.3'

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
Expand Down
2 changes: 1 addition & 1 deletion docs/usage/main.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# About owlapy

**Version:** owlapy 1.3.2
**Version:** owlapy 1.3.3

**GitHub repository:** [https://github.com/dice-group/owlapy](https://github.com/dice-group/owlapy)

Expand Down
2 changes: 1 addition & 1 deletion owlapy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from .converter import owl_expression_to_sparql, owl_expression_to_sparql_with_confusion_matrix
from .owl_ontology_manager import OntologyManager

__version__ = '1.3.2'
__version__ = '1.3.3'

__all__ = [
'owl_expression_to_dl', 'owl_expression_to_manchester',
Expand Down
87 changes: 41 additions & 46 deletions owlapy/class_expression/restriction.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from ..owl_individual import OWLIndividual
from ..owl_datatype import OWLDatatype
from ..owl_object import OWLObject
from owlapy.vocab import OWLFacet
from ..vocab import OWLFacet
from datetime import datetime, date
from pandas import Timedelta

Expand Down Expand Up @@ -65,7 +65,7 @@ def __init__(self, value: _T):
def __eq__(self, other):
if type(other) is type(self):
return self._v == other._v
return NotImplemented
return False

def __hash__(self):
return hash(self._v)
Expand Down Expand Up @@ -272,10 +272,11 @@ def __repr__(self):
def __eq__(self, other):
if type(other) is type(self):
return self._filler == other._filler and self._property == other._property
return NotImplemented
else:
return False

def __hash__(self):
return hash((self._filler, self._property))
return hash(("OWLObjectSomeValuesFrom",self._filler, self._property))

def get_property(self) -> OWLObjectPropertyExpression:
# documented in parent
Expand Down Expand Up @@ -303,7 +304,7 @@ def __eq__(self, other):
return False

def __hash__(self):
return hash((self._filler, self._property))
return hash(("OWLObjectAllValuesFrom",self._filler, self._property))

def get_property(self) -> OWLObjectPropertyExpression:
# documented in parent
Expand Down Expand Up @@ -341,8 +342,9 @@ def __eq__(self, other):
else:
return False


def __hash__(self):
return hash(self._property)
return hash(("OWLObjectHasSelf", self._property))

def __repr__(self):
return f'OWLObjectHasSelf({self._property})'
Expand Down Expand Up @@ -403,7 +405,7 @@ def __init__(self, values: OWLIndividual | Iterable[OWLIndividual]):
else:
for _ in values:
assert isinstance(_, OWLIndividual)
self._values = {i for i in values}
self._values = frozenset(values)

def individuals(self) -> Iterable[OWLIndividual]:
"""Gets the individuals that are in the oneOf. These individuals represent the exact instances (extension)
Expand All @@ -428,16 +430,13 @@ def as_object_union_of(self) -> OWLClassExpression:
if len(self._values) == 1:
return self
return OWLObjectUnionOf(map(lambda _: OWLObjectOneOf(_), self.individuals()))

def __hash__(self):
return hash(self._values)

return hash(("OWLObjectOneOf", self._values))
def __eq__(self, other):
if type(other) is type(self):
return self._values == other._values
else:
return False

def __repr__(self):
return f'OWLObjectOneOf({self._values})'

Expand Down Expand Up @@ -485,25 +484,22 @@ def __init__(self, cardinality: int, property: OWLDataPropertyExpression, filler
assert isinstance(filler, OWLDataRange), "filler must be an OWLDataRange"
super().__init__(cardinality, filler)
self._property = property

def get_property(self) -> OWLDataPropertyExpression:
# documented in parent
return self._property

def __hash__(self):
return hash(("OWLDataCardinalityRestriction",self._property, self._cardinality, self._filler))
def __repr__(self):
return f"{type(self).__name__}(" \
f"property={repr(self.get_property())},{self.get_cardinality()},filler={repr(self.get_filler())})"

def __eq__(self, other):
if type(other) is type(self):
return self._property == other._property \
and self._cardinality == other._cardinality \
and self._filler == other._filler
return NotImplemented

def __hash__(self):
return hash((self._property, self._cardinality, self._filler))
return (self._property == other._property and self._cardinality == other._cardinality
and self._filler == other._filler)
else:
return False

def get_property(self) -> OWLDataPropertyExpression:
# documented in parent
return self._property

class OWLDataMinCardinality(OWLDataCardinalityRestriction):
"""A minimum cardinality expression DataMinCardinality( n DPE DR ) consists of a nonnegative integer n, a data
Expand Down Expand Up @@ -619,7 +615,7 @@ def __eq__(self, other):
else:
return False
def __hash__(self):
return hash((self._filler, self._property))
return hash(("OWLDataSomeValuesFrom",self._filler, self._property))

def get_property(self) -> OWLDataPropertyExpression:
# documented in parent
Expand Down Expand Up @@ -661,9 +657,8 @@ def __eq__(self, other):
return self._filler == other._filler and self._property == other._property
else:
return False

def __hash__(self):
return hash((self._filler, self._property))
return hash(("OWLDataAllValuesFrom",self._filler, self._property))

def get_property(self) -> OWLDataPropertyExpression:
# documented in parent
Expand Down Expand Up @@ -703,10 +698,10 @@ def __repr__(self):
def __eq__(self, other):
if type(other) is type(self):
return self._v == other._v and self._property == other._property
return NotImplemented

else:
return False
def __hash__(self):
return hash((self._v, self._property))
return hash(("OWLDataHasValue",self._v, self._property))

def as_some_values_from(self) -> OWLClassExpression:
"""A convenience method that obtains this restriction as an existential restriction with a nominal filler.
Expand Down Expand Up @@ -735,6 +730,17 @@ def __init__(self, values: Union[OWLLiteral, Iterable[OWLLiteral]]):
for _ in values:
assert isinstance(_, OWLLiteral)
self._values = tuple(values)
def __repr__(self):
return f'OWLDataOneOf({self._values})'

def __hash__(self):
return hash(("OWLDataOneOf",self._values))

def __eq__(self, other):
if type(other) is type(self):
return {i for i in self._values} == {j for j in other._values}
else:
return False
# TODO:CD: define it as @property as the name of the class method does not correspond to an action
def values(self) -> Iterable[OWLLiteral]:
"""Gets the values that are in the oneOf.
Expand All @@ -748,18 +754,6 @@ def operands(self) -> Iterable[OWLLiteral]:
# documented in parent
yield from self.values()

def __hash__(self):
return hash(self._values)

def __eq__(self, other):
if type(other) is type(self):
return {i for i in self._values} == {j for j in other._values}
else:
return False

def __repr__(self):
return f'OWLDataOneOf({self._values})'


class OWLDatatypeRestriction(OWLDataRange):
"""A datatype restriction DatatypeRestriction( DT F1 lt1 ... Fn ltn ) consists of a unary datatype DT and n pairs
Expand Down Expand Up @@ -792,10 +786,10 @@ def __eq__(self, other):
if type(other) is type(self):
return self._type == other._type \
and self._facet_restrictions == other._facet_restrictions
return NotImplemented

else:
return False
def __hash__(self):
return hash((self._type, self._facet_restrictions))
return hash(("OWLDatatypeRestriction", self._type, self._facet_restrictions))

def __repr__(self):
return f'OWLDatatypeRestriction({repr(self._type)}, {repr(self._facet_restrictions)})'
Expand Down Expand Up @@ -827,10 +821,11 @@ def get_facet_value(self) -> 'OWLLiteral':
def __eq__(self, other):
if type(other) is type(self):
return self._facet == other._facet and self._literal == other._literal
return NotImplemented
else:
return False

def __hash__(self):
return hash((self._facet, self._literal))
return hash(("OWLFacetRestriction",self._facet, self._literal))

def __repr__(self):
return f'OWLFacetRestriction({self._facet}, {repr(self._literal)})'
Expand Down
4 changes: 3 additions & 1 deletion owlapy/iri.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def __init__(self, namespace: Union[str, Namespaces], remainder: str=""):
else:
assert namespace[-1] in ("/", ":", "#"), "It should be a valid IRI based on /, :, and #"
import sys
# https://docs.python.org/3.2/library/sys.html?highlight=sys.intern#sys.intern
self._namespace = sys.intern(namespace)
self._remainder = remainder

Expand Down Expand Up @@ -94,7 +95,8 @@ def __repr__(self):
def __eq__(self, other):
if type(other) is type(self):
return self._namespace is other._namespace and self._remainder == other._remainder
return NotImplemented
else:
raise RuntimeError(f"Invalid equality checking:{self} cannot be compared with {other}")

def __hash__(self):
return hash((self._namespace, self._remainder))
Expand Down
10 changes: 9 additions & 1 deletion owlapy/owl_axiom.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,13 @@ def __init__(self, sub_class: OWLClassExpression, super_class: OWLClassExpressio
self._super_class = super_class
super().__init__(annotations=annotations)

@property
def sub_class(self) -> OWLClassExpression:
return self._sub_class
@property
def super_class(self) -> OWLClassExpression:
return self._super_class

def get_sub_class(self) -> OWLClassExpression:
return self._sub_class

Expand All @@ -533,7 +540,8 @@ def __eq__(self, other):
if type(other) is type(self):
return self._super_class == other._super_class and self._sub_class == other._sub_class \
and self._annotations == other._annotations
return NotImplemented
else:
return False

def __hash__(self):
return hash((self._super_class, self._sub_class, *self._annotations))
Expand Down
5 changes: 3 additions & 2 deletions owlapy/owl_individual.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ def __init__(self, iri: Union[IRI, str]):
self._iri = iri
else:
self._iri = IRI.create(iri)

@property
def iri(self) -> IRI:
return self._iri

@property
def str(self):
return self._iri.as_str()
@property
def reminder(self):
return self._iri.reminder
4 changes: 3 additions & 1 deletion owlapy/owl_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ class OWLNamedObject(OWLObject, HasIRI, metaclass=ABCMeta):
def __eq__(self, other):
if type(other) is type(self):
return self._iri == other._iri
return NotImplemented
else:
return False
# raise RuntimeError(f"Invalid equality checking:{self} cannot be compared with {other}")

def __lt__(self, other):
if type(other) is type(self):
Expand Down
Loading

0 comments on commit d3cf32e

Please sign in to comment.