diff options
| author | yujiao <yujiao.zhou@gmail.com> | 2015-05-25 22:07:14 -0700 |
|---|---|---|
| committer | yujiao <yujiao.zhou@gmail.com> | 2015-05-25 22:07:14 -0700 |
| commit | 4f98cb7df7f2921808d825cdcd82f95a0899640e (patch) | |
| tree | fad60a143e8f6a300c24900b53d9a32af2875e24 /src/uk/ac/ox/cs | |
| parent | e02ad77cefc3005e36ae48fe47bf7914007f094a (diff) | |
| download | ACQuA-4f98cb7df7f2921808d825cdcd82f95a0899640e.tar.gz ACQuA-4f98cb7df7f2921808d825cdcd82f95a0899640e.zip | |
fixed a bug in the process of generating gap tuples, see test in
TestGapMappedToLower.java
Diffstat (limited to 'src/uk/ac/ox/cs')
13 files changed, 226 insertions, 51 deletions
diff --git a/src/uk/ac/ox/cs/pagoda/approx/RLPlusOntology.java b/src/uk/ac/ox/cs/pagoda/approx/RLPlusOntology.java index a60b664..1ed8ba6 100644 --- a/src/uk/ac/ox/cs/pagoda/approx/RLPlusOntology.java +++ b/src/uk/ac/ox/cs/pagoda/approx/RLPlusOntology.java | |||
| @@ -99,7 +99,12 @@ public class RLPlusOntology implements KnowledgeBase { | |||
| 99 | 99 | ||
| 100 | try { | 100 | try { |
| 101 | String path = OWLHelper.getOntologyPath(inputOntology); | 101 | String path = OWLHelper.getOntologyPath(inputOntology); |
| 102 | String name = path.substring(path.lastIndexOf(Utility.JAVA_FILE_SEPARATOR)); | 102 | String name; |
| 103 | if (path.contains(Utility.JAVA_FILE_SEPARATOR)) | ||
| 104 | name = path.substring(path.lastIndexOf(Utility.JAVA_FILE_SEPARATOR)); | ||
| 105 | else | ||
| 106 | name = path.substring(path.lastIndexOf(":")); | ||
| 107 | |||
| 103 | String originalExtension = name.lastIndexOf(".") >= 0 ? name.substring(name.lastIndexOf(".")) : ""; | 108 | String originalExtension = name.lastIndexOf(".") >= 0 ? name.substring(name.lastIndexOf(".")) : ""; |
| 104 | 109 | ||
| 105 | if (inputOntology.getOntologyID().getOntologyIRI() == null) | 110 | if (inputOntology.getOntologyID().getOntologyIRI() == null) |
diff --git a/src/uk/ac/ox/cs/pagoda/endomorph/Clique.java b/src/uk/ac/ox/cs/pagoda/endomorph/Clique.java index 1c269ea..9daea7e 100644 --- a/src/uk/ac/ox/cs/pagoda/endomorph/Clique.java +++ b/src/uk/ac/ox/cs/pagoda/endomorph/Clique.java | |||
| @@ -13,6 +13,7 @@ public class Clique { | |||
| 13 | public Clique(NodeTuple u) { | 13 | public Clique(NodeTuple u) { |
| 14 | nodeTuples = new HashSet<NodeTuple>(); | 14 | nodeTuples = new HashSet<NodeTuple>(); |
| 15 | representative = u; | 15 | representative = u; |
| 16 | nodeTuples.add(u); | ||
| 16 | } | 17 | } |
| 17 | 18 | ||
| 18 | public boolean addNodeTuple(NodeTuple nodeTuple) { | 19 | public boolean addNodeTuple(NodeTuple nodeTuple) { |
diff --git a/src/uk/ac/ox/cs/pagoda/endomorph/plan/OpenEndMultiThreadPlan.java b/src/uk/ac/ox/cs/pagoda/endomorph/plan/OpenEndMultiThreadPlan.java index 8c7ce6a..4e2fc5f 100644 --- a/src/uk/ac/ox/cs/pagoda/endomorph/plan/OpenEndMultiThreadPlan.java +++ b/src/uk/ac/ox/cs/pagoda/endomorph/plan/OpenEndMultiThreadPlan.java | |||
| @@ -69,7 +69,7 @@ public class OpenEndMultiThreadPlan implements CheckPlan { | |||
| 69 | int count = 0; | 69 | int count = 0; |
| 70 | for (Clique c: dGraph.getTopologicalOrder()) { | 70 | for (Clique c: dGraph.getTopologicalOrder()) { |
| 71 | if (validated.contains(c)) | 71 | if (validated.contains(c)) |
| 72 | count += c.getNodeTuples().size() + 1; | 72 | count += c.getNodeTuples().size(); |
| 73 | } | 73 | } |
| 74 | return count; | 74 | return count; |
| 75 | } | 75 | } |
diff --git a/src/uk/ac/ox/cs/pagoda/endomorph/plan/OpenEndPlan.java b/src/uk/ac/ox/cs/pagoda/endomorph/plan/OpenEndPlan.java index 202021d..a740833 100644 --- a/src/uk/ac/ox/cs/pagoda/endomorph/plan/OpenEndPlan.java +++ b/src/uk/ac/ox/cs/pagoda/endomorph/plan/OpenEndPlan.java | |||
| @@ -1,7 +1,6 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.endomorph.plan; | 1 | package uk.ac.ox.cs.pagoda.endomorph.plan; |
| 2 | 2 | ||
| 3 | import java.util.Collection; | 3 | import java.util.Collection; |
| 4 | import java.util.Deque; | ||
| 5 | import java.util.HashSet; | 4 | import java.util.HashSet; |
| 6 | import java.util.LinkedList; | 5 | import java.util.LinkedList; |
| 7 | import java.util.Map; | 6 | import java.util.Map; |
| @@ -23,35 +22,39 @@ public class OpenEndPlan implements CheckPlan { | |||
| 23 | Checker checker; | 22 | Checker checker; |
| 24 | DependencyGraph dGraph; | 23 | DependencyGraph dGraph; |
| 25 | QueryRecord m_record; | 24 | QueryRecord m_record; |
| 25 | int m_answerArity; | ||
| 26 | 26 | ||
| 27 | public OpenEndPlan(Checker checker, DependencyGraph dGraph, QueryRecord record) { | 27 | public OpenEndPlan(Checker checker, DependencyGraph dGraph, QueryRecord record) { |
| 28 | this.checker = checker; | 28 | this.checker = checker; |
| 29 | this.dGraph = dGraph; | 29 | this.dGraph = dGraph; |
| 30 | m_record = record; | 30 | m_record = record; |
| 31 | m_answerArity = record.getAnswerVariables().length; | ||
| 31 | } | 32 | } |
| 32 | 33 | ||
| 34 | Set<Clique> validated = new HashSet<Clique>(); | ||
| 35 | Set<Clique> falsified = new HashSet<Clique>(); | ||
| 36 | Set<AnswerTuple> passedAnswers = new HashSet<AnswerTuple>(); | ||
| 37 | |||
| 33 | @Override | 38 | @Override |
| 34 | public int check() { | 39 | public int check() { |
| 35 | Deque<Clique> topo = new LinkedList<Clique>(dGraph.getTopologicalOrder()); | 40 | LinkedList<Clique> topo = new LinkedList<Clique>(dGraph.getTopologicalOrder()); |
| 36 | Utility.logInfo("Entrances: " + dGraph.getEntrances().size() + " Exists: " + dGraph.getExits().size()); | 41 | Utility.logInfo("Entrances: " + dGraph.getEntrances().size() + " Exists: " + dGraph.getExits().size()); |
| 37 | Set<Clique> validated = new HashSet<Clique>(); | ||
| 38 | Set<Clique> falsified = new HashSet<Clique>(); | ||
| 39 | 42 | ||
| 40 | boolean flag = true; | 43 | boolean flag = true; |
| 41 | Clique clique; | 44 | Clique clique; |
| 42 | Timer t = new Timer(); | 45 | Timer t = new Timer(); |
| 43 | 46 | ||
| 44 | 47 | AnswerTuple answerTuple; | |
| 45 | AnswerTuple answerTuple; | ||
| 46 | while (!topo.isEmpty()) { | 48 | while (!topo.isEmpty()) { |
| 47 | if (flag) { | 49 | if (flag) { |
| 48 | clique = topo.removeFirst(); | 50 | clique = topo.removeFirst(); |
| 51 | if (redundant(clique)) continue; | ||
| 49 | if (validated.contains(clique)) continue; | 52 | if (validated.contains(clique)) continue; |
| 50 | if (falsified.contains(clique)) { flag = false; continue; } | 53 | if (falsified.contains(clique)) { flag = false; continue; } |
| 51 | Utility.logDebug("start checking front ... " + (answerTuple = clique.getRepresentative().getAnswerTuple())); | 54 | Utility.logDebug("start checking front ... " + (answerTuple = clique.getRepresentative().getAnswerTuple())); |
| 52 | if (checker.check(answerTuple)) { | 55 | if (checker.check(answerTuple)) { |
| 53 | Utility.logDebug(answerTuple.toString() + " is verified."); | 56 | Utility.logDebug(answerTuple.toString() + " is verified."); |
| 54 | setMarkCascadely(clique, validated, dGraph.getOutGoingEdges()); | 57 | setMarkCascadelyValidated(clique); |
| 55 | } | 58 | } |
| 56 | else { | 59 | else { |
| 57 | falsified.add(clique); | 60 | falsified.add(clique); |
| @@ -64,10 +67,10 @@ public class OpenEndPlan implements CheckPlan { | |||
| 64 | if (validated.contains(clique)) { flag = true; continue; } | 67 | if (validated.contains(clique)) { flag = true; continue; } |
| 65 | Utility.logDebug("start checking back ... " + (answerTuple = clique.getRepresentative().getAnswerTuple())); | 68 | Utility.logDebug("start checking back ... " + (answerTuple = clique.getRepresentative().getAnswerTuple())); |
| 66 | if (!checker.check(answerTuple)) | 69 | if (!checker.check(answerTuple)) |
| 67 | setMarkCascadely(clique, falsified, dGraph.getInComingEdges()); | 70 | setMarkCascadelyFasified(clique); |
| 68 | else { | 71 | else { |
| 69 | Utility.logDebug(answerTuple.toString() + " is verified."); | 72 | Utility.logDebug(answerTuple.toString() + " is verified."); |
| 70 | validated.add(clique); | 73 | addProjections(clique); |
| 71 | flag = true; | 74 | flag = true; |
| 72 | } | 75 | } |
| 73 | } | 76 | } |
| @@ -80,9 +83,8 @@ public class OpenEndPlan implements CheckPlan { | |||
| 80 | Collection<AnswerTuple> validAnswers = new LinkedList<AnswerTuple>(); | 83 | Collection<AnswerTuple> validAnswers = new LinkedList<AnswerTuple>(); |
| 81 | for (Clique c: dGraph.getTopologicalOrder()) | 84 | for (Clique c: dGraph.getTopologicalOrder()) |
| 82 | if (validated.contains(c)) { | 85 | if (validated.contains(c)) { |
| 83 | count += c.getNodeTuples().size() + 1; | 86 | count += c.getNodeTuples().size(); |
| 84 | validAnswers.add(c.getRepresentative().getAnswerTuple()); | 87 | // validAnswers.add(c.getRepresentative().getAnswerTuple()); |
| 85 | |||
| 86 | for (NodeTuple nodeTuple: c.getNodeTuples()) { | 88 | for (NodeTuple nodeTuple: c.getNodeTuples()) { |
| 87 | ans = nodeTuple.getAnswerTuple(); | 89 | ans = nodeTuple.getAnswerTuple(); |
| 88 | validAnswers.add(ans); | 90 | validAnswers.add(ans); |
| @@ -95,12 +97,35 @@ public class OpenEndPlan implements CheckPlan { | |||
| 95 | return count; | 97 | return count; |
| 96 | } | 98 | } |
| 97 | 99 | ||
| 98 | private void setMarkCascadely(Clique clique, Set<Clique> marked, Map<Clique, Collection<Clique>> edges) { | 100 | private boolean redundant(Clique clique) { |
| 99 | marked.add(clique); | 101 | for (NodeTuple nodeTuple: clique.getNodeTuples()) |
| 102 | if (!passedAnswers.contains(AnswerTuple.create(nodeTuple.getAnswerTuple(), m_answerArity))) | ||
| 103 | return false; | ||
| 104 | return true; | ||
| 105 | } | ||
| 106 | |||
| 107 | private void addProjections(Clique clique) { | ||
| 108 | for (NodeTuple nodeTuple: clique.getNodeTuples()) | ||
| 109 | passedAnswers.add(AnswerTuple.create(nodeTuple.getAnswerTuple(), m_answerArity)); | ||
| 110 | } | ||
| 111 | |||
| 112 | private void setMarkCascadelyValidated(Clique clique) { | ||
| 113 | validated.add(clique); | ||
| 114 | addProjections(clique); | ||
| 115 | Map<Clique, Collection<Clique>> edges = dGraph.getOutGoingEdges(); | ||
| 116 | if (edges.containsKey(clique)) | ||
| 117 | for (Clique c: edges.get(clique)) | ||
| 118 | if (!validated.contains(c)) | ||
| 119 | setMarkCascadelyValidated(c); | ||
| 120 | } | ||
| 121 | |||
| 122 | private void setMarkCascadelyFasified(Clique clique) { | ||
| 123 | falsified.add(clique); | ||
| 124 | Map<Clique, Collection<Clique>> edges = dGraph.getInComingEdges(); | ||
| 100 | if (edges.containsKey(clique)) | 125 | if (edges.containsKey(clique)) |
| 101 | for (Clique c: edges.get(clique)) | 126 | for (Clique c: edges.get(clique)) |
| 102 | if (!marked.contains(c)) | 127 | if (!falsified.contains(c)) |
| 103 | setMarkCascadely(c, marked, edges); | 128 | setMarkCascadelyFasified(c); |
| 104 | } | 129 | } |
| 105 | 130 | ||
| 106 | } | 131 | } |
diff --git a/src/uk/ac/ox/cs/pagoda/endomorph/plan/PlainPlan.java b/src/uk/ac/ox/cs/pagoda/endomorph/plan/PlainPlan.java index d6067d0..6931ccc 100644 --- a/src/uk/ac/ox/cs/pagoda/endomorph/plan/PlainPlan.java +++ b/src/uk/ac/ox/cs/pagoda/endomorph/plan/PlainPlan.java | |||
| @@ -22,7 +22,7 @@ public class PlainPlan implements CheckPlan { | |||
| 22 | int count = 0; | 22 | int count = 0; |
| 23 | for (Clique clique: toCheck) | 23 | for (Clique clique: toCheck) |
| 24 | if (checker.check(clique.getRepresentative().getAnswerTuple())) { | 24 | if (checker.check(clique.getRepresentative().getAnswerTuple())) { |
| 25 | count += clique.getNodeTuples().size() + 1; | 25 | count += clique.getNodeTuples().size(); |
| 26 | for (NodeTuple nodeTuple: clique.getNodeTuples()) | 26 | for (NodeTuple nodeTuple: clique.getNodeTuples()) |
| 27 | Utility.logDebug(nodeTuple.getAnswerTuple().toString()); | 27 | Utility.logDebug(nodeTuple.getAnswerTuple().toString()); |
| 28 | } | 28 | } |
diff --git a/src/uk/ac/ox/cs/pagoda/query/GapByStore4ID.java b/src/uk/ac/ox/cs/pagoda/query/GapByStore4ID.java index 1c0eb48..84929ad 100644 --- a/src/uk/ac/ox/cs/pagoda/query/GapByStore4ID.java +++ b/src/uk/ac/ox/cs/pagoda/query/GapByStore4ID.java | |||
| @@ -8,6 +8,7 @@ import uk.ac.ox.cs.pagoda.MyPrefixes; | |||
| 8 | //import uk.ac.ox.cs.pagoda.multistage.AnswerTupleID; | 8 | //import uk.ac.ox.cs.pagoda.multistage.AnswerTupleID; |
| 9 | import uk.ac.ox.cs.pagoda.reasoner.light.BasicQueryEngine; | 9 | import uk.ac.ox.cs.pagoda.reasoner.light.BasicQueryEngine; |
| 10 | import uk.ac.ox.cs.pagoda.reasoner.light.RDFoxTripleManager; | 10 | import uk.ac.ox.cs.pagoda.reasoner.light.RDFoxTripleManager; |
| 11 | import uk.ac.ox.cs.pagoda.util.Namespace; | ||
| 11 | import uk.ac.ox.cs.pagoda.util.Timer; | 12 | import uk.ac.ox.cs.pagoda.util.Timer; |
| 12 | import uk.ac.ox.cs.pagoda.util.Utility; | 13 | import uk.ac.ox.cs.pagoda.util.Utility; |
| 13 | import uk.ac.ox.cs.JRDFox.JRDFStoreException; | 14 | import uk.ac.ox.cs.JRDFox.JRDFStoreException; |
| @@ -17,14 +18,14 @@ import uk.ac.ox.cs.JRDFox.store.TupleIterator; | |||
| 17 | //public class GapByStore4ID extends GapTupleIterator<AnswerTupleID> { | 18 | //public class GapByStore4ID extends GapTupleIterator<AnswerTupleID> { |
| 18 | public class GapByStore4ID extends GapTupleIterator<int[]> { | 19 | public class GapByStore4ID extends GapTupleIterator<int[]> { |
| 19 | 20 | ||
| 20 | private MyPrefixes prefixes = MyPrefixes.PAGOdAPrefixes; | 21 | protected MyPrefixes prefixes = MyPrefixes.PAGOdAPrefixes; |
| 21 | private TupleIterator iterator = null; | 22 | protected TupleIterator iterator = null; |
| 22 | 23 | ||
| 23 | // AnswerTupleID tuple; | 24 | // AnswerTupleID tuple; |
| 24 | int[] tuple; | 25 | protected int[] tuple; |
| 25 | private BasicQueryEngine m_engine; | 26 | protected BasicQueryEngine m_engine; |
| 26 | private DataStore m_store; | 27 | protected DataStore m_store; |
| 27 | private RDFoxTripleManager tripleManager; | 28 | protected RDFoxTripleManager tripleManager; |
| 28 | 29 | ||
| 29 | public GapByStore4ID(BasicQueryEngine engine) { | 30 | public GapByStore4ID(BasicQueryEngine engine) { |
| 30 | m_engine = engine; | 31 | m_engine = engine; |
| @@ -32,7 +33,7 @@ public class GapByStore4ID extends GapTupleIterator<int[]> { | |||
| 32 | tripleManager = new RDFoxTripleManager(m_store, false); | 33 | tripleManager = new RDFoxTripleManager(m_store, false); |
| 33 | } | 34 | } |
| 34 | 35 | ||
| 35 | long multi; | 36 | protected long multi; |
| 36 | 37 | ||
| 37 | @Override | 38 | @Override |
| 38 | public void compile(String program) throws JRDFStoreException { | 39 | public void compile(String program) throws JRDFStoreException { |
| @@ -117,7 +118,7 @@ public class GapByStore4ID extends GapTupleIterator<int[]> { | |||
| 117 | return predicatesWithGap; | 118 | return predicatesWithGap; |
| 118 | } | 119 | } |
| 119 | 120 | ||
| 120 | private Integer getGapPredicateID(int originalID) { | 121 | protected Integer getGapPredicateID(int originalID) { |
| 121 | Integer gapID; | 122 | Integer gapID; |
| 122 | if ((gapID = original2gap.get(originalID)) != null) | 123 | if ((gapID = original2gap.get(originalID)) != null) |
| 123 | return gapID; | 124 | return gapID; |
| @@ -136,11 +137,14 @@ public class GapByStore4ID extends GapTupleIterator<int[]> { | |||
| 136 | return gapID; | 137 | return gapID; |
| 137 | } | 138 | } |
| 138 | 139 | ||
| 139 | private boolean isAuxPredicate(String originalPredicate) { | 140 | protected boolean isAuxPredicate(String originalPredicate) { |
| 140 | return originalPredicate.contains("_AUX"); | 141 | if (originalPredicate.equals(Namespace.EQUALITY_QUOTED)) return false; |
| 142 | return originalPredicate.contains("_AUX") || | ||
| 143 | originalPredicate.startsWith("<" + Namespace.OWL_NS) || | ||
| 144 | originalPredicate.startsWith("<" + Namespace.PAGODA_ORIGINAL); | ||
| 141 | } | 145 | } |
| 142 | 146 | ||
| 143 | private boolean isRDF_TYPE() { | 147 | protected boolean isRDF_TYPE() { |
| 144 | // return tripleManager.isRdfTypeID(tuple.getTerm(1)); | 148 | // return tripleManager.isRdfTypeID(tuple.getTerm(1)); |
| 145 | return tripleManager.isRdfTypeID(tuple[1]); | 149 | return tripleManager.isRdfTypeID(tuple[1]); |
| 146 | } | 150 | } |
| @@ -150,8 +154,6 @@ public class GapByStore4ID extends GapTupleIterator<int[]> { | |||
| 150 | Utility.logError("Unsupported operation!"); | 154 | Utility.logError("Unsupported operation!"); |
| 151 | } | 155 | } |
| 152 | 156 | ||
| 153 | private boolean valid = false; | ||
| 154 | |||
| 155 | @Override | 157 | @Override |
| 156 | public void save(String file) { | 158 | public void save(String file) { |
| 157 | Utility.logError("Unsupported Operation..."); | 159 | Utility.logError("Unsupported Operation..."); |
| @@ -168,7 +170,6 @@ public class GapByStore4ID extends GapTupleIterator<int[]> { | |||
| 168 | ++tupleCounter; | 170 | ++tupleCounter; |
| 169 | tripleManager.addTripleByID(tuple); | 171 | tripleManager.addTripleByID(tuple); |
| 170 | } | 172 | } |
| 171 | valid = true; | ||
| 172 | 173 | ||
| 173 | long tripleCounter = m_store.getTriplesCount(); | 174 | long tripleCounter = m_store.getTriplesCount(); |
| 174 | Utility.logDebug("There are " + tupleCounter + " tuples in the gap between lower and upper bound materialisation.", | 175 | Utility.logDebug("There are " + tupleCounter + " tuples in the gap between lower and upper bound materialisation.", |
| @@ -183,8 +184,6 @@ public class GapByStore4ID extends GapTupleIterator<int[]> { | |||
| 183 | } | 184 | } |
| 184 | } | 185 | } |
| 185 | 186 | ||
| 186 | public boolean isValid() {return valid; } | ||
| 187 | |||
| 188 | @Override | 187 | @Override |
| 189 | public void addTo(DataStore store) throws JRDFStoreException { | 188 | public void addTo(DataStore store) throws JRDFStoreException { |
| 190 | Utility.logError("Unsupported Operation..."); | 189 | Utility.logError("Unsupported Operation..."); |
diff --git a/src/uk/ac/ox/cs/pagoda/query/GapByStore4ID2.java b/src/uk/ac/ox/cs/pagoda/query/GapByStore4ID2.java new file mode 100644 index 0000000..f8e1709 --- /dev/null +++ b/src/uk/ac/ox/cs/pagoda/query/GapByStore4ID2.java | |||
| @@ -0,0 +1,146 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.query; | ||
| 2 | |||
| 3 | import java.util.HashMap; | ||
| 4 | import java.util.HashSet; | ||
| 5 | import java.util.LinkedList; | ||
| 6 | import java.util.Map; | ||
| 7 | import java.util.Set; | ||
| 8 | |||
| 9 | import uk.ac.ox.cs.pagoda.reasoner.light.BasicQueryEngine; | ||
| 10 | import uk.ac.ox.cs.pagoda.util.UFS; | ||
| 11 | import uk.ac.ox.cs.JRDFox.JRDFStoreException; | ||
| 12 | import uk.ac.ox.cs.JRDFox.store.TupleIterator; | ||
| 13 | |||
| 14 | public class GapByStore4ID2 extends GapByStore4ID { | ||
| 15 | |||
| 16 | private BasicQueryEngine m_baseEngine; | ||
| 17 | private UFS<String> m_equality = null, m_baseEquality = null; | ||
| 18 | |||
| 19 | public GapByStore4ID2(BasicQueryEngine engine, BasicQueryEngine baseEngine) { | ||
| 20 | super(engine); | ||
| 21 | m_baseEngine = baseEngine; | ||
| 22 | } | ||
| 23 | |||
| 24 | @Override | ||
| 25 | public boolean hasNext() { | ||
| 26 | if (getNewGapTuple(iterator, -1)) return true; | ||
| 27 | if (iterator != null) { | ||
| 28 | iterator.dispose(); | ||
| 29 | iterator = null; | ||
| 30 | } | ||
| 31 | return getNextGapFactAboutEquality(); | ||
| 32 | } | ||
| 33 | |||
| 34 | private boolean getNewGapTuple(TupleIterator it, int firstElement) { | ||
| 35 | if (it == null) return false; | ||
| 36 | int firstIndex = 0; | ||
| 37 | tuple = new int[3]; | ||
| 38 | if (firstElement > 0) { | ||
| 39 | tuple[0] = firstElement; | ||
| 40 | firstIndex = 1; | ||
| 41 | } | ||
| 42 | Integer predicate; | ||
| 43 | try { | ||
| 44 | for (; multi != 0; multi = it.getNext()) { | ||
| 45 | for (int i = firstIndex; i < 3; ++i) | ||
| 46 | tuple[i] = (int) it.getResourceID(i - firstIndex); | ||
| 47 | |||
| 48 | if (isRDF_TYPE()) { | ||
| 49 | predicate = getGapPredicateID(tuple[2]); | ||
| 50 | if (predicate == null) continue; | ||
| 51 | tuple[2] = predicate; | ||
| 52 | } | ||
| 53 | else { | ||
| 54 | predicate = getGapPredicateID(tuple[1]); | ||
| 55 | if (predicate == null) continue; | ||
| 56 | tuple[1] = predicate; | ||
| 57 | } | ||
| 58 | return true; | ||
| 59 | } | ||
| 60 | } catch (JRDFStoreException e) { | ||
| 61 | e.printStackTrace(); | ||
| 62 | return false; | ||
| 63 | } | ||
| 64 | return false; | ||
| 65 | } | ||
| 66 | |||
| 67 | private LinkedList<String> toAddedIndividuals = null; | ||
| 68 | private TupleIterator iter_individual = null; | ||
| 69 | private int currentID = -1; | ||
| 70 | |||
| 71 | private boolean getNextGapFactAboutEquality() { | ||
| 72 | if (toAddedIndividuals == null) { | ||
| 73 | m_equality = m_engine.getEqualityGroups(false); | ||
| 74 | m_baseEquality = m_baseEngine.getEqualityGroups(false); | ||
| 75 | toAddedIndividuals = new LinkedList<String>(); | ||
| 76 | Map<String, Integer> rep2cnt = new HashMap<String, Integer>(); | ||
| 77 | Map<String, Integer> rep2cnt_base = new HashMap<String, Integer>(); | ||
| 78 | count(m_engine, m_equality, rep2cnt); | ||
| 79 | count(m_baseEngine, m_baseEquality, rep2cnt_base); | ||
| 80 | Set<String> visitedrep = new HashSet<String>(); | ||
| 81 | for (String individual : m_equality.keySet()) { | ||
| 82 | String rep = m_equality.find(individual); | ||
| 83 | if (visitedrep.contains(rep)) continue; | ||
| 84 | visitedrep.add(rep); | ||
| 85 | String rep_base = m_baseEquality.find(individual); | ||
| 86 | if (!rep2cnt.get(rep).equals(rep2cnt_base.get(rep_base))) { | ||
| 87 | toAddedIndividuals.add(rep); | ||
| 88 | } | ||
| 89 | } | ||
| 90 | |||
| 91 | } | ||
| 92 | while (true) { | ||
| 93 | if (getNewGapTuple(iter_individual, currentID)) return true; | ||
| 94 | if (iter_individual != null) { | ||
| 95 | iter_individual.dispose(); | ||
| 96 | iter_individual = null; | ||
| 97 | } | ||
| 98 | if (toAddedIndividuals.isEmpty()) { | ||
| 99 | currentID = -1; | ||
| 100 | return false; | ||
| 101 | } | ||
| 102 | String individual = toAddedIndividuals.remove(); | ||
| 103 | currentID = tripleManager.getResourceID(individual); | ||
| 104 | try { | ||
| 105 | iter_individual = m_engine.internal_evaluateNotExpanded(String.format("select distinct ?y ?z where { <%s> ?y ?z }", individual)); | ||
| 106 | multi = iter_individual.open(); | ||
| 107 | } catch (JRDFStoreException e) { | ||
| 108 | e.printStackTrace(); | ||
| 109 | } | ||
| 110 | } | ||
| 111 | } | ||
| 112 | |||
| 113 | private void count(BasicQueryEngine engine, UFS<String> equality, Map<String, Integer> map) { | ||
| 114 | for (String ind : equality.keySet()) { | ||
| 115 | Integer exist = map.get(ind); | ||
| 116 | if (exist == null) | ||
| 117 | map.put(equality.find(ind), 1); | ||
| 118 | else | ||
| 119 | map.put(equality.find(ind), ++exist); | ||
| 120 | } | ||
| 121 | } | ||
| 122 | |||
| 123 | @Override | ||
| 124 | public int[] next() { | ||
| 125 | try { | ||
| 126 | if (iterator != null) | ||
| 127 | multi = iterator.getNext(); | ||
| 128 | else if (iter_individual != null) | ||
| 129 | multi = iter_individual.getNext(); | ||
| 130 | else | ||
| 131 | multi = 0; | ||
| 132 | } catch (JRDFStoreException e) { | ||
| 133 | e.printStackTrace(); | ||
| 134 | } | ||
| 135 | return tuple; | ||
| 136 | } | ||
| 137 | |||
| 138 | public void clear() { | ||
| 139 | super.clear(); | ||
| 140 | if (iter_individual != null) { | ||
| 141 | iter_individual.dispose(); | ||
| 142 | iter_individual = null; | ||
| 143 | } | ||
| 144 | } | ||
| 145 | |||
| 146 | } | ||
diff --git a/src/uk/ac/ox/cs/pagoda/query/GapByTriple.java b/src/uk/ac/ox/cs/pagoda/query/GapByTriple.java index a1c1b0e..d2e9b90 100644 --- a/src/uk/ac/ox/cs/pagoda/query/GapByTriple.java +++ b/src/uk/ac/ox/cs/pagoda/query/GapByTriple.java | |||
| @@ -164,11 +164,6 @@ public class GapByTriple extends GapTupleIterator<String> { | |||
| 164 | } | 164 | } |
| 165 | 165 | ||
| 166 | @Override | 166 | @Override |
| 167 | public boolean isValid() { | ||
| 168 | return true; | ||
| 169 | } | ||
| 170 | |||
| 171 | @Override | ||
| 172 | public void clear() { | 167 | public void clear() { |
| 173 | iterator.dispose(); | 168 | iterator.dispose(); |
| 174 | } | 169 | } |
diff --git a/src/uk/ac/ox/cs/pagoda/query/GapTupleIterator.java b/src/uk/ac/ox/cs/pagoda/query/GapTupleIterator.java index 58303bb..61b6364 100644 --- a/src/uk/ac/ox/cs/pagoda/query/GapTupleIterator.java +++ b/src/uk/ac/ox/cs/pagoda/query/GapTupleIterator.java | |||
| @@ -17,8 +17,6 @@ public abstract class GapTupleIterator<T> implements Iterator<T> { | |||
| 17 | 17 | ||
| 18 | public void compile(String programText) throws JRDFStoreException {} | 18 | public void compile(String programText) throws JRDFStoreException {} |
| 19 | 19 | ||
| 20 | public abstract boolean isValid(); | ||
| 21 | |||
| 22 | public abstract void save(String file); | 20 | public abstract void save(String file); |
| 23 | 21 | ||
| 24 | public abstract void addBackTo() throws JRDFStoreException; | 22 | public abstract void addBackTo() throws JRDFStoreException; |
| @@ -26,5 +24,5 @@ public abstract class GapTupleIterator<T> implements Iterator<T> { | |||
| 26 | public abstract void addTo(DataStore store) throws JRDFStoreException; | 24 | public abstract void addTo(DataStore store) throws JRDFStoreException; |
| 27 | 25 | ||
| 28 | public abstract void clear(); | 26 | public abstract void clear(); |
| 29 | 27 | ||
| 30 | } | 28 | } |
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java b/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java index 17838ae..55ecb81 100644 --- a/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java +++ b/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java | |||
| @@ -145,7 +145,8 @@ public class MyQueryReasoner extends QueryReasoner { | |||
| 145 | trackingStore.materialise("saturate named individuals", originalMarkProgram); | 145 | trackingStore.materialise("saturate named individuals", originalMarkProgram); |
| 146 | 146 | ||
| 147 | // materialiseFullUpper(); | 147 | // materialiseFullUpper(); |
| 148 | GapByStore4ID gap = new GapByStore4ID(trackingStore); | 148 | // GapByStore4ID gap = new GapByStore4ID(trackingStore); |
| 149 | GapByStore4ID gap = new GapByStore4ID2(trackingStore, rlLowerStore); | ||
| 149 | trackingStore.materialiseFoldedly(program, gap); | 150 | trackingStore.materialiseFoldedly(program, gap); |
| 150 | predicatesWithGap = gap.getPredicatesWithGap(); | 151 | predicatesWithGap = gap.getPredicatesWithGap(); |
| 151 | gap.clear(); | 152 | gap.clear(); |
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/light/BasicQueryEngine.java b/src/uk/ac/ox/cs/pagoda/reasoner/light/BasicQueryEngine.java index 11588ce..79be8aa 100644 --- a/src/uk/ac/ox/cs/pagoda/reasoner/light/BasicQueryEngine.java +++ b/src/uk/ac/ox/cs/pagoda/reasoner/light/BasicQueryEngine.java | |||
| @@ -309,8 +309,8 @@ public class BasicQueryEngine extends RDFoxQueryEngine { | |||
| 309 | 309 | ||
| 310 | private UFS<String> equalityGroups = null; | 310 | private UFS<String> equalityGroups = null; |
| 311 | 311 | ||
| 312 | public UFS<String> getEqualityGroups() { | 312 | public UFS<String> getEqualityGroups(boolean reuse) { |
| 313 | if (equalityGroups != null) return equalityGroups; | 313 | if (reuse && equalityGroups != null) return equalityGroups; |
| 314 | 314 | ||
| 315 | equalityGroups = new UFS<String>(); | 315 | equalityGroups = new UFS<String>(); |
| 316 | 316 | ||
diff --git a/src/uk/ac/ox/cs/pagoda/tracking/QueryTracker.java b/src/uk/ac/ox/cs/pagoda/tracking/QueryTracker.java index f836212..2973109 100644 --- a/src/uk/ac/ox/cs/pagoda/tracking/QueryTracker.java +++ b/src/uk/ac/ox/cs/pagoda/tracking/QueryTracker.java | |||
| @@ -54,7 +54,7 @@ public class QueryTracker { | |||
| 54 | m_record = queryRecord; | 54 | m_record = queryRecord; |
| 55 | 55 | ||
| 56 | m_manager = m_encoder.getOntology().getOWLOntologyManager(); | 56 | m_manager = m_encoder.getOntology().getOWLOntologyManager(); |
| 57 | equalityGroups = m_dataStore.getEqualityGroups(); | 57 | equalityGroups = m_dataStore.getEqualityGroups(true); |
| 58 | 58 | ||
| 59 | } | 59 | } |
| 60 | 60 | ||
diff --git a/src/uk/ac/ox/cs/pagoda/tracking/TrackingRuleEncoderWithGap.java b/src/uk/ac/ox/cs/pagoda/tracking/TrackingRuleEncoderWithGap.java index 555f0af..99028ca 100644 --- a/src/uk/ac/ox/cs/pagoda/tracking/TrackingRuleEncoderWithGap.java +++ b/src/uk/ac/ox/cs/pagoda/tracking/TrackingRuleEncoderWithGap.java | |||
| @@ -1,6 +1,7 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.tracking; | 1 | package uk.ac.ox.cs.pagoda.tracking; |
| 2 | 2 | ||
| 3 | import java.util.Collection; | 3 | import java.util.Collection; |
| 4 | import java.util.HashSet; | ||
| 4 | import java.util.LinkedList; | 5 | import java.util.LinkedList; |
| 5 | import java.util.Set; | 6 | import java.util.Set; |
| 6 | 7 | ||
| @@ -37,7 +38,8 @@ public class TrackingRuleEncoderWithGap extends TrackingRuleEncoder { | |||
| 37 | AtomicRole trackingSameAs = AtomicRole.create(Namespace.EQUALITY + "_tn"); | 38 | AtomicRole trackingSameAs = AtomicRole.create(Namespace.EQUALITY + "_tn"); |
| 38 | OWLOntology onto = program.getOntology(); | 39 | OWLOntology onto = program.getOntology(); |
| 39 | Atom[] headAtom = new Atom[] {Atom.create(trackingSameAs, X, X)}, bodyAtom; | 40 | Atom[] headAtom = new Atom[] {Atom.create(trackingSameAs, X, X)}, bodyAtom; |
| 40 | for (OWLClass cls: onto.getClassesInSignature(true)) { | 41 | for (OWLOntology o: onto.getImportsClosure()) |
| 42 | for (OWLClass cls: o.getClassesInSignature()) { | ||
| 41 | String clsIRI = cls.getIRI().toString(); | 43 | String clsIRI = cls.getIRI().toString(); |
| 42 | unaryPredicates.add(clsIRI); | 44 | unaryPredicates.add(clsIRI); |
| 43 | bodyAtom = new Atom[] { | 45 | bodyAtom = new Atom[] { |
| @@ -47,7 +49,10 @@ public class TrackingRuleEncoderWithGap extends TrackingRuleEncoder { | |||
| 47 | } | 49 | } |
| 48 | 50 | ||
| 49 | Variable Y = Variable.create("Y"); | 51 | Variable Y = Variable.create("Y"); |
| 50 | Set<OWLObjectProperty> setOfProperties = onto.getObjectPropertiesInSignature(true); | 52 | Set<OWLObjectProperty> setOfProperties = new HashSet<OWLObjectProperty>(); |
| 53 | for (OWLOntology o: onto.getImportsClosure()) | ||
| 54 | for (OWLObjectProperty prop: o.getObjectPropertiesInSignature()) | ||
| 55 | setOfProperties.add(prop); | ||
| 51 | setOfProperties.add(onto.getOWLOntologyManager().getOWLDataFactory().getOWLObjectProperty(IRI.create(Namespace.INEQUALITY))); | 56 | setOfProperties.add(onto.getOWLOntologyManager().getOWLDataFactory().getOWLObjectProperty(IRI.create(Namespace.INEQUALITY))); |
| 52 | for (OWLObjectProperty prop: setOfProperties) { | 57 | for (OWLObjectProperty prop: setOfProperties) { |
| 53 | String propIRI = prop.getIRI().toString(); | 58 | String propIRI = prop.getIRI().toString(); |
