diff options
Diffstat (limited to 'src/uk/ac/ox/cs/pagoda/query')
| -rw-r--r-- | src/uk/ac/ox/cs/pagoda/query/GapByStore4ID.java | 31 | ||||
| -rw-r--r-- | src/uk/ac/ox/cs/pagoda/query/GapByStore4ID2.java | 146 | ||||
| -rw-r--r-- | src/uk/ac/ox/cs/pagoda/query/GapByTriple.java | 5 | ||||
| -rw-r--r-- | src/uk/ac/ox/cs/pagoda/query/GapTupleIterator.java | 4 |
4 files changed, 162 insertions, 24 deletions
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 | } |
