diff --git a/README.md b/README.md index e24bc777..b13af488 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,7 @@ from owlapy.owlapi_adaptor import OWLAPIAdaptor adaptor = OWLAPIAdaptor(path="KGs/Family/family-benchmark_rich_background.owl", name_reasoner="Pellet") # Infer missing class assertions -adaptor.infer_and_save(output_path="KGs/Family/inferred_family-benchmark_rich_background.ttl", +adaptor.infer_axioms_and_save(output_path="KGs/Family/inferred_family-benchmark_rich_background.ttl", output_format="ttl", inference_types=[ "InferredClassAssertionAxiomGenerator", diff --git a/docs/conf.py b/docs/conf.py index 948ea4fc..55a57422 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -70,6 +70,8 @@ html_favicon = '_static/images/favicon.ico' +html_extra_path = ["googlec4c425077889c69c.html"] + if stanford_theme_mod: html_theme = 'sphinx_rtd_theme' diff --git a/docs/googlec4c425077889c69c.html b/docs/googlec4c425077889c69c.html new file mode 100644 index 00000000..097d4e5f --- /dev/null +++ b/docs/googlec4c425077889c69c.html @@ -0,0 +1 @@ +google-site-verification: googlec4c425077889c69c.html \ No newline at end of file diff --git a/owlapy/owl_axiom.py b/owlapy/owl_axiom.py index 4fd4119f..2792738c 100644 --- a/owlapy/owl_axiom.py +++ b/owlapy/owl_axiom.py @@ -723,7 +723,8 @@ class OWLAnnotationAssertionAxiom(OWLAnnotationAxiom): _subject: OWLAnnotationSubject _annotation: OWLAnnotation - def __init__(self, subject: OWLAnnotationSubject, annotation: OWLAnnotation): + def __init__(self, subject: OWLAnnotationSubject, annotation: OWLAnnotation, + annotations: Optional[Iterable['OWLAnnotation']] = None): """Get an annotation assertion axiom - with annotations. Args: @@ -732,7 +733,7 @@ def __init__(self, subject: OWLAnnotationSubject, annotation: OWLAnnotation): """ assert isinstance(subject, OWLAnnotationSubject) assert isinstance(annotation, OWLAnnotation) - + super().__init__(annotations) self._subject = subject self._annotation = annotation @@ -769,7 +770,7 @@ def __hash__(self): return hash((self._subject, self._annotation)) def __repr__(self): - return f'OWLAnnotationAssertionAxiom({self._subject}, {self._annotation})' + return f'OWLAnnotationAssertionAxiom({self._subject}, {self._annotation}, {self.annotations()})' class OWLSubAnnotationPropertyOfAxiom(OWLAnnotationAxiom): """An annotation subproperty axiom SubAnnotationPropertyOf( AP1 AP2 ) states that the annotation property AP1 is a subproperty of the annotation property AP2. diff --git a/owlapy/owlapi_adaptor.py b/owlapy/owlapi_adaptor.py index a6cddb00..856cef2b 100644 --- a/owlapy/owlapi_adaptor.py +++ b/owlapy/owlapi_adaptor.py @@ -7,10 +7,11 @@ import pkg_resources from owlapy.class_expression import OWLClassExpression +from owlapy.owl_axiom import OWLAxiom from owlapy.owl_individual import OWLNamedIndividual from owlapy.owl_object import OWLEntity from owlapy.owl_property import OWLDataProperty, OWLObjectProperty -from typing import List +from typing import List, Iterable def to_list(stream_obj): @@ -86,6 +87,30 @@ def _setup(self): from owlapy.owlapi_mapper import OWLAPIMapper from org.semanticweb.owlapi.apibinding import OWLManager from java.io import File + from org.semanticweb.owlapi.util import (InferredClassAssertionAxiomGenerator, InferredSubClassAxiomGenerator, + InferredEquivalentClassAxiomGenerator, + InferredDisjointClassesAxiomGenerator, + InferredEquivalentDataPropertiesAxiomGenerator, + InferredEquivalentObjectPropertyAxiomGenerator, + InferredInverseObjectPropertiesAxiomGenerator, + InferredSubDataPropertyAxiomGenerator, + InferredSubObjectPropertyAxiomGenerator, + InferredDataPropertyCharacteristicAxiomGenerator, + InferredObjectPropertyCharacteristicAxiomGenerator) + + self.inference_types_mapping = {"InferredClassAssertionAxiomGenerator": InferredClassAssertionAxiomGenerator(), + "InferredSubClassAxiomGenerator": InferredSubClassAxiomGenerator(), + "InferredDisjointClassesAxiomGenerator": InferredDisjointClassesAxiomGenerator(), + "InferredEquivalentClassAxiomGenerator": InferredEquivalentClassAxiomGenerator(), + "InferredInverseObjectPropertiesAxiomGenerator": InferredInverseObjectPropertiesAxiomGenerator(), + "InferredEquivalentDataPropertiesAxiomGenerator": InferredEquivalentDataPropertiesAxiomGenerator(), + "InferredEquivalentObjectPropertyAxiomGenerator": InferredEquivalentObjectPropertyAxiomGenerator(), + "InferredSubDataPropertyAxiomGenerator": InferredSubDataPropertyAxiomGenerator(), + "InferredSubObjectPropertyAxiomGenerator": InferredSubObjectPropertyAxiomGenerator(), + "InferredDataPropertyCharacteristicAxiomGenerator": InferredDataPropertyCharacteristicAxiomGenerator(), + "InferredObjectPropertyCharacteristicAxiomGenerator": InferredObjectPropertyCharacteristicAxiomGenerator(), + } + if self.name_reasoner == "HermiT": from org.semanticweb.HermiT import ReasonerFactory elif self.name_reasoner == "Pellet": @@ -450,12 +475,65 @@ def types(self, i: OWLNamedIndividual, direct: bool = False): yield from [self.mapper.map_(ind) for ind in self.reasoner.getTypes(self.mapper.map_(i), direct).getFlattened()] - def infer_and_save(self, output_path: str = None, output_format: str = None, inference_types: list[str] = None): + def infer_axioms(self, inference_types: list[str]) -> Iterable[OWLAxiom]: + """ + Infer the specified inference type of axioms for the ontology managed by this instance's reasoner and + return them. + + Args: + inference_types: Axiom inference types: Avaliable options (can set more than 1): + ["InferredClassAssertionAxiomGenerator", "InferredSubClassAxiomGenerator", + "InferredDisjointClassesAxiomGenerator", "InferredEquivalentClassAxiomGenerator", + "InferredEquivalentDataPropertiesAxiomGenerator","InferredEquivalentObjectPropertyAxiomGenerator", + "InferredInverseObjectPropertiesAxiomGenerator","InferredSubDataPropertyAxiomGenerator", + "InferredSubObjectPropertyAxiomGenerator","InferredDataPropertyCharacteristicAxiomGenerator", + "InferredObjectPropertyCharacteristicAxiomGenerator" + ] + + Returns: + Iterable of inferred axioms. + """ + from java.util import ArrayList + from org.semanticweb.owlapi.util import InferredOntologyGenerator + + generators = ArrayList() + for i in inference_types: + if java_object := self.inference_types_mapping.get(i, None): + generators.add(java_object) + iog = InferredOntologyGenerator(self.reasoner, generators) + inferred_axioms = list(iog.getAxiomGenerators()) + for ia in inferred_axioms: + for axiom in ia.createAxioms(self.manager.getOWLDataFactory(), self.reasoner): + yield self.mapper.map_(axiom) + + def infer_axioms_and_save(self, output_path: str = None, output_format: str = None, inference_types: list[str] = None): + """ + Generates inferred axioms for the ontology managed by this instance's reasoner and saves them to a file. + This function uses the OWL API to generate inferred class assertion axioms based on the ontology and reasoner + associated with this instance. The inferred axioms are saved to the specified output file in the desired format. + + Args: + output_path : The name of the file where the inferred axioms will be saved. + output_format : The format in which to save the inferred axioms. Supported formats are: + - "ttl" or "turtle" for Turtle format + - "rdf/xml" for RDF/XML format + - "owl/xml" for OWL/XML format + If not specified, the format of the original ontology is used. + inference_types: Axiom inference types: Avaliable options (can set more than 1): + ["InferredClassAssertionAxiomGenerator", "InferredSubClassAxiomGenerator", + "InferredDisjointClassesAxiomGenerator", "InferredEquivalentClassAxiomGenerator", + "InferredEquivalentDataPropertiesAxiomGenerator","InferredEquivalentObjectPropertyAxiomGenerator", + "InferredInverseObjectPropertiesAxiomGenerator","InferredSubDataPropertyAxiomGenerator", + "InferredSubObjectPropertyAxiomGenerator","InferredDataPropertyCharacteristicAxiomGenerator", + "InferredObjectPropertyCharacteristicAxiomGenerator" + ] + + Returns: + None (the file is saved to the specified directory) + """ from java.io import File, FileOutputStream from java.util import ArrayList - from org.semanticweb.owlapi.util import InferredSubClassAxiomGenerator, InferredClassAssertionAxiomGenerator - from org.semanticweb.owlapi.util import InferredOntologyGenerator, InferredEquivalentClassAxiomGenerator,InferredInverseObjectPropertiesAxiomGenerator - from org.semanticweb.owlapi.util import InferredDisjointClassesAxiomGenerator + from org.semanticweb.owlapi.util import InferredOntologyGenerator from org.semanticweb.owlapi.formats import TurtleDocumentFormat, RDFXMLDocumentFormat, OWLXMLDocumentFormat if output_format == "ttl" or output_format == "turtle": document_format = TurtleDocumentFormat() @@ -466,14 +544,9 @@ def infer_and_save(self, output_path: str = None, output_format: str = None, inf else: document_format = self.manager.getOntologyFormat(self.ontology) generators = ArrayList() - inference_types_mapping = {"InferredClassAssertionAxiomGenerator": InferredClassAssertionAxiomGenerator(), - "InferredSubClassAxiomGenerator": InferredSubClassAxiomGenerator(), - "InferredDisjointClassesAxiomGenerator":InferredDisjointClassesAxiomGenerator(), - "InferredEquivalentClassAxiomGenerator":InferredEquivalentClassAxiomGenerator(), - "InferredInverseObjectPropertiesAxiomGenerator":InferredInverseObjectPropertiesAxiomGenerator(), - "InferredEquivalentClassAxiomGenerator":InferredEquivalentClassAxiomGenerator()} + for i in inference_types: - if java_object := inference_types_mapping.get(i, None): + if java_object := self.inference_types_mapping.get(i, None): generators.add(java_object) iog = InferredOntologyGenerator(self.reasoner, generators) inferred_axioms_ontology = self.manager.createOntology() @@ -482,7 +555,7 @@ def infer_and_save(self, output_path: str = None, output_format: str = None, inf output_stream = FileOutputStream(inferred_ontology_file) self.manager.saveOntology(inferred_axioms_ontology, document_format, output_stream) - def generate_inferred_class_assertion_axioms(self, output="temp.ttl", output_format: str = None): + def generate_and_save_inferred_class_assertion_axioms(self, output="temp.ttl", output_format: str = None): """ Generates inferred class assertion axioms for the ontology managed by this instance's reasoner and saves them to a file. This function uses the OWL API to generate inferred class assertion axioms based on the ontology and reasoner @@ -508,4 +581,4 @@ def generate_inferred_class_assertion_axioms(self, output="temp.ttl", output_for >>> instance.generate_inferred_class_assertion_axioms(output="inferred_axioms.ttl", format="ttl") This will save the inferred class assertion axioms to the file "inferred_axioms.ttl" in Turtle format. """ - self.infer_and_save(output, output_format, ["InferredClassAssertionAxiomGenerator"]) + self.infer_axioms_and_save(output, output_format, ["InferredClassAssertionAxiomGenerator"]) diff --git a/owlapy/owlapi_mapper.py b/owlapy/owlapi_mapper.py index b2b82ec5..1b9d0be9 100644 --- a/owlapy/owlapi_mapper.py +++ b/owlapy/owlapi_mapper.py @@ -1,40 +1,93 @@ from functools import singledispatchmethod +from typing import Iterable + import jpype.imports from owlapy import owl_expression_to_manchester, manchester_to_owl_expression -from owlapy.class_expression import OWLClassExpression +from owlapy.class_expression import OWLClassExpression, OWLDataOneOf, OWLFacetRestriction, OWLDatatypeRestriction from owlapy.iri import IRI +from owlapy.owl_axiom import OWLDeclarationAxiom, OWLAnnotation, OWLAnnotationProperty, OWLClassAssertionAxiom, \ + OWLDataPropertyAssertionAxiom, OWLDataPropertyDomainAxiom, OWLDataPropertyRangeAxiom, OWLObjectPropertyDomainAxiom, \ + OWLObjectPropertyRangeAxiom, OWLObjectPropertyAssertionAxiom, OWLEquivalentClassesAxiom, \ + OWLEquivalentDataPropertiesAxiom, OWLEquivalentObjectPropertiesAxiom, OWLDisjointClassesAxiom, \ + OWLDisjointDataPropertiesAxiom, OWLDisjointObjectPropertiesAxiom, OWLHasKeyAxiom, OWLSubDataPropertyOfAxiom, \ + OWLSubClassOfAxiom, OWLSubObjectPropertyOfAxiom, OWLAsymmetricObjectPropertyAxiom, OWLDatatypeDefinitionAxiom, \ + OWLDifferentIndividualsAxiom, OWLDisjointUnionAxiom, OWLFunctionalDataPropertyAxiom, \ + OWLFunctionalObjectPropertyAxiom, OWLInverseFunctionalObjectPropertyAxiom, OWLInverseObjectPropertiesAxiom, \ + OWLIrreflexiveObjectPropertyAxiom, OWLNegativeDataPropertyAssertionAxiom, OWLReflexiveObjectPropertyAxiom, \ + OWLNegativeObjectPropertyAssertionAxiom, OWLSameIndividualAxiom, OWLSymmetricObjectPropertyAxiom, \ + OWLTransitiveObjectPropertyAxiom, OWLAnnotationAssertionAxiom, OWLAnnotationPropertyDomainAxiom, \ + OWLAnnotationPropertyRangeAxiom, OWLSubAnnotationPropertyOfAxiom +from owlapy.owl_data_ranges import OWLDataIntersectionOf, OWLDataComplementOf, OWLDataUnionOf, OWLNaryDataRange +from owlapy.owl_datatype import OWLDatatype from owlapy.owl_individual import OWLNamedIndividual from owlapy.owl_literal import OWLLiteral from owlapy.owl_property import OWLObjectProperty, OWLDataProperty +from owlapy.vocab import OWLFacet if jpype.isJVMStarted(): - from uk.ac.manchester.cs.owl.owlapi import OWLObjectPropertyImpl, OWLDataPropertyImpl, OWLNamedIndividualImpl from org.semanticweb.owlapi.model import IRI as owlapi_IRI + from org.semanticweb.owlapi.vocab import OWLFacet as owlapi_OWLFacet from org.semanticweb.owlapi.manchestersyntax.parser import ManchesterOWLSyntaxClassExpressionParser from org.semanticweb.owlapi.manchestersyntax.renderer import ManchesterOWLSyntaxOWLObjectRendererImpl from org.semanticweb.owlapi.util import BidirectionalShortFormProviderAdapter, SimpleShortFormProvider from org.semanticweb.owlapi.expression import ShortFormEntityChecker - from java.util import HashSet + from java.util import HashSet, ArrayList, List, Set + from java.util.stream import Stream from uk.ac.manchester.cs.owl.owlapi import (OWLAnonymousClassExpressionImpl, OWLCardinalityRestrictionImpl, OWLClassExpressionImpl, OWLClassImpl, OWLDataAllValuesFromImpl, OWLDataCardinalityRestrictionImpl, OWLDataExactCardinalityImpl, - OWLDataHasValueImpl, OWLDataMaxCardinalityImpl, + OWLDataHasValueImpl, OWLDataMaxCardinalityImpl, OWLDataUnionOfImpl, OWLDataMinCardinalityImpl, OWLDataSomeValuesFromImpl, OWLNaryBooleanClassExpressionImpl, OWLObjectAllValuesFromImpl, OWLObjectCardinalityRestrictionImpl, OWLObjectComplementOfImpl, OWLObjectExactCardinalityImpl, OWLObjectHasSelfImpl, OWLObjectHasValueImpl, OWLObjectIntersectionOfImpl, OWLObjectMaxCardinalityImpl, OWLObjectMinCardinalityImpl, - OWLObjectOneOfImpl, OWLObjectSomeValuesFromImpl, + OWLObjectOneOfImpl, OWLObjectSomeValuesFromImpl, OWLNaryDataRangeImpl, OWLObjectUnionOfImpl, OWLQuantifiedDataRestrictionImpl, OWLQuantifiedObjectRestrictionImpl, OWLQuantifiedRestrictionImpl, OWLValueRestrictionImpl, OWLLiteralImplBoolean, OWLLiteralImplString, - OWLLiteralImplDouble, OWLLiteralImplFloat, OWLLiteralImplInteger) + OWLLiteralImplDouble, OWLLiteralImplFloat, OWLLiteralImplInteger, + OWLDisjointClassesAxiomImpl, OWLDeclarationAxiomImpl, OWLAnnotationImpl, + OWLAnnotationPropertyImpl, OWLClassAssertionAxiomImpl, + OWLDataPropertyAssertionAxiomImpl, OWLDataPropertyDomainAxiomImpl, + OWLDataPropertyRangeAxiomImpl, OWLEquivalentClassesAxiomImpl, + OWLEquivalentDataPropertiesAxiomImpl, OWLDataIntersectionOfImpl, + OWLEquivalentObjectPropertiesAxiomImpl, OWLDataOneOfImpl, + OWLObjectPropertyDomainAxiomImpl, OWLObjectPropertyRangeAxiomImpl, + OWLObjectPropertyAssertionAxiomImpl, OWLDisjointDataPropertiesAxiomImpl, + OWLDisjointObjectPropertiesAxiomImpl, OWLHasKeyAxiomImpl, + OWLSubClassOfAxiomImpl, OWLSubDataPropertyOfAxiomImpl, + OWLSubObjectPropertyOfAxiomImpl, OWLAsymmetricObjectPropertyAxiomImpl, + OWLDatatypeDefinitionAxiomImpl, OWLDatatypeImpl, OWLObjectPropertyImpl, + OWLDataPropertyImpl, OWLNamedIndividualImpl, OWLDisjointUnionAxiomImpl, + OWLDifferentIndividualsAxiomImpl, OWLFunctionalDataPropertyAxiomImpl, + OWLFunctionalObjectPropertyAxiomImpl, OWLSameIndividualAxiomImpl, + OWLInverseFunctionalObjectPropertyAxiomImpl, OWLDataComplementOfImpl, + OWLInverseObjectPropertiesAxiomImpl,OWLReflexiveObjectPropertyAxiomImpl, + OWLIrreflexiveObjectPropertyAxiomImpl, OWLAnnotationAssertionAxiomImpl, + OWLNegativeDataPropertyAssertionAxiomImpl, OWLFacetRestrictionImpl, + OWLNegativeObjectPropertyAssertionAxiomImpl, OWLDatatypeRestrictionImpl, + OWLSymmetricObjectPropertyAxiomImpl, + OWLTransitiveObjectPropertyAxiomImpl, + OWLAnnotationPropertyDomainAxiomImpl, + OWLAnnotationPropertyRangeAxiomImpl, + OWLSubAnnotationPropertyOfAxiomImpl + ) + else: raise ImportError("Jpype JVM is not started! Tip: Import OWLAPIMapper after JVM has started") +def init(the_class): + 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") + + class OWLAPIMapper: def __init__(self, ontology): @@ -65,31 +118,34 @@ def map_(self, e): Args: e: OWL entity/expression. """ - raise NotImplementedError() + if isinstance(e, Iterable): + return self.map_(list(e)) - @map_.register - def _(self, e: OWLObjectProperty): - return OWLObjectPropertyImpl(owlapi_IRI.create(e.str)) - - @map_.register - def _(self, e: OWLObjectPropertyImpl): - return OWLObjectProperty(IRI.create(str(e.getIRI().getIRIString()))) + raise NotImplementedError(f"Not implemented type: {e}") @map_.register - def _(self, e: OWLDataProperty): - return OWLDataPropertyImpl(owlapi_IRI.create(e.str)) + def _(self, e: IRI): + return owlapi_IRI.create(e.str) @map_.register - def _(self, e: OWLDataPropertyImpl): - return OWLDataProperty(IRI.create(str(e.getIRI().getIRIString()))) + def _(self, e: owlapi_IRI): + return IRI.create(str(e.getIRIString())) - @map_.register - def _(self, e: OWLNamedIndividual): - return OWLNamedIndividualImpl(owlapi_IRI.create(e.str)) + @map_.register(OWLNamedIndividual) + @map_.register(OWLDataProperty) + @map_.register(OWLObjectProperty) + @map_.register(OWLDatatype) + @map_.register(OWLAnnotationProperty) + def _(self, e): + return init(e)(self.map_(e.iri)) - @map_.register - def _(self, e: OWLNamedIndividualImpl): - return OWLNamedIndividual(IRI.create(str(e.getIRI().getIRIString()))) + @map_.register(OWLNamedIndividualImpl) + @map_.register(OWLDataPropertyImpl) + @map_.register(OWLObjectPropertyImpl) + @map_.register(OWLDatatypeImpl) + @map_.register(OWLAnnotationPropertyImpl) + def _(self, e): + return init(e)(self.map_(e.getIRI())) @map_.register def _(self, e: OWLClassExpression): @@ -128,6 +184,19 @@ def _(self, e): # have to register all possible implementations return manchester_to_owl_expression(str(self.renderer.render(e)), self.namespace) + @map_.register + def _(self, e: OWLLiteral): + if e.is_string(): + return OWLLiteralImplString(e.get_literal()) + elif e.is_boolean(): + return OWLLiteralImplBoolean(e.parse_boolean()) + elif e.is_integer(): + return OWLLiteralImplInteger(e.parse_integer()) + elif e.is_double(): + return OWLLiteralImplDouble(e.parse_double()) + else: + raise NotImplementedError(f"Type of this literal: {e} cannot be mapped!") + @map_.register(OWLLiteralImplBoolean) def _(self, e): raw_value = str(e.getLiteral()) @@ -144,6 +213,270 @@ def _(self, e): def _(self, e): return OWLLiteral(str(e.getLiteral())) - @map_.register(OWLLiteralImplInteger) - def _(self, e): + @map_.register + def _(self, e: OWLLiteralImplInteger): return OWLLiteral(int(str(e.getLiteral()))) + + @map_.register(OWLDataIntersectionOf) + @map_.register(OWLDataOneOf) + @map_.register(OWLDataUnionOf) + @map_.register(OWLNaryDataRange) + def _(self, e): + return init(e)(self.map_(e.operands())) + + @map_.register(OWLDataIntersectionOfImpl) + @map_.register(OWLDataOneOfImpl) + @map_.register(OWLDataUnionOfImpl) + @map_.register(OWLNaryDataRangeImpl) + def _(self, e): + return init(e)(self.map_(e.getOperandsAsList())) + + @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) + @map_.register(OWLAnnotationPropertyRangeAxiom) + 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) + @map_.register(OWLAnnotationPropertyRangeAxiomImpl) + def _(self, e): + return init(e)(self.map_(e.getProperty()), self.map_(e.getDomain()), self.map_(e.annotationsAsList())) + + @map_.register(OWLObjectPropertyRangeAxiom) + @map_.register(OWLDataPropertyRangeAxiom) + 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) + def _(self, e): + return init(e)(self.map_(e.getProperty()), self.map_(e.getRange()), 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 OWLDifferentIndividualsAxiomImpl(self.map_(e.individuals()), self.map_(e.annotations())) + + @map_.register(OWLDifferentIndividualsAxiomImpl) + @map_.register(OWLSameIndividualAxiomImpl) + def _(self, e): + return OWLDifferentIndividualsAxiom(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(List) + @map_.register(Set) + 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)) + return python_list + + @map_.register(list) + @map_.register(set) + 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)) + return java_list