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/GapByTriple.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/GapByTriple.java')
| -rw-r--r-- | src/uk/ac/ox/cs/pagoda/query/GapByTriple.java | 163 |
1 files changed, 0 insertions, 163 deletions
diff --git a/src/uk/ac/ox/cs/pagoda/query/GapByTriple.java b/src/uk/ac/ox/cs/pagoda/query/GapByTriple.java deleted file mode 100644 index eaa629b..0000000 --- a/src/uk/ac/ox/cs/pagoda/query/GapByTriple.java +++ /dev/null | |||
| @@ -1,163 +0,0 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.query; | ||
| 2 | |||
| 3 | import org.semanticweb.HermiT.model.*; | ||
| 4 | import uk.ac.ox.cs.JRDFox.JRDFStoreException; | ||
| 5 | import uk.ac.ox.cs.JRDFox.Prefixes; | ||
| 6 | import uk.ac.ox.cs.JRDFox.store.DataStore; | ||
| 7 | import uk.ac.ox.cs.JRDFox.store.Parameters; | ||
| 8 | import uk.ac.ox.cs.JRDFox.store.TupleIterator; | ||
| 9 | import uk.ac.ox.cs.pagoda.MyPrefixes; | ||
| 10 | import uk.ac.ox.cs.pagoda.owl.OWLHelper; | ||
| 11 | import uk.ac.ox.cs.pagoda.reasoner.light.BasicQueryEngine; | ||
| 12 | import uk.ac.ox.cs.pagoda.reasoner.light.RDFoxTripleManager; | ||
| 13 | import uk.ac.ox.cs.pagoda.util.Namespace; | ||
| 14 | import uk.ac.ox.cs.pagoda.util.Utility; | ||
| 15 | |||
| 16 | import java.io.BufferedWriter; | ||
| 17 | import java.io.FileOutputStream; | ||
| 18 | import java.io.IOException; | ||
| 19 | import java.io.OutputStreamWriter; | ||
| 20 | import java.util.Collection; | ||
| 21 | |||
| 22 | public class GapByTriple extends GapTupleIterator<String> { | ||
| 23 | |||
| 24 | static final String allTripleQuery = "SELECT ?X ?Y ?Z WHERE { ?X ?Y ?Z }"; | ||
| 25 | private static final String RDF_TYPE = Namespace.RDF_NS + "type"; | ||
| 26 | private static final String BRIEF_RDF_TYPE = "rdf:type"; | ||
| 27 | DataStore lowerStore, upperStore; | ||
| 28 | long multi; | ||
| 29 | TupleIterator iterator; | ||
| 30 | String sub, obj, predicate; | ||
| 31 | // GroundTerm subTerm, objTerm; | ||
| 32 | Prefixes prefixes; | ||
| 33 | Parameters parameters; | ||
| 34 | |||
| 35 | public GapByTriple(BasicQueryEngine lowerStore, BasicQueryEngine upperStore) { | ||
| 36 | this.lowerStore = lowerStore.getDataStore(); | ||
| 37 | this.upperStore = upperStore.getDataStore(); | ||
| 38 | prefixes = MyPrefixes.PAGOdAPrefixes.getRDFoxPrefixes(); | ||
| 39 | parameters = new Parameters(); | ||
| 40 | } | ||
| 41 | |||
| 42 | public void compile(Collection<DLClause> clauses) throws JRDFStoreException { | ||
| 43 | iterator = this.upperStore.compileQuery(allTripleQuery, prefixes, parameters); | ||
| 44 | multi = iterator.open(); | ||
| 45 | } | ||
| 46 | |||
| 47 | @Override | ||
| 48 | public boolean hasNext() { | ||
| 49 | TupleIterator iter = null; | ||
| 50 | boolean inGap; | ||
| 51 | StringBuffer queryBuffer = new StringBuffer(); | ||
| 52 | try { | ||
| 53 | for (; multi != 0; multi = iterator.getNext()) { | ||
| 54 | // iterator.getRawGroundTerm(0); | ||
| 55 | // iterator.getRawGroundTerm(1); | ||
| 56 | // iterator.getRawGroundTerm(2); | ||
| 57 | |||
| 58 | sub = RDFoxTripleManager.getQuotedTerm(iterator.getResource(0)); | ||
| 59 | predicate = RDFoxTripleManager.getQuotedTerm(iterator.getResource(1)); | ||
| 60 | obj = RDFoxTripleManager.getQuotedTerm(iterator.getResource(2)); | ||
| 61 | |||
| 62 | if (!obj.startsWith("<")) { | ||
| 63 | // This fragment of code ignores data types assertions. | ||
| 64 | // Utility.LOGS.info(sub + " " + predicate + " " + obj); | ||
| 65 | continue; | ||
| 66 | } | ||
| 67 | |||
| 68 | queryBuffer.setLength(0); | ||
| 69 | queryBuffer.append("SELECT WHERE { ").append(sub).append(" ").append(predicate).append(" ").append(obj).append(" }"); | ||
| 70 | |||
| 71 | try { | ||
| 72 | iter = lowerStore.compileQuery(queryBuffer.toString(), prefixes, parameters); | ||
| 73 | inGap = iter.open() != 0; | ||
| 74 | } finally { | ||
| 75 | if (iter != null) iter.dispose(); | ||
| 76 | iter = null; | ||
| 77 | } | ||
| 78 | if (inGap) | ||
| 79 | return true; | ||
| 80 | } | ||
| 81 | } catch (JRDFStoreException e) { | ||
| 82 | // TODO Auto-generated catch block | ||
| 83 | e.printStackTrace(); | ||
| 84 | } | ||
| 85 | return false; | ||
| 86 | } | ||
| 87 | |||
| 88 | @Override | ||
| 89 | public String next() { | ||
| 90 | try { | ||
| 91 | multi = iterator.getNext(); | ||
| 92 | } catch (JRDFStoreException e) { | ||
| 93 | e.printStackTrace(); | ||
| 94 | } | ||
| 95 | StringBuilder sb = new StringBuilder(); | ||
| 96 | if (isRDF_TYPE()) { | ||
| 97 | sb.append(sub).append(" ").append(predicate).append(" ").append(getGapPredicate(obj)).append("."); | ||
| 98 | } | ||
| 99 | else sb.append(sub).append(" ").append(getGapPredicate(predicate)).append(" ").append(obj).append("."); | ||
| 100 | return sb.toString(); | ||
| 101 | } | ||
| 102 | |||
| 103 | private boolean isRDF_TYPE() { | ||
| 104 | return predicate.equals(RDF_TYPE) || predicate.equals(BRIEF_RDF_TYPE); | ||
| 105 | } | ||
| 106 | |||
| 107 | @Override | ||
| 108 | public void remove() { | ||
| 109 | Utility.logError("Unsupported operation!"); | ||
| 110 | } | ||
| 111 | |||
| 112 | public void save(String file) { | ||
| 113 | int tupleCounter = 0; | ||
| 114 | try { | ||
| 115 | BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file))); | ||
| 116 | String tuple; | ||
| 117 | while (hasNext()) { | ||
| 118 | tuple = next(); | ||
| 119 | writer.write(tuple); | ||
| 120 | writer.newLine(); | ||
| 121 | ++tupleCounter; | ||
| 122 | } | ||
| 123 | writer.close(); | ||
| 124 | } catch (IOException e) { | ||
| 125 | e.printStackTrace(); | ||
| 126 | } | ||
| 127 | |||
| 128 | Utility.logError("There are " + tupleCounter + " tuples in the gap between lower and upper bound materialisation."); | ||
| 129 | } | ||
| 130 | |||
| 131 | public void addTo(DataStore store) throws JRDFStoreException { | ||
| 132 | int tupleCounter = 0; | ||
| 133 | RDFoxTripleManager tripleManager = new RDFoxTripleManager(store, false); | ||
| 134 | while (hasNext()) { | ||
| 135 | multi = iterator.getNext(); | ||
| 136 | ++tupleCounter; | ||
| 137 | if (isRDF_TYPE()) { | ||
| 138 | obj = OWLHelper.removeAngles(obj); | ||
| 139 | tripleManager.addTripleByTerm( | ||
| 140 | Atom.create(AtomicConcept.create(getGapPredicate(obj)), Individual.create(sub))); | ||
| 141 | } | ||
| 142 | else { | ||
| 143 | predicate = OWLHelper.removeAngles(predicate); | ||
| 144 | tripleManager.addTripleByTerm( | ||
| 145 | Atom.create(AtomicRole.create(getGapPredicate(predicate)), Individual.create(sub), Individual.create(obj))); | ||
| 146 | } | ||
| 147 | if (tupleCounter % 10000 == 0) | ||
| 148 | Utility.logDebug(tupleCounter); | ||
| 149 | } | ||
| 150 | |||
| 151 | Utility.logDebug("There are " + tupleCounter + " tuples in the gap between lower and upper bound materialisation."); | ||
| 152 | } | ||
| 153 | |||
| 154 | @Override | ||
| 155 | public void addBackTo() throws JRDFStoreException { | ||
| 156 | addTo(upperStore); | ||
| 157 | } | ||
| 158 | |||
| 159 | @Override | ||
| 160 | public void clear() { | ||
| 161 | iterator.dispose(); | ||
| 162 | } | ||
| 163 | } | ||
