Skip to content

Commit

Permalink
Merge pull request #22 from dice-group/fixing_iri
Browse files Browse the repository at this point in the history
Fixing iri
  • Loading branch information
Demirrr committed Apr 9, 2024
2 parents 54d0db5 + 9aeac95 commit 066e046
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,30 @@ In this example we start with a simple atomic class expression and move to some
ones and finally render and print the last of them in description logics syntax.

```python
from owlapy.model import IRI, OWLClass, OWLObjectProperty, OWLObjectSomeValuesFrom, \
OWLObjectIntersectionOf
from owlapy.iri import IRI
from owlapy.owl_class_expression import OWLClass, OWLObjectIntersectionOf
from owlapy.owl_property import OWLObjectProperty
from owlapy.owl_restriction import OWLObjectSomeValuesFrom

from owlapy.owl2sparql.converter import owl_expression_to_sparql
from owlapy.render import owl_expression_to_dl

# Create an IRI object using the iri as a string for 'male' class.
male_iri = IRI.create('http://example.com/society#male')

# Create the male class
male = OWLClass(male_iri)
male = OWLClass("http://example.com/society#male")

# Create an object property using the iri as a string for 'hasChild' property.
hasChild = OWLObjectProperty(IRI.create('http://example.com/society#hasChild'))
hasChild = OWLObjectProperty("http://example.com/society#hasChild")

# Create an existential restrictions
males_with_children = OWLObjectSomeValuesFrom(hasChild, male)

# Let's make it more complex by intersecting with another class
teacher = OWLClass(IRI.create('http://example.com/society#teacher'))
teacher = OWLClass("http://example.com/society#teacher")
male_teachers_with_children = OWLObjectIntersectionOf([males_with_children, teacher])

# You can render and print owl class expressions in description logics syntax (and vice-versa)
print(owl_expression_to_dl(male_teachers_with_children))
print(owl_expression_to_dl(male_teachers_with_children))
# (∃ hasChild.male) ⊓ teacher
print(owl_expression_to_sparql("?x", male_teachers_with_children))
# SELECT DISTINCT ?x WHERE { ?x <http://example.com/society#hasChild> ?s_1 . ?s_1 a <http://example.com/society#male> . ?x a <http://example.com/society#teacher> . } }
Expand Down
16 changes: 10 additions & 6 deletions owlapy/owl_class_expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from .owl_literal import OWLLiteral
from typing import Final, Sequence, Union, Iterable
from .owl_property import OWLDataPropertyExpression, OWLObjectProperty, OWLDataProperty

from .iri import IRI
from owlapy.vocab import OWLRDFVocabulary, XSDVocabulary


Expand Down Expand Up @@ -123,15 +123,19 @@ class OWLClass(OWLClassExpression, OWLEntity):
_is_nothing: bool
_is_thing: bool

def __init__(self, iri: 'IRI'):
def __init__(self, iri: Union[IRI,str]):
"""Gets an instance of OWLClass that has the specified IRI.
Args:
iri: The IRI.
iri:
"""
self._is_nothing = iri.is_nothing()
self._is_thing = iri.is_thing()
self._iri = iri
if isinstance(iri, IRI):
self._iri = iri
else:
self._iri = IRI.create(iri)

self._is_nothing = self._iri.is_nothing()
self._is_thing = self._iri.is_thing()

def get_iri(self) -> 'IRI':
# documented in parent
Expand Down

0 comments on commit 066e046

Please sign in to comment.