from datetime import date, datetime, time
from decimal import Decimal
from functools import singledispatchmethod
from typing import Iterable, TypeVar
import jpype.imports
from owlapy import namespaces
from owlapy.class_expression import (
OWLClass,
OWLDataAllValuesFrom,
OWLDataExactCardinality,
OWLDataHasValue,
OWLDataMaxCardinality,
OWLDataMinCardinality,
OWLDataOneOf,
OWLDataSomeValuesFrom,
OWLDatatypeRestriction,
OWLFacetRestriction,
OWLObjectAllValuesFrom,
OWLObjectComplementOf,
OWLObjectExactCardinality,
OWLObjectHasSelf,
OWLObjectHasValue,
OWLObjectIntersectionOf,
OWLObjectMaxCardinality,
OWLObjectMinCardinality,
OWLObjectOneOf,
OWLObjectSomeValuesFrom,
OWLObjectUnionOf,
)
from owlapy.iri import IRI
from owlapy.owl_axiom import (
OWLAnnotation,
OWLAnnotationAssertionAxiom,
OWLAnnotationProperty,
OWLAnnotationPropertyDomainAxiom,
OWLAnnotationPropertyRangeAxiom,
OWLAsymmetricObjectPropertyAxiom,
OWLClassAssertionAxiom,
OWLDataPropertyAssertionAxiom,
OWLDataPropertyDomainAxiom,
OWLDataPropertyRangeAxiom,
OWLDatatypeDefinitionAxiom,
OWLDeclarationAxiom,
OWLDifferentIndividualsAxiom,
OWLDisjointClassesAxiom,
OWLDisjointDataPropertiesAxiom,
OWLDisjointObjectPropertiesAxiom,
OWLDisjointUnionAxiom,
OWLEquivalentClassesAxiom,
OWLEquivalentDataPropertiesAxiom,
OWLEquivalentObjectPropertiesAxiom,
OWLFunctionalDataPropertyAxiom,
OWLFunctionalObjectPropertyAxiom,
OWLHasKeyAxiom,
OWLInverseFunctionalObjectPropertyAxiom,
OWLInverseObjectPropertiesAxiom,
OWLIrreflexiveObjectPropertyAxiom,
OWLNegativeDataPropertyAssertionAxiom,
OWLNegativeObjectPropertyAssertionAxiom,
OWLObjectPropertyAssertionAxiom,
OWLObjectPropertyDomainAxiom,
OWLObjectPropertyRangeAxiom,
OWLReflexiveObjectPropertyAxiom,
OWLSameIndividualAxiom,
OWLSubAnnotationPropertyOfAxiom,
OWLSubClassOfAxiom,
OWLSubDataPropertyOfAxiom,
OWLSubObjectPropertyOfAxiom,
OWLSubPropertyChainAxiom,
OWLSymmetricObjectPropertyAxiom,
OWLTransitiveObjectPropertyAxiom,
)
from owlapy.owl_data_ranges import OWLDataComplementOf, OWLDataIntersectionOf, OWLDataUnionOf, OWLNaryDataRange
from owlapy.owl_datatype import OWLDatatype
from owlapy.owl_individual import OWLAnonymousIndividual, OWLNamedIndividual
from owlapy.owl_literal import (
BooleanOWLDatatype,
DateOWLDatatype,
DateTimeOWLDatatype,
DecimalOWLDatatype,
DoubleOWLDatatype,
FloatOWLDatatype,
IntegerOWLDatatype,
IntOWLDatatype,
LongOWLDatatype,
NegativeIntegerOWLDatatype,
NonNegativeIntegerOWLDatatype,
NonPositiveIntegerOWLDatatype,
OWLLiteral,
PositiveIntegerOWLDatatype,
StringOWLDatatype,
TimeOWLDatatype,
lexical_literal,
)
from owlapy.owl_ontology import OWLOntologyID
from owlapy.owl_property import OWLDataProperty, OWLObjectInverseOf, OWLObjectProperty
from owlapy.static_funcs import startJVM
from owlapy.vocab import OWLFacet
if not jpype.isJVMStarted():
startJVM()
from java.util import ArrayList, Collections, HashSet, LinkedHashSet, List, Optional, Set
from java.util.stream import Stream
from org.semanticweb.owlapi.model import IRI as owlapi_IRI
from org.semanticweb.owlapi.model import NodeID as owlapi_NodeID
from org.semanticweb.owlapi.model import OWLOntologyID as owlapi_OWLOntologyID
from org.semanticweb.owlapi.vocab import OWLFacet as owlapi_OWLFacet
from uk.ac.manchester.cs.owl.owlapi import (
OWL2DatatypeImpl,
OWLAnnotationAssertionAxiomImpl,
OWLAnnotationImpl,
OWLAnnotationPropertyDomainAxiomImpl,
OWLAnnotationPropertyImpl,
OWLAnnotationPropertyRangeAxiomImpl,
OWLAnonymousIndividualImpl,
OWLAsymmetricObjectPropertyAxiomImpl,
OWLClassAssertionAxiomImpl,
OWLClassImpl,
OWLDataAllValuesFromImpl,
OWLDataComplementOfImpl,
OWLDataExactCardinalityImpl,
OWLDataHasValueImpl,
OWLDataIntersectionOfImpl,
OWLDataMaxCardinalityImpl,
OWLDataMinCardinalityImpl,
OWLDataOneOfImpl,
OWLDataPropertyAssertionAxiomImpl,
OWLDataPropertyDomainAxiomImpl,
OWLDataPropertyImpl,
OWLDataPropertyRangeAxiomImpl,
OWLDataSomeValuesFromImpl,
OWLDatatypeDefinitionAxiomImpl,
OWLDatatypeImpl,
OWLDatatypeRestrictionImpl,
OWLDataUnionOfImpl,
OWLDeclarationAxiomImpl,
OWLDifferentIndividualsAxiomImpl,
OWLDisjointClassesAxiomImpl,
OWLDisjointDataPropertiesAxiomImpl,
OWLDisjointObjectPropertiesAxiomImpl,
OWLDisjointUnionAxiomImpl,
OWLEquivalentClassesAxiomImpl,
OWLEquivalentDataPropertiesAxiomImpl,
OWLEquivalentObjectPropertiesAxiomImpl,
OWLFacetRestrictionImpl,
OWLFunctionalDataPropertyAxiomImpl,
OWLFunctionalObjectPropertyAxiomImpl,
OWLHasKeyAxiomImpl,
OWLInverseFunctionalObjectPropertyAxiomImpl,
OWLInverseObjectPropertiesAxiomImpl,
OWLIrreflexiveObjectPropertyAxiomImpl,
OWLLiteralImplBoolean,
OWLLiteralImplDouble,
OWLLiteralImplFloat,
OWLLiteralImplInteger,
OWLLiteralImplNoCompression,
OWLLiteralImplPlain,
OWLLiteralImplString,
OWLNamedIndividualImpl,
OWLNaryDataRangeImpl,
OWLNegativeDataPropertyAssertionAxiomImpl,
OWLNegativeObjectPropertyAssertionAxiomImpl,
OWLObjectAllValuesFromImpl,
OWLObjectComplementOfImpl,
OWLObjectExactCardinalityImpl,
OWLObjectHasSelfImpl,
OWLObjectHasValueImpl,
OWLObjectIntersectionOfImpl,
OWLObjectInverseOfImpl,
OWLObjectMaxCardinalityImpl,
OWLObjectMinCardinalityImpl,
OWLObjectOneOfImpl,
OWLObjectPropertyAssertionAxiomImpl,
OWLObjectPropertyDomainAxiomImpl,
OWLObjectPropertyImpl,
OWLObjectPropertyRangeAxiomImpl,
OWLObjectSomeValuesFromImpl,
OWLObjectUnionOfImpl,
OWLReflexiveObjectPropertyAxiomImpl,
OWLSameIndividualAxiomImpl,
OWLSubAnnotationPropertyOfAxiomImpl,
OWLSubClassOfAxiomImpl,
OWLSubDataPropertyOfAxiomImpl,
OWLSubObjectPropertyOfAxiomImpl,
OWLSubPropertyChainAxiomImpl,
OWLSymmetricObjectPropertyAxiomImpl,
OWLTransitiveObjectPropertyAxiomImpl,
)
[docs]
def init(the_class):
"""Since classes names in owlapi and owlapy are pretty much similar with the small difference that in owlapi they
usually have the 'Impl' part then we can create the mapping class name dynamically reducing the amount of code
significantly. That's what this method does."""
cls_name = the_class.__class__.__name__
if "Impl" in cls_name:
return globals().get(cls_name.split(".")[-1].replace("Impl", ""))
else:
return globals().get(cls_name + "Impl")
# Integer-valued XSD types without a dedicated owlapy constant are represented by a plain OWLDatatype.
_XSD_OTHER_INTEGER_TYPES = tuple(
OWLDatatype(IRI(namespaces.XSD, name))
for name in ("short", "byte", "unsignedLong", "unsignedInt", "unsignedShort", "unsignedByte"))
_XSD_INTEGER_TYPES = (IntegerOWLDatatype, IntOWLDatatype, LongOWLDatatype, PositiveIntegerOWLDatatype, NegativeIntegerOWLDatatype,
NonPositiveIntegerOWLDatatype, NonNegativeIntegerOWLDatatype) + _XSD_OTHER_INTEGER_TYPES
# Full datatype IRI -> OWLDatatype, used to map OWLAPI literals back to typed owlapy literals.
_XSD_NUMERIC_TYPES = {t.str: t for t in (*_XSD_INTEGER_TYPES, FloatOWLDatatype, DoubleOWLDatatype, DecimalOWLDatatype)}
def _lexical_form(literal: OWLLiteral) -> str:
"""Lexical form of a literal as XSD defines it (ISO 8601 for date/time values)."""
if literal.is_datetime():
return literal.parse_datetime().isoformat()
if literal.is_date():
return literal.parse_date().isoformat()
if literal.is_time():
return literal.parse_time().isoformat()
if literal.is_boolean():
return "true" if literal.parse_boolean() else "false"
return literal.get_literal()
_SO = TypeVar('_SO', bound='SyncOntology') # noqa: F821
[docs]
class OWLAPIMapper:
"""A bridge between owlapy and owlapi owl-related classes."""
[docs]
@singledispatchmethod
def map_(self, e):
""" (owlapy <--> owlapi) entity mapping.
Args:
e: OWL entity/expression.
"""
if isinstance(e, Iterable):
return self.map_(list(e))
raise NotImplementedError(f"Not implemented type: {e}")
@map_.register
def _(self, e: IRI):
return owlapi_IRI.create(e.str)
@map_.register
def _(self, e: owlapi_IRI):
return IRI.create(str(e.getIRIString()))
@map_.register(OWLNamedIndividual)
@map_.register(OWLDataProperty)
@map_.register(OWLObjectProperty)
@map_.register(OWLDatatype)
@map_.register(OWLAnnotationProperty)
@map_.register(OWLClass)
def _(self, e):
return init(e)(self.map_(e.iri))
@map_.register(OWLNamedIndividualImpl)
@map_.register(OWLDataPropertyImpl)
@map_.register(OWLObjectPropertyImpl)
@map_.register(OWLDatatypeImpl)
@map_.register(OWLAnnotationPropertyImpl)
@map_.register(OWLClassImpl)
def _(self, e):
return init(e)(self.map_(e.getIRI()))
@map_.register(OWLAnonymousIndividual)
def _(self, e):
return OWLAnonymousIndividualImpl(owlapi_NodeID.getNodeID(e.node_id))
@map_.register(OWLAnonymousIndividualImpl)
def _(self, e):
return OWLAnonymousIndividual(str(e.getID().getID()))
@map_.register(OWL2DatatypeImpl)
def _(self, e):
return OWLDatatype(self.map_(e.getIRI()))
@map_.register
def _(self, e: OWLObjectComplementOf):
return init(e)(self.map_(e.get_operand()))
@map_.register
def _(self, e: OWLObjectComplementOfImpl):
return init(e)(self.map_(e.getOperand()))
@map_.register(OWLObjectMinCardinality)
@map_.register(OWLObjectMaxCardinality)
@map_.register(OWLObjectExactCardinality)
@map_.register(OWLDataMinCardinality)
@map_.register(OWLDataMaxCardinality)
@map_.register(OWLDataExactCardinality)
def _(self, e):
return init(e)(self.map_(e.get_property()), e.get_cardinality(), self.map_(e.get_filler()))
@map_.register(OWLObjectMinCardinalityImpl)
@map_.register(OWLObjectMaxCardinalityImpl)
@map_.register(OWLObjectExactCardinalityImpl)
@map_.register(OWLDataMinCardinalityImpl)
@map_.register(OWLDataMaxCardinalityImpl)
@map_.register(OWLDataExactCardinalityImpl)
def _(self, e):
return init(e)(e.getCardinality(), self.map_(e.getProperty()), self.map_(e.getFiller()))
@map_.register(OWLObjectHasSelf)
def _(self, e):
return init(e)(self.map_(e.get_property()))
@map_.register(OWLObjectHasSelfImpl)
def _(self, e):
return init(e)(self.map_(e.getProperty()))
@map_.register(OWLObjectHasValue)
@map_.register(OWLObjectSomeValuesFrom)
@map_.register(OWLObjectAllValuesFrom)
@map_.register(OWLDataSomeValuesFrom)
@map_.register(OWLDataAllValuesFrom)
@map_.register(OWLDataHasValue)
def _(self, e):
return init(e)(self.map_(e.get_property()), self.map_(e.get_filler()))
@map_.register(OWLObjectHasValueImpl)
@map_.register(OWLObjectSomeValuesFromImpl)
@map_.register(OWLObjectAllValuesFromImpl)
@map_.register(OWLDataSomeValuesFromImpl)
@map_.register(OWLDataAllValuesFromImpl)
@map_.register(OWLDataHasValueImpl)
def _(self, e):
return init(e)(self.map_(e.getProperty()), self.map_(e.getFiller()))
@map_.register
def _(self, e: OWLLiteral):
datatype = e.get_datatype()
# Types OWLAPI has a compact implementation for; everything else (xsd:int, xsd:long, xsd:decimal,
# dates, ...) is built with its own datatype so it survives the round trip.
if datatype == StringOWLDatatype:
return OWLLiteralImplString(e.get_literal())
elif datatype == BooleanOWLDatatype:
return OWLLiteralImplBoolean(e.parse_boolean())
elif datatype == IntegerOWLDatatype:
return OWLLiteralImplInteger(e.parse_integer())
elif datatype == DoubleOWLDatatype:
return OWLLiteralImplDouble(e.parse_double())
elif datatype == FloatOWLDatatype:
return OWLLiteralImplFloat(e.parse_float())
return OWLLiteralImplNoCompression(_lexical_form(e), "", self.map_(datatype))
@map_.register(OWLLiteralImplBoolean)
def _(self, e):
raw_value = str(e.getLiteral())
if raw_value.lower() == "true":
return OWLLiteral(True)
return OWLLiteral(False)
@map_.register(OWLLiteralImplDouble)
def _(self, e):
return OWLLiteral(float(str(e.getLiteral())))
@map_.register(OWLLiteralImplFloat)
def _(self, e):
return OWLLiteral(float(str(e.getLiteral())), type_=FloatOWLDatatype)
@map_.register(OWLLiteralImplString)
def _(self, e):
return OWLLiteral(str(e.getLiteral()))
@map_.register
def _(self, e: OWLLiteralImplInteger):
return OWLLiteral(int(str(e.getLiteral())))
@map_.register
def _(self, e: OWLLiteralImplNoCompression):
datatype_iri = str(e.getDatatype().getIRI())
literal_val = str(e.getLiteral())
type_ = _XSD_NUMERIC_TYPES.get(datatype_iri)
try:
if type_ in _XSD_INTEGER_TYPES:
return OWLLiteral(int(literal_val), type_=type_)
elif type_ in (FloatOWLDatatype, DoubleOWLDatatype):
return OWLLiteral(float(literal_val), type_=type_)
elif type_ == DecimalOWLDatatype:
return OWLLiteral(Decimal(literal_val), type_=type_)
elif datatype_iri == BooleanOWLDatatype.str:
return OWLLiteral(literal_val.strip().lower() in ("true", "1"))
elif datatype_iri == DateOWLDatatype.str:
return OWLLiteral(date.fromisoformat(literal_val), type_=DateOWLDatatype)
elif datatype_iri == DateTimeOWLDatatype.str:
return OWLLiteral(datetime.fromisoformat(literal_val), type_=DateTimeOWLDatatype)
elif datatype_iri == TimeOWLDatatype.str:
return OWLLiteral(time.fromisoformat(literal_val), type_=TimeOWLDatatype)
except (ValueError, ArithmeticError):
pass # lexical form not representable by the Python type: keep it verbatim below
if datatype_iri == StringOWLDatatype.str:
return OWLLiteral(literal_val)
# Any other datatype (duration, gYear..., hexBinary, anyURI, string-derived, custom): keep the lexical
# form together with the original datatype rather than degrading to xsd:string.
return lexical_literal(literal_val, OWLDatatype(IRI.create(datatype_iri)))
@map_.register
def _(self, e: OWLLiteralImplPlain):
# Language-tagged / plain literals: owlapy literals carry no language tag, so only the lexical form is kept.
return OWLLiteral(str(e.getLiteral()))
@map_.register
def _(self, e: OWLObjectInverseOf):
return init(e)(self.map_(e.get_named_property()))
@map_.register
def _(self, e: OWLObjectInverseOfImpl):
return init(e)(self.map_(e.getNamedProperty()))
@map_.register(OWLDataIntersectionOf)
@map_.register(OWLDataOneOf)
@map_.register(OWLDataUnionOf)
@map_.register(OWLNaryDataRange)
@map_.register(OWLObjectIntersectionOf)
@map_.register(OWLObjectUnionOf)
def _(self, e):
return init(e)(self.map_(e.operands()))
@map_.register(OWLDataIntersectionOfImpl)
@map_.register(OWLDataOneOfImpl)
@map_.register(OWLDataUnionOfImpl)
@map_.register(OWLNaryDataRangeImpl)
@map_.register(OWLObjectIntersectionOfImpl)
@map_.register(OWLObjectUnionOfImpl)
@map_.register(OWLObjectOneOfImpl)
def _(self, e):
return init(e)(self.map_(e.getOperandsAsList()))
@map_.register(OWLObjectOneOf)
def _(self, e):
return init(e)(self.map_(e.operands()).stream())
@map_.register(OWLDataComplementOfImpl)
def _(self, e):
return OWLDataComplementOf(self.map_(e.getDataRange()))
@map_.register(OWLDataComplementOf)
def _(self, e):
return OWLDataComplementOfImpl(self.map_(e.get_data_range()))
@map_.register(OWLFacet)
def _(self, e):
return owlapi_OWLFacet.getFacetBySymbolicName(e.symbolic_form)
@map_.register(owlapi_OWLFacet)
def _(self, e):
return OWLFacet.from_str(str(e.getSymbolicForm()))
@map_.register(OWLFacetRestriction)
def _(self, e):
return OWLFacetRestrictionImpl(self.map_(e.get_facet()), self.map_(e.get_facet_value()))
@map_.register(OWLFacetRestrictionImpl)
def _(self, e):
return OWLFacetRestriction(self.map_(e.getFacet()), self.map_(e.getFacetValue()))
@map_.register(OWLDatatypeRestriction)
def _(self, e):
return OWLDatatypeRestrictionImpl(self.map_(e.get_datatype()), self.map_(e.get_facet_restrictions()))
@map_.register(OWLDatatypeRestrictionImpl)
def _(self, e):
return OWLDatatypeRestriction(self.map_(e.getDatatype()), self.map_(e.facetRestrictionsAsList()))
@map_.register
def _(self, e: OWLAnnotation):
return OWLAnnotationImpl(self.map_(e.get_property()), self.map_(e.get_value()), Stream.empty())
@map_.register
def _(self, e: OWLAnnotationImpl):
return OWLAnnotation(self.map_(e.getProperty()), self.map_(e.getValue()))
@map_.register
def _(self, e: OWLAnnotationAssertionAxiom):
return OWLAnnotationAssertionAxiomImpl(self.map_(e.get_subject()), self.map_(e.get_property()),
self.map_(e.get_value()), self.map_(e.annotations()))
@map_.register
def _(self, e: OWLAnnotationAssertionAxiomImpl):
return OWLAnnotationAssertionAxiom(self.map_(e.getSubject()),
OWLAnnotation(self.map_(e.getProperty()), self.map_(e.getValue())),
self.map_(e.annotationsAsList()))
@map_.register(OWLDeclarationAxiom)
def _(self, e):
return OWLDeclarationAxiomImpl(self.map_(e.get_entity()), self.map_(e.annotations()))
@map_.register(OWLDeclarationAxiomImpl)
def _(self, e):
return OWLDeclarationAxiom(self.map_(e.getEntity()), self.map_(e.annotationsAsList()))
@map_.register
def _(self, e: OWLClassAssertionAxiom):
return OWLClassAssertionAxiomImpl(self.map_(e.get_individual()), self.map_(e.get_class_expression()),
self.map_(e.annotations()))
@map_.register(OWLClassAssertionAxiomImpl)
def _(self, e):
return OWLClassAssertionAxiom(self.map_(e.getIndividual()), self.map_(e.getClassExpression()),
self.map_(e.annotationsAsList()))
@map_.register(OWLObjectPropertyAssertionAxiom)
@map_.register(OWLDataPropertyAssertionAxiom)
@map_.register(OWLNegativeDataPropertyAssertionAxiom)
@map_.register(OWLNegativeObjectPropertyAssertionAxiom)
def _(self, e):
return init(e)(self.map_(e.get_subject()), self.map_(e.get_property()), self.map_(e.get_object()),
self.map_(e.annotations()))
@map_.register(OWLObjectPropertyAssertionAxiomImpl)
@map_.register(OWLDataPropertyAssertionAxiomImpl)
@map_.register(OWLNegativeDataPropertyAssertionAxiomImpl)
@map_.register(OWLNegativeObjectPropertyAssertionAxiomImpl)
def _(self, e):
return init(e)(self.map_(e.getSubject()), self.map_(e.getProperty()), self.map_(e.getObject()),
self.map_(e.annotationsAsList()))
@map_.register(OWLObjectPropertyDomainAxiom)
@map_.register(OWLDataPropertyDomainAxiom)
@map_.register(OWLAnnotationPropertyDomainAxiom)
def _(self, e):
return init(e)(self.map_(e.get_property()), self.map_(e.get_domain()), self.map_(e.annotations()))
@map_.register(OWLObjectPropertyDomainAxiomImpl)
@map_.register(OWLDataPropertyDomainAxiomImpl)
@map_.register(OWLAnnotationPropertyDomainAxiomImpl)
def _(self, e):
return init(e)(self.map_(e.getProperty()), self.map_(e.getDomain()), self.map_(e.annotationsAsList()))
@map_.register(OWLObjectPropertyRangeAxiom)
@map_.register(OWLDataPropertyRangeAxiom)
@map_.register(OWLAnnotationPropertyRangeAxiom)
def _(self, e):
return init(e)(self.map_(e.get_property()), self.map_(e.get_range()), self.map_(e.annotations()))
@map_.register(OWLObjectPropertyRangeAxiomImpl)
@map_.register(OWLDataPropertyRangeAxiomImpl)
@map_.register(OWLAnnotationPropertyRangeAxiomImpl)
def _(self, e):
return init(e)(self.map_(e.getProperty()), self.map_(e.getRange()), self.map_(e.annotationsAsList()))
@map_.register(OWLSubPropertyChainAxiom)
def _(self, e):
return init(e)(
self.map_(e.get_property_chain()),
self.map_(e.get_super_property()),
self.map_(e.annotations()))
@map_.register(OWLSubPropertyChainAxiomImpl)
def _(self, e):
property_chain_list = self.map_(e.getPropertyChain())
return init(e)(
tuple(property_chain_list),
self.map_(e.getSuperProperty()),
self.map_(e.annotationsAsList()))
@map_.register(OWLEquivalentDataPropertiesAxiom)
@map_.register(OWLEquivalentObjectPropertiesAxiom)
def _(self, e):
return init(e)(self.map_(e.properties()), self.map_(e.annotations()))
@map_.register(OWLEquivalentClassesAxiomImpl)
@map_.register(OWLEquivalentDataPropertiesAxiomImpl)
@map_.register(OWLEquivalentObjectPropertiesAxiomImpl)
def _(self, e):
return init(e)(self.map_(e.getOperandsAsList()), self.map_(e.annotationsAsList()))
@map_.register(OWLEquivalentClassesAxiom)
@map_.register(OWLDisjointClassesAxiom)
def _(self, e):
return init(e)(self.map_(e.class_expressions()), self.map_(e.annotations()))
@map_.register(OWLDisjointDataPropertiesAxiom)
@map_.register(OWLDisjointObjectPropertiesAxiom)
def _(self, e):
return init(e)(self.map_(e.properties()), self.map_(e.annotations()))
@map_.register(OWLDisjointClassesAxiomImpl)
@map_.register(OWLDisjointDataPropertiesAxiomImpl)
@map_.register(OWLDisjointObjectPropertiesAxiomImpl)
def _(self, e):
return init(e)(self.map_(e.getOperandsAsList()), self.map_(e.annotationsAsList()))
@map_.register
def _(self, e: OWLHasKeyAxiom):
return OWLHasKeyAxiomImpl(self.map_(e.get_class_expression()), self.map_(e.get_property_expressions()),
self.map_(e.annotations()))
@map_.register(OWLHasKeyAxiomImpl)
def _(self, e):
return OWLHasKeyAxiom(self.map_(e.getClassExpression()), self.map_(e.getOperandsAsList()),
self.map_(e.annotationsAsList()))
@map_.register
def _(self, e: OWLSubClassOfAxiom):
return OWLSubClassOfAxiomImpl(self.map_(e.get_sub_class()), self.map_(e.get_super_class()),
self.map_(e.annotations()))
@map_.register(OWLSubClassOfAxiomImpl)
def _(self, e):
return OWLSubClassOfAxiom(self.map_(e.getSubClass()), self.map_(e.getSuperClass()),
self.map_(e.annotationsAsList()))
@map_.register(OWLSubDataPropertyOfAxiom)
@map_.register(OWLSubObjectPropertyOfAxiom)
@map_.register(OWLSubAnnotationPropertyOfAxiom)
def _(self, e):
return init(e)(self.map_(e.get_sub_property()), self.map_(e.get_super_property()), self.map_(e.annotations()))
@map_.register(OWLSubDataPropertyOfAxiomImpl)
@map_.register(OWLSubObjectPropertyOfAxiomImpl)
@map_.register(OWLSubAnnotationPropertyOfAxiomImpl)
def _(self, e):
return init(e)(self.map_(e.getSubProperty()), self.map_(e.getSuperProperty()),
self.map_(e.annotationsAsList()))
@map_.register(OWLAsymmetricObjectPropertyAxiom)
@map_.register(OWLFunctionalDataPropertyAxiom)
@map_.register(OWLFunctionalObjectPropertyAxiom)
@map_.register(OWLInverseFunctionalObjectPropertyAxiom)
@map_.register(OWLIrreflexiveObjectPropertyAxiom)
@map_.register(OWLReflexiveObjectPropertyAxiom)
@map_.register(OWLSymmetricObjectPropertyAxiom)
@map_.register(OWLTransitiveObjectPropertyAxiom)
def _(self, e):
return init(e)(self.map_(e.get_property()), self.map_(e.annotations()))
@map_.register(OWLAsymmetricObjectPropertyAxiomImpl)
@map_.register(OWLFunctionalDataPropertyAxiomImpl)
@map_.register(OWLFunctionalObjectPropertyAxiomImpl)
@map_.register(OWLInverseFunctionalObjectPropertyAxiomImpl)
@map_.register(OWLIrreflexiveObjectPropertyAxiomImpl)
@map_.register(OWLReflexiveObjectPropertyAxiomImpl)
@map_.register(OWLSymmetricObjectPropertyAxiomImpl)
@map_.register(OWLTransitiveObjectPropertyAxiomImpl)
def _(self, e):
return init(e)(self.map_(e.getProperty()), self.map_(e.annotationsAsList()))
@map_.register(OWLDatatypeDefinitionAxiom)
def _(self, e):
return OWLDatatypeDefinitionAxiomImpl(self.map_(e.get_datatype()), self.map_(e.get_datarange()),
self.map_(e.annotations()))
@map_.register(OWLDatatypeDefinitionAxiomImpl)
def _(self, e):
return OWLDatatypeDefinitionAxiom(self.map_(e.getDatatype()), self.map_(e.getDataRange()),
self.map_(e.annotationsAsList()))
@map_.register(OWLDifferentIndividualsAxiom)
@map_.register(OWLSameIndividualAxiom)
def _(self, e):
return init(e)(self.map_(e.individuals()), self.map_(e.annotations()))
@map_.register(OWLDifferentIndividualsAxiomImpl)
@map_.register(OWLSameIndividualAxiomImpl)
def _(self, e):
return init(e)(self.map_(e.getIndividualsAsList()), self.map_(e.annotationsAsList()))
@map_.register(OWLDisjointUnionAxiom)
def _(self, e):
return OWLDisjointUnionAxiomImpl(self.map_(e.get_owl_class()), self.map_(e.get_class_expressions()).stream(),
self.map_(e.annotations()))
@map_.register(OWLDisjointUnionAxiomImpl)
def _(self, e):
return OWLDisjointUnionAxiom(self.map_(e.getOWLClass()), self.map_(e.getOperandsAsList()),
self.map_(e.annotationsAsList()))
@map_.register(OWLInverseObjectPropertiesAxiom)
def _(self, e):
return OWLInverseObjectPropertiesAxiomImpl(self.map_(e.get_first_property()),
self.map_(e.get_second_property()), self.map_(e.annotations()))
@map_.register(OWLInverseObjectPropertiesAxiomImpl)
def _(self, e):
return OWLInverseObjectPropertiesAxiom(self.map_(e.getFirstProperty()), self.map_(e.getSecondProperty()),
self.map_(e.annotationsAsList()))
@map_.register(OWLOntologyID)
def _(self, e):
if e.get_ontology_iri():
i1 = self.map_(e.get_ontology_iri())
else:
i1 = None
if e.get_version_iri():
i2 = self.map_(e.get_version_iri())
else:
i2 = None
return owlapi_OWLOntologyID(i1, i2)
@map_.register(owlapi_OWLOntologyID)
def _(self, e):
return OWLOntologyID(self.map_(e.getOntologyIRI()), self.map_(e.getVersionIRI()))
@map_.register(Optional)
def _(self, e):
if bool(e.isPresent()):
return self.map_(e.get())
else:
return None
@map_.register(List)
@map_.register(Set)
@map_.register(LinkedHashSet)
@map_.register(HashSet)
@map_.register(ArrayList)
def _(self, e):
python_list = list()
casted_list = list(e)
if e and len(casted_list) > 0:
for obj in list(e):
python_list.append(self.map_(obj))
# reverse to have the same order as the mapped iterable object
python_list.reverse()
return python_list
@map_.register(list)
@map_.register(set)
@map_.register(frozenset)
@map_.register(tuple)
def _(self, e):
java_list = ArrayList()
if e is not None and len(e) > 0:
for item in e:
java_list.add(self.map_(item))
# reverse to have the same order as the mapped iterable object
Collections.reverse(java_list)
return java_list
@map_.register(Stream)
def _(self, e):
for en in self.to_list(e):
yield self.map_(en)
[docs]
@staticmethod
def to_list(stream_obj):
"""Converts Java Stream object to Python list"""
return stream_obj.collect(jpype.JClass("java.util.stream.Collectors").toList())