diff --git a/README.md b/README.md index 4512ebd2..ee3dd83a 100644 --- a/README.md +++ b/README.md @@ -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') @@ -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 ?s_1 . ?s_1 a . ?x a . } } diff --git a/owlapy/parser.py b/owlapy/parser.py index f6f2b761..e3eb950d 100644 --- a/owlapy/parser.py +++ b/owlapy/parser.py @@ -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) diff --git a/owlapy/render.py b/owlapy/render.py index f68b1fb7..e72e69ae 100644 --- a/owlapy/render.py +++ b/owlapy/render.py @@ -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)