Skip to content

Commit

Permalink
OWLSubClassOfAxiom OWLObjectPropertyRangeAxiom OWLObjectPropertyDomai…
Browse files Browse the repository at this point in the history
…nAxiom included
  • Loading branch information
Demirrr committed Nov 15, 2024
1 parent 69946c8 commit 1018819
Showing 1 changed file with 30 additions and 5 deletions.
35 changes: 30 additions & 5 deletions owlapy/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@
from .class_expression import OWLObjectHasValue, OWLFacetRestriction, OWLDatatypeRestriction, OWLObjectOneOf
from .owl_datatype import OWLDatatype
from .abstracts.abstract_owl_reasoner import AbstractOWLReasoner
from .owl_axiom import (OWLEquivalentClassesAxiom, OWLSubClassOfAxiom,
OWLObjectPropertyRangeAxiom, OWLObjectPropertyDomainAxiom)
import requests
import warnings
import abc

_DL_SYNTAX = types.SimpleNamespace(
SUBCLASS="⊑",
EQUIVALENT_TO="≡",
Expand All @@ -45,8 +48,7 @@
WEDGE="⋀",
IMPLIES="←",
COMMA=",",
SELF="Self",
)
SELF="Self")


def _simple_short_form_provider(e: OWLEntity) -> str:
Expand Down Expand Up @@ -350,8 +352,8 @@ def _render_nested(self, c: OWLClassExpression) -> str:
COMMA=",",
SELF="Self",
VALUE="value",
)

RANGE="Range",
DOMAIN="Domain")

class ManchesterOWLSyntaxOWLObjectRenderer(OWLObjectRenderer):
"""Manchester Syntax renderer for OWL Objects"""
Expand All @@ -376,7 +378,7 @@ def set_short_form_provider(self, short_form_provider: Callable[[OWLEntity], str
@singledispatchmethod
def render(self, o: OWLObject) -> str:
assert isinstance(o, OWLObject), f"Tried to render non-OWLObject {o} of {type(o)}"
raise NotImplementedError
raise NotImplementedError(f"We cannot render {o}\t{type(o)}")

@render.register
def _(self, o: OWLClass) -> str:
Expand Down Expand Up @@ -515,6 +517,29 @@ def _(self, t: OWLDatatype):
def _(self, t: OWLLiteral) -> str:
return t.get_literal()

@render.register
def _(self, equiv: OWLEquivalentClassesAxiom) -> str:
# TODO:CD:Can we assume that the size of equiv will be 2 ?
return (" %s " % _MAN_SYNTAX.EQUIVALENT_TO).join([self.render(i) for i in equiv])

@render.register
def _(self, equiv: OWLSubClassOfAxiom) -> str:
return (" %s " % _MAN_SYNTAX.SUBCLASS).join([self.render(i) for i in [equiv.sub_class,equiv.super_class]])

@render.register
def _(self, axiom: OWLObjectPropertyRangeAxiom) -> str:
# objectPropertyFrame ObjectProperty: IRI Range: annotations description ObjectPropertyRange(T(annotations) IRI T(description))
return f"{self.render(axiom.prop)} {_MAN_SYNTAX.RANGE} {self.render(axiom.range)}"
@render.register
def _(self, axiom: OWLObjectPropertyDomainAxiom) -> str:
# objectPropertyFrame ObjectProperty: IRI Domain: annotations description ObjectPropertyDomain(T(annotations) IRI T(description))
return f"{self.render(axiom.prop)} {_MAN_SYNTAX.DOMAIN} {self.render(axiom.get_domain())}"

@render.register
def _(self, axiom: OWLObjectPropertyDomainAxiom) -> str:
# objectPropertyFrame ObjectProperty: IRI Domain: annotations description ObjectPropertyDomain(T(annotations) IRI T(description))
return f"{self.render(axiom.prop)} {_MAN_SYNTAX.DOMAIN} {self.render(axiom.get_domain())}"

def _render_operands(self, c: OWLNaryBooleanClassExpression) -> List[str]:
return [self._render_nested(_) for _ in c.operands()]

Expand Down

0 comments on commit 1018819

Please sign in to comment.