diff options
Diffstat (limited to 'src/uk/ac/ox/cs/pagoda/reasoner/full')
| -rw-r--r-- | src/uk/ac/ox/cs/pagoda/reasoner/full/HermitChecker.java | 71 |
1 files changed, 35 insertions, 36 deletions
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/full/HermitChecker.java b/src/uk/ac/ox/cs/pagoda/reasoner/full/HermitChecker.java index 4dd11d8..5dcf0f8 100644 --- a/src/uk/ac/ox/cs/pagoda/reasoner/full/HermitChecker.java +++ b/src/uk/ac/ox/cs/pagoda/reasoner/full/HermitChecker.java | |||
| @@ -77,8 +77,7 @@ public class HermitChecker implements Checker { | |||
| 77 | } | 77 | } |
| 78 | 78 | ||
| 79 | private int tag = 0; | 79 | private int tag = 0; |
| 80 | // AnswerTuple topAnswerTuple = null; | 80 | AnswerTuple topAnswerTuple = null, botAnswerTuple = null; |
| 81 | AnswerTuple botAnswerTuple = null; | ||
| 82 | 81 | ||
| 83 | private void initialiseReasoner() { | 82 | private void initialiseReasoner() { |
| 84 | qGraph = new QueryGraph(queryClause.getBodyAtoms(), answerVariable[1], ontology); | 83 | qGraph = new QueryGraph(queryClause.getBodyAtoms(), answerVariable[1], ontology); |
| @@ -88,17 +87,20 @@ public class HermitChecker implements Checker { | |||
| 88 | if (hermit != null) hermit.dispose(); | 87 | if (hermit != null) hermit.dispose(); |
| 89 | 88 | ||
| 90 | if (dGraph != null && answerVariable[1].length == 1 && (dGraph.getExits().size() > 1 || dGraph.getEntrances().size() > 1)) { | 89 | if (dGraph != null && answerVariable[1].length == 1 && (dGraph.getExits().size() > 1 || dGraph.getEntrances().size() > 1)) { |
| 91 | Set<OWLAxiom> axioms = new HashSet<OWLAxiom>(); | 90 | Set<OWLAxiom> topAxioms = new HashSet<OWLAxiom>(); |
| 92 | addTopAndBotTuple(axioms); | 91 | Set<OWLAxiom> botAxioms = new HashSet<OWLAxiom>(); |
| 93 | manager.addAxioms(ontology, axioms); | 92 | addTopAndBotTuple(topAxioms, botAxioms); |
| 93 | manager.addAxioms(ontology, topAxioms); | ||
| 94 | manager.addAxioms(ontology, botAxioms); | ||
| 94 | hermit = new Reasoner(ontology); | 95 | hermit = new Reasoner(ontology); |
| 95 | if (!hermit.isConsistent()) { | 96 | boolean topValid = true; |
| 97 | if (!hermit.isConsistent() || topAnswerTuple != null && (topValid = check(topAnswerTuple))) { | ||
| 96 | hermit.dispose(); | 98 | hermit.dispose(); |
| 97 | manager.removeAxioms(ontology, axioms); | 99 | manager.removeAxioms(ontology, topAxioms); |
| 98 | hermit = new Reasoner(ontology); | 100 | hermit = new Reasoner(ontology); |
| 99 | } else { | 101 | } else { |
| 100 | // if (topAnswerTuple != null && !check(topAnswerTuple)) tag = -1; | 102 | if (!topValid) tag = -1; |
| 101 | // else | 103 | else |
| 102 | if (botAnswerTuple != null && check(botAnswerTuple)) tag = 1; | 104 | if (botAnswerTuple != null && check(botAnswerTuple)) tag = 1; |
| 103 | } | 105 | } |
| 104 | } | 106 | } |
| @@ -106,23 +108,20 @@ public class HermitChecker implements Checker { | |||
| 106 | hermit = new Reasoner(ontology); | 108 | hermit = new Reasoner(ontology); |
| 107 | } | 109 | } |
| 108 | 110 | ||
| 109 | private void addTopAndBotTuple(Set<OWLAxiom> axioms) { | 111 | private void addTopAndBotTuple(Set<OWLAxiom> topAxioms, Set<OWLAxiom> botAxioms) { |
| 110 | // String top_str = Namespace.PAGODA_ANONY + "top"; | 112 | String top_str = Namespace.PAGODA_ANONY + "top", bot_str = Namespace.PAGODA_ANONY + "bot"; |
| 111 | String bot_str = Namespace.PAGODA_ANONY + "bot"; | 113 | topAnswerTuple = new AnswerTuple(new uk.ac.ox.cs.JRDFox.model.Individual[] { uk.ac.ox.cs.JRDFox.model.Individual.create(top_str) } ); |
| 112 | // topAnswerTuple = new AnswerTuple(new uk.ac.ox.cs.JRDFox.model.Individual[] { uk.ac.ox.cs.JRDFox.model.Individual.create(top_str) } ); | ||
| 113 | botAnswerTuple = new AnswerTuple(new uk.ac.ox.cs.JRDFox.model.Individual[] { uk.ac.ox.cs.JRDFox.model.Individual.create(bot_str) } ); | 114 | botAnswerTuple = new AnswerTuple(new uk.ac.ox.cs.JRDFox.model.Individual[] { uk.ac.ox.cs.JRDFox.model.Individual.create(bot_str) } ); |
| 114 | // OWLIndividual top_ind = factory.getOWLNamedIndividual(IRI.create(top_str)); | 115 | OWLIndividual top_ind = factory.getOWLNamedIndividual(IRI.create(top_str)), bot_ind = factory.getOWLNamedIndividual(IRI.create(bot_str)); |
| 115 | OWLIndividual bot_ind = factory.getOWLNamedIndividual(IRI.create(bot_str)); | ||
| 116 | Map<OWLAxiom, Integer> counter = new HashMap<OWLAxiom, Integer>(); | 116 | Map<OWLAxiom, Integer> counter = new HashMap<OWLAxiom, Integer>(); |
| 117 | 117 | ||
| 118 | // Set<String> topAnswers = new HashSet<String>(); | 118 | Set<String> topAnswers = new HashSet<String>(), botAnswers = new HashSet<String>(); |
| 119 | Set<String> botAnswers = new HashSet<String>(); | ||
| 120 | OWLIndividual sub, obj; | 119 | OWLIndividual sub, obj; |
| 121 | // if (dGraph.getExits().size() > 1) { | 120 | if (dGraph.getExits().size() > 1) { |
| 122 | // for (Clique answerClique: dGraph.getExits()) | 121 | for (Clique answerClique: dGraph.getExits()) |
| 123 | // topAnswers.add(((uk.ac.ox.cs.JRDFox.model.Individual) answerClique.getRepresentative().getAnswerTuple().getGroundTerm(0)).getIRI()); | 122 | topAnswers.add(((uk.ac.ox.cs.JRDFox.model.Individual) answerClique.getRepresentative().getAnswerTuple().getGroundTerm(0)).getIRI()); |
| 124 | // } | 123 | } |
| 125 | // else topAnswerTuple = null; | 124 | else topAnswerTuple = null; |
| 126 | 125 | ||
| 127 | if (dGraph.getEntrances().size() > 1) { | 126 | if (dGraph.getEntrances().size() > 1) { |
| 128 | for (Clique answerClique: dGraph.getEntrances()) | 127 | for (Clique answerClique: dGraph.getEntrances()) |
| @@ -134,23 +133,23 @@ public class HermitChecker implements Checker { | |||
| 134 | if (axiom instanceof OWLClassAssertionAxiom) { | 133 | if (axiom instanceof OWLClassAssertionAxiom) { |
| 135 | OWLClassAssertionAxiom ca = (OWLClassAssertionAxiom) axiom; | 134 | OWLClassAssertionAxiom ca = (OWLClassAssertionAxiom) axiom; |
| 136 | sub = ca.getIndividual(); | 135 | sub = ca.getIndividual(); |
| 137 | // if (topAnswers.contains(sub.toStringID())) | 136 | if (topAnswers.contains(sub.toStringID())) |
| 138 | // axioms.add(factory.getOWLClassAssertionAxiom(ca.getClassExpression(), top_ind)); | 137 | topAxioms.add(factory.getOWLClassAssertionAxiom(ca.getClassExpression(), top_ind)); |
| 139 | if (botAnswers.contains(sub.toStringID())) | 138 | if (botAnswers.contains(sub.toStringID())) |
| 140 | inc(counter, factory.getOWLClassAssertionAxiom(ca.getClassExpression(), bot_ind)); | 139 | inc(counter, factory.getOWLClassAssertionAxiom(ca.getClassExpression(), bot_ind)); |
| 141 | } | 140 | } |
| 142 | else if (axiom instanceof OWLObjectPropertyAssertionAxiom) { | 141 | else if (axiom instanceof OWLObjectPropertyAssertionAxiom) { |
| 143 | OWLObjectPropertyAssertionAxiom oa = (OWLObjectPropertyAssertionAxiom) axiom; | 142 | OWLObjectPropertyAssertionAxiom oa = (OWLObjectPropertyAssertionAxiom) axiom; |
| 144 | sub = oa.getSubject(); obj = oa.getObject(); | 143 | sub = oa.getSubject(); obj = oa.getObject(); |
| 145 | //// if (topAnswers.contains(sub.toStringID())) | 144 | if (topAnswers.contains(sub.toStringID())) |
| 146 | //// if (topAnswers.contains(obj.toStringID())) | 145 | if (topAnswers.contains(obj.toStringID())) |
| 147 | //// axioms.add(factory.getOWLObjectPropertyAssertionAxiom(oa.getProperty(), top_ind, top_ind)); | 146 | topAxioms.add(factory.getOWLObjectPropertyAssertionAxiom(oa.getProperty(), top_ind, top_ind)); |
| 148 | //// else | 147 | else |
| 149 | //// axioms.add(factory.getOWLObjectPropertyAssertionAxiom(oa.getProperty(), top_ind, obj)); | 148 | topAxioms.add(factory.getOWLObjectPropertyAssertionAxiom(oa.getProperty(), top_ind, obj)); |
| 150 | //// else { | 149 | else { |
| 151 | //// if (topAnswers.contains(obj.toStringID())) | 150 | if (topAnswers.contains(obj.toStringID())) |
| 152 | //// axioms.add(factory.getOWLObjectPropertyAssertionAxiom(oa.getProperty(), sub, top_ind)); | 151 | topAxioms.add(factory.getOWLObjectPropertyAssertionAxiom(oa.getProperty(), sub, top_ind)); |
| 153 | //// } | 152 | } |
| 154 | 153 | ||
| 155 | if (botAnswers.contains(sub.toStringID())) | 154 | if (botAnswers.contains(sub.toStringID())) |
| 156 | if (botAnswers.contains(obj.toStringID())) | 155 | if (botAnswers.contains(obj.toStringID())) |
| @@ -166,8 +165,8 @@ public class HermitChecker implements Checker { | |||
| 166 | else if (axiom instanceof OWLDataPropertyAssertionAxiom) { | 165 | else if (axiom instanceof OWLDataPropertyAssertionAxiom) { |
| 167 | OWLDataPropertyAssertionAxiom da = (OWLDataPropertyAssertionAxiom) axiom; | 166 | OWLDataPropertyAssertionAxiom da = (OWLDataPropertyAssertionAxiom) axiom; |
| 168 | sub = da.getSubject(); | 167 | sub = da.getSubject(); |
| 169 | // if (topAnswers.contains(sub.toStringID())) | 168 | if (topAnswers.contains(sub.toStringID())) |
| 170 | // axioms.add(factory.getOWLDataPropertyAssertionAxiom(da.getProperty(), top_ind, da.getObject())); | 169 | topAxioms.add(factory.getOWLDataPropertyAssertionAxiom(da.getProperty(), top_ind, da.getObject())); |
| 171 | 170 | ||
| 172 | if (botAnswers.contains(sub.toStringID())) | 171 | if (botAnswers.contains(sub.toStringID())) |
| 173 | inc(counter, factory.getOWLDataPropertyAssertionAxiom(da.getProperty(), bot_ind, da.getObject())); | 172 | inc(counter, factory.getOWLDataPropertyAssertionAxiom(da.getProperty(), bot_ind, da.getObject())); |
| @@ -176,7 +175,7 @@ public class HermitChecker implements Checker { | |||
| 176 | int number = botAnswers.size(); | 175 | int number = botAnswers.size(); |
| 177 | for (Map.Entry<OWLAxiom, Integer> entry: counter.entrySet()) { | 176 | for (Map.Entry<OWLAxiom, Integer> entry: counter.entrySet()) { |
| 178 | if (entry.getValue() == number) | 177 | if (entry.getValue() == number) |
| 179 | axioms.add(entry.getKey()); | 178 | botAxioms.add(entry.getKey()); |
| 180 | } | 179 | } |
| 181 | } | 180 | } |
| 182 | 181 | ||
