Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing iri #22

Merged
merged 2 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading