diff options
| author | RncLsn <rnc.lsn@gmail.com> | 2015-05-28 10:29:11 +0100 |
|---|---|---|
| committer | RncLsn <rnc.lsn@gmail.com> | 2015-05-28 10:29:11 +0100 |
| commit | 2e069a4966e6305194c4168d6fc5c406123d7f64 (patch) | |
| tree | dc70e541b78494ac13f899db2831422b28fc5f72 /src/uk/ac/ox/cs/pagoda/approx/RLPlusOntology.java | |
| parent | c9c8d03e957fa56df5dc1304f7a81dfa61b7b70e (diff) | |
| download | ACQuA-2e069a4966e6305194c4168d6fc5c406123d7f64.tar.gz ACQuA-2e069a4966e6305194c4168d6fc5c406123d7f64.zip | |
NOT-WORKING: trying to add query-dependent Skolemisation.
Diffstat (limited to 'src/uk/ac/ox/cs/pagoda/approx/RLPlusOntology.java')
| -rw-r--r-- | src/uk/ac/ox/cs/pagoda/approx/RLPlusOntology.java | 178 |
1 files changed, 87 insertions, 91 deletions
diff --git a/src/uk/ac/ox/cs/pagoda/approx/RLPlusOntology.java b/src/uk/ac/ox/cs/pagoda/approx/RLPlusOntology.java index 1e17dac..767d379 100644 --- a/src/uk/ac/ox/cs/pagoda/approx/RLPlusOntology.java +++ b/src/uk/ac/ox/cs/pagoda/approx/RLPlusOntology.java | |||
| @@ -38,46 +38,51 @@ public class RLPlusOntology implements KnowledgeBase { | |||
| 38 | LinkedList<Clause> clauses; | 38 | LinkedList<Clause> clauses; |
| 39 | Map<OWLAxiom, OWLAxiom> correspondence; | 39 | Map<OWLAxiom, OWLAxiom> correspondence; |
| 40 | 40 | ||
| 41 | BottomStrategy botStrategy; | 41 | BottomStrategy botStrategy; |
| 42 | 42 | Random random = new Random(19900114); | |
| 43 | private Map<OWLClassExpression, Integer> subCounter = null; | ||
| 44 | private Map<OWLClass, OWLClass> atomic2negation = new HashMap<OWLClass, OWLClass>(); | ||
| 45 | |||
| 46 | // FIXME multiple anonymous ontologies | ||
| 43 | @Override | 47 | @Override |
| 44 | public void load(OWLOntology o, uk.ac.ox.cs.pagoda.constraints.BottomStrategy bottomStrategy) { | 48 | public void load(OWLOntology o, uk.ac.ox.cs.pagoda.constraints.BottomStrategy bottomStrategy) { |
| 45 | if (bottomStrategy instanceof UnaryBottom) | 49 | if (bottomStrategy instanceof UnaryBottom) |
| 46 | botStrategy = BottomStrategy.UNARY; | 50 | botStrategy = BottomStrategy.UNARY; |
| 47 | else if (bottomStrategy instanceof NullaryBottom) | 51 | else if (bottomStrategy instanceof NullaryBottom) |
| 48 | botStrategy = BottomStrategy.NULLARY; | 52 | botStrategy = BottomStrategy.NULLARY; |
| 49 | else | 53 | else |
| 50 | botStrategy = BottomStrategy.TOREMOVE; | 54 | botStrategy = BottomStrategy.TOREMOVE; |
| 51 | 55 | ||
| 52 | if (corrFileName == null) | 56 | if(corrFileName == null) |
| 53 | corrFileName = "rlplus.crr"; | 57 | corrFileName = "rlplus.crr"; |
| 54 | manager = o.getOWLOntologyManager(); | 58 | manager = o.getOWLOntologyManager(); |
| 55 | // manager = OWLManager.createOWLOntologyManager(); | 59 | // manager = OWLManager.createOWLOntologyManager(); |
| 56 | factory = manager.getOWLDataFactory(); | 60 | factory = manager.getOWLDataFactory(); |
| 57 | inputOntology = o; | 61 | inputOntology = o; |
| 58 | 62 | ||
| 59 | try { | 63 | try { |
| 60 | String path = OWLHelper.getOntologyPath(inputOntology); | 64 | String path = OWLHelper.getOntologyPath(inputOntology); |
| 61 | String name = path.substring(path.lastIndexOf(Utility.JAVA_FILE_SEPARATOR)); | 65 | String name = path.substring(path.lastIndexOf(Utility.JAVA_FILE_SEPARATOR)); |
| 62 | String originalExtension = name.lastIndexOf(".") >= 0 ? name.substring(name.lastIndexOf(".")) : ""; | 66 | String originalExtension = name.lastIndexOf(".") >= 0 ? name.substring(name.lastIndexOf(".")) : ""; |
| 63 | 67 | ||
| 64 | if (inputOntology.getOntologyID().getOntologyIRI() == null) | 68 | if (inputOntology.getOntologyID().getOntologyIRI() == null) |
| 65 | ontologyIRI = "http://www.example.org/anonymous-ontology" + originalExtension; | 69 | ontologyIRI = "http://www.example.org/anonymous-ontology" + originalExtension; |
| 66 | else | 70 | else |
| 67 | ontologyIRI = inputOntology.getOntologyID().getOntologyIRI().toString(); | 71 | ontologyIRI = inputOntology.getOntologyID().getOntologyIRI().toString(); |
| 68 | 72 | ||
| 69 | String tOntoIRI = ontologyIRI; | 73 | String tOntoIRI = ontologyIRI; |
| 70 | if (!tOntoIRI.endsWith(originalExtension)) tOntoIRI += originalExtension; | 74 | if (!tOntoIRI.endsWith(originalExtension)) tOntoIRI += originalExtension; |
| 71 | 75 | ||
| 72 | String rlOntologyIRI = originalExtension.isEmpty() ? tOntoIRI + "-RL.owl" : tOntoIRI.replaceFirst(originalExtension, "-RL.owl"); | 76 | String rlOntologyIRI = originalExtension.isEmpty() ? tOntoIRI + "-RL.owl" : tOntoIRI.replaceFirst(originalExtension, "-RL.owl"); |
| 73 | String rlDocumentIRI = (outputPath = Paths.get(Utility.getGlobalTempDirAbsolutePath(), "RL.owl").toString()); | 77 | String rlDocumentIRI = (outputPath = Paths.get(Utility.getGlobalTempDirAbsolutePath(), "RL.owl").toString()); |
| 74 | outputOntology = manager.createOntology(IRI.create(rlOntologyIRI)); | 78 | outputOntology = manager.createOntology(IRI.create(rlOntologyIRI)); |
| 75 | manager.setOntologyDocumentIRI(outputOntology, IRI.create(Utility.toFileIRI(rlDocumentIRI))); | 79 | manager.setOntologyDocumentIRI(outputOntology, IRI.create(Utility.toFileIRI(rlDocumentIRI))); |
| 76 | 80 | ||
| 77 | String tBoxOntologyIRI, aBoxOntologyIRI; | 81 | String tBoxOntologyIRI, aBoxOntologyIRI; |
| 78 | tBoxOntologyIRI = originalExtension.isEmpty() ? tOntoIRI + "-TBox.owl" : tOntoIRI.replaceFirst(originalExtension, "-TBox.owl"); | 82 | tBoxOntologyIRI = |
| 83 | originalExtension.isEmpty() ? tOntoIRI + "-TBox.owl" : tOntoIRI.replaceFirst(originalExtension, "-TBox.owl"); | ||
| 79 | aBoxOntologyIRI = originalExtension.isEmpty() ? tOntoIRI + "-ABox.owl" : tOntoIRI.replaceFirst(originalExtension, "-ABox.owl"); | 84 | aBoxOntologyIRI = originalExtension.isEmpty() ? tOntoIRI + "-ABox.owl" : tOntoIRI.replaceFirst(originalExtension, "-ABox.owl"); |
| 80 | 85 | ||
| 81 | String tBoxDocumentIRI = Paths.get(Utility.getGlobalTempDirAbsolutePath(), "TBox.owl").toString(); | 86 | String tBoxDocumentIRI = Paths.get(Utility.getGlobalTempDirAbsolutePath(), "TBox.owl").toString(); |
| 82 | String aBoxDocumentIRI = (aBoxPath = Paths.get(Utility.getGlobalTempDirAbsolutePath(), "ABox.owl").toString()); | 87 | String aBoxDocumentIRI = (aBoxPath = Paths.get(Utility.getGlobalTempDirAbsolutePath(), "ABox.owl").toString()); |
| 83 | tBox = manager.createOntology(IRI.create(tBoxOntologyIRI)); | 88 | tBox = manager.createOntology(IRI.create(tBoxOntologyIRI)); |
| @@ -85,10 +90,10 @@ public class RLPlusOntology implements KnowledgeBase { | |||
| 85 | manager.setOntologyDocumentIRI(tBox, IRI.create(Utility.toFileIRI(tBoxDocumentIRI))); | 90 | manager.setOntologyDocumentIRI(tBox, IRI.create(Utility.toFileIRI(tBoxDocumentIRI))); |
| 86 | manager.setOntologyDocumentIRI(aBox, IRI.create(Utility.toFileIRI(aBoxDocumentIRI))); | 91 | manager.setOntologyDocumentIRI(aBox, IRI.create(Utility.toFileIRI(aBoxDocumentIRI))); |
| 87 | 92 | ||
| 88 | FileOutputStream aBoxOut = new FileOutputStream(aBoxPath); | 93 | FileOutputStream aBoxOut = new FileOutputStream(aBoxPath); |
| 89 | manager.saveOntology(aBox, aBoxOut); | 94 | manager.saveOntology(aBox, aBoxOut); |
| 90 | aBoxOut.close(); | 95 | aBoxOut.close(); |
| 91 | 96 | ||
| 92 | restOntology = manager.createOntology(); | 97 | restOntology = manager.createOntology(); |
| 93 | } | 98 | } |
| 94 | catch (OWLOntologyCreationException e) { | 99 | catch (OWLOntologyCreationException e) { |
| @@ -103,11 +108,11 @@ public class RLPlusOntology implements KnowledgeBase { | |||
| 103 | } | 108 | } |
| 104 | 109 | ||
| 105 | public OWLOntology getTBox() { | 110 | public OWLOntology getTBox() { |
| 106 | return tBox; | 111 | return tBox; |
| 107 | } | 112 | } |
| 108 | 113 | ||
| 109 | public String getABoxPath() { | 114 | public String getABoxPath() { |
| 110 | return aBoxPath; | 115 | return aBoxPath; |
| 111 | } | 116 | } |
| 112 | 117 | ||
| 113 | private void add2SubCounter(OWLClassExpression exp) { | 118 | private void add2SubCounter(OWLClassExpression exp) { |
| @@ -118,24 +123,23 @@ public class RLPlusOntology implements KnowledgeBase { | |||
| 118 | } | 123 | } |
| 119 | 124 | ||
| 120 | public void simplify() { | 125 | public void simplify() { |
| 121 | if (simplifyABox()) { | 126 | if(simplifyABox()) { |
| 122 | save(aBox); | 127 | save(aBox); |
| 123 | // save(tBox); | 128 | // save(tBox); |
| 124 | } | 129 | } else |
| 125 | else | 130 | tBox = inputOntology; |
| 126 | tBox = inputOntology; | ||
| 127 | } | 131 | } |
| 128 | 132 | ||
| 129 | @Override | 133 | @Override |
| 130 | public void transform() { | 134 | public void transform() { |
| 131 | simplify(); | 135 | simplify(); |
| 132 | filter(); | 136 | filter(); |
| 133 | clausify(); | 137 | clausify(); |
| 134 | 138 | ||
| 135 | subCounter = new HashMap<OWLClassExpression, Integer>(); | 139 | subCounter = new HashMap<OWLClassExpression, Integer>(); |
| 136 | clauses = new LinkedList<Clause>(); | 140 | clauses = new LinkedList<Clause>(); |
| 137 | Clausifier clausifier = Clausifier.getInstance(restOntology); | 141 | Clausifier clausifier = Clausifier.getInstance(restOntology); |
| 138 | 142 | ||
| 139 | for (DLClause c: dlOntology.getDLClauses()) { | 143 | for (DLClause c: dlOntology.getDLClauses()) { |
| 140 | Clause clause = new Clause(clausifier, c); | 144 | Clause clause = new Clause(clausifier, c); |
| 141 | clauses.add(clause); | 145 | clauses.add(clause); |
| @@ -144,7 +148,7 @@ public class RLPlusOntology implements KnowledgeBase { | |||
| 144 | * count the expressions in the left | 148 | * count the expressions in the left |
| 145 | */ | 149 | */ |
| 146 | for (OWLClassExpression exp: clause.getSubClasses()) { | 150 | for (OWLClassExpression exp: clause.getSubClasses()) { |
| 147 | if (exp instanceof OWLClass) | 151 | if(exp instanceof OWLClass) |
| 148 | add2SubCounter(exp); | 152 | add2SubCounter(exp); |
| 149 | else if (exp instanceof OWLObjectSomeValuesFrom) { | 153 | else if (exp instanceof OWLObjectSomeValuesFrom) { |
| 150 | OWLObjectSomeValuesFrom someValue = (OWLObjectSomeValuesFrom)exp; | 154 | OWLObjectSomeValuesFrom someValue = (OWLObjectSomeValuesFrom)exp; |
| @@ -155,8 +159,7 @@ public class RLPlusOntology implements KnowledgeBase { | |||
| 155 | OWLObjectMinCardinality minCard = (OWLObjectMinCardinality)exp; | 159 | OWLObjectMinCardinality minCard = (OWLObjectMinCardinality)exp; |
| 156 | add2SubCounter(factory.getOWLObjectSomeValuesFrom(minCard.getProperty(), factory.getOWLThing())); | 160 | add2SubCounter(factory.getOWLObjectSomeValuesFrom(minCard.getProperty(), factory.getOWLThing())); |
| 157 | add2SubCounter(minCard.getFiller()); | 161 | add2SubCounter(minCard.getFiller()); |
| 158 | } | 162 | } else |
| 159 | else | ||
| 160 | Utility.logError("strange class expression: " + exp); | 163 | Utility.logError("strange class expression: " + exp); |
| 161 | 164 | ||
| 162 | } | 165 | } |
| @@ -170,12 +173,12 @@ public class RLPlusOntology implements KnowledgeBase { | |||
| 170 | addedAxioms.clear(); | 173 | addedAxioms.clear(); |
| 171 | for (OWLClassExpression exp: getDisjunctionApprox0(clause.getSuperClasses())) { | 174 | for (OWLClassExpression exp: getDisjunctionApprox0(clause.getSuperClasses())) { |
| 172 | addedAxioms.add(factory.getOWLSubClassOfAxiom(subExp, transform(exp, addedAxioms))); | 175 | addedAxioms.add(factory.getOWLSubClassOfAxiom(subExp, transform(exp, addedAxioms))); |
| 173 | for (OWLAxiom a: addedAxioms) | 176 | for(OWLAxiom a : addedAxioms) |
| 174 | addAxiom2output(a, factory.getOWLSubClassOfAxiom(subExp, | 177 | addAxiom2output(a, factory.getOWLSubClassOfAxiom(subExp, |
| 175 | OWLHelper.getSimplifiedDisjunction(factory, clause.getSuperClasses()))); | 178 | OWLHelper.getSimplifiedDisjunction(factory, clause.getSuperClasses()))); |
| 176 | } | 179 | } |
| 177 | } | 180 | } |
| 178 | 181 | ||
| 179 | subCounter.clear(); | 182 | subCounter.clear(); |
| 180 | } | 183 | } |
| 181 | 184 | ||
| @@ -185,7 +188,7 @@ public class RLPlusOntology implements KnowledgeBase { | |||
| 185 | save(correspondence, corrFileName); | 188 | save(correspondence, corrFileName); |
| 186 | save(outputOntology); | 189 | save(outputOntology); |
| 187 | } | 190 | } |
| 188 | 191 | ||
| 189 | private void save(Map<OWLAxiom, OWLAxiom> map, String corrFileName) { | 192 | private void save(Map<OWLAxiom, OWLAxiom> map, String corrFileName) { |
| 190 | if (corrFileName == null) return ; | 193 | if (corrFileName == null) return ; |
| 191 | ObjectOutput output; | 194 | ObjectOutput output; |
| @@ -205,63 +208,61 @@ public class RLPlusOntology implements KnowledgeBase { | |||
| 205 | e.printStackTrace(); | 208 | e.printStackTrace(); |
| 206 | } | 209 | } |
| 207 | } | 210 | } |
| 208 | 211 | ||
| 209 | /* | 212 | /* |
| 210 | * treat disjunction as conjunction | 213 | * treat disjunction as conjunction |
| 211 | */ | 214 | */ |
| 212 | private Set<OWLClassExpression> getDisjunctionApprox0(Set<OWLClassExpression> superClasses) { | 215 | private Set<OWLClassExpression> getDisjunctionApprox0(Set<OWLClassExpression> superClasses) { |
| 213 | return superClasses; | 216 | return superClasses; |
| 214 | } | 217 | } |
| 215 | 218 | ||
| 216 | /* | 219 | /* |
| 217 | * choose one simple class disjunct | 220 | * choose one simple class disjunct |
| 218 | */ | 221 | */ |
| 219 | @SuppressWarnings("unused") | 222 | @SuppressWarnings("unused") |
| 220 | private Set<OWLClassExpression> getDisjunctionApprox1(Set<OWLClassExpression> superClasses) { | 223 | private Set<OWLClassExpression> getDisjunctionApprox1(Set<OWLClassExpression> superClasses) { |
| 221 | if (superClasses.isEmpty() || superClasses.size() == 1) | 224 | if(superClasses.isEmpty() || superClasses.size() == 1) |
| 222 | return superClasses; | 225 | return superClasses; |
| 223 | 226 | ||
| 224 | OWLClassExpression rep = null; | 227 | OWLClassExpression rep = null; |
| 225 | int min = Integer.MAX_VALUE, o; | 228 | int min = Integer.MAX_VALUE, o; |
| 226 | for (OWLClassExpression exp: superClasses) | 229 | for(OWLClassExpression exp : superClasses) |
| 227 | if (exp instanceof OWLClass && (o = getOccurrence(exp)) < min) { | 230 | if(exp instanceof OWLClass && (o = getOccurrence(exp)) < min) { |
| 228 | min = o; | 231 | min = o; |
| 229 | rep = exp; | 232 | rep = exp; |
| 230 | } | 233 | } |
| 231 | 234 | ||
| 232 | if (rep == null) rep = superClasses.iterator().next(); | 235 | if(rep == null) rep = superClasses.iterator().next(); |
| 233 | 236 | ||
| 234 | return Collections.singleton(rep); | 237 | return Collections.singleton(rep); |
| 235 | } | 238 | } |
| 236 | 239 | ||
| 237 | Random random = new Random(19900114); | ||
| 238 | /* | 240 | /* |
| 239 | * randomly choose a class expression to represent this disjunction | 241 | * randomly choose a class expression to represent this disjunction |
| 240 | */ | 242 | */ |
| 241 | @SuppressWarnings("unused") | 243 | @SuppressWarnings("unused") |
| 242 | private Set<OWLClassExpression> getDisjunctionApprox2(Set<OWLClassExpression> superClasses) { | 244 | private Set<OWLClassExpression> getDisjunctionApprox2(Set<OWLClassExpression> superClasses) { |
| 243 | if (superClasses.isEmpty() || superClasses.size() == 1) | 245 | if(superClasses.isEmpty() || superClasses.size() == 1) |
| 244 | return superClasses; | 246 | return superClasses; |
| 245 | 247 | ||
| 246 | int index = random.nextInt() % superClasses.size(); | 248 | int index = random.nextInt() % superClasses.size(); |
| 247 | if (index < 0) index += superClasses.size(); | 249 | if (index < 0) index += superClasses.size(); |
| 248 | 250 | ||
| 249 | int i = 0; | 251 | int i = 0; |
| 250 | for (OWLClassExpression exp: superClasses) | 252 | for(OWLClassExpression exp : superClasses) |
| 251 | if (i++ == index) | 253 | if (i++ == index) |
| 252 | return Collections.singleton(exp); | 254 | return Collections.singleton(exp); |
| 253 | return null; | 255 | return null; |
| 254 | } | 256 | } |
| 255 | 257 | ||
| 256 | private Map<OWLClassExpression, Integer> subCounter = null; | ||
| 257 | /* | 258 | /* |
| 258 | * choose the one that appears least in the l.h.s. | 259 | * choose the one that appears least in the l.h.s. |
| 259 | */ | 260 | */ |
| 260 | @SuppressWarnings("unused") | 261 | @SuppressWarnings("unused") |
| 261 | private Set<OWLClassExpression> getDisjunctionApprox3(Set<OWLClassExpression> superClasses) { | 262 | private Set<OWLClassExpression> getDisjunctionApprox3(Set<OWLClassExpression> superClasses) { |
| 262 | if (superClasses.isEmpty() || superClasses.size() == 1) | 263 | if(superClasses.isEmpty() || superClasses.size() == 1) |
| 263 | return superClasses; | 264 | return superClasses; |
| 264 | 265 | ||
| 265 | OWLClassExpression rep = null, exp1; | 266 | OWLClassExpression rep = null, exp1; |
| 266 | int occurrence = Integer.MAX_VALUE, o; | 267 | int occurrence = Integer.MAX_VALUE, o; |
| 267 | for (OWLClassExpression exp: superClasses) { | 268 | for (OWLClassExpression exp: superClasses) { |
| @@ -272,16 +273,16 @@ public class RLPlusOntology implements KnowledgeBase { | |||
| 272 | if (minCard.getCardinality() == 1) | 273 | if (minCard.getCardinality() == 1) |
| 273 | exp1 = factory.getOWLObjectSomeValuesFrom(minCard.getProperty(), minCard.getFiller()); | 274 | exp1 = factory.getOWLObjectSomeValuesFrom(minCard.getProperty(), minCard.getFiller()); |
| 274 | } | 275 | } |
| 275 | 276 | ||
| 276 | if (!subCounter.containsKey(exp1) || (o = subCounter.get(exp1)) < occurrence) { | 277 | if (!subCounter.containsKey(exp1) || (o = subCounter.get(exp1)) < occurrence) { |
| 277 | rep = exp; | 278 | rep = exp; |
| 278 | occurrence = o; | 279 | occurrence = o; |
| 279 | } | 280 | } |
| 280 | } | 281 | } |
| 281 | 282 | ||
| 282 | return Collections.singleton(rep); | 283 | return Collections.singleton(rep); |
| 283 | } | 284 | } |
| 284 | 285 | ||
| 285 | private int getOccurrence(OWLClassExpression exp) { | 286 | private int getOccurrence(OWLClassExpression exp) { |
| 286 | if (!subCounter.containsKey(exp)) | 287 | if (!subCounter.containsKey(exp)) |
| 287 | return 0; | 288 | return 0; |
| @@ -290,9 +291,9 @@ public class RLPlusOntology implements KnowledgeBase { | |||
| 290 | 291 | ||
| 291 | @SuppressWarnings("unused") | 292 | @SuppressWarnings("unused") |
| 292 | private Set<OWLClassExpression> getDisjunctionApprox4(Set<OWLClassExpression> superClasses) { | 293 | private Set<OWLClassExpression> getDisjunctionApprox4(Set<OWLClassExpression> superClasses) { |
| 293 | if (superClasses.isEmpty() || superClasses.size() == 1) | 294 | if(superClasses.isEmpty() || superClasses.size() == 1) |
| 294 | return superClasses; | 295 | return superClasses; |
| 295 | 296 | ||
| 296 | OWLClassExpression rep = null; | 297 | OWLClassExpression rep = null; |
| 297 | int occurrence = Integer.MAX_VALUE, o; | 298 | int occurrence = Integer.MAX_VALUE, o; |
| 298 | for (OWLClassExpression exp: superClasses) { | 299 | for (OWLClassExpression exp: superClasses) { |
| @@ -304,10 +305,9 @@ public class RLPlusOntology implements KnowledgeBase { | |||
| 304 | o += getOccurrence(minCard.getFiller()); | 305 | o += getOccurrence(minCard.getFiller()); |
| 305 | // if (o < o1) o = o1; | 306 | // if (o < o1) o = o1; |
| 306 | } | 307 | } |
| 307 | } | 308 | } else |
| 308 | else | ||
| 309 | o = getOccurrence(exp); | 309 | o = getOccurrence(exp); |
| 310 | 310 | ||
| 311 | if (o < occurrence || o == occurrence && !(rep instanceof OWLClass)) { | 311 | if (o < occurrence || o == occurrence && !(rep instanceof OWLClass)) { |
| 312 | rep = exp; | 312 | rep = exp; |
| 313 | occurrence = o; | 313 | occurrence = o; |
| @@ -320,11 +320,11 @@ public class RLPlusOntology implements KnowledgeBase { | |||
| 320 | private boolean simplifyABox() { | 320 | private boolean simplifyABox() { |
| 321 | boolean flag = false; | 321 | boolean flag = false; |
| 322 | Map<OWLClassExpression, OWLClass> complex2atomic= new HashMap<OWLClassExpression, OWLClass>(); | 322 | Map<OWLClassExpression, OWLClass> complex2atomic= new HashMap<OWLClassExpression, OWLClass>(); |
| 323 | 323 | ||
| 324 | OWLDatatype anyURI = factory.getOWLDatatype(IRI.create(Namespace.XSD_NS + "anyURI")); | 324 | OWLDatatype anyURI = factory.getOWLDatatype(IRI.create(Namespace.XSD_NS + "anyURI")); |
| 325 | OWLObjectProperty sameAs = factory.getOWLObjectProperty(IRI.create(Namespace.EQUALITY)); | 325 | OWLObjectProperty sameAs = factory.getOWLObjectProperty(IRI.create(Namespace.EQUALITY)); |
| 326 | OWLObjectProperty differentFrom = factory.getOWLObjectProperty(IRI.create(Namespace.INEQUALITY)); | 326 | OWLObjectProperty differentFrom = factory.getOWLObjectProperty(IRI.create(Namespace.INEQUALITY)); |
| 327 | 327 | ||
| 328 | for (OWLOntology imported: inputOntology.getImportsClosure()) | 328 | for (OWLOntology imported: inputOntology.getImportsClosure()) |
| 329 | for (OWLAxiom axiom: imported.getAxioms()) { | 329 | for (OWLAxiom axiom: imported.getAxioms()) { |
| 330 | if (axiom instanceof OWLClassAssertionAxiom) { | 330 | if (axiom instanceof OWLClassAssertionAxiom) { |
| @@ -334,7 +334,7 @@ public class RLPlusOntology implements KnowledgeBase { | |||
| 334 | OWLClass cls; | 334 | OWLClass cls; |
| 335 | if (clsExp instanceof OWLClass) { | 335 | if (clsExp instanceof OWLClass) { |
| 336 | if (((OWLClass) clsExp).toStringID().startsWith("owl:")) | 336 | if (((OWLClass) clsExp).toStringID().startsWith("owl:")) |
| 337 | manager.addAxiom(tBox, axiom); | 337 | manager.addAxiom(tBox, axiom); |
| 338 | else manager.addAxiom(aBox, axiom); | 338 | else manager.addAxiom(aBox, axiom); |
| 339 | } | 339 | } |
| 340 | else { | 340 | else { |
| @@ -343,40 +343,38 @@ public class RLPlusOntology implements KnowledgeBase { | |||
| 343 | manager.addAxiom(tBox, factory.getOWLSubClassOfAxiom(cls, clsExp)); | 343 | manager.addAxiom(tBox, factory.getOWLSubClassOfAxiom(cls, clsExp)); |
| 344 | } | 344 | } |
| 345 | manager.addAxiom(aBox, factory.getOWLClassAssertionAxiom(cls, assertion.getIndividual())); | 345 | manager.addAxiom(aBox, factory.getOWLClassAssertionAxiom(cls, assertion.getIndividual())); |
| 346 | } | 346 | } |
| 347 | } | 347 | } |
| 348 | else if (axiom instanceof OWLObjectPropertyAssertionAxiom || axiom instanceof OWLDataPropertyAssertionAxiom || axiom instanceof OWLAnnotationAssertionAxiom) { | 348 | else if (axiom instanceof OWLObjectPropertyAssertionAxiom || axiom instanceof OWLDataPropertyAssertionAxiom || axiom instanceof OWLAnnotationAssertionAxiom) { |
| 349 | if (axiom.getDataPropertiesInSignature().contains(anyURI)) continue; | 349 | if(axiom.getDataPropertiesInSignature().contains(anyURI)) continue; |
| 350 | flag = true; | 350 | flag = true; |
| 351 | manager.addAxiom(aBox, axiom); | 351 | manager.addAxiom(aBox, axiom); |
| 352 | } | 352 | } |
| 353 | else if (axiom instanceof OWLSameIndividualAxiom) { | 353 | else if (axiom instanceof OWLSameIndividualAxiom) { |
| 354 | OWLIndividual firstIndividual = null, previousIndividual = null, lastIndividual = null; | 354 | OWLIndividual firstIndividual = null, previousIndividual = null, lastIndividual = null; |
| 355 | for (OWLIndividual next: ((OWLSameIndividualAxiom) axiom).getIndividuals()) { | 355 | for (OWLIndividual next: ((OWLSameIndividualAxiom) axiom).getIndividuals()) { |
| 356 | if (firstIndividual == null) firstIndividual = previousIndividual = next; | 356 | if(firstIndividual == null) firstIndividual = previousIndividual = next; |
| 357 | else | 357 | else |
| 358 | manager.addAxiom(aBox, factory.getOWLObjectPropertyAssertionAxiom(sameAs, previousIndividual, next)); | 358 | manager.addAxiom(aBox, factory.getOWLObjectPropertyAssertionAxiom(sameAs, previousIndividual, next)); |
| 359 | previousIndividual = lastIndividual = next; | 359 | previousIndividual = lastIndividual = next; |
| 360 | } | 360 | } |
| 361 | manager.addAxiom(aBox, factory.getOWLObjectPropertyAssertionAxiom(sameAs, lastIndividual, firstIndividual)); | 361 | manager.addAxiom(aBox, factory.getOWLObjectPropertyAssertionAxiom(sameAs, lastIndividual, firstIndividual)); |
| 362 | } | 362 | } |
| 363 | else if (axiom instanceof OWLDifferentIndividualsAxiom) { | 363 | else if (axiom instanceof OWLDifferentIndividualsAxiom) { |
| 364 | int index1 = 0, index2; | 364 | int index1 = 0, index2; |
| 365 | for (OWLIndividual individual1: ((OWLDifferentIndividualsAxiom) axiom).getIndividuals()) { | 365 | for (OWLIndividual individual1: ((OWLDifferentIndividualsAxiom) axiom).getIndividuals()) { |
| 366 | ++index1; | 366 | ++index1; |
| 367 | index2 = 0; | 367 | index2 = 0; |
| 368 | for (OWLIndividual individual2: ((OWLDifferentIndividualsAxiom) axiom).getIndividuals()) { | 368 | for (OWLIndividual individual2: ((OWLDifferentIndividualsAxiom) axiom).getIndividuals()) { |
| 369 | if (index2++ < index1) { | 369 | if (index2++ < index1) { |
| 370 | manager.addAxiom(aBox, factory.getOWLObjectPropertyAssertionAxiom(differentFrom, individual1, individual2)); | 370 | manager.addAxiom(aBox, factory.getOWLObjectPropertyAssertionAxiom(differentFrom, individual1, individual2)); |
| 371 | } | 371 | } else break; |
| 372 | else break; | ||
| 373 | } | 372 | } |
| 374 | } | 373 | } |
| 375 | } | 374 | } else |
| 376 | else | ||
| 377 | manager.addAxiom(tBox, axiom); | 375 | manager.addAxiom(tBox, axiom); |
| 378 | } | 376 | } |
| 379 | 377 | ||
| 380 | return flag; | 378 | return flag; |
| 381 | } | 379 | } |
| 382 | 380 | ||
| @@ -384,15 +382,15 @@ public class RLPlusOntology implements KnowledgeBase { | |||
| 384 | OWL2RLProfile profile = new OWL2RLProfile(); | 382 | OWL2RLProfile profile = new OWL2RLProfile(); |
| 385 | OWLProfileReport report = profile.checkOntology(tBox); | 383 | OWLProfileReport report = profile.checkOntology(tBox); |
| 386 | Set<OWLAxiom> rlAxioms = tBox.getAxioms(); | 384 | Set<OWLAxiom> rlAxioms = tBox.getAxioms(); |
| 387 | OWLAxiom axiom; | 385 | OWLAxiom axiom; |
| 388 | 386 | ||
| 389 | for (OWLProfileViolation violation: report.getViolations()) { | 387 | for (OWLProfileViolation violation: report.getViolations()) { |
| 390 | manager.addAxiom(restOntology, axiom = violation.getAxiom()); | 388 | manager.addAxiom(restOntology, axiom = violation.getAxiom()); |
| 391 | rlAxioms.remove(axiom); | 389 | rlAxioms.remove(axiom); |
| 392 | } | 390 | } |
| 393 | 391 | ||
| 394 | for (Iterator<OWLAxiom> iter = rlAxioms.iterator(); iter.hasNext(); ) | 392 | for (Iterator<OWLAxiom> iter = rlAxioms.iterator(); iter.hasNext(); ) |
| 395 | addAxiom2output(iter.next(), null); | 393 | addAxiom2output(iter.next(), null); |
| 396 | } | 394 | } |
| 397 | 395 | ||
| 398 | private void clausify() { | 396 | private void clausify() { |
| @@ -407,8 +405,6 @@ public class RLPlusOntology implements KnowledgeBase { | |||
| 407 | if (correspondingAxiom != null) | 405 | if (correspondingAxiom != null) |
| 408 | correspondence.put(axiom, correspondingAxiom); | 406 | correspondence.put(axiom, correspondingAxiom); |
| 409 | } | 407 | } |
| 410 | |||
| 411 | private Map<OWLClass, OWLClass> atomic2negation = new HashMap<OWLClass, OWLClass>(); | ||
| 412 | 408 | ||
| 413 | private OWLClassExpression transform(OWLClassExpression exp, Set<OWLAxiom> addedAxioms) { | 409 | private OWLClassExpression transform(OWLClassExpression exp, Set<OWLAxiom> addedAxioms) { |
| 414 | if (exp instanceof OWLClass) | 410 | if (exp instanceof OWLClass) |
