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 | |
| parent | 4298cdef8e551325cd16b4e24ae6699c44b60751 (diff) | |
| download | ACQuA-de3749532d060f26c966a81c03f9a5d846c33d06.tar.gz ACQuA-de3749532d060f26c966a81c03f9a5d846c33d06.zip | |
Merged updates from upstream.
Diffstat (limited to 'src/uk/ac/ox/cs')
| -rw-r--r-- | src/uk/ac/ox/cs/pagoda/endomorph/Clique.java | 5 | ||||
| -rw-r--r-- | src/uk/ac/ox/cs/pagoda/endomorph/plan/OpenEndMultiThreadPlan.java | 85 | ||||
| -rw-r--r-- | src/uk/ac/ox/cs/pagoda/endomorph/plan/OpenEndPlan.java | 74 | ||||
| -rw-r--r-- | src/uk/ac/ox/cs/pagoda/endomorph/plan/PlainPlan.java | 6 | ||||
| -rw-r--r-- | src/uk/ac/ox/cs/pagoda/query/GapByStore4ID.java | 120 | ||||
| -rw-r--r-- | src/uk/ac/ox/cs/pagoda/query/GapByStore4ID2.java | 141 | ||||
| -rw-r--r-- | src/uk/ac/ox/cs/pagoda/query/GapByTriple.java | 40 | ||||
| -rw-r--r-- | src/uk/ac/ox/cs/pagoda/query/GapTupleIterator.java | 6 | ||||
| -rw-r--r-- | src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java | 5 | ||||
| -rw-r--r-- | src/uk/ac/ox/cs/pagoda/reasoner/light/BasicQueryEngine.java | 154 | ||||
| -rw-r--r-- | src/uk/ac/ox/cs/pagoda/tracking/QueryTracker.java | 2 | ||||
| -rw-r--r-- | src/uk/ac/ox/cs/pagoda/tracking/TrackingRuleEncoderWithGap.java | 38 | ||||
| -rw-r--r-- | src/uk/ac/ox/cs/pagoda/util/Utility.java | 104 |
13 files changed, 453 insertions, 327 deletions
diff --git a/src/uk/ac/ox/cs/pagoda/endomorph/Clique.java b/src/uk/ac/ox/cs/pagoda/endomorph/Clique.java index 1c269ea..9b0d88e 100644 --- a/src/uk/ac/ox/cs/pagoda/endomorph/Clique.java +++ b/src/uk/ac/ox/cs/pagoda/endomorph/Clique.java | |||
| @@ -1,11 +1,11 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.endomorph; | 1 | package uk.ac.ox.cs.pagoda.endomorph; |
| 2 | 2 | ||
| 3 | import uk.ac.ox.cs.pagoda.summary.NodeTuple; | ||
| 4 | |||
| 3 | import java.util.Collection; | 5 | import java.util.Collection; |
| 4 | import java.util.HashSet; | 6 | import java.util.HashSet; |
| 5 | import java.util.Set; | 7 | import java.util.Set; |
| 6 | 8 | ||
| 7 | import uk.ac.ox.cs.pagoda.summary.NodeTuple; | ||
| 8 | |||
| 9 | public class Clique { | 9 | public class Clique { |
| 10 | NodeTuple representative; | 10 | NodeTuple representative; |
| 11 | Set<NodeTuple> nodeTuples = null; | 11 | Set<NodeTuple> nodeTuples = null; |
| @@ -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..862fdc8 100644 --- a/src/uk/ac/ox/cs/pagoda/endomorph/plan/OpenEndMultiThreadPlan.java +++ b/src/uk/ac/ox/cs/pagoda/endomorph/plan/OpenEndMultiThreadPlan.java | |||
| @@ -1,88 +1,81 @@ | |||
| 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; | ||
| 4 | import java.util.Collections; | ||
| 5 | import java.util.LinkedList; | ||
| 6 | import java.util.Map; | ||
| 7 | import java.util.Set; | ||
| 8 | import java.util.concurrent.ConcurrentHashMap; | ||
| 9 | import java.util.concurrent.ConcurrentLinkedDeque; | ||
| 10 | import java.util.concurrent.atomic.AtomicInteger; | ||
| 11 | |||
| 12 | import uk.ac.ox.cs.pagoda.endomorph.DependencyGraph; | ||
| 13 | import uk.ac.ox.cs.pagoda.endomorph.Clique; | 3 | import uk.ac.ox.cs.pagoda.endomorph.Clique; |
| 4 | import uk.ac.ox.cs.pagoda.endomorph.DependencyGraph; | ||
| 14 | import uk.ac.ox.cs.pagoda.query.AnswerTuple; | 5 | import uk.ac.ox.cs.pagoda.query.AnswerTuple; |
| 15 | import uk.ac.ox.cs.pagoda.reasoner.full.Checker; | 6 | import uk.ac.ox.cs.pagoda.reasoner.full.Checker; |
| 16 | import uk.ac.ox.cs.pagoda.reasoner.full.HermitChecker; | 7 | import uk.ac.ox.cs.pagoda.reasoner.full.HermitChecker; |
| 17 | import uk.ac.ox.cs.pagoda.util.Utility; | 8 | import uk.ac.ox.cs.pagoda.util.Utility; |
| 18 | 9 | ||
| 10 | import java.util.*; | ||
| 11 | import java.util.concurrent.ConcurrentHashMap; | ||
| 12 | import java.util.concurrent.ConcurrentLinkedDeque; | ||
| 13 | import java.util.concurrent.atomic.AtomicInteger; | ||
| 14 | |||
| 19 | public class OpenEndMultiThreadPlan implements CheckPlan { | 15 | public class OpenEndMultiThreadPlan implements CheckPlan { |
| 20 | 16 | ||
| 21 | Checker checker; | 17 | Checker checker; |
| 22 | DependencyGraph dGraph; | 18 | DependencyGraph dGraph; |
| 23 | 19 | // Clique[] topo; | |
| 20 | // AtomicInteger open, end; | ||
| 21 | ConcurrentLinkedDeque<Clique> topo; | ||
| 22 | Set<Clique> validated, falsified; | ||
| 23 | AtomicInteger counter = new AtomicInteger(); | ||
| 24 | |||
| 24 | public OpenEndMultiThreadPlan(Checker checker, DependencyGraph dGraph) { | 25 | public OpenEndMultiThreadPlan(Checker checker, DependencyGraph dGraph) { |
| 25 | this.checker = checker; | 26 | this.checker = checker; |
| 26 | this.dGraph = dGraph; | 27 | this.dGraph = dGraph; |
| 27 | } | 28 | } |
| 28 | 29 | ||
| 29 | // Clique[] topo; | ||
| 30 | // AtomicInteger open, end; | ||
| 31 | ConcurrentLinkedDeque<Clique> topo; | ||
| 32 | |||
| 33 | Set<Clique> validated, falsified; | ||
| 34 | |||
| 35 | @Override | 30 | @Override |
| 36 | public int check() { | 31 | public int check() { |
| 37 | Collection<Clique> cliques = dGraph.getTopologicalOrder(); | 32 | Collection<Clique> cliques = dGraph.getTopologicalOrder(); |
| 38 | // topo = new LinkedBlockingDeque<Clique>(cliques); | 33 | // topo = new LinkedBlockingDeque<Clique>(cliques); |
| 39 | topo = new ConcurrentLinkedDeque<Clique>(cliques); | 34 | topo = new ConcurrentLinkedDeque<Clique>(cliques); |
| 40 | 35 | ||
| 41 | // topo = new Clique[cliques.size()]; | 36 | // topo = new Clique[cliques.size()]; |
| 42 | // int index = 0; | 37 | // int index = 0; |
| 43 | // for (Clique clique: cliques) topo[index++] = clique; | 38 | // for (Clique clique: cliques) topo[index++] = clique; |
| 44 | // open = new AtomicInteger(); | 39 | // open = new AtomicInteger(); |
| 45 | // end = new AtomicInteger(cliques.size() - 1); | 40 | // end = new AtomicInteger(cliques.size() - 1); |
| 46 | 41 | ||
| 47 | // validated = Collections.synchronizedSet(new HashSet<Clique>()); | 42 | // validated = Collections.synchronizedSet(new HashSet<Clique>()); |
| 48 | // falsified = Collections.synchronizedSet(new HashSet<Clique>()); | 43 | // falsified = Collections.synchronizedSet(new HashSet<Clique>()); |
| 49 | validated = Collections.newSetFromMap(new ConcurrentHashMap<Clique, Boolean>()); | 44 | validated = Collections.newSetFromMap(new ConcurrentHashMap<Clique, Boolean>()); |
| 50 | falsified = Collections.newSetFromMap(new ConcurrentHashMap<Clique, Boolean>()); | 45 | falsified = Collections.newSetFromMap(new ConcurrentHashMap<Clique, Boolean>()); |
| 51 | 46 | ||
| 52 | int numOfThreads = 10; | 47 | int numOfThreads = 10; |
| 53 | Collection<Thread> threads = new LinkedList<Thread>(); | 48 | Collection<Thread> threads = new LinkedList<Thread>(); |
| 54 | for (int i = 0; i < numOfThreads; ++i) | 49 | for(int i = 0; i < numOfThreads; ++i) |
| 55 | threads.add(new Thread(new SubThread(new HermitChecker(checker), i))); | 50 | threads.add(new Thread(new SubThread(new HermitChecker(checker), i))); |
| 56 | 51 | ||
| 57 | for (Thread thread: threads) thread.start(); | 52 | for (Thread thread: threads) thread.start(); |
| 58 | 53 | ||
| 59 | for (Thread thread: threads) { | 54 | for (Thread thread: threads) { |
| 60 | try { | 55 | try { |
| 61 | thread.join(); | 56 | thread.join(); |
| 62 | } catch (InterruptedException e) { | 57 | } catch (InterruptedException e) { |
| 63 | e.printStackTrace(); | 58 | e.printStackTrace(); |
| 64 | } | 59 | } |
| 65 | } | 60 | } |
| 66 | 61 | ||
| 67 | Utility.logDebug("HermiT was called " + counter.get() + " times."); | 62 | Utility.logDebug("HermiT was called " + counter.get() + " times."); |
| 68 | 63 | ||
| 69 | int count = 0; | 64 | int count = 0; |
| 70 | for (Clique c: dGraph.getTopologicalOrder()) { | 65 | for (Clique c: dGraph.getTopologicalOrder()) { |
| 71 | if (validated.contains(c)) | 66 | if (validated.contains(c)) |
| 72 | count += c.getNodeTuples().size() + 1; | 67 | count += c.getNodeTuples().size(); |
| 73 | } | 68 | } |
| 74 | return count; | 69 | return count; |
| 75 | } | 70 | } |
| 76 | 71 | ||
| 77 | private void setMarkCascadely(Clique clique, Set<Clique> marked, Map<Clique, Collection<Clique>> edges) { | 72 | private void setMarkCascadely(Clique clique, Set<Clique> marked, Map<Clique, Collection<Clique>> edges) { |
| 78 | marked.add(clique); | 73 | marked.add(clique); |
| 79 | if (edges.containsKey(clique)) | 74 | if (edges.containsKey(clique)) |
| 80 | for (Clique c: edges.get(clique)) | 75 | for (Clique c: edges.get(clique)) |
| 81 | if (!marked.contains(c)) | 76 | if(!marked.contains(c)) |
| 82 | setMarkCascadely(c, marked, edges); | 77 | setMarkCascadely(c, marked, edges); |
| 83 | } | 78 | } |
| 84 | |||
| 85 | AtomicInteger counter = new AtomicInteger(); | ||
| 86 | 79 | ||
| 87 | class SubThread implements Runnable { | 80 | class SubThread implements Runnable { |
| 88 | 81 | ||
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 19d567a..3294c31 100644 --- a/src/uk/ac/ox/cs/pagoda/endomorph/plan/OpenEndPlan.java +++ b/src/uk/ac/ox/cs/pagoda/endomorph/plan/OpenEndPlan.java | |||
| @@ -17,37 +17,39 @@ public class OpenEndPlan implements CheckPlan { | |||
| 17 | public static final int TIME_OUT_MIN = 1; | 17 | public static final int TIME_OUT_MIN = 1; |
| 18 | 18 | ||
| 19 | Checker checker; | 19 | Checker checker; |
| 20 | DependencyGraph dGraph; | 20 | DependencyGraph dGraph; |
| 21 | QueryRecord m_record; | 21 | QueryRecord m_record; |
| 22 | 22 | int m_answerArity; | |
| 23 | Set<Clique> validated = new HashSet<Clique>(); | ||
| 24 | Set<Clique> falsified = new HashSet<Clique>(); | ||
| 25 | Set<AnswerTuple> passedAnswers = new HashSet<AnswerTuple>(); | ||
| 23 | public OpenEndPlan(Checker checker, DependencyGraph dGraph, QueryRecord record) { | 26 | public OpenEndPlan(Checker checker, DependencyGraph dGraph, QueryRecord record) { |
| 24 | this.checker = checker; | 27 | this.checker = checker; |
| 25 | this.dGraph = dGraph; | 28 | this.dGraph = dGraph; |
| 26 | m_record = record; | 29 | m_record = record; |
| 30 | m_answerArity = record.getAnswerVariables().length; | ||
| 27 | } | 31 | } |
| 28 | 32 | ||
| 29 | @Override | 33 | @Override |
| 30 | public int check() { | 34 | public int check() { |
| 31 | Deque<Clique> topo = new LinkedList<Clique>(dGraph.getTopologicalOrder()); | 35 | LinkedList<Clique> topo = new LinkedList<Clique>(dGraph.getTopologicalOrder()); |
| 32 | Utility.logInfo("Entrances: " + dGraph.getEntrances().size() + " Exists: " + dGraph.getExits().size()); | 36 | Utility.logInfo("Entrances: " + dGraph.getEntrances().size() + " Exists: " + dGraph.getExits().size()); |
| 33 | Set<Clique> validated = new HashSet<Clique>(); | ||
| 34 | Set<Clique> falsified = new HashSet<Clique>(); | ||
| 35 | 37 | ||
| 36 | boolean flag = true; | 38 | boolean flag = true; |
| 37 | Clique clique; | 39 | Clique clique; |
| 38 | Timer t = new Timer(); | 40 | Timer t = new Timer(); |
| 39 | |||
| 40 | 41 | ||
| 41 | AnswerTuple answerTuple; | 42 | AnswerTuple answerTuple; |
| 42 | while (!topo.isEmpty()) { | 43 | while (!topo.isEmpty()) { |
| 43 | if (flag) { | 44 | if (flag) { |
| 44 | clique = topo.removeFirst(); | 45 | clique = topo.removeFirst(); |
| 46 | if(redundant(clique)) continue; | ||
| 45 | if (validated.contains(clique)) continue; | 47 | if (validated.contains(clique)) continue; |
| 46 | if (falsified.contains(clique)) { flag = false; continue; } | 48 | if (falsified.contains(clique)) { flag = false; continue; } |
| 47 | Utility.logDebug("start checking front ... " + (answerTuple = clique.getRepresentative().getAnswerTuple())); | 49 | Utility.logDebug("start checking front ... " + (answerTuple = clique.getRepresentative().getAnswerTuple())); |
| 48 | if (checker.check(answerTuple)) { | 50 | if (checker.check(answerTuple)) { |
| 49 | Utility.logDebug(answerTuple.toString() + " is verified."); | 51 | Utility.logDebug(answerTuple.toString() + " is verified."); |
| 50 | setMarkCascadely(clique, validated, dGraph.getOutGoingEdges()); | 52 | setMarkCascadelyValidated(clique); |
| 51 | } | 53 | } |
| 52 | else { | 54 | else { |
| 53 | falsified.add(clique); | 55 | falsified.add(clique); |
| @@ -58,12 +60,12 @@ public class OpenEndPlan implements CheckPlan { | |||
| 58 | clique = topo.removeLast(); | 60 | clique = topo.removeLast(); |
| 59 | if (falsified.contains(clique)) continue; | 61 | if (falsified.contains(clique)) continue; |
| 60 | if (validated.contains(clique)) { flag = true; continue; } | 62 | if (validated.contains(clique)) { flag = true; continue; } |
| 61 | Utility.logDebug("start checking back ... " + (answerTuple = clique.getRepresentative().getAnswerTuple())); | 63 | Utility.logDebug("start checking back ... " + (answerTuple = clique.getRepresentative().getAnswerTuple())); |
| 62 | if (!checker.check(answerTuple)) | 64 | if(!checker.check(answerTuple)) |
| 63 | setMarkCascadely(clique, falsified, dGraph.getInComingEdges()); | 65 | setMarkCascadelyFasified(clique); |
| 64 | else { | 66 | else { |
| 65 | Utility.logDebug(answerTuple.toString() + " is verified."); | 67 | Utility.logDebug(answerTuple.toString() + " is verified."); |
| 66 | validated.add(clique); | 68 | addProjections(clique); |
| 67 | flag = true; | 69 | flag = true; |
| 68 | } | 70 | } |
| 69 | } | 71 | } |
| @@ -76,9 +78,8 @@ public class OpenEndPlan implements CheckPlan { | |||
| 76 | Collection<AnswerTuple> validAnswers = new LinkedList<AnswerTuple>(); | 78 | Collection<AnswerTuple> validAnswers = new LinkedList<AnswerTuple>(); |
| 77 | for (Clique c: dGraph.getTopologicalOrder()) | 79 | for (Clique c: dGraph.getTopologicalOrder()) |
| 78 | if (validated.contains(c)) { | 80 | if (validated.contains(c)) { |
| 79 | count += c.getNodeTuples().size() + 1; | 81 | count += c.getNodeTuples().size(); |
| 80 | validAnswers.add(c.getRepresentative().getAnswerTuple()); | 82 | // validAnswers.add(c.getRepresentative().getAnswerTuple()); |
| 81 | |||
| 82 | for (NodeTuple nodeTuple: c.getNodeTuples()) { | 83 | for (NodeTuple nodeTuple: c.getNodeTuples()) { |
| 83 | ans = nodeTuple.getAnswerTuple(); | 84 | ans = nodeTuple.getAnswerTuple(); |
| 84 | validAnswers.add(ans); | 85 | validAnswers.add(ans); |
| @@ -91,12 +92,35 @@ public class OpenEndPlan implements CheckPlan { | |||
| 91 | return count; | 92 | return count; |
| 92 | } | 93 | } |
| 93 | 94 | ||
| 94 | private void setMarkCascadely(Clique clique, Set<Clique> marked, Map<Clique, Collection<Clique>> edges) { | 95 | private boolean redundant(Clique clique) { |
| 95 | marked.add(clique); | 96 | for(NodeTuple nodeTuple : clique.getNodeTuples()) |
| 97 | if(!passedAnswers.contains(AnswerTuple.getInstance(nodeTuple.getAnswerTuple(), m_answerArity))) | ||
| 98 | return false; | ||
| 99 | return true; | ||
| 100 | } | ||
| 101 | |||
| 102 | private void addProjections(Clique clique) { | ||
| 103 | for(NodeTuple nodeTuple : clique.getNodeTuples()) | ||
| 104 | passedAnswers.add(AnswerTuple.getInstance(nodeTuple.getAnswerTuple(), m_answerArity)); | ||
| 105 | } | ||
| 106 | |||
| 107 | private void setMarkCascadelyValidated(Clique clique) { | ||
| 108 | validated.add(clique); | ||
| 109 | addProjections(clique); | ||
| 110 | Map<Clique, Collection<Clique>> edges = dGraph.getOutGoingEdges(); | ||
| 96 | if (edges.containsKey(clique)) | 111 | if (edges.containsKey(clique)) |
| 97 | for (Clique c: edges.get(clique)) | 112 | for (Clique c: edges.get(clique)) |
| 98 | if (!marked.contains(c)) | 113 | if(!validated.contains(c)) |
| 99 | setMarkCascadely(c, marked, edges); | 114 | setMarkCascadelyValidated(c); |
| 115 | } | ||
| 116 | |||
| 117 | private void setMarkCascadelyFasified(Clique clique) { | ||
| 118 | falsified.add(clique); | ||
| 119 | Map<Clique, Collection<Clique>> edges = dGraph.getInComingEdges(); | ||
| 120 | if(edges.containsKey(clique)) | ||
| 121 | for(Clique c : edges.get(clique)) | ||
| 122 | if(!falsified.contains(c)) | ||
| 123 | setMarkCascadelyFasified(c); | ||
| 100 | } | 124 | } |
| 101 | 125 | ||
| 102 | } | 126 | } |
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..5e1a700 100644 --- a/src/uk/ac/ox/cs/pagoda/endomorph/plan/PlainPlan.java +++ b/src/uk/ac/ox/cs/pagoda/endomorph/plan/PlainPlan.java | |||
| @@ -1,12 +1,12 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.endomorph.plan; | 1 | package uk.ac.ox.cs.pagoda.endomorph.plan; |
| 2 | 2 | ||
| 3 | import java.util.Set; | ||
| 4 | |||
| 5 | import uk.ac.ox.cs.pagoda.endomorph.Clique; | 3 | import uk.ac.ox.cs.pagoda.endomorph.Clique; |
| 6 | import uk.ac.ox.cs.pagoda.reasoner.full.Checker; | 4 | import uk.ac.ox.cs.pagoda.reasoner.full.Checker; |
| 7 | import uk.ac.ox.cs.pagoda.summary.NodeTuple; | 5 | import uk.ac.ox.cs.pagoda.summary.NodeTuple; |
| 8 | import uk.ac.ox.cs.pagoda.util.Utility; | 6 | import uk.ac.ox.cs.pagoda.util.Utility; |
| 9 | 7 | ||
| 8 | import java.util.Set; | ||
| 9 | |||
| 10 | public class PlainPlan implements CheckPlan { | 10 | public class PlainPlan implements CheckPlan { |
| 11 | 11 | ||
| 12 | Checker checker; | 12 | Checker checker; |
| @@ -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..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..."); |
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..19efc58 --- /dev/null +++ b/src/uk/ac/ox/cs/pagoda/query/GapByStore4ID2.java | |||
| @@ -0,0 +1,141 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.query; | ||
| 2 | |||
| 3 | import uk.ac.ox.cs.JRDFox.JRDFStoreException; | ||
| 4 | import uk.ac.ox.cs.JRDFox.store.TupleIterator; | ||
| 5 | import uk.ac.ox.cs.pagoda.reasoner.light.BasicQueryEngine; | ||
| 6 | import uk.ac.ox.cs.pagoda.util.UFS; | ||
| 7 | |||
| 8 | import java.util.*; | ||
| 9 | |||
| 10 | public class GapByStore4ID2 extends GapByStore4ID { | ||
| 11 | |||
| 12 | private BasicQueryEngine m_baseEngine; | ||
| 13 | private UFS<String> m_equality = null, m_baseEquality = null; | ||
| 14 | private LinkedList<String> toAddedIndividuals = null; | ||
| 15 | private TupleIterator iter_individual = null; | ||
| 16 | private int currentID = -1; | ||
| 17 | |||
| 18 | public GapByStore4ID2(BasicQueryEngine engine, BasicQueryEngine baseEngine) { | ||
| 19 | super(engine); | ||
| 20 | m_baseEngine = baseEngine; | ||
| 21 | } | ||
| 22 | |||
| 23 | @Override | ||
| 24 | public boolean hasNext() { | ||
| 25 | if(getNewGapTuple(iterator, -1)) return true; | ||
| 26 | if(iterator != null) { | ||
| 27 | iterator.dispose(); | ||
| 28 | iterator = null; | ||
| 29 | } | ||
| 30 | return getNextGapFactAboutEquality(); | ||
| 31 | } | ||
| 32 | |||
| 33 | private boolean getNewGapTuple(TupleIterator it, int firstElement) { | ||
| 34 | if(it == null) return false; | ||
| 35 | int firstIndex = 0; | ||
| 36 | tuple = new int[3]; | ||
| 37 | if(firstElement > 0) { | ||
| 38 | tuple[0] = firstElement; | ||
| 39 | firstIndex = 1; | ||
| 40 | } | ||
| 41 | Integer predicate; | ||
| 42 | try { | ||
| 43 | for(; multi != 0; multi = it.getNext()) { | ||
| 44 | for(int i = firstIndex; i < 3; ++i) | ||
| 45 | tuple[i] = it.getResourceID(i - firstIndex); | ||
| 46 | |||
| 47 | if(isRDF_TYPE()) { | ||
| 48 | predicate = getGapPredicateID(tuple[2]); | ||
| 49 | if(predicate == null) continue; | ||
| 50 | tuple[2] = predicate; | ||
| 51 | } else { | ||
| 52 | predicate = getGapPredicateID(tuple[1]); | ||
| 53 | if(predicate == null) continue; | ||
| 54 | tuple[1] = predicate; | ||
| 55 | } | ||
| 56 | return true; | ||
| 57 | } | ||
| 58 | } catch(JRDFStoreException e) { | ||
| 59 | e.printStackTrace(); | ||
| 60 | return false; | ||
| 61 | } | ||
| 62 | return false; | ||
| 63 | } | ||
| 64 | |||
| 65 | private boolean getNextGapFactAboutEquality() { | ||
| 66 | if(toAddedIndividuals == null) { | ||
| 67 | m_equality = m_engine.getEqualityGroups(false); | ||
| 68 | m_baseEquality = m_baseEngine.getEqualityGroups(false); | ||
| 69 | toAddedIndividuals = new LinkedList<String>(); | ||
| 70 | Map<String, Integer> rep2cnt = new HashMap<String, Integer>(); | ||
| 71 | Map<String, Integer> rep2cnt_base = new HashMap<String, Integer>(); | ||
| 72 | count(m_engine, m_equality, rep2cnt); | ||
| 73 | count(m_baseEngine, m_baseEquality, rep2cnt_base); | ||
| 74 | Set<String> visitedrep = new HashSet<String>(); | ||
| 75 | for(String individual : m_equality.keySet()) { | ||
| 76 | String rep = m_equality.find(individual); | ||
| 77 | if(visitedrep.contains(rep)) continue; | ||
| 78 | visitedrep.add(rep); | ||
| 79 | String rep_base = m_baseEquality.find(individual); | ||
| 80 | if(!rep2cnt.get(rep).equals(rep2cnt_base.get(rep_base))) { | ||
| 81 | toAddedIndividuals.add(rep); | ||
| 82 | } | ||
| 83 | } | ||
| 84 | |||
| 85 | } | ||
| 86 | while(true) { | ||
| 87 | if(getNewGapTuple(iter_individual, currentID)) return true; | ||
| 88 | if(iter_individual != null) { | ||
| 89 | iter_individual.dispose(); | ||
| 90 | iter_individual = null; | ||
| 91 | } | ||
| 92 | if(toAddedIndividuals.isEmpty()) { | ||
| 93 | currentID = -1; | ||
| 94 | return false; | ||
| 95 | } | ||
| 96 | String individual = toAddedIndividuals.remove(); | ||
| 97 | currentID = tripleManager.getResourceID(individual); | ||
| 98 | try { | ||
| 99 | iter_individual = | ||
| 100 | m_engine.internal_evaluateNotExpanded(String.format("select distinct ?y ?z where { <%s> ?y ?z }", individual)); | ||
| 101 | multi = iter_individual.open(); | ||
| 102 | } catch(JRDFStoreException e) { | ||
| 103 | e.printStackTrace(); | ||
| 104 | } | ||
| 105 | } | ||
| 106 | } | ||
| 107 | |||
| 108 | private void count(BasicQueryEngine engine, UFS<String> equality, Map<String, Integer> map) { | ||
| 109 | for(String ind : equality.keySet()) { | ||
| 110 | Integer exist = map.get(ind); | ||
| 111 | if(exist == null) | ||
| 112 | map.put(equality.find(ind), 1); | ||
| 113 | else | ||
| 114 | map.put(equality.find(ind), ++exist); | ||
| 115 | } | ||
| 116 | } | ||
| 117 | |||
| 118 | @Override | ||
| 119 | public int[] next() { | ||
| 120 | try { | ||
| 121 | if(iterator != null) | ||
| 122 | multi = iterator.getNext(); | ||
| 123 | else if(iter_individual != null) | ||
| 124 | multi = iter_individual.getNext(); | ||
| 125 | else | ||
| 126 | multi = 0; | ||
| 127 | } catch(JRDFStoreException e) { | ||
| 128 | e.printStackTrace(); | ||
| 129 | } | ||
| 130 | return tuple; | ||
| 131 | } | ||
| 132 | |||
| 133 | public void clear() { | ||
| 134 | super.clear(); | ||
| 135 | if(iter_individual != null) { | ||
| 136 | iter_individual.dispose(); | ||
| 137 | iter_individual = null; | ||
| 138 | } | ||
| 139 | } | ||
| 140 | |||
| 141 | } | ||
diff --git a/src/uk/ac/ox/cs/pagoda/query/GapByTriple.java b/src/uk/ac/ox/cs/pagoda/query/GapByTriple.java index a1c1b0e..eaa629b 100644 --- a/src/uk/ac/ox/cs/pagoda/query/GapByTriple.java +++ b/src/uk/ac/ox/cs/pagoda/query/GapByTriple.java | |||
| @@ -1,36 +1,29 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.query; | 1 | package uk.ac.ox.cs.pagoda.query; |
| 2 | 2 | ||
| 3 | import java.io.BufferedWriter; | 3 | import org.semanticweb.HermiT.model.*; |
| 4 | import java.io.FileOutputStream; | 4 | import uk.ac.ox.cs.JRDFox.JRDFStoreException; |
| 5 | import java.io.IOException; | 5 | import uk.ac.ox.cs.JRDFox.Prefixes; |
| 6 | import java.io.OutputStreamWriter; | 6 | import uk.ac.ox.cs.JRDFox.store.DataStore; |
| 7 | import java.util.Collection; | 7 | import uk.ac.ox.cs.JRDFox.store.Parameters; |
| 8 | 8 | import uk.ac.ox.cs.JRDFox.store.TupleIterator; | |
| 9 | import org.semanticweb.HermiT.model.Atom; | ||
| 10 | import org.semanticweb.HermiT.model.AtomicConcept; | ||
| 11 | import org.semanticweb.HermiT.model.AtomicRole; | ||
| 12 | import org.semanticweb.HermiT.model.DLClause; | ||
| 13 | import org.semanticweb.HermiT.model.Individual; | ||
| 14 | |||
| 15 | import uk.ac.ox.cs.pagoda.MyPrefixes; | 9 | import uk.ac.ox.cs.pagoda.MyPrefixes; |
| 16 | import uk.ac.ox.cs.pagoda.owl.OWLHelper; | 10 | import uk.ac.ox.cs.pagoda.owl.OWLHelper; |
| 17 | import uk.ac.ox.cs.pagoda.reasoner.light.BasicQueryEngine; | 11 | import uk.ac.ox.cs.pagoda.reasoner.light.BasicQueryEngine; |
| 18 | import uk.ac.ox.cs.pagoda.reasoner.light.RDFoxTripleManager; | 12 | import uk.ac.ox.cs.pagoda.reasoner.light.RDFoxTripleManager; |
| 19 | import uk.ac.ox.cs.pagoda.util.Namespace; | 13 | import uk.ac.ox.cs.pagoda.util.Namespace; |
| 20 | import uk.ac.ox.cs.pagoda.util.Utility; | 14 | import uk.ac.ox.cs.pagoda.util.Utility; |
| 21 | import uk.ac.ox.cs.JRDFox.JRDFStoreException; | 15 | |
| 22 | import uk.ac.ox.cs.JRDFox.Prefixes; | 16 | import java.io.BufferedWriter; |
| 23 | import uk.ac.ox.cs.JRDFox.store.DataStore; | 17 | import java.io.FileOutputStream; |
| 24 | import uk.ac.ox.cs.JRDFox.store.Parameters; | 18 | import java.io.IOException; |
| 25 | import uk.ac.ox.cs.JRDFox.store.TupleIterator; | 19 | import java.io.OutputStreamWriter; |
| 20 | import java.util.Collection; | ||
| 26 | 21 | ||
| 27 | public class GapByTriple extends GapTupleIterator<String> { | 22 | public class GapByTriple extends GapTupleIterator<String> { |
| 28 | 23 | ||
| 29 | private static final String RDF_TYPE = Namespace.RDF_NS + "type"; | ||
| 30 | private static final String BRIEF_RDF_TYPE = "rdf:type"; | ||
| 31 | |||
| 32 | static final String allTripleQuery = "SELECT ?X ?Y ?Z WHERE { ?X ?Y ?Z }"; | 24 | static final String allTripleQuery = "SELECT ?X ?Y ?Z WHERE { ?X ?Y ?Z }"; |
| 33 | 25 | private static final String RDF_TYPE = Namespace.RDF_NS + "type"; | |
| 26 | private static final String BRIEF_RDF_TYPE = "rdf:type"; | ||
| 34 | DataStore lowerStore, upperStore; | 27 | DataStore lowerStore, upperStore; |
| 35 | long multi; | 28 | long multi; |
| 36 | TupleIterator iterator; | 29 | TupleIterator iterator; |
| @@ -164,11 +157,6 @@ public class GapByTriple extends GapTupleIterator<String> { | |||
| 164 | } | 157 | } |
| 165 | 158 | ||
| 166 | @Override | 159 | @Override |
| 167 | public boolean isValid() { | ||
| 168 | return true; | ||
| 169 | } | ||
| 170 | |||
| 171 | @Override | ||
| 172 | public void clear() { | 160 | public void clear() { |
| 173 | iterator.dispose(); | 161 | iterator.dispose(); |
| 174 | } | 162 | } |
diff --git a/src/uk/ac/ox/cs/pagoda/query/GapTupleIterator.java b/src/uk/ac/ox/cs/pagoda/query/GapTupleIterator.java index 58303bb..2983b2e 100644 --- a/src/uk/ac/ox/cs/pagoda/query/GapTupleIterator.java +++ b/src/uk/ac/ox/cs/pagoda/query/GapTupleIterator.java | |||
| @@ -1,10 +1,10 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.query; | 1 | package uk.ac.ox.cs.pagoda.query; |
| 2 | 2 | ||
| 3 | import java.util.Iterator; | ||
| 4 | |||
| 5 | import uk.ac.ox.cs.JRDFox.JRDFStoreException; | 3 | import uk.ac.ox.cs.JRDFox.JRDFStoreException; |
| 6 | import uk.ac.ox.cs.JRDFox.store.DataStore; | 4 | import uk.ac.ox.cs.JRDFox.store.DataStore; |
| 7 | 5 | ||
| 6 | import java.util.Iterator; | ||
| 7 | |||
| 8 | public abstract class GapTupleIterator<T> implements Iterator<T> { | 8 | public abstract class GapTupleIterator<T> implements Iterator<T> { |
| 9 | 9 | ||
| 10 | public static final String gapPredicateSuffix = "_AUXg"; | 10 | public static final String gapPredicateSuffix = "_AUXg"; |
| @@ -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; |
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java b/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java index b5b9534..618fb70 100644 --- a/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java +++ b/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java | |||
| @@ -7,6 +7,7 @@ import uk.ac.ox.cs.pagoda.owl.EqualitiesEliminator; | |||
| 7 | import uk.ac.ox.cs.pagoda.owl.OWLHelper; | 7 | import uk.ac.ox.cs.pagoda.owl.OWLHelper; |
| 8 | import uk.ac.ox.cs.pagoda.query.AnswerTuples; | 8 | import uk.ac.ox.cs.pagoda.query.AnswerTuples; |
| 9 | import uk.ac.ox.cs.pagoda.query.GapByStore4ID; | 9 | import uk.ac.ox.cs.pagoda.query.GapByStore4ID; |
| 10 | import uk.ac.ox.cs.pagoda.query.GapByStore4ID2; | ||
| 10 | import uk.ac.ox.cs.pagoda.query.QueryRecord; | 11 | import uk.ac.ox.cs.pagoda.query.QueryRecord; |
| 11 | import uk.ac.ox.cs.pagoda.query.QueryRecord.Step; | 12 | import uk.ac.ox.cs.pagoda.query.QueryRecord.Step; |
| 12 | import uk.ac.ox.cs.pagoda.reasoner.full.Checker; | 13 | import uk.ac.ox.cs.pagoda.reasoner.full.Checker; |
| @@ -164,7 +165,9 @@ class MyQueryReasoner extends QueryReasoner { | |||
| 164 | trackingStore.importRDFData(name, datafile); | 165 | trackingStore.importRDFData(name, datafile); |
| 165 | trackingStore.materialise("saturate named individuals", originalMarkProgram); | 166 | trackingStore.materialise("saturate named individuals", originalMarkProgram); |
| 166 | 167 | ||
| 167 | GapByStore4ID gap = new GapByStore4ID(trackingStore); | 168 | // materialiseFullUpper(); |
| 169 | // GapByStore4ID gap = new GapByStore4ID(trackingStore); | ||
| 170 | GapByStore4ID gap = new GapByStore4ID2(trackingStore, rlLowerStore); | ||
| 168 | trackingStore.materialiseFoldedly(program, gap); | 171 | trackingStore.materialiseFoldedly(program, gap); |
| 169 | predicatesWithGap = gap.getPredicatesWithGap(); | 172 | predicatesWithGap = gap.getPredicatesWithGap(); |
| 170 | gap.clear(); | 173 | 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 5d2e411..9aa6235 100644 --- a/src/uk/ac/ox/cs/pagoda/reasoner/light/BasicQueryEngine.java +++ b/src/uk/ac/ox/cs/pagoda/reasoner/light/BasicQueryEngine.java | |||
| @@ -19,16 +19,18 @@ import java.util.*; | |||
| 19 | 19 | ||
| 20 | public class BasicQueryEngine extends RDFoxQueryEngine { | 20 | public class BasicQueryEngine extends RDFoxQueryEngine { |
| 21 | 21 | ||
| 22 | protected DataStore store; | 22 | protected DataStore store; |
| 23 | protected Parameters parameters = new Parameters(); | 23 | protected Parameters parameters = new Parameters(); |
| 24 | Set<DLClause> materialisedRules = new HashSet<DLClause>(); | ||
| 25 | private UFS<String> equalityGroups = null; | ||
| 24 | 26 | ||
| 25 | public BasicQueryEngine(String name) { | 27 | public BasicQueryEngine(String name) { |
| 26 | super(name); | 28 | super(name); |
| 27 | store = RDFoxQueryEngine.createDataStore(); | 29 | store = RDFoxQueryEngine.createDataStore(); |
| 28 | parameters.m_allAnswersInRoot = true; | 30 | parameters.m_allAnswersInRoot = true; |
| 29 | parameters.m_useBushy = true; | 31 | parameters.m_useBushy = true; |
| 30 | } | 32 | } |
| 31 | 33 | ||
| 32 | public void materialiseFoldedly(DatalogProgram dProgram, GapByStore4ID gap) { | 34 | public void materialiseFoldedly(DatalogProgram dProgram, GapByStore4ID gap) { |
| 33 | if (gap != null) { | 35 | if (gap != null) { |
| 34 | materialise("lower program", dProgram.getLower().toString()); | 36 | materialise("lower program", dProgram.getLower().toString()); |
| @@ -40,10 +42,9 @@ public class BasicQueryEngine extends RDFoxQueryEngine { | |||
| 40 | } catch (JRDFStoreException e) { | 42 | } catch (JRDFStoreException e) { |
| 41 | e.printStackTrace(); | 43 | e.printStackTrace(); |
| 42 | } finally { | 44 | } finally { |
| 43 | gap.clear(); | 45 | gap.clear(); |
| 44 | } | 46 | } |
| 45 | } | 47 | } else |
| 46 | else | ||
| 47 | materialise("upper program", dProgram.getUpper().toString()); | 48 | materialise("upper program", dProgram.getUpper().toString()); |
| 48 | } | 49 | } |
| 49 | 50 | ||
| @@ -58,24 +59,23 @@ public class BasicQueryEngine extends RDFoxQueryEngine { | |||
| 58 | } catch (JRDFStoreException e) { | 59 | } catch (JRDFStoreException e) { |
| 59 | e.printStackTrace(); | 60 | e.printStackTrace(); |
| 60 | } finally { | 61 | } finally { |
| 61 | gap.clear(); | 62 | gap.clear(); |
| 62 | } | 63 | } |
| 63 | } | 64 | } else |
| 64 | else | ||
| 65 | materialise("upper program", dProgram.getUpper().toString()); | 65 | materialise("upper program", dProgram.getUpper().toString()); |
| 66 | |||
| 67 | return 1; | ||
| 68 | } | ||
| 69 | 66 | ||
| 67 | return 1; | ||
| 68 | } | ||
| 69 | |||
| 70 | public int materialiseSkolemly(DatalogProgram dProgram, GapByStore4ID gap) { | 70 | public int materialiseSkolemly(DatalogProgram dProgram, GapByStore4ID gap) { |
| 71 | throw new UnsupportedOperationException(); | 71 | throw new UnsupportedOperationException(); |
| 72 | } | 72 | } |
| 73 | 73 | ||
| 74 | @Override | 74 | @Override |
| 75 | public AnswerTuples evaluate(String queryText) { | 75 | public AnswerTuples evaluate(String queryText) { |
| 76 | return evaluate(queryText, ConjunctiveQueryHelper.getAnswerVariables(queryText)[0]); | 76 | return evaluate(queryText, ConjunctiveQueryHelper.getAnswerVariables(queryText)[0]); |
| 77 | } | 77 | } |
| 78 | 78 | ||
| 79 | @Override | 79 | @Override |
| 80 | public AnswerTuples evaluate(String queryText, String[] answerVars) { | 80 | public AnswerTuples evaluate(String queryText, String[] answerVars) { |
| 81 | TupleIterator tupleIterator; | 81 | TupleIterator tupleIterator; |
| @@ -83,9 +83,9 @@ public class BasicQueryEngine extends RDFoxQueryEngine { | |||
| 83 | tupleIterator = store.compileQuery(queryText.replace("_:", "?"), prefixes, parameters); | 83 | tupleIterator = store.compileQuery(queryText.replace("_:", "?"), prefixes, parameters); |
| 84 | } catch (JRDFStoreException e) { | 84 | } catch (JRDFStoreException e) { |
| 85 | e.printStackTrace(); | 85 | e.printStackTrace(); |
| 86 | return null; | 86 | return null; |
| 87 | } | 87 | } |
| 88 | return new RDFoxAnswerTuples(answerVars, tupleIterator); | 88 | return new RDFoxAnswerTuples(answerVars, tupleIterator); |
| 89 | } | 89 | } |
| 90 | 90 | ||
| 91 | @Override | 91 | @Override |
| @@ -95,17 +95,18 @@ public class BasicQueryEngine extends RDFoxQueryEngine { | |||
| 95 | 95 | ||
| 96 | @Override | 96 | @Override |
| 97 | public void dispose() { | 97 | public void dispose() { |
| 98 | store.dispose(); | 98 | store.dispose(); |
| 99 | } | 99 | } |
| 100 | 100 | ||
| 101 | protected void outputClassAssertions(String filename) { | 101 | protected void outputClassAssertions(String filename) { |
| 102 | TupleIterator allTuples = null; | 102 | TupleIterator allTuples = null; |
| 103 | boolean redirect = false; | 103 | boolean redirect = false; |
| 104 | try { | 104 | try { |
| 105 | allTuples = getDataStore().compileQuery("SELECT ?X ?Z WHERE { ?X <" + Namespace.RDF_TYPE + "> ?Z }", prefixes, parameters); | 105 | allTuples = getDataStore().compileQuery("SELECT ?X ?Z WHERE { ?X <" + Namespace.RDF_TYPE + "> ?Z }", prefixes, parameters); |
| 106 | redirect = Utility.redirectCurrentOut(filename); | 106 | redirect = Utility.redirectCurrentOut(filename); |
| 107 | for (long multi = allTuples.open(); multi != 0; multi = allTuples.getNext()) | 107 | for(long multi = allTuples.open(); multi != 0; multi = allTuples.getNext()) |
| 108 | System.out.println(RDFoxTripleManager.getQuotedTerm(allTuples.getResource(0)) + " " + RDFoxTripleManager.getQuotedTerm(allTuples.getResource(1))); | 108 | System.out.println(RDFoxTripleManager.getQuotedTerm(allTuples.getResource(0)) + " " + RDFoxTripleManager |
| 109 | .getQuotedTerm(allTuples.getResource(1))); | ||
| 109 | } catch (JRDFStoreException e) { | 110 | } catch (JRDFStoreException e) { |
| 110 | e.printStackTrace(); | 111 | e.printStackTrace(); |
| 111 | } finally { | 112 | } finally { |
| @@ -123,137 +124,134 @@ public class BasicQueryEngine extends RDFoxQueryEngine { | |||
| 123 | public void outputInstance4BinaryPredicate(String iri) { | 124 | public void outputInstance4BinaryPredicate(String iri) { |
| 124 | outputAnswers("select ?x ?y where { ?x <" + iri + "> ?y . }"); | 125 | outputAnswers("select ?x ?y where { ?x <" + iri + "> ?y . }"); |
| 125 | } | 126 | } |
| 126 | 127 | ||
| 127 | public void outputInstanceNumbers(String filename) { | 128 | public void outputInstanceNumbers(String filename) { |
| 128 | TupleIterator predicateTuples = null; | 129 | TupleIterator predicateTuples = null; |
| 129 | TupleIterator instanceTuples; | 130 | TupleIterator instanceTuples; |
| 130 | Set<String> number = new HashSet<String>(); | 131 | Set<String> number = new HashSet<String>(); |
| 131 | String predicate; | 132 | String predicate; |
| 132 | try { | 133 | try { |
| 133 | predicateTuples = getDataStore().compileQuery("SELECT DISTINCT ?Y WHERE { ?X <" + Namespace.RDF_TYPE + "> ?Y }", prefixes, parameters); | 134 | predicateTuples = getDataStore().compileQuery("SELECT DISTINCT ?Y WHERE { ?X <" + Namespace.RDF_TYPE + "> ?Y }", prefixes, parameters); |
| 134 | for (long multi = predicateTuples.open(); multi != 0; multi = predicateTuples.getNext()) { | 135 | for (long multi = predicateTuples.open(); multi != 0; multi = predicateTuples.getNext()) { |
| 135 | predicate = RDFoxTripleManager.getQuotedTerm(predicateTuples.getResource(0)); | 136 | predicate = RDFoxTripleManager.getQuotedTerm(predicateTuples.getResource(0)); |
| 136 | instanceTuples = null; | 137 | instanceTuples = null; |
| 137 | try { | 138 | try { |
| 138 | instanceTuples = getDataStore().compileQuery("SELECT ?X WHERE { ?X <" + Namespace.RDF_TYPE + "> " + predicate + " }", prefixes, parameters); | 139 | instanceTuples = getDataStore().compileQuery("SELECT ?X WHERE { ?X <" + Namespace.RDF_TYPE + "> " + predicate + " }", prefixes, parameters); |
| 139 | long totalCount = 0; | 140 | long totalCount = 0; |
| 140 | for (long multi1 = instanceTuples.open(); multi1 != 0; multi1 = instanceTuples.getNext()) { | 141 | for (long multi1 = instanceTuples.open(); multi1 != 0; multi1 = instanceTuples.getNext()) { |
| 141 | totalCount += instanceTuples.getMultiplicity(); | 142 | totalCount += instanceTuples.getMultiplicity(); |
| 142 | } | 143 | } |
| 143 | number.add(predicate + " * " + totalCount); | 144 | number.add(predicate + " * " + totalCount); |
| 144 | } finally { | 145 | } finally { |
| 145 | if (instanceTuples != null) instanceTuples.dispose(); | 146 | if(instanceTuples != null) instanceTuples.dispose(); |
| 146 | } | 147 | } |
| 147 | } | 148 | } |
| 148 | } catch (JRDFStoreException e) { | 149 | } catch (JRDFStoreException e) { |
| 149 | e.printStackTrace(); | 150 | e.printStackTrace(); |
| 150 | } finally { | 151 | } finally { |
| 151 | if (predicateTuples != null) predicateTuples.dispose(); | 152 | if (predicateTuples != null) predicateTuples.dispose(); |
| 152 | predicateTuples = null; | 153 | predicateTuples = null; |
| 153 | } | 154 | } |
| 154 | 155 | ||
| 155 | try { | 156 | try { |
| 156 | predicateTuples = getDataStore().compileQuery("SELECT DISTINCT ?Y WHERE { ?X ?Y ?Z }", prefixes, parameters); | 157 | predicateTuples = getDataStore().compileQuery("SELECT DISTINCT ?Y WHERE { ?X ?Y ?Z }", prefixes, parameters); |
| 157 | for (long multi = predicateTuples.open(); multi != 0; multi = predicateTuples.getNext()) { | 158 | for (long multi = predicateTuples.open(); multi != 0; multi = predicateTuples.getNext()) { |
| 158 | predicate = RDFoxTripleManager.getQuotedTerm(predicateTuples.getResource(0)); | 159 | predicate = RDFoxTripleManager.getQuotedTerm(predicateTuples.getResource(0)); |
| 159 | instanceTuples = null; | 160 | instanceTuples = null; |
| 160 | try { | 161 | try { |
| 161 | instanceTuples = getDataStore().compileQuery("SELECT ?X ?Z WHERE { ?X " + predicate + " ?Z }", prefixes, parameters); | 162 | instanceTuples = getDataStore().compileQuery("SELECT ?X ?Z WHERE { ?X " + predicate + " ?Z }", prefixes, parameters); |
| 162 | long totalCount = 0; | 163 | long totalCount = 0; |
| 163 | for (long multi1 = instanceTuples.open(); multi1 != 0; multi1 = instanceTuples.getNext()) | 164 | for (long multi1 = instanceTuples.open(); multi1 != 0; multi1 = instanceTuples.getNext()) |
| 164 | totalCount += instanceTuples.getMultiplicity(); | 165 | totalCount += instanceTuples.getMultiplicity(); |
| 165 | number.add(predicate + " * " + totalCount); | 166 | number.add(predicate + " * " + totalCount); |
| 166 | } finally { | 167 | } finally { |
| 167 | if (instanceTuples != null) instanceTuples.dispose(); | 168 | if(instanceTuples != null) instanceTuples.dispose(); |
| 168 | } | 169 | } |
| 169 | } | 170 | } |
| 170 | 171 | ||
| 171 | } catch (JRDFStoreException e) { | 172 | } catch (JRDFStoreException e) { |
| 172 | e.printStackTrace(); | 173 | e.printStackTrace(); |
| 173 | } finally { | 174 | } finally { |
| 174 | if (predicateTuples != null) predicateTuples.dispose(); | 175 | if (predicateTuples != null) predicateTuples.dispose(); |
| 175 | predicateTuples = null; | 176 | predicateTuples = null; |
| 176 | } | 177 | } |
| 177 | 178 | ||
| 178 | Utility.redirectCurrentOut(filename); | 179 | Utility.redirectCurrentOut(filename); |
| 179 | String[] ordered = number.toArray(new String[0]); | 180 | String[] ordered = number.toArray(new String[0]); |
| 180 | Arrays.sort(ordered, new DLPredicateComparator()); | 181 | Arrays.sort(ordered, new DLPredicateComparator()); |
| 181 | for (String line: ordered) System.out.println(line); | 182 | for(String line : ordered) System.out.println(line); |
| 182 | Utility.closeCurrentOut(); | 183 | Utility.closeCurrentOut(); |
| 183 | 184 | ||
| 184 | } | 185 | } |
| 185 | 186 | ||
| 186 | public TupleIterator internal_evaluateAgainstIDBs(String queryText) throws JRDFStoreException { | 187 | public TupleIterator internal_evaluateAgainstIDBs(String queryText) throws JRDFStoreException { |
| 187 | TupleIterator iter = store.compileQuery(queryText, prefixes, parameters, TripleStatus.TUPLE_STATUS_IDB.union(TripleStatus.TUPLE_STATUS_EDB), TripleStatus.TUPLE_STATUS_IDB); | 188 | TupleIterator iter = store.compileQuery(queryText, prefixes, parameters, TripleStatus.TUPLE_STATUS_IDB.union(TripleStatus.TUPLE_STATUS_EDB), TripleStatus.TUPLE_STATUS_IDB); |
| 188 | // iter.open(); | 189 | // iter.open(); |
| 189 | return iter; | 190 | return iter; |
| 190 | } | 191 | } |
| 191 | 192 | ||
| 192 | public TupleIterator internal_evaluate(String queryText) throws JRDFStoreException { | 193 | public TupleIterator internal_evaluate(String queryText) throws JRDFStoreException { |
| 193 | TupleIterator iter = store.compileQuery(queryText, prefixes, parameters); | 194 | TupleIterator iter = store.compileQuery(queryText, prefixes, parameters); |
| 194 | // iter.open(); | 195 | // iter.open(); |
| 195 | return iter; | 196 | return iter; |
| 196 | } | 197 | } |
| 197 | 198 | ||
| 198 | public void setExpandEquality(boolean flag) { | 199 | public void setExpandEquality(boolean flag) { |
| 199 | parameters.m_expandEquality = flag; | 200 | parameters.m_expandEquality = flag; |
| 200 | } | 201 | } |
| 201 | 202 | ||
| 202 | public TupleIterator internal_evaluateNotExpanded(String queryText) throws JRDFStoreException { | 203 | public TupleIterator internal_evaluateNotExpanded(String queryText) throws JRDFStoreException { |
| 203 | parameters.m_expandEquality = false; | 204 | parameters.m_expandEquality = false; |
| 204 | TupleIterator iter = store.compileQuery(queryText, prefixes, parameters); | 205 | TupleIterator iter = store.compileQuery(queryText, prefixes, parameters); |
| 205 | // iter.open(); | 206 | // iter.open(); |
| 206 | parameters.m_expandEquality = true; | 207 | parameters.m_expandEquality = true; |
| 207 | return iter; | 208 | return iter; |
| 208 | } | 209 | } |
| 209 | |||
| 210 | 210 | ||
| 211 | public TupleIterator internal_evaluate(String queryText, boolean incrementally) throws JRDFStoreException { | 211 | public TupleIterator internal_evaluate(String queryText, boolean incrementally) throws JRDFStoreException { |
| 212 | return incrementally ? internal_evaluateAgainstIDBs(queryText) : internal_evaluate(queryText); | 212 | return incrementally ? internal_evaluateAgainstIDBs(queryText) : internal_evaluate(queryText); |
| 213 | } | 213 | } |
| 214 | 214 | ||
| 215 | Set<DLClause> materialisedRules = new HashSet<DLClause>(); | ||
| 216 | |||
| 217 | public String getUnusedRules(Collection<DLClause> clauses, boolean toUpdate) { | 215 | public String getUnusedRules(Collection<DLClause> clauses, boolean toUpdate) { |
| 218 | DLClause clause; | 216 | DLClause clause; |
| 219 | for (Iterator<DLClause> iter = clauses.iterator(); iter.hasNext(); ) { | 217 | for (Iterator<DLClause> iter = clauses.iterator(); iter.hasNext(); ) { |
| 220 | if (materialisedRules.contains(clause = iter.next())) | 218 | if (materialisedRules.contains(clause = iter.next())) |
| 221 | iter.remove(); | 219 | iter.remove(); |
| 222 | else if (toUpdate) materialisedRules.add(clause); | 220 | else if(toUpdate) materialisedRules.add(clause); |
| 223 | } | 221 | } |
| 224 | 222 | ||
| 225 | if (clauses.isEmpty()) return null; | 223 | if (clauses.isEmpty()) return null; |
| 226 | 224 | ||
| 227 | return Program.toString(clauses); | 225 | return Program.toString(clauses); |
| 228 | } | 226 | } |
| 229 | 227 | ||
| 230 | public void outputMaterialisedRules() { | 228 | public void outputMaterialisedRules() { |
| 231 | System.out.println(DLClauseHelper.toString(materialisedRules)); | 229 | System.out.println(DLClauseHelper.toString(materialisedRules)); |
| 232 | } | 230 | } |
| 233 | 231 | ||
| 234 | public void outputAnswers(String query) { | 232 | public void outputAnswers(String query) { |
| 235 | TupleIterator iter = null; | 233 | TupleIterator iter = null; |
| 236 | try { | 234 | try { |
| 237 | iter = internal_evaluate(query); | 235 | iter = internal_evaluate(query); |
| 238 | System.out.println(query); | 236 | System.out.println(query); |
| 239 | int arity = iter.getArity(); | 237 | int arity = iter.getArity(); |
| 240 | for (long multi = iter.open(); multi != 0; multi = iter.getNext()) { | 238 | for (long multi = iter.open(); multi != 0; multi = iter.getNext()) { |
| 241 | for (int i = 0; i < arity; ++i) | 239 | for (int i = 0; i < arity; ++i) |
| 242 | System.out.print(RDFoxTripleManager.getQuotedTerm(iter.getResource(i)) + "\t"); | 240 | System.out.print(RDFoxTripleManager.getQuotedTerm(iter.getResource(i)) + "\t"); |
| 243 | System.out.println(); | 241 | System.out.println(); |
| 244 | } | 242 | } |
| 245 | } catch (JRDFStoreException e) { | 243 | } catch (JRDFStoreException e) { |
| 246 | e.printStackTrace(); | 244 | e.printStackTrace(); |
| 247 | } finally { | 245 | } finally { |
| 248 | if (iter != null) iter.dispose(); | 246 | if(iter != null) iter.dispose(); |
| 249 | } | 247 | } |
| 250 | } | 248 | } |
| 251 | 249 | ||
| 252 | public void outputInstance4UnaryPredicate(String iri) { | 250 | public void outputInstance4UnaryPredicate(String iri) { |
| 253 | outputAnswers("select ?x where { ?x " | 251 | outputAnswers("select ?x where { ?x " |
| 254 | + "<http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <" | 252 | + "<http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <" |
| 255 | + iri | 253 | + iri |
| 256 | + "> .}"); | 254 | + "> .}"); |
| 257 | } | 255 | } |
| 258 | 256 | ||
| 259 | public void outputSubjects(String p, String o) { | 257 | public void outputSubjects(String p, String o) { |
| @@ -265,13 +263,13 @@ public class BasicQueryEngine extends RDFoxQueryEngine { | |||
| 265 | } | 263 | } |
| 266 | 264 | ||
| 267 | public void outputIDBFacts() { | 265 | public void outputIDBFacts() { |
| 268 | TupleIterator iter = null; | 266 | TupleIterator iter = null; |
| 269 | try { | 267 | try { |
| 270 | iter = internal_evaluateAgainstIDBs("select distict ?x ?y ?z where { ?x ?y ?z }"); | 268 | iter = internal_evaluateAgainstIDBs("select distict ?x ?y ?z where { ?x ?y ?z }"); |
| 271 | for (long multi = iter.open(); multi != 0; multi = iter.getNext()) { | 269 | for (long multi = iter.open(); multi != 0; multi = iter.getNext()) { |
| 272 | for (int i = 0; i < 3; ++i) | 270 | for (int i = 0; i < 3; ++i) |
| 273 | System.out.print(RDFoxTripleManager.getQuotedTerm(iter.getResource(i)) + "\t"); | 271 | System.out.print(RDFoxTripleManager.getQuotedTerm(iter.getResource(i)) + "\t"); |
| 274 | System.out.println(); | 272 | System.out.println(); |
| 275 | } | 273 | } |
| 276 | } catch (JRDFStoreException e) { | 274 | } catch (JRDFStoreException e) { |
| 277 | // TODO Auto-generated catch block | 275 | // TODO Auto-generated catch block |
| @@ -279,7 +277,7 @@ public class BasicQueryEngine extends RDFoxQueryEngine { | |||
| 279 | } finally { | 277 | } finally { |
| 280 | if (iter != null) iter.dispose(); | 278 | if (iter != null) iter.dispose(); |
| 281 | } | 279 | } |
| 282 | 280 | ||
| 283 | } | 281 | } |
| 284 | 282 | ||
| 285 | public void outputType4Individual(String iri) { | 283 | public void outputType4Individual(String iri) { |
| @@ -287,25 +285,23 @@ public class BasicQueryEngine extends RDFoxQueryEngine { | |||
| 287 | } | 285 | } |
| 288 | 286 | ||
| 289 | public int getSameAsNumber() { | 287 | public int getSameAsNumber() { |
| 290 | TupleIterator iter = null; | 288 | TupleIterator iter = null; |
| 291 | int counter = 0; | 289 | int counter = 0; |
| 292 | try { | 290 | try { |
| 293 | iter = internal_evaluate("select ?x ?y where {?x " + Namespace.EQUALITY_QUOTED + " ?y . }"); | 291 | iter = internal_evaluate("select ?x ?y where {?x " + Namespace.EQUALITY_QUOTED + " ?y . }"); |
| 294 | for (long multi = iter.open(); multi != 0; multi = iter.getNext()) | 292 | for(long multi = iter.open(); multi != 0; multi = iter.getNext()) |
| 295 | if (iter.getResourceID(0) != iter.getResourceID(1)) | 293 | if (iter.getResourceID(0) != iter.getResourceID(1)) |
| 296 | ++counter; | 294 | ++counter; |
| 297 | } catch (JRDFStoreException e) { | 295 | } catch (JRDFStoreException e) { |
| 298 | e.printStackTrace(); | 296 | e.printStackTrace(); |
| 299 | } finally { | 297 | } finally { |
| 300 | if (iter != null) iter.dispose(); | 298 | if (iter != null) iter.dispose(); |
| 301 | } | 299 | } |
| 302 | return counter; | 300 | return counter; |
| 303 | } | 301 | } |
| 304 | 302 | ||
| 305 | private UFS<String> equalityGroups = null; | 303 | public UFS<String> getEqualityGroups(boolean reuse) { |
| 306 | 304 | if(reuse && equalityGroups != null) return equalityGroups; | |
| 307 | public UFS<String> getEqualityGroups() { | ||
| 308 | if (equalityGroups != null) return equalityGroups; | ||
| 309 | 305 | ||
| 310 | equalityGroups = new UFS<String>(); | 306 | equalityGroups = new UFS<String>(); |
| 311 | 307 | ||
diff --git a/src/uk/ac/ox/cs/pagoda/tracking/QueryTracker.java b/src/uk/ac/ox/cs/pagoda/tracking/QueryTracker.java index ee55be7..d2d041f 100644 --- a/src/uk/ac/ox/cs/pagoda/tracking/QueryTracker.java +++ b/src/uk/ac/ox/cs/pagoda/tracking/QueryTracker.java | |||
| @@ -42,7 +42,7 @@ public class QueryTracker { | |||
| 42 | m_record = queryRecord; | 42 | m_record = queryRecord; |
| 43 | 43 | ||
| 44 | m_manager = m_encoder.getOntology().getOWLOntologyManager(); | 44 | m_manager = m_encoder.getOntology().getOWLOntologyManager(); |
| 45 | equalityGroups = m_dataStore.getEqualityGroups(); | 45 | equalityGroups = m_dataStore.getEqualityGroups(true); |
| 46 | 46 | ||
| 47 | } | 47 | } |
| 48 | 48 | ||
diff --git a/src/uk/ac/ox/cs/pagoda/tracking/TrackingRuleEncoderWithGap.java b/src/uk/ac/ox/cs/pagoda/tracking/TrackingRuleEncoderWithGap.java index 67d07a8..c3694ad 100644 --- a/src/uk/ac/ox/cs/pagoda/tracking/TrackingRuleEncoderWithGap.java +++ b/src/uk/ac/ox/cs/pagoda/tracking/TrackingRuleEncoderWithGap.java | |||
| @@ -1,25 +1,21 @@ | |||
| 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 org.semanticweb.HermiT.model.*; |
| 4 | import java.util.LinkedList; | 4 | import org.semanticweb.owlapi.model.IRI; |
| 5 | |||
| 6 | import org.semanticweb.HermiT.model.AnnotatedEquality; | ||
| 7 | import org.semanticweb.HermiT.model.Atom; | ||
| 8 | import org.semanticweb.HermiT.model.AtomicConcept; | ||
| 9 | import org.semanticweb.HermiT.model.AtomicRole; | ||
| 10 | import org.semanticweb.HermiT.model.DLClause; | ||
| 11 | import org.semanticweb.HermiT.model.Equality; | ||
| 12 | import org.semanticweb.HermiT.model.Variable; | ||
| 13 | import org.semanticweb.owlapi.model.OWLClass; | 5 | import org.semanticweb.owlapi.model.OWLClass; |
| 14 | import org.semanticweb.owlapi.model.OWLObjectProperty; | 6 | import org.semanticweb.owlapi.model.OWLObjectProperty; |
| 15 | import org.semanticweb.owlapi.model.OWLOntology; | 7 | import org.semanticweb.owlapi.model.OWLOntology; |
| 16 | |||
| 17 | import uk.ac.ox.cs.pagoda.hermit.DLClauseHelper; | 8 | import uk.ac.ox.cs.pagoda.hermit.DLClauseHelper; |
| 18 | import uk.ac.ox.cs.pagoda.query.*; | 9 | import uk.ac.ox.cs.pagoda.query.GapTupleIterator; |
| 19 | import uk.ac.ox.cs.pagoda.reasoner.light.BasicQueryEngine; | 10 | import uk.ac.ox.cs.pagoda.reasoner.light.BasicQueryEngine; |
| 20 | import uk.ac.ox.cs.pagoda.rules.UpperDatalogProgram; | 11 | import uk.ac.ox.cs.pagoda.rules.UpperDatalogProgram; |
| 21 | import uk.ac.ox.cs.pagoda.util.Namespace; | 12 | import uk.ac.ox.cs.pagoda.util.Namespace; |
| 22 | 13 | ||
| 14 | import java.util.Collection; | ||
| 15 | import java.util.HashSet; | ||
| 16 | import java.util.LinkedList; | ||
| 17 | import java.util.Set; | ||
| 18 | |||
| 23 | public class TrackingRuleEncoderWithGap extends TrackingRuleEncoder { | 19 | public class TrackingRuleEncoderWithGap extends TrackingRuleEncoder { |
| 24 | 20 | ||
| 25 | public TrackingRuleEncoderWithGap(UpperDatalogProgram program, BasicQueryEngine store) { | 21 | public TrackingRuleEncoderWithGap(UpperDatalogProgram program, BasicQueryEngine store) { |
| @@ -34,8 +30,9 @@ public class TrackingRuleEncoderWithGap extends TrackingRuleEncoder { | |||
| 34 | Variable X = Variable.create("X"); | 30 | Variable X = Variable.create("X"); |
| 35 | AtomicRole trackingSameAs = AtomicRole.create(Namespace.EQUALITY + "_tn"); | 31 | AtomicRole trackingSameAs = AtomicRole.create(Namespace.EQUALITY + "_tn"); |
| 36 | OWLOntology onto = program.getOntology(); | 32 | OWLOntology onto = program.getOntology(); |
| 37 | Atom[] headAtom = new Atom[] {Atom.create(trackingSameAs, X, X)}, bodyAtom; | 33 | Atom[] headAtom = new Atom[]{Atom.create(trackingSameAs, X, X)}, bodyAtom; |
| 38 | for (OWLClass cls: onto.getClassesInSignature(true)) { | 34 | for(OWLOntology o : onto.getImportsClosure()) |
| 35 | for(OWLClass cls : o.getClassesInSignature()) { | ||
| 39 | String clsIRI = cls.getIRI().toString(); | 36 | String clsIRI = cls.getIRI().toString(); |
| 40 | unaryPredicates.add(clsIRI); | 37 | unaryPredicates.add(clsIRI); |
| 41 | bodyAtom = new Atom[] { | 38 | bodyAtom = new Atom[] { |
| @@ -43,9 +40,16 @@ public class TrackingRuleEncoderWithGap extends TrackingRuleEncoder { | |||
| 43 | Atom.create(AtomicConcept.create(GapTupleIterator.getGapPredicate(clsIRI)), X)}; | 40 | Atom.create(AtomicConcept.create(GapTupleIterator.getGapPredicate(clsIRI)), X)}; |
| 44 | equalityRelatedClauses.add(DLClause.create(headAtom, bodyAtom)); | 41 | equalityRelatedClauses.add(DLClause.create(headAtom, bodyAtom)); |
| 45 | } | 42 | } |
| 46 | 43 | ||
| 47 | Variable Y = Variable.create("Y"); | 44 | Variable Y = Variable.create("Y"); |
| 48 | for (OWLObjectProperty prop: onto.getObjectPropertiesInSignature(true)) { | 45 | Set<OWLObjectProperty> setOfProperties = new HashSet<OWLObjectProperty>(); |
| 46 | for(OWLOntology o : onto.getImportsClosure()) | ||
| 47 | for(OWLObjectProperty prop : o.getObjectPropertiesInSignature()) | ||
| 48 | setOfProperties.add(prop); | ||
| 49 | setOfProperties.add(onto.getOWLOntologyManager() | ||
| 50 | .getOWLDataFactory() | ||
| 51 | .getOWLObjectProperty(IRI.create(Namespace.INEQUALITY))); | ||
| 52 | for(OWLObjectProperty prop : setOfProperties) { | ||
| 49 | String propIRI = prop.getIRI().toString(); | 53 | String propIRI = prop.getIRI().toString(); |
| 50 | binaryPredicates.add(propIRI); | 54 | binaryPredicates.add(propIRI); |
| 51 | AtomicRole trackingRole = AtomicRole.create(propIRI + "_tn"); | 55 | AtomicRole trackingRole = AtomicRole.create(propIRI + "_tn"); |
diff --git a/src/uk/ac/ox/cs/pagoda/util/Utility.java b/src/uk/ac/ox/cs/pagoda/util/Utility.java index 7b23e0d..e98cc81 100644 --- a/src/uk/ac/ox/cs/pagoda/util/Utility.java +++ b/src/uk/ac/ox/cs/pagoda/util/Utility.java | |||
| @@ -12,25 +12,30 @@ import java.util.*; | |||
| 12 | 12 | ||
| 13 | public class Utility { | 13 | public class Utility { |
| 14 | 14 | ||
| 15 | private static Logger LOGS; | ||
| 16 | static { | ||
| 17 | LOGS = Logger.getLogger("PAGOdA"); | ||
| 18 | LOGS.setLevel(Level.INFO); | ||
| 19 | } | ||
| 20 | |||
| 21 | public static final String JAVA_FILE_SEPARATOR = "/"; | 15 | public static final String JAVA_FILE_SEPARATOR = "/"; |
| 22 | public static final String FILE_SEPARATOR = System.getProperty("file.separator"); | 16 | public static final String FILE_SEPARATOR = System.getProperty("file.separator"); |
| 23 | public static final String LINE_SEPARATOR = System.getProperty("line.separator"); | 17 | public static final String LINE_SEPARATOR = System.getProperty("line.separator"); |
| 24 | 18 | public static final int TEST = -1; | |
| 25 | private static final String TEMP_DIR_PATH= "pagoda_tmp"; | ||
| 26 | private static String tempDir; | ||
| 27 | |||
| 28 | public static final int TEST = -1; | ||
| 29 | public static final int FLY = 0; | 19 | public static final int FLY = 0; |
| 30 | public static final int UOBM = 1; | 20 | public static final int UOBM = 1; |
| 31 | public static final int LUBM = 2; | 21 | public static final int LUBM = 2; |
| 32 | public static final int AEO = 3; | 22 | public static final int AEO = 3; |
| 33 | public static final int WINE = 4; | 23 | public static final int WINE = 4; |
| 24 | private static final String TEMP_DIR_PATH = "pagoda_tmp"; | ||
| 25 | static Stack<PrintStream> outs = new Stack<PrintStream>(); | ||
| 26 | private static Logger LOGS; | ||
| 27 | private static String tempDir; | ||
| 28 | private static int asciiX = (int) 'X'; | ||
| 29 | private static StringBuilder logMessage = new StringBuilder(); | ||
| 30 | |||
| 31 | static { | ||
| 32 | LOGS = Logger.getLogger("PAGOdA"); | ||
| 33 | LOGS.setLevel(Level.DEBUG); | ||
| 34 | } | ||
| 35 | |||
| 36 | static { | ||
| 37 | outs.push(System.out); | ||
| 38 | } | ||
| 34 | 39 | ||
| 35 | public static String getGlobalTempDirAbsolutePath() { | 40 | public static String getGlobalTempDirAbsolutePath() { |
| 36 | if(tempDir == null) { | 41 | if(tempDir == null) { |
| @@ -38,7 +43,7 @@ public class Utility { | |||
| 38 | Path path = Files.createTempDirectory(TEMP_DIR_PATH); | 43 | Path path = Files.createTempDirectory(TEMP_DIR_PATH); |
| 39 | tempDir = path.toString(); | 44 | tempDir = path.toString(); |
| 40 | new File(tempDir).deleteOnExit(); | 45 | new File(tempDir).deleteOnExit(); |
| 41 | } catch (IOException e) { | 46 | } catch(IOException e) { |
| 42 | e.printStackTrace(); | 47 | e.printStackTrace(); |
| 43 | System.exit(1); | 48 | System.exit(1); |
| 44 | } | 49 | } |
| @@ -46,46 +51,39 @@ public class Utility { | |||
| 46 | return tempDir; | 51 | return tempDir; |
| 47 | } | 52 | } |
| 48 | 53 | ||
| 49 | public static Set<Atom> toSet(Atom[] data) | 54 | public static Set<Atom> toSet(Atom[] data) { |
| 50 | { | ||
| 51 | HashSet<Atom> ret = new HashSet<Atom>(); | 55 | HashSet<Atom> ret = new HashSet<Atom>(); |
| 52 | for (Atom element: data) | 56 | for(Atom element : data) |
| 53 | ret.add(element); | 57 | ret.add(element); |
| 54 | return ret; | 58 | return ret; |
| 55 | } | 59 | } |
| 56 | 60 | ||
| 57 | static Stack<PrintStream> outs = new Stack<PrintStream>(); | ||
| 58 | |||
| 59 | static { | ||
| 60 | outs.push(System.out); | ||
| 61 | } | ||
| 62 | |||
| 63 | public static boolean redirectSystemOut() | 61 | public static boolean redirectSystemOut() |
| 64 | { | 62 | { |
| 65 | String stamp = new SimpleDateFormat( "HH:mm:ss").format(new Date()); | 63 | String stamp = new SimpleDateFormat( "HH:mm:ss").format(new Date()); |
| 66 | return redirectCurrentOut("./console" + stamp + ".txt"); | 64 | return redirectCurrentOut("./console" + stamp + ".txt"); |
| 67 | } | 65 | } |
| 68 | 66 | ||
| 69 | public static boolean redirectCurrentOut(String fileName) | 67 | public static boolean redirectCurrentOut(String fileName) |
| 70 | { | 68 | { |
| 71 | File file = new File(fileName); | 69 | File file = new File(fileName); |
| 72 | PrintStream out; | 70 | PrintStream out; |
| 73 | try { | 71 | try { |
| 74 | out = new PrintStream(new FileOutputStream(file)); | 72 | out = new PrintStream(new FileOutputStream(file)); |
| 75 | } catch (FileNotFoundException e) { | 73 | } catch (FileNotFoundException e) { |
| 76 | e.printStackTrace(); | 74 | e.printStackTrace(); |
| 77 | return false; | 75 | return false; |
| 78 | } | 76 | } |
| 79 | outs.push(out); | 77 | outs.push(out); |
| 80 | System.setOut(out); | 78 | System.setOut(out); |
| 81 | return true; | 79 | return true; |
| 82 | } | 80 | } |
| 83 | 81 | ||
| 84 | public static void closeCurrentOut() { | 82 | public static void closeCurrentOut() { |
| 85 | if (!outs.isEmpty()) | 83 | if (!outs.isEmpty()) |
| 86 | outs.pop().close(); | 84 | outs.pop().close(); |
| 87 | 85 | ||
| 88 | if (!outs.isEmpty()) | 86 | if(!outs.isEmpty()) |
| 89 | System.setOut(outs.peek()); | 87 | System.setOut(outs.peek()); |
| 90 | } | 88 | } |
| 91 | 89 | ||
| @@ -103,7 +101,7 @@ public class Utility { | |||
| 103 | while ((line = reader.readLine()) != null && !line.startsWith("}")) | 101 | while ((line = reader.readLine()) != null && !line.startsWith("}")) |
| 104 | if (first) { | 102 | if (first) { |
| 105 | first = false; | 103 | first = false; |
| 106 | query = expression(line.trim()); | 104 | query = expression(line.trim()); |
| 107 | } | 105 | } |
| 108 | else query += ", " + expression(line.trim()); | 106 | else query += ", " + expression(line.trim()); |
| 109 | writer.write(query); | 107 | writer.write(query); |
| @@ -122,8 +120,6 @@ public class Utility { | |||
| 122 | else return parts[1] + "(?" + variableIndex(parts[0]) + ",?" + variableIndex(parts[2]) + ")"; | 120 | else return parts[1] + "(?" + variableIndex(parts[0]) + ",?" + variableIndex(parts[2]) + ")"; |
| 123 | } | 121 | } |
| 124 | 122 | ||
| 125 | private static int asciiX = (int)'X'; | ||
| 126 | |||
| 127 | private static int variableIndex(String exp) { | 123 | private static int variableIndex(String exp) { |
| 128 | char var = exp.charAt(1); | 124 | char var = exp.charAt(1); |
| 129 | return (int)var - asciiX; | 125 | return (int)var - asciiX; |
| @@ -135,12 +131,12 @@ public class Utility { | |||
| 135 | return null; | 131 | return null; |
| 136 | return line.trim(); | 132 | return line.trim(); |
| 137 | } | 133 | } |
| 138 | 134 | ||
| 139 | public static String getTextfromFile(String fileName) throws FileNotFoundException { | 135 | public static String getTextfromFile(String fileName) throws FileNotFoundException { |
| 140 | Scanner scanner = new Scanner(new File(fileName)); | 136 | Scanner scanner = new Scanner(new File(fileName)); |
| 141 | String program = scanner.useDelimiter("\\Z").next(); | 137 | String program = scanner.useDelimiter("\\Z").next(); |
| 142 | scanner.close(); | 138 | scanner.close(); |
| 143 | return program; | 139 | return program; |
| 144 | } | 140 | } |
| 145 | 141 | ||
| 146 | public static String[] getPattern(BufferedReader answerReader) throws IOException { | 142 | public static String[] getPattern(BufferedReader answerReader) throws IOException { |
| @@ -152,59 +148,57 @@ public class Utility { | |||
| 152 | 148 | ||
| 153 | public static void removeRecursively(File file) { | 149 | public static void removeRecursively(File file) { |
| 154 | if (!file.exists()) return; | 150 | if (!file.exists()) return; |
| 155 | 151 | ||
| 156 | if (file.isDirectory()) | 152 | if (file.isDirectory()) |
| 157 | for (File tFile: file.listFiles()) | 153 | for (File tFile: file.listFiles()) |
| 158 | removeRecursively(tFile); | 154 | removeRecursively(tFile); |
| 159 | file.delete(); | 155 | file.delete(); |
| 160 | } | 156 | } |
| 161 | 157 | ||
| 162 | public static void removeRecursively(String fileName) { | 158 | public static void removeRecursively(String fileName) { |
| 163 | removeRecursively(new File(fileName)); | 159 | removeRecursively(new File(fileName)); |
| 164 | } | 160 | } |
| 165 | 161 | ||
| 166 | public static Collection<String> getQueryTexts(String fileName) throws IOException { | 162 | public static Collection<String> getQueryTexts(String fileName) throws IOException { |
| 167 | BufferedReader queryReader = new BufferedReader(new InputStreamReader(new FileInputStream(fileName))); | 163 | BufferedReader queryReader = new BufferedReader(new InputStreamReader(new FileInputStream(fileName))); |
| 168 | String line; | 164 | String line; |
| 169 | Collection<String> queryTexts = new LinkedList<String>(); | 165 | Collection<String> queryTexts = new LinkedList<String>(); |
| 170 | while (true) { | 166 | while (true) { |
| 171 | while ((line = queryReader.readLine()) != null && ((line = line.trim()).isEmpty() || line.startsWith("#"))); | 167 | while((line = queryReader.readLine()) != null && ((line = line.trim()).isEmpty() || line.startsWith("#"))) ; |
| 172 | if (line == null) { | 168 | if (line == null) { |
| 173 | queryReader.close(); | 169 | queryReader.close(); |
| 174 | return queryTexts; | 170 | return queryTexts; |
| 175 | } | 171 | } |
| 176 | 172 | ||
| 177 | StringBuffer query = new StringBuffer(); | 173 | StringBuffer query = new StringBuffer(); |
| 178 | if (!line.startsWith("^[")) | 174 | if (!line.startsWith("^[")) |
| 179 | query.append(line).append(LINE_SEPARATOR); | 175 | query.append(line).append(LINE_SEPARATOR); |
| 180 | 176 | ||
| 181 | while ((line = queryReader.readLine()) != null && !line.trim().endsWith("}")) | 177 | while((line = queryReader.readLine()) != null && !line.trim().endsWith("}")) |
| 182 | query.append(line).append(LINE_SEPARATOR); | 178 | query.append(line).append(LINE_SEPARATOR); |
| 183 | query.append(line); | 179 | query.append(line); |
| 184 | queryTexts.add(query.toString()); | 180 | queryTexts.add(query.toString()); |
| 185 | } | 181 | } |
| 186 | } | 182 | } |
| 187 | 183 | ||
| 188 | /** | 184 | /** |
| 189 | * | 185 | * |
| 190 | * @param answerReader | 186 | * @param answerReader |
| 191 | * @return all lines before the next empty line | 187 | * @return all lines before the next empty line |
| 192 | * @throws IOException | 188 | * @throws IOException |
| 193 | */ | 189 | */ |
| 194 | public static Collection<String> getLines(BufferedReader answerReader) throws IOException { | 190 | public static Collection<String> getLines(BufferedReader answerReader) throws IOException { |
| 195 | Collection<String> answerTuples = new LinkedList<String>(); | 191 | Collection<String> answerTuples = new LinkedList<String>(); |
| 196 | String line; | 192 | String line; |
| 197 | while ((line = answerReader.readLine()) != null) { | 193 | while ((line = answerReader.readLine()) != null) { |
| 198 | line = line.trim(); | 194 | line = line.trim(); |
| 199 | if (line.isEmpty()) | 195 | if (line.isEmpty()) |
| 200 | break; | 196 | break; |
| 201 | answerTuples.add(line); | 197 | answerTuples.add(line); |
| 202 | } | 198 | } |
| 203 | return answerTuples; | 199 | return answerTuples; |
| 204 | } | 200 | } |
| 205 | 201 | ||
| 206 | private static StringBuilder logMessage = new StringBuilder(); | ||
| 207 | |||
| 208 | private static String getLogMessage(Object[] messages) { | 202 | private static String getLogMessage(Object[] messages) { |
| 209 | if (messages.length == 1) return messages[0].toString(); | 203 | if (messages.length == 1) return messages[0].toString(); |
| 210 | else { | 204 | else { |
| @@ -242,20 +236,6 @@ public class Utility { | |||
| 242 | if (LOGS != null) | 236 | if (LOGS != null) |
| 243 | LOGS.error(getLogMessage(messages)); | 237 | LOGS.error(getLogMessage(messages)); |
| 244 | } | 238 | } |
| 245 | |||
| 246 | // public static void initialise() { | ||
| 247 | // File tmp = new File(TempDirectory); | ||
| 248 | // if (!tmp.exists()) tmp.mkdirs(); | ||
| 249 | // } | ||
| 250 | // | ||
| 251 | // public static void cleanup() { | ||
| 252 | // File tmp = new File(TempDirectory); | ||
| 253 | // if (tmp.exists()) { | ||
| 254 | // for (File file: tmp.listFiles()) | ||
| 255 | // file.delete(); | ||
| 256 | // tmp.delete(); | ||
| 257 | // } | ||
| 258 | // } | ||
| 259 | 239 | ||
| 260 | public static String toFileIRI(String path) { | 240 | public static String toFileIRI(String path) { |
| 261 | String iri; | 241 | String iri; |
