Skip to content

Commit

Permalink
added convenient methods
Browse files Browse the repository at this point in the history
  • Loading branch information
alkidbaci committed Apr 1, 2024
1 parent 6f07176 commit 06b48d1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ 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.render import DLSyntaxObjectRenderer
from owlapy.model import IRI, OWLClass, OWLObjectProperty, OWLObjectSomeValuesFrom, \
OWLObjectIntersectionOf
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')
Expand All @@ -42,8 +42,8 @@ males_with_children = OWLObjectSomeValuesFrom(hasChild, male)
teacher = OWLClass(IRI.create('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
print(DLSyntaxObjectRenderer().render(male_teachers_with_children))
# You can render and print owl class expressions in description logics syntax (and vice-versa)
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
12 changes: 12 additions & 0 deletions owlapy/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -764,3 +764,15 @@ def visit_parentheses(self, node, children) -> OWLClassExpression:

def generic_visit(self, node, children):
return children or node


DLparser = DLSyntaxParser()
ManchesterParser = ManchesterOWLSyntaxParser()


def dl_to_owl_expression(dl_expression: str):
return DLparser.parse_expression(dl_expression)


def manchester_to_owl_expression(manchester_expression: str):
return ManchesterParser.parse_expression(manchester_expression)
12 changes: 12 additions & 0 deletions owlapy/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,3 +420,15 @@ def _render_nested(self, c: OWLClassExpression) -> str:
return "(%s)" % self.render(c)
else:
return self.render(c)


DLrenderer = DLSyntaxObjectRenderer()
ManchesterRenderer = ManchesterOWLSyntaxOWLObjectRenderer()


def owl_expression_to_dl(o: OWLObject) -> str:
return DLrenderer.render(o)


def owl_expression_to_manchester(o: OWLObject) -> str:
return ManchesterRenderer.render(o)

0 comments on commit 06b48d1

Please sign in to comment.