Skip to content

Commit

Permalink
owlclass can accept iri in str form
Browse files Browse the repository at this point in the history
  • Loading branch information
Demirrr committed Apr 9, 2024
1 parent 823b2da commit 9aeac95
Showing 1 changed file with 9 additions and 8 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

0 comments on commit 9aeac95

Please sign in to comment.