diff --git a/README.md b/README.md index ee3dd83..2975c3a 100644 --- a/README.md +++ b/README.md @@ -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 ?s_1 . ?s_1 a . ?x a . } } diff --git a/owlapy/owl_class_expression.py b/owlapy/owl_class_expression.py index a971cee..edb1a96 100644 --- a/owlapy/owl_class_expression.py +++ b/owlapy/owl_class_expression.py @@ -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 @@ -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