diff options
| author | Federico Igne <federico.igne@cs.ox.ac.uk> | 2022-05-10 18:17:06 +0100 |
|---|---|---|
| committer | Federico Igne <federico.igne@cs.ox.ac.uk> | 2022-05-11 12:34:47 +0100 |
| commit | 17bd9beaf7f358a44e5bf36a5855fe6727d506dc (patch) | |
| tree | 47e9310a0cff869d9ec017dcb2c81876407782c8 /src/uk/ac/ox/cs/pagoda/approx/RLOntology.java | |
| parent | 8651164cd632a5db310b457ce32d4fbc97bdc41c (diff) | |
| download | ACQuA-17bd9beaf7f358a44e5bf36a5855fe6727d506dc.tar.gz ACQuA-17bd9beaf7f358a44e5bf36a5855fe6727d506dc.zip | |
[pagoda] Move project to Scala
This commit includes a few changes:
- The repository still uses Maven to manage dependency but it is now a
Scala project.
- The code has been ported from OWLAPI 3.4.10 to 5.1.20
- A proof of concept program using both RSAComb and PAGOdA has been
added.
Diffstat (limited to 'src/uk/ac/ox/cs/pagoda/approx/RLOntology.java')
| -rw-r--r-- | src/uk/ac/ox/cs/pagoda/approx/RLOntology.java | 190 |
1 files changed, 0 insertions, 190 deletions
diff --git a/src/uk/ac/ox/cs/pagoda/approx/RLOntology.java b/src/uk/ac/ox/cs/pagoda/approx/RLOntology.java deleted file mode 100644 index dba6a56..0000000 --- a/src/uk/ac/ox/cs/pagoda/approx/RLOntology.java +++ /dev/null | |||
| @@ -1,190 +0,0 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.approx; | ||
| 2 | |||
| 3 | import java.util.Collection; | ||
| 4 | import java.util.HashMap; | ||
| 5 | import java.util.HashSet; | ||
| 6 | import java.util.LinkedList; | ||
| 7 | import java.util.Map; | ||
| 8 | import java.util.Set; | ||
| 9 | |||
| 10 | import org.semanticweb.owlapi.model.IRI; | ||
| 11 | import org.semanticweb.owlapi.model.OWLAxiom; | ||
| 12 | import org.semanticweb.owlapi.model.OWLClass; | ||
| 13 | import org.semanticweb.owlapi.model.OWLClassExpression; | ||
| 14 | import org.semanticweb.owlapi.model.OWLIndividual; | ||
| 15 | import org.semanticweb.owlapi.model.OWLObjectAllValuesFrom; | ||
| 16 | import org.semanticweb.owlapi.model.OWLObjectHasSelf; | ||
| 17 | import org.semanticweb.owlapi.model.OWLObjectOneOf; | ||
| 18 | import org.semanticweb.owlapi.model.OWLObjectProperty; | ||
| 19 | import org.semanticweb.owlapi.model.OWLSubClassOfAxiom; | ||
| 20 | |||
| 21 | import uk.ac.ox.cs.pagoda.owl.OWLHelper; | ||
| 22 | import uk.ac.ox.cs.pagoda.util.Utility; | ||
| 23 | |||
| 24 | public class RLOntology extends RLPlusOntology { | ||
| 25 | |||
| 26 | @Override | ||
| 27 | public void transform() { | ||
| 28 | super.transform(); | ||
| 29 | |||
| 30 | eliminateSelf(); | ||
| 31 | eliminateNominals(); | ||
| 32 | eliminateOWLThing(); | ||
| 33 | |||
| 34 | save(); | ||
| 35 | if (aBox.getAxiomCount() != 0) | ||
| 36 | save(aBox); | ||
| 37 | } | ||
| 38 | |||
| 39 | private void eliminateSelf() { | ||
| 40 | Collection<OWLAxiom> axioms = new LinkedList<OWLAxiom>(outputOntology.getAxioms()); | ||
| 41 | OWLClassExpression subExp, superExp, newSubExp, newSuperExp; | ||
| 42 | for (OWLAxiom axiom: axioms) | ||
| 43 | if (axiom instanceof OWLSubClassOfAxiom) { | ||
| 44 | subExp = ((OWLSubClassOfAxiom) axiom).getSubClass(); | ||
| 45 | superExp = ((OWLSubClassOfAxiom) axiom).getSuperClass(); | ||
| 46 | newSubExp = approximateSelf4Sub(subExp); | ||
| 47 | newSuperExp = approximateSelf4Super(superExp); | ||
| 48 | if (newSubExp != subExp || newSuperExp != superExp) | ||
| 49 | replaceAxiom4output(axiom, factory.getOWLSubClassOfAxiom(newSubExp, newSuperExp)); | ||
| 50 | } | ||
| 51 | } | ||
| 52 | |||
| 53 | private void replaceAxiom4output(OWLAxiom oldAxiom, OWLAxiom newAxiom) { | ||
| 54 | manager.removeAxiom(outputOntology, oldAxiom); | ||
| 55 | manager.addAxiom(outputOntology, newAxiom); | ||
| 56 | correspondence.put(newAxiom, correspondence.remove(oldAxiom)); | ||
| 57 | } | ||
| 58 | |||
| 59 | private boolean hasSelf(OWLClassExpression conjunction) { | ||
| 60 | for (OWLClassExpression conjunct: conjunction.asConjunctSet()) | ||
| 61 | if (conjunct instanceof OWLObjectHasSelf) | ||
| 62 | return true; | ||
| 63 | return false; | ||
| 64 | } | ||
| 65 | |||
| 66 | private OWLClassExpression approximateSelf4Sub(OWLClassExpression exp) { | ||
| 67 | if (!hasSelf(exp)) return exp; | ||
| 68 | Set<OWLClassExpression> newConjuncts = new HashSet<OWLClassExpression>(); | ||
| 69 | for (OWLClassExpression conjunct: exp.asConjunctSet()) | ||
| 70 | if (conjunct instanceof OWLObjectHasSelf) | ||
| 71 | newConjuncts.add(factory.getOWLObjectSomeValuesFrom(((OWLObjectHasSelf) exp).getProperty(), factory.getOWLThing())); | ||
| 72 | else | ||
| 73 | newConjuncts.add(conjunct); | ||
| 74 | return OWLHelper.getSimplifiedConjunction(factory, newConjuncts); | ||
| 75 | } | ||
| 76 | |||
| 77 | private OWLClassExpression approximateSelf4Super(OWLClassExpression exp) { | ||
| 78 | if (!hasSelf(exp)) return exp; | ||
| 79 | Set<OWLClassExpression> newConjuncts = new HashSet<OWLClassExpression>(); | ||
| 80 | for (OWLClassExpression conjunct: exp.asConjunctSet()) | ||
| 81 | if (conjunct instanceof OWLObjectHasSelf) { | ||
| 82 | OWLIndividual freshNominal = getNewIndividual(outputOntology, rlCounter++); | ||
| 83 | newConjuncts.add(factory.getOWLObjectOneOf(freshNominal)); | ||
| 84 | newConjuncts.add(factory.getOWLObjectHasValue(((OWLObjectHasSelf) exp).getProperty(), freshNominal)); | ||
| 85 | } | ||
| 86 | else | ||
| 87 | newConjuncts.add(conjunct); | ||
| 88 | |||
| 89 | return OWLHelper.getSimplifiedConjunction(factory, newConjuncts); | ||
| 90 | } | ||
| 91 | |||
| 92 | private void eliminateNominals() { | ||
| 93 | Collection<OWLAxiom> axioms = new LinkedList<OWLAxiom>(outputOntology.getAxioms()); | ||
| 94 | OWLClassExpression superExp, newSuperExp; | ||
| 95 | for (OWLAxiom axiom: axioms) | ||
| 96 | if (axiom instanceof OWLSubClassOfAxiom) { | ||
| 97 | superExp = ((OWLSubClassOfAxiom) axiom).getSuperClass(); | ||
| 98 | newSuperExp = approximateNominals(superExp); | ||
| 99 | if (newSuperExp != superExp) | ||
| 100 | replaceAxiom4output(axiom, factory.getOWLSubClassOfAxiom(((OWLSubClassOfAxiom) axiom).getSubClass(), newSuperExp)); | ||
| 101 | } | ||
| 102 | } | ||
| 103 | |||
| 104 | private OWLClassExpression approximateNominals(OWLClassExpression exp) { | ||
| 105 | if (!hasIllegalNominals(exp)) return exp; | ||
| 106 | Set<OWLIndividual> nominals; | ||
| 107 | Set<OWLClassExpression> newConjuncts = new HashSet<OWLClassExpression>(); | ||
| 108 | for (OWLClassExpression conjunct: exp.asConjunctSet()) { | ||
| 109 | if (conjunct instanceof OWLObjectOneOf) { | ||
| 110 | nominals = ((OWLObjectOneOf) conjunct).getIndividuals(); | ||
| 111 | newConjuncts.add(approximateNominal(nominals)); | ||
| 112 | } | ||
| 113 | else if (conjunct instanceof OWLObjectAllValuesFrom) { | ||
| 114 | OWLObjectAllValuesFrom allValuesFrom = ((OWLObjectAllValuesFrom) conjunct); | ||
| 115 | if (allValuesFrom.getFiller() instanceof OWLObjectOneOf) { | ||
| 116 | nominals = ((OWLObjectOneOf) allValuesFrom.getFiller()).getIndividuals(); | ||
| 117 | newConjuncts.add(factory.getOWLObjectAllValuesFrom(allValuesFrom.getProperty(), | ||
| 118 | approximateNominal(nominals))); | ||
| 119 | } | ||
| 120 | } | ||
| 121 | } | ||
| 122 | return OWLHelper.getSimplifiedConjunction(factory, newConjuncts); | ||
| 123 | } | ||
| 124 | |||
| 125 | private OWLClassExpression approximateNominal(Set<OWLIndividual> nominals) { | ||
| 126 | if (nominals.size() > 1) { | ||
| 127 | Utility.logError("Error: more than one nominal appearing in OWLObjectOneOf"); | ||
| 128 | return null; | ||
| 129 | } | ||
| 130 | OWLIndividual nominal = nominals.iterator().next(); | ||
| 131 | OWLObjectProperty freshProperty = getNewRole4Nominal(nominal); | ||
| 132 | addAxiom2output(factory.getOWLInverseFunctionalObjectPropertyAxiom(freshProperty), null); | ||
| 133 | manager.addAxiom(aBox, factory.getOWLObjectPropertyAssertionAxiom(freshProperty, nominal, nominal)); | ||
| 134 | return factory.getOWLObjectHasValue(freshProperty, nominal); | ||
| 135 | } | ||
| 136 | |||
| 137 | Map<OWLIndividual, OWLObjectProperty> role4nominal = new HashMap<OWLIndividual, OWLObjectProperty>(); | ||
| 138 | |||
| 139 | private OWLObjectProperty getNewRole4Nominal(OWLIndividual nominal) { | ||
| 140 | OWLObjectProperty property; | ||
| 141 | if ((property = role4nominal.get(nominal)) == null) | ||
| 142 | role4nominal.put(nominal, property = getNewRole(outputOntology, rlCounter++)); | ||
| 143 | return property; | ||
| 144 | } | ||
| 145 | |||
| 146 | private boolean hasIllegalNominals(OWLClassExpression exp) { | ||
| 147 | for (OWLClassExpression conjunct: exp.asConjunctSet()) { | ||
| 148 | if (conjunct instanceof OWLObjectOneOf) return true; | ||
| 149 | if (conjunct instanceof OWLObjectAllValuesFrom) { | ||
| 150 | OWLObjectAllValuesFrom allValuesFrom = ((OWLObjectAllValuesFrom) conjunct); | ||
| 151 | if (allValuesFrom.getFiller() instanceof OWLObjectOneOf) | ||
| 152 | return true; | ||
| 153 | } | ||
| 154 | } | ||
| 155 | return false; | ||
| 156 | } | ||
| 157 | |||
| 158 | private void eliminateOWLThing() { | ||
| 159 | OWLClassExpression subExp; | ||
| 160 | boolean mark = false; | ||
| 161 | for (Clause clause: clauses) { | ||
| 162 | subExp = OWLHelper.getSimplifiedConjunction(factory, clause.getSubClasses()); | ||
| 163 | if (subExp.equals(factory.getOWLThing())) { | ||
| 164 | mark = true; | ||
| 165 | } | ||
| 166 | } | ||
| 167 | |||
| 168 | if (mark) { | ||
| 169 | Utility.logDebug("Top appears in the left of an axiom."); | ||
| 170 | |||
| 171 | OWLSubClassOfAxiom subClassAxiom; | ||
| 172 | OWLClass TOP = factory.getOWLClass(IRI.create(ontologyIRI + "#TOP")); | ||
| 173 | for (OWLAxiom axiom: new HashSet<OWLAxiom>(outputOntology.getAxioms())) | ||
| 174 | if (axiom instanceof OWLSubClassOfAxiom && (subClassAxiom = (OWLSubClassOfAxiom) axiom).getSubClass().equals(factory.getOWLThing())) | ||
| 175 | replaceAxiom4output(axiom, factory.getOWLSubClassOfAxiom(TOP, subClassAxiom.getSuperClass())); | ||
| 176 | |||
| 177 | for (OWLClass c: outputOntology.getClassesInSignature(true)) { | ||
| 178 | if (!c.equals(factory.getOWLThing())) | ||
| 179 | addAxiom2output(factory.getOWLSubClassOfAxiom(c, TOP), null); | ||
| 180 | else | ||
| 181 | addAxiom2output(factory.getOWLSubClassOfAxiom(TOP, c), null); | ||
| 182 | } | ||
| 183 | for (OWLObjectProperty p: outputOntology.getObjectPropertiesInSignature(true)) { | ||
| 184 | addAxiom2output(factory.getOWLObjectPropertyDomainAxiom(p, TOP), null); | ||
| 185 | addAxiom2output(factory.getOWLObjectPropertyRangeAxiom(p, TOP), null); | ||
| 186 | } | ||
| 187 | } | ||
| 188 | } | ||
| 189 | |||
| 190 | } | ||
