diff options
| author | Federico Igne <federico.igne@cs.ox.ac.uk> | 2022-05-10 18:17:06 +0100 |
|---|---|---|
| committer | Federico Igne <federico.igne@cs.ox.ac.uk> | 2022-05-11 12:34:47 +0100 |
| commit | 17bd9beaf7f358a44e5bf36a5855fe6727d506dc (patch) | |
| tree | 47e9310a0cff869d9ec017dcb2c81876407782c8 /src/uk/ac/ox/cs/pagoda/query/GapByStore4ID.java | |
| parent | 8651164cd632a5db310b457ce32d4fbc97bdc41c (diff) | |
| download | ACQuA-17bd9beaf7f358a44e5bf36a5855fe6727d506dc.tar.gz ACQuA-17bd9beaf7f358a44e5bf36a5855fe6727d506dc.zip | |
[pagoda] Move project to Scala
This commit includes a few changes:
- The repository still uses Maven to manage dependency but it is now a
Scala project.
- The code has been ported from OWLAPI 3.4.10 to 5.1.20
- A proof of concept program using both RSAComb and PAGOdA has been
added.
Diffstat (limited to 'src/uk/ac/ox/cs/pagoda/query/GapByStore4ID.java')
| -rw-r--r-- | src/uk/ac/ox/cs/pagoda/query/GapByStore4ID.java | 191 |
1 files changed, 0 insertions, 191 deletions
diff --git a/src/uk/ac/ox/cs/pagoda/query/GapByStore4ID.java b/src/uk/ac/ox/cs/pagoda/query/GapByStore4ID.java deleted file mode 100644 index 84929ad..0000000 --- a/src/uk/ac/ox/cs/pagoda/query/GapByStore4ID.java +++ /dev/null | |||
| @@ -1,191 +0,0 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.query; | ||
| 2 | |||
| 3 | import java.util.HashMap; | ||
| 4 | import java.util.LinkedList; | ||
| 5 | import java.util.Map; | ||
| 6 | |||
| 7 | 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; | ||
| 10 | import uk.ac.ox.cs.pagoda.reasoner.light.RDFoxTripleManager; | ||
| 11 | import uk.ac.ox.cs.pagoda.util.Namespace; | ||
| 12 | import uk.ac.ox.cs.pagoda.util.Timer; | ||
| 13 | import uk.ac.ox.cs.pagoda.util.Utility; | ||
| 14 | import uk.ac.ox.cs.JRDFox.JRDFStoreException; | ||
| 15 | import uk.ac.ox.cs.JRDFox.store.DataStore; | ||
| 16 | import uk.ac.ox.cs.JRDFox.store.TupleIterator; | ||
| 17 | |||
| 18 | //public class GapByStore4ID extends GapTupleIterator<AnswerTupleID> { | ||
| 19 | public class GapByStore4ID extends GapTupleIterator<int[]> { | ||
| 20 | |||
| 21 | protected MyPrefixes prefixes = MyPrefixes.PAGOdAPrefixes; | ||
| 22 | protected TupleIterator iterator = null; | ||
| 23 | |||
| 24 | // AnswerTupleID tuple; | ||
| 25 | protected int[] tuple; | ||
| 26 | protected BasicQueryEngine m_engine; | ||
| 27 | protected DataStore m_store; | ||
| 28 | protected RDFoxTripleManager tripleManager; | ||
| 29 | |||
| 30 | public GapByStore4ID(BasicQueryEngine engine) { | ||
| 31 | m_engine = engine; | ||
| 32 | m_store = engine.getDataStore(); | ||
| 33 | tripleManager = new RDFoxTripleManager(m_store, false); | ||
| 34 | } | ||
| 35 | |||
| 36 | protected long multi; | ||
| 37 | |||
| 38 | @Override | ||
| 39 | public void compile(String program) throws JRDFStoreException { | ||
| 40 | clear(); | ||
| 41 | |||
| 42 | boolean incrementally = true; | ||
| 43 | Timer t = new Timer(); | ||
| 44 | long oldTripleCount = m_store.getTriplesCount(); | ||
| 45 | |||
| 46 | if (program != null) { | ||
| 47 | // m_store.addRules(new String[] {program}); | ||
| 48 | m_store.importRules(program); | ||
| 49 | incrementally = false; | ||
| 50 | } | ||
| 51 | |||
| 52 | m_store.applyReasoning(incrementally); | ||
| 53 | |||
| 54 | long tripleCount = m_store.getTriplesCount(); | ||
| 55 | |||
| 56 | Utility.logDebug("current store after materialising upper related rules: " + tripleCount + " (" + (tripleCount - oldTripleCount) + " new)", | ||
| 57 | "current store finished the materialisation of upper related rules in " + t.duration() + " seconds."); | ||
| 58 | |||
| 59 | m_engine.setExpandEquality(false); | ||
| 60 | iterator = m_engine.internal_evaluateAgainstIDBs("select ?x ?y ?z where { ?x ?y ?z . }"); | ||
| 61 | m_engine.setExpandEquality(true); | ||
| 62 | |||
| 63 | multi = iterator.open(); | ||
| 64 | Utility.logDebug("gap query evaluted ..."); | ||
| 65 | } | ||
| 66 | |||
| 67 | @Override | ||
| 68 | public boolean hasNext() { | ||
| 69 | if (iterator == null) return false; | ||
| 70 | try { | ||
| 71 | // tuple = new AnswerTupleID(3); | ||
| 72 | tuple = new int[3]; | ||
| 73 | Integer predicate; | ||
| 74 | for (; multi != 0; multi = iterator.getNext()) { | ||
| 75 | for (int i = 0; i < 3; ++i) | ||
| 76 | // tuple.setTerm(i, (int) iterator.getResourceID(i)); | ||
| 77 | tuple[i] = (int) iterator.getResourceID(i); | ||
| 78 | |||
| 79 | if (isRDF_TYPE()) { | ||
| 80 | // predicate = getGapPredicateID(tuple.getTerm(2)); | ||
| 81 | predicate = getGapPredicateID(tuple[2]); | ||
| 82 | if (predicate == null) continue; | ||
| 83 | // tuple.setTerm(2, predicate); | ||
| 84 | tuple[2] = predicate; | ||
| 85 | } | ||
| 86 | else { | ||
| 87 | // predicate = getGapPredicateID(tuple.getTerm(1)); | ||
| 88 | predicate = getGapPredicateID(tuple[1]); | ||
| 89 | if (predicate == null) continue; | ||
| 90 | // tuple.setTerm(1, predicate); | ||
| 91 | tuple[1] = predicate; | ||
| 92 | } | ||
| 93 | return true; | ||
| 94 | } | ||
| 95 | } catch (JRDFStoreException e) { | ||
| 96 | e.printStackTrace(); | ||
| 97 | return false; | ||
| 98 | } | ||
| 99 | return false; | ||
| 100 | } | ||
| 101 | |||
| 102 | @Override | ||
| 103 | // public AnswerTupleID next() { | ||
| 104 | public int[] next() { | ||
| 105 | try { | ||
| 106 | multi = iterator.getNext(); | ||
| 107 | } catch (JRDFStoreException e) { | ||
| 108 | e.printStackTrace(); | ||
| 109 | } | ||
| 110 | |||
| 111 | return tuple; | ||
| 112 | } | ||
| 113 | |||
| 114 | Map<Integer, Integer> original2gap = new HashMap<Integer, Integer>(); | ||
| 115 | LinkedList<String> predicatesWithGap = new LinkedList<String>(); | ||
| 116 | |||
| 117 | public LinkedList<String> getPredicatesWithGap() { | ||
| 118 | return predicatesWithGap; | ||
| 119 | } | ||
| 120 | |||
| 121 | protected Integer getGapPredicateID(int originalID) { | ||
| 122 | Integer gapID; | ||
| 123 | if ((gapID = original2gap.get(originalID)) != null) | ||
| 124 | return gapID; | ||
| 125 | |||
| 126 | String originalPredicate = tripleManager.getRawTerm(originalID); | ||
| 127 | if (isAuxPredicate(originalPredicate)) { | ||
| 128 | // Utility.LOGS.info(originalPredicate); | ||
| 129 | return null; | ||
| 130 | } | ||
| 131 | |||
| 132 | predicatesWithGap.add(originalPredicate); | ||
| 133 | String gapPredicate = prefixes.expandIRI(getGapPredicate(originalPredicate)); | ||
| 134 | gapID = tripleManager.getResourceID(gapPredicate); | ||
| 135 | original2gap.put(originalID, gapID); | ||
| 136 | |||
| 137 | return gapID; | ||
| 138 | } | ||
| 139 | |||
| 140 | protected boolean isAuxPredicate(String originalPredicate) { | ||
| 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); | ||
| 145 | } | ||
| 146 | |||
| 147 | protected boolean isRDF_TYPE() { | ||
| 148 | // return tripleManager.isRdfTypeID(tuple.getTerm(1)); | ||
| 149 | return tripleManager.isRdfTypeID(tuple[1]); | ||
| 150 | } | ||
| 151 | |||
| 152 | @Override | ||
| 153 | public void remove() { | ||
| 154 | Utility.logError("Unsupported operation!"); | ||
| 155 | } | ||
| 156 | |||
| 157 | @Override | ||
| 158 | public void save(String file) { | ||
| 159 | Utility.logError("Unsupported Operation..."); | ||
| 160 | } | ||
| 161 | |||
| 162 | @Override | ||
| 163 | public void addBackTo() throws JRDFStoreException { | ||
| 164 | int tupleCounter = 0; | ||
| 165 | Timer t = new Timer(); | ||
| 166 | long oldTripleCounter; | ||
| 167 | Utility.logDebug("current store before importing gap tuples: " + (oldTripleCounter = m_store.getTriplesCount())); | ||
| 168 | while (hasNext()) { | ||
| 169 | next(); | ||
| 170 | ++tupleCounter; | ||
| 171 | tripleManager.addTripleByID(tuple); | ||
| 172 | } | ||
| 173 | |||
| 174 | long tripleCounter = m_store.getTriplesCount(); | ||
| 175 | Utility.logDebug("There are " + tupleCounter + " tuples in the gap between lower and upper bound materialisation.", | ||
| 176 | "current store after importing gap tuples: " + tripleCounter + " (" + (tripleCounter - oldTripleCounter) + ").", | ||
| 177 | "current store finished importing gap tuples: " + tripleCounter + " in " + t.duration() + "."); | ||
| 178 | } | ||
| 179 | |||
| 180 | public void clear() { | ||
| 181 | if (iterator != null) { | ||
| 182 | iterator.dispose(); | ||
| 183 | iterator = null; | ||
| 184 | } | ||
| 185 | } | ||
| 186 | |||
| 187 | @Override | ||
| 188 | public void addTo(DataStore store) throws JRDFStoreException { | ||
| 189 | Utility.logError("Unsupported Operation..."); | ||
| 190 | } | ||
| 191 | } | ||
