Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normalization error #11

Open
omashkova opened this issue Sep 28, 2024 · 0 comments
Open

Normalization error #11

omashkova opened this issue Sep 28, 2024 · 0 comments

Comments

@omashkova
Copy link

Hello. I tried to normalize the following axiom:

EquivalentClasses(<A> ObjectIntersectionOf(<B> ObjectSomeValuesFrom(<r> ObjectIntersectionOf(<C> ObjectSomeValuesFrom(<s> <D>)))))

The axiom was saved in small_ontology.owl file, the list of axioms is as follows:

Declaration(Class(<B>))
Declaration(Class(<A>))
Declaration(Class(<D>))
Declaration(ObjectProperty(<s>))
Declaration(Class(<C>))
Declaration(ObjectProperty(<r>))
EquivalentClasses(<A> ObjectIntersectionOf(<B> ObjectSomeValuesFrom(<r> ObjectIntersectionOf(<C> ObjectSomeValuesFrom(<s> <D>)))))

Here's the code; mOWL is used for loading the ontology small_ontology.owl containing the axiom, the code is written in Python and utilizes JPype to access Java:

from de.tudresden.inf.lat.jcel.ontology.normalization import OntologyNormalizer, SimpleNormalizer
from de.tudresden.inf.lat.jcel.ontology.axiom.extension import IntegerOntologyObjectFactoryImpl
from de.tudresden.inf.lat.jcel.owlapi.translator import ReverseAxiomTranslator, Translator
from de.tudresden.inf.lat.jcel.ontology.axiom.complex import IntegerInverseObjectPropertiesAxiom
from de.tudresden.inf.lat.jcel.coreontology.axiom import NormalizedIntegerAxiom
from org.semanticweb.owlapi.model.parameters import Imports
from java.util import HashSet
import logging
logging.basicConfig(level=logging.INFO)
from mowl.owlapi import OWLAPIAdapter
from mowl.datasets import PathDataset

small_ontology = PathDataset("small_ontology.owl").ontology

translator = Translator(small_ontology.getOWLOntologyManager().getOWLDataFactory(), IntegerOntologyObjectFactoryImpl())
small_axioms = HashSet()
small_axioms.addAll(small_ontology.getAxioms())
translator.getTranslationRepository().addAxiomEntities(small_ontology)

for o in small_ontology.getImportsClosure():
    small_axioms.addAll(o.getAxioms())
    translator.getTranslationRepository().addAxiomEntities(o)

intAxioms = translator.translateSA(small_axioms)

factory = IntegerOntologyObjectFactoryImpl()

n = SimpleNormalizer(factory)
objectPropIdSet = HashSet()
currentAxiomSet = HashSet()

for ax in intAxioms:
    objectPropIdSet.addAll(ax.getObjectPropertiesInSignature())
    if isinstance(ax, IntegerInverseObjectPropertiesAxiom):
        newSet = n.normalize(axiom)
        currentAxiomSet.addAll(newSet)
    else:
        currentAxiomSet.add(ax)

for propId in list(objectPropIdSet): 
	inversePropId = factory.getEntityManager().createOrGetInverseObjectPropertyOf(propId)
	currentAxiomSet.addAll(n.getAxiomsForInverseObjectProperties(propId, inversePropId))

ret = HashSet()
while currentAxiomSet.size() > 0:
    nextAxiomSet = HashSet()
    for axiom in list(currentAxiomSet):
        if isinstance(axiom, NormalizedIntegerAxiom):
            ret.add(axiom)
        else:
            newSet = n.normalize(axiom)
            nextAxiomSet.addAll(newSet)
    currentAxiomSet = nextAxiomSet

The integer-encoded normalized set of axioms is as follows:

for ax in list(ret):
    print(str(ax))

# SubClassOf*(9 8)
# SubClassOf*(ObjectIntersectionOf(8 11) 10)
# SubClassOf*(6 ObjectSomeValuesFrom(10 9))
# SubClassOf*(9 ObjectSomeValuesFrom(11 9))
# SubClassOf*(ObjectSomeValuesFrom(10 10) 8)
# SubClassOf*(ObjectIntersectionOf(7 8) 6)
# SubClassOf*(ObjectSomeValuesFrom(11 9) 11)
# SubClassOf*(6 7)

After reverse translation

rTranslator = ReverseAxiomTranslator(translator, small_ontology)
for ax in list(ret):
    try:
        axiom = rTranslator.visit(ax)
        key, value = process_axiom(axiom)
        print(str(value.owl_axiom))
    except Exception as e:
        logging.info("Reverse translation. Ignoring axiom: %s", ax)
        logging.info(e)

the output is as follows:

INFO:root:Reverse translation. Ignoring axiom: SubClassOf*(ObjectIntersectionOf(8 11) 10)
INFO:root:de.tudresden.inf.lat.jcel.owlapi.translator.TranslationException: The translation map is incomplete. Item id was not found: '11'.
INFO:root:Reverse translation. Ignoring axiom: SubClassOf*(ObjectSomeValuesFrom(10 10) 8)
INFO:root:de.tudresden.inf.lat.jcel.owlapi.translator.TranslationException: The translation map is incomplete. Item id was not found: '10'.
INFO:root:Reverse translation. Ignoring axiom: SubClassOf*(ObjectSomeValuesFrom(11 9) 11)
INFO:root:de.tudresden.inf.lat.jcel.owlapi.translator.TranslationException: The translation map is incomplete. Item id was not found: '11'.
SubClassOf(<D> <C>)
SubClassOf(<A> ObjectSomeValuesFrom(<r> <D>))
SubClassOf(<D> ObjectSomeValuesFrom(<s> <D>))
SubClassOf(ObjectIntersectionOf(<B> <C>) <A>)
SubClassOf(<A> <B>)

whereas according to normalization rules described here (table 4.2) the output should look similar to this:

SubClassOf(<A> ObjectSomeValuesFrom(<r> <A1>))
SubClassOf(ObjectSomeValuesFrom(<r> <B1>) <C1>)
SubClassOf(<A1> ObjectSomeValuesFrom(<s> <D>))
SubClassOf(ObjectSomeValuesFrom(<s> <D>) <D1>)
SubClassOf(ObjectIntersectionOf(<C> <D1>) <B1>)
SubClassOf(ObjectIntersectionOf(<C1> <B>) <A>)
SubClassOf(<A> <B>)
SubClassOf(<A1> <C>)

where A1, B1, C1, D1 are fresh concept names.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant