diff options
Diffstat (limited to 'src/uk/ac/ox/cs/pagoda/approx')
| -rw-r--r-- | src/uk/ac/ox/cs/pagoda/approx/Clause.java | 91 | ||||
| -rw-r--r-- | src/uk/ac/ox/cs/pagoda/approx/RLPlusOntology.java | 31 |
2 files changed, 77 insertions, 45 deletions
diff --git a/src/uk/ac/ox/cs/pagoda/approx/Clause.java b/src/uk/ac/ox/cs/pagoda/approx/Clause.java index 9c3f5d0..29bc74e 100644 --- a/src/uk/ac/ox/cs/pagoda/approx/Clause.java +++ b/src/uk/ac/ox/cs/pagoda/approx/Clause.java | |||
| @@ -68,7 +68,7 @@ public class Clause { | |||
| 68 | getVariableOccurrence(var2atom, bodyAtoms); | 68 | getVariableOccurrence(var2atom, bodyAtoms); |
| 69 | 69 | ||
| 70 | DLPredicate predicate; | 70 | DLPredicate predicate; |
| 71 | Variable W = null; | 71 | Term W = null; |
| 72 | 72 | ||
| 73 | Map<Variable, String> nom2iri = new HashMap<Variable, String>(); | 73 | Map<Variable, String> nom2iri = new HashMap<Variable, String>(); |
| 74 | Map<Variable, Constant> nom2datatype = new HashMap<Variable, Constant>(); | 74 | Map<Variable, Constant> nom2datatype = new HashMap<Variable, Constant>(); |
| @@ -97,8 +97,7 @@ public class Clause { | |||
| 97 | AtomicConcept concept = (AtomicConcept) predicate; | 97 | AtomicConcept concept = (AtomicConcept) predicate; |
| 98 | Variable v = atom.getArgumentVariable(0); | 98 | Variable v = atom.getArgumentVariable(0); |
| 99 | if (v == X) | 99 | if (v == X) |
| 100 | subClasses.add(factory.getOWLClass(IRI.create(concept | 100 | subClasses.add(factory.getOWLClass(IRI.create(concept.getIRI()))); |
| 101 | .getIRI()))); | ||
| 102 | else if (predicate.toString().startsWith("<internal:nom#")) | 101 | else if (predicate.toString().startsWith("<internal:nom#")) |
| 103 | nom2iri.put(v, DLClauseHelper.getIRI4Nominal(concept)); | 102 | nom2iri.put(v, DLClauseHelper.getIRI4Nominal(concept)); |
| 104 | } else if (predicate instanceof AtomicRole) { | 103 | } else if (predicate instanceof AtomicRole) { |
| @@ -168,54 +167,58 @@ public class Clause { | |||
| 168 | 167 | ||
| 169 | OWLObjectPropertyExpression roleExp = factory | 168 | OWLObjectPropertyExpression roleExp = factory |
| 170 | .getOWLObjectProperty(IRI.create(role.getIRI())); | 169 | .getOWLObjectProperty(IRI.create(role.getIRI())); |
| 171 | if ((W = atom.getArgumentVariable(1)) == X) { | 170 | if ((W = atom.getArgument(1)).equals(X)) { |
| 172 | roleExp = roleExp.getInverseProperty(); | 171 | roleExp = roleExp.getInverseProperty(); |
| 173 | W = atom.getArgumentVariable(0); | 172 | W = atom.getArgument(0); |
| 174 | } | 173 | } |
| 175 | 174 | ||
| 176 | if (X == W) | 175 | if (X == W) |
| 177 | subClasses.add(factory.getOWLObjectHasSelf(roleExp)); | 176 | subClasses.add(factory.getOWLObjectHasSelf(roleExp)); |
| 178 | 177 | else if (W instanceof Individual) | |
| 179 | AtomicConcept concept; | 178 | subClasses.add(factory.getOWLObjectHasValue(roleExp, factory.getOWLNamedIndividual(IRI.create(((Individual) W).getIRI())))); |
| 180 | OWLClassExpression clsExp = null; | 179 | else { |
| 181 | int number = 1; | 180 | AtomicConcept concept; |
| 182 | Set<Variable> set = varCliques.get(W); | 181 | OWLClassExpression clsExp = null; |
| 183 | if (set != null) | 182 | int number = 1; |
| 184 | number = set.size(); | 183 | Set<Variable> set = varCliques.get(W); |
| 185 | 184 | if (set != null) | |
| 186 | if (var2atom.containsKey(W)) { | 185 | number = set.size(); |
| 187 | Atom tAtom = var2atom.get(W); | 186 | |
| 188 | DLPredicate tPredicate = tAtom.getDLPredicate(); | 187 | if (var2atom.containsKey(W)) { |
| 189 | if (tPredicate instanceof AtomicConcept) { | 188 | Atom tAtom = var2atom.get(W); |
| 190 | concept = (AtomicConcept) tPredicate; | 189 | DLPredicate tPredicate = tAtom.getDLPredicate(); |
| 191 | clsExp = factory.getOWLClass(IRI.create(concept | 190 | if (tPredicate instanceof AtomicConcept) { |
| 192 | .getIRI())); | 191 | concept = (AtomicConcept) tPredicate; |
| 193 | if (headAtoms.contains(tAtom)) { | 192 | clsExp = factory.getOWLClass(IRI.create(concept |
| 194 | superClasses.add(factory.getOWLObjectAllValuesFrom( | 193 | .getIRI())); |
| 195 | roleExp, clsExp)); | 194 | if (headAtoms.contains(tAtom)) { |
| 196 | subClasses.add(factory.getOWLObjectSomeValuesFrom( | 195 | superClasses.add(factory.getOWLObjectAllValuesFrom( |
| 197 | roleExp, factory.getOWLThing())); | 196 | roleExp, clsExp)); |
| 198 | headAtoms.remove(tAtom); | 197 | subClasses.add(factory.getOWLObjectSomeValuesFrom( |
| 198 | roleExp, factory.getOWLThing())); | ||
| 199 | headAtoms.remove(tAtom); | ||
| 200 | } else { | ||
| 201 | if (number == 1) | ||
| 202 | subClasses.add(factory | ||
| 203 | .getOWLObjectSomeValuesFrom(roleExp, | ||
| 204 | clsExp)); | ||
| 205 | else | ||
| 206 | subClasses.add(factory | ||
| 207 | .getOWLObjectMinCardinality(number, | ||
| 208 | roleExp, clsExp)); | ||
| 209 | } | ||
| 199 | } else { | 210 | } else { |
| 200 | if (number == 1) | 211 | Utility.logDebug(tAtom, "strange ... -___-|||"); |
| 201 | subClasses.add(factory | ||
| 202 | .getOWLObjectSomeValuesFrom(roleExp, | ||
| 203 | clsExp)); | ||
| 204 | else | ||
| 205 | subClasses.add(factory | ||
| 206 | .getOWLObjectMinCardinality(number, | ||
| 207 | roleExp, clsExp)); | ||
| 208 | } | 212 | } |
| 209 | } else { | ||
| 210 | Utility.logDebug(tAtom, "strange ... -___-|||"); | ||
| 211 | } | 213 | } |
| 212 | } else { | 214 | else { |
| 213 | if (number == 1) | 215 | if (number == 1) |
| 214 | subClasses.add(factory.getOWLObjectSomeValuesFrom( | 216 | subClasses.add(factory.getOWLObjectSomeValuesFrom( |
| 215 | roleExp, factory.getOWLThing())); | 217 | roleExp, factory.getOWLThing())); |
| 216 | else | 218 | else |
| 217 | subClasses.add(factory.getOWLObjectMinCardinality( | 219 | subClasses.add(factory.getOWLObjectMinCardinality( |
| 218 | number, roleExp)); | 220 | number, roleExp)); |
| 221 | } | ||
| 219 | } | 222 | } |
| 220 | } | 223 | } |
| 221 | } | 224 | } |
diff --git a/src/uk/ac/ox/cs/pagoda/approx/RLPlusOntology.java b/src/uk/ac/ox/cs/pagoda/approx/RLPlusOntology.java index a43d9af..a60b664 100644 --- a/src/uk/ac/ox/cs/pagoda/approx/RLPlusOntology.java +++ b/src/uk/ac/ox/cs/pagoda/approx/RLPlusOntology.java | |||
| @@ -31,6 +31,8 @@ import org.semanticweb.owlapi.model.OWLDataMinCardinality; | |||
| 31 | import org.semanticweb.owlapi.model.OWLDataPropertyAssertionAxiom; | 31 | import org.semanticweb.owlapi.model.OWLDataPropertyAssertionAxiom; |
| 32 | import org.semanticweb.owlapi.model.OWLDataSomeValuesFrom; | 32 | import org.semanticweb.owlapi.model.OWLDataSomeValuesFrom; |
| 33 | import org.semanticweb.owlapi.model.OWLDatatype; | 33 | import org.semanticweb.owlapi.model.OWLDatatype; |
| 34 | import org.semanticweb.owlapi.model.OWLDifferentIndividualsAxiom; | ||
| 35 | import org.semanticweb.owlapi.model.OWLIndividual; | ||
| 34 | import org.semanticweb.owlapi.model.OWLNamedIndividual; | 36 | import org.semanticweb.owlapi.model.OWLNamedIndividual; |
| 35 | import org.semanticweb.owlapi.model.OWLObjectAllValuesFrom; | 37 | import org.semanticweb.owlapi.model.OWLObjectAllValuesFrom; |
| 36 | import org.semanticweb.owlapi.model.OWLObjectComplementOf; | 38 | import org.semanticweb.owlapi.model.OWLObjectComplementOf; |
| @@ -46,6 +48,7 @@ import org.semanticweb.owlapi.model.OWLOntology; | |||
| 46 | import org.semanticweb.owlapi.model.OWLOntologyCreationException; | 48 | import org.semanticweb.owlapi.model.OWLOntologyCreationException; |
| 47 | import org.semanticweb.owlapi.model.OWLOntologyManager; | 49 | import org.semanticweb.owlapi.model.OWLOntologyManager; |
| 48 | import org.semanticweb.owlapi.model.OWLOntologyStorageException; | 50 | import org.semanticweb.owlapi.model.OWLOntologyStorageException; |
| 51 | import org.semanticweb.owlapi.model.OWLSameIndividualAxiom; | ||
| 49 | import org.semanticweb.owlapi.profiles.OWL2RLProfile; | 52 | import org.semanticweb.owlapi.profiles.OWL2RLProfile; |
| 50 | import org.semanticweb.owlapi.profiles.OWLProfileReport; | 53 | import org.semanticweb.owlapi.profiles.OWLProfileReport; |
| 51 | import org.semanticweb.owlapi.profiles.OWLProfileViolation; | 54 | import org.semanticweb.owlapi.profiles.OWLProfileViolation; |
| @@ -360,6 +363,9 @@ public class RLPlusOntology implements KnowledgeBase { | |||
| 360 | Map<OWLClassExpression, OWLClass> complex2atomic= new HashMap<OWLClassExpression, OWLClass>(); | 363 | Map<OWLClassExpression, OWLClass> complex2atomic= new HashMap<OWLClassExpression, OWLClass>(); |
| 361 | 364 | ||
| 362 | OWLDatatype anyURI = factory.getOWLDatatype(IRI.create(Namespace.XSD_NS + "anyURI")); | 365 | OWLDatatype anyURI = factory.getOWLDatatype(IRI.create(Namespace.XSD_NS + "anyURI")); |
| 366 | OWLObjectProperty sameAs = factory.getOWLObjectProperty(IRI.create(Namespace.EQUALITY)); | ||
| 367 | OWLObjectProperty differentFrom = factory.getOWLObjectProperty(IRI.create(Namespace.INEQUALITY)); | ||
| 368 | |||
| 363 | for (OWLOntology imported: inputOntology.getImportsClosure()) | 369 | for (OWLOntology imported: inputOntology.getImportsClosure()) |
| 364 | for (OWLAxiom axiom: imported.getAxioms()) { | 370 | for (OWLAxiom axiom: imported.getAxioms()) { |
| 365 | if (axiom instanceof OWLClassAssertionAxiom) { | 371 | if (axiom instanceof OWLClassAssertionAxiom) { |
| @@ -381,10 +387,33 @@ public class RLPlusOntology implements KnowledgeBase { | |||
| 381 | } | 387 | } |
| 382 | } | 388 | } |
| 383 | else if (axiom instanceof OWLObjectPropertyAssertionAxiom || axiom instanceof OWLDataPropertyAssertionAxiom || axiom instanceof OWLAnnotationAssertionAxiom) { | 389 | else if (axiom instanceof OWLObjectPropertyAssertionAxiom || axiom instanceof OWLDataPropertyAssertionAxiom || axiom instanceof OWLAnnotationAssertionAxiom) { |
| 384 | if (axiom.containsEntityInSignature(anyURI)) continue; | 390 | if (axiom.getDataPropertiesInSignature().contains(anyURI)) continue; |
| 385 | flag = true; | 391 | flag = true; |
| 386 | manager.addAxiom(aBox, axiom); | 392 | manager.addAxiom(aBox, axiom); |
| 387 | } | 393 | } |
| 394 | else if (axiom instanceof OWLSameIndividualAxiom) { | ||
| 395 | OWLIndividual firstIndividual = null, previousIndividual = null, lastIndividual = null; | ||
| 396 | for (OWLIndividual next: ((OWLSameIndividualAxiom) axiom).getIndividuals()) { | ||
| 397 | if (firstIndividual == null) firstIndividual = previousIndividual = next; | ||
| 398 | else | ||
| 399 | manager.addAxiom(aBox, factory.getOWLObjectPropertyAssertionAxiom(sameAs, previousIndividual, next)); | ||
| 400 | previousIndividual = lastIndividual = next; | ||
| 401 | } | ||
| 402 | manager.addAxiom(aBox, factory.getOWLObjectPropertyAssertionAxiom(sameAs, lastIndividual, firstIndividual)); | ||
| 403 | } | ||
| 404 | else if (axiom instanceof OWLDifferentIndividualsAxiom) { | ||
| 405 | int index1 = 0, index2; | ||
| 406 | for (OWLIndividual individual1: ((OWLDifferentIndividualsAxiom) axiom).getIndividuals()) { | ||
| 407 | ++index1; | ||
| 408 | index2 = 0; | ||
| 409 | for (OWLIndividual individual2: ((OWLDifferentIndividualsAxiom) axiom).getIndividuals()) { | ||
| 410 | if (index2++ < index1) { | ||
| 411 | manager.addAxiom(aBox, factory.getOWLObjectPropertyAssertionAxiom(differentFrom, individual1, individual2)); | ||
| 412 | } | ||
| 413 | else break; | ||
| 414 | } | ||
| 415 | } | ||
| 416 | } | ||
| 388 | else | 417 | else |
| 389 | manager.addAxiom(tBox, axiom); | 418 | manager.addAxiom(tBox, axiom); |
| 390 | } | 419 | } |
