diff options
| author | RncLsn <rnc.lsn@gmail.com> | 2015-05-28 17:11:35 +0100 |
|---|---|---|
| committer | RncLsn <rnc.lsn@gmail.com> | 2015-05-28 17:11:35 +0100 |
| commit | de3749532d060f26c966a81c03f9a5d846c33d06 (patch) | |
| tree | 6cc5ba2837dc3c167b100f5e8be4e8c16da7be98 /src/uk/ac/ox/cs/pagoda/query/GapByStore4ID.java | |
| parent | 4298cdef8e551325cd16b4e24ae6699c44b60751 (diff) | |
| download | ACQuA-de3749532d060f26c966a81c03f9a5d846c33d06.tar.gz ACQuA-de3749532d060f26c966a81c03f9a5d846c33d06.zip | |
Merged updates from upstream.
Diffstat (limited to 'src/uk/ac/ox/cs/pagoda/query/GapByStore4ID.java')
| -rw-r--r-- | src/uk/ac/ox/cs/pagoda/query/GapByStore4ID.java | 120 |
1 files changed, 59 insertions, 61 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..02db18d 100644 --- a/src/uk/ac/ox/cs/pagoda/query/GapByStore4ID.java +++ b/src/uk/ac/ox/cs/pagoda/query/GapByStore4ID.java | |||
| @@ -1,103 +1,106 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.query; | 1 | package uk.ac.ox.cs.pagoda.query; |
| 2 | 2 | ||
| 3 | import java.util.HashMap; | 3 | import uk.ac.ox.cs.JRDFox.JRDFStoreException; |
| 4 | import java.util.LinkedList; | 4 | import uk.ac.ox.cs.JRDFox.store.DataStore; |
| 5 | import java.util.Map; | 5 | import uk.ac.ox.cs.JRDFox.store.TupleIterator; |
| 6 | |||
| 7 | import uk.ac.ox.cs.pagoda.MyPrefixes; | 6 | import uk.ac.ox.cs.pagoda.MyPrefixes; |
| 8 | //import uk.ac.ox.cs.pagoda.multistage.AnswerTupleID; | ||
| 9 | import uk.ac.ox.cs.pagoda.reasoner.light.BasicQueryEngine; | 7 | import uk.ac.ox.cs.pagoda.reasoner.light.BasicQueryEngine; |
| 10 | import uk.ac.ox.cs.pagoda.reasoner.light.RDFoxTripleManager; | 8 | import uk.ac.ox.cs.pagoda.reasoner.light.RDFoxTripleManager; |
| 9 | import uk.ac.ox.cs.pagoda.util.Namespace; | ||
| 11 | import uk.ac.ox.cs.pagoda.util.Timer; | 10 | import uk.ac.ox.cs.pagoda.util.Timer; |
| 12 | import uk.ac.ox.cs.pagoda.util.Utility; | 11 | import uk.ac.ox.cs.pagoda.util.Utility; |
| 13 | import uk.ac.ox.cs.JRDFox.JRDFStoreException; | 12 | |
| 14 | import uk.ac.ox.cs.JRDFox.store.DataStore; | 13 | import java.util.HashMap; |
| 15 | import uk.ac.ox.cs.JRDFox.store.TupleIterator; | 14 | import java.util.LinkedList; |
| 15 | import java.util.Map; | ||
| 16 | |||
| 17 | //import uk.ac.ox.cs.pagoda.multistage.AnswerTupleID; | ||
| 16 | 18 | ||
| 17 | //public class GapByStore4ID extends GapTupleIterator<AnswerTupleID> { | 19 | //public class GapByStore4ID extends GapTupleIterator<AnswerTupleID> { |
| 18 | public class GapByStore4ID extends GapTupleIterator<int[]> { | 20 | public class GapByStore4ID extends GapTupleIterator<int[]> { |
| 19 | 21 | ||
| 20 | private MyPrefixes prefixes = MyPrefixes.PAGOdAPrefixes; | 22 | protected MyPrefixes prefixes = MyPrefixes.PAGOdAPrefixes; |
| 21 | private TupleIterator iterator = null; | 23 | protected TupleIterator iterator = null; |
| 22 | 24 | ||
| 23 | // AnswerTupleID tuple; | 25 | // AnswerTupleID tuple; |
| 24 | int[] tuple; | 26 | protected int[] tuple; |
| 25 | private BasicQueryEngine m_engine; | 27 | protected BasicQueryEngine m_engine; |
| 26 | private DataStore m_store; | 28 | protected DataStore m_store; |
| 27 | private RDFoxTripleManager tripleManager; | 29 | protected RDFoxTripleManager tripleManager; |
| 30 | protected long multi; | ||
| 31 | Map<Integer, Integer> original2gap = new HashMap<Integer, Integer>(); | ||
| 32 | LinkedList<String> predicatesWithGap = new LinkedList<String>(); | ||
| 28 | 33 | ||
| 29 | public GapByStore4ID(BasicQueryEngine engine) { | 34 | public GapByStore4ID(BasicQueryEngine engine) { |
| 30 | m_engine = engine; | 35 | m_engine = engine; |
| 31 | m_store = engine.getDataStore(); | 36 | m_store = engine.getDataStore(); |
| 32 | tripleManager = new RDFoxTripleManager(m_store, false); | 37 | tripleManager = new RDFoxTripleManager(m_store, false); |
| 33 | } | 38 | } |
| 34 | 39 | ||
| 35 | long multi; | ||
| 36 | |||
| 37 | @Override | 40 | @Override |
| 38 | public void compile(String program) throws JRDFStoreException { | 41 | public void compile(String program) throws JRDFStoreException { |
| 39 | clear(); | 42 | clear(); |
| 40 | 43 | ||
| 41 | boolean incrementally = true; | 44 | boolean incrementally = true; |
| 42 | Timer t = new Timer(); | 45 | Timer t = new Timer(); |
| 43 | long oldTripleCount = m_store.getTriplesCount(); | 46 | long oldTripleCount = m_store.getTriplesCount(); |
| 44 | 47 | ||
| 45 | if (program != null) { | 48 | if (program != null) { |
| 46 | // m_store.addRules(new String[] {program}); | 49 | // m_store.addRules(new String[] {program}); |
| 47 | m_store.importRules(program); | 50 | m_store.importRules(program); |
| 48 | incrementally = false; | 51 | incrementally = false; |
| 49 | } | 52 | } |
| 50 | 53 | ||
| 51 | m_store.applyReasoning(incrementally); | 54 | m_store.applyReasoning(incrementally); |
| 52 | 55 | ||
| 53 | long tripleCount = m_store.getTriplesCount(); | 56 | long tripleCount = m_store.getTriplesCount(); |
| 54 | 57 | ||
| 55 | Utility.logDebug("current store after materialising upper related rules: " + tripleCount + " (" + (tripleCount - oldTripleCount) + " new)", | 58 | Utility.logDebug("current store after materialising upper related rules: " + tripleCount + " (" + (tripleCount - oldTripleCount) + " new)", |
| 56 | "current store finished the materialisation of upper related rules in " + t.duration() + " seconds."); | 59 | "current store finished the materialisation of upper related rules in " + t.duration() + " seconds."); |
| 57 | 60 | ||
| 58 | m_engine.setExpandEquality(false); | 61 | m_engine.setExpandEquality(false); |
| 59 | iterator = m_engine.internal_evaluateAgainstIDBs("select ?x ?y ?z where { ?x ?y ?z . }"); | 62 | iterator = m_engine.internal_evaluateAgainstIDBs("select ?x ?y ?z where { ?x ?y ?z . }"); |
| 60 | m_engine.setExpandEquality(true); | 63 | m_engine.setExpandEquality(true); |
| 61 | 64 | ||
| 62 | multi = iterator.open(); | 65 | multi = iterator.open(); |
| 63 | Utility.logDebug("gap query evaluted ..."); | 66 | Utility.logDebug("gap query evaluted ..."); |
| 64 | } | 67 | } |
| 65 | 68 | ||
| 66 | @Override | 69 | @Override |
| 67 | public boolean hasNext() { | 70 | public boolean hasNext() { |
| 68 | if (iterator == null) return false; | 71 | if(iterator == null) return false; |
| 69 | try { | 72 | try { |
| 70 | // tuple = new AnswerTupleID(3); | 73 | // tuple = new AnswerTupleID(3); |
| 71 | tuple = new int[3]; | 74 | tuple = new int[3]; |
| 72 | Integer predicate; | 75 | Integer predicate; |
| 73 | for (; multi != 0; multi = iterator.getNext()) { | 76 | for (; multi != 0; multi = iterator.getNext()) { |
| 74 | for (int i = 0; i < 3; ++i) | 77 | for (int i = 0; i < 3; ++i) |
| 75 | // tuple.setTerm(i, (int) iterator.getResourceID(i)); | 78 | // tuple.setTerm(i, (int) iterator.getResourceID(i)); |
| 76 | tuple[i] = (int) iterator.getResourceID(i); | 79 | tuple[i] = iterator.getResourceID(i); |
| 77 | 80 | ||
| 78 | if (isRDF_TYPE()) { | 81 | if (isRDF_TYPE()) { |
| 79 | // predicate = getGapPredicateID(tuple.getTerm(2)); | 82 | // predicate = getGapPredicateID(tuple.getTerm(2)); |
| 80 | predicate = getGapPredicateID(tuple[2]); | 83 | predicate = getGapPredicateID(tuple[2]); |
| 81 | if (predicate == null) continue; | 84 | if(predicate == null) continue; |
| 82 | // tuple.setTerm(2, predicate); | 85 | // tuple.setTerm(2, predicate); |
| 83 | tuple[2] = predicate; | 86 | tuple[2] = predicate; |
| 84 | } | 87 | } |
| 85 | else { | 88 | else { |
| 86 | // predicate = getGapPredicateID(tuple.getTerm(1)); | 89 | // predicate = getGapPredicateID(tuple.getTerm(1)); |
| 87 | predicate = getGapPredicateID(tuple[1]); | 90 | predicate = getGapPredicateID(tuple[1]); |
| 88 | if (predicate == null) continue; | 91 | if(predicate == null) continue; |
| 89 | // tuple.setTerm(1, predicate); | 92 | // tuple.setTerm(1, predicate); |
| 90 | tuple[1] = predicate; | 93 | tuple[1] = predicate; |
| 91 | } | 94 | } |
| 92 | return true; | 95 | return true; |
| 93 | } | 96 | } |
| 94 | } catch (JRDFStoreException e) { | 97 | } catch (JRDFStoreException e) { |
| 95 | e.printStackTrace(); | 98 | e.printStackTrace(); |
| 96 | return false; | 99 | return false; |
| 97 | } | 100 | } |
| 98 | return false; | 101 | return false; |
| 99 | } | 102 | } |
| 100 | 103 | ||
| 101 | @Override | 104 | @Override |
| 102 | // public AnswerTupleID next() { | 105 | // public AnswerTupleID next() { |
| 103 | public int[] next() { | 106 | public int[] next() { |
| @@ -105,19 +108,16 @@ public class GapByStore4ID extends GapTupleIterator<int[]> { | |||
| 105 | multi = iterator.getNext(); | 108 | multi = iterator.getNext(); |
| 106 | } catch (JRDFStoreException e) { | 109 | } catch (JRDFStoreException e) { |
| 107 | e.printStackTrace(); | 110 | e.printStackTrace(); |
| 108 | } | 111 | } |
| 109 | 112 | ||
| 110 | return tuple; | 113 | return tuple; |
| 111 | } | 114 | } |
| 112 | 115 | ||
| 113 | Map<Integer, Integer> original2gap = new HashMap<Integer, Integer>(); | ||
| 114 | LinkedList<String> predicatesWithGap = new LinkedList<String>(); | ||
| 115 | |||
| 116 | public LinkedList<String> getPredicatesWithGap() { | 116 | public LinkedList<String> getPredicatesWithGap() { |
| 117 | return predicatesWithGap; | 117 | return predicatesWithGap; |
| 118 | } | 118 | } |
| 119 | 119 | ||
| 120 | private Integer getGapPredicateID(int originalID) { | 120 | protected Integer getGapPredicateID(int originalID) { |
| 121 | Integer gapID; | 121 | Integer gapID; |
| 122 | if ((gapID = original2gap.get(originalID)) != null) | 122 | if ((gapID = original2gap.get(originalID)) != null) |
| 123 | return gapID; | 123 | return gapID; |
| @@ -136,11 +136,14 @@ public class GapByStore4ID extends GapTupleIterator<int[]> { | |||
| 136 | return gapID; | 136 | return gapID; |
| 137 | } | 137 | } |
| 138 | 138 | ||
| 139 | private boolean isAuxPredicate(String originalPredicate) { | 139 | protected boolean isAuxPredicate(String originalPredicate) { |
| 140 | return originalPredicate.contains("_AUX"); | 140 | if(originalPredicate.equals(Namespace.EQUALITY_QUOTED)) return false; |
| 141 | return originalPredicate.contains("_AUX") || | ||
| 142 | originalPredicate.startsWith("<" + Namespace.OWL_NS) || | ||
| 143 | originalPredicate.startsWith("<" + Namespace.PAGODA_ORIGINAL); | ||
| 141 | } | 144 | } |
| 142 | 145 | ||
| 143 | private boolean isRDF_TYPE() { | 146 | protected boolean isRDF_TYPE() { |
| 144 | // return tripleManager.isRdfTypeID(tuple.getTerm(1)); | 147 | // return tripleManager.isRdfTypeID(tuple.getTerm(1)); |
| 145 | return tripleManager.isRdfTypeID(tuple[1]); | 148 | return tripleManager.isRdfTypeID(tuple[1]); |
| 146 | } | 149 | } |
| @@ -150,8 +153,6 @@ public class GapByStore4ID extends GapTupleIterator<int[]> { | |||
| 150 | Utility.logError("Unsupported operation!"); | 153 | Utility.logError("Unsupported operation!"); |
| 151 | } | 154 | } |
| 152 | 155 | ||
| 153 | private boolean valid = false; | ||
| 154 | |||
| 155 | @Override | 156 | @Override |
| 156 | public void save(String file) { | 157 | public void save(String file) { |
| 157 | Utility.logError("Unsupported Operation..."); | 158 | Utility.logError("Unsupported Operation..."); |
| @@ -168,7 +169,6 @@ public class GapByStore4ID extends GapTupleIterator<int[]> { | |||
| 168 | ++tupleCounter; | 169 | ++tupleCounter; |
| 169 | tripleManager.addTripleByID(tuple); | 170 | tripleManager.addTripleByID(tuple); |
| 170 | } | 171 | } |
| 171 | valid = true; | ||
| 172 | 172 | ||
| 173 | long tripleCounter = m_store.getTriplesCount(); | 173 | long tripleCounter = m_store.getTriplesCount(); |
| 174 | Utility.logDebug("There are " + tupleCounter + " tuples in the gap between lower and upper bound materialisation.", | 174 | Utility.logDebug("There are " + tupleCounter + " tuples in the gap between lower and upper bound materialisation.", |
| @@ -183,8 +183,6 @@ public class GapByStore4ID extends GapTupleIterator<int[]> { | |||
| 183 | } | 183 | } |
| 184 | } | 184 | } |
| 185 | 185 | ||
| 186 | public boolean isValid() {return valid; } | ||
| 187 | |||
| 188 | @Override | 186 | @Override |
| 189 | public void addTo(DataStore store) throws JRDFStoreException { | 187 | public void addTo(DataStore store) throws JRDFStoreException { |
| 190 | Utility.logError("Unsupported Operation..."); | 188 | Utility.logError("Unsupported Operation..."); |
