aboutsummaryrefslogtreecommitdiff
path: root/src/uk/ac/ox/cs/pagoda/reasoner/RLUQueryReasoner.java
diff options
context:
space:
mode:
authorFederico Igne <federico.igne@cs.ox.ac.uk>2022-05-10 18:17:06 +0100
committerFederico Igne <federico.igne@cs.ox.ac.uk>2022-05-11 12:34:47 +0100
commit17bd9beaf7f358a44e5bf36a5855fe6727d506dc (patch)
tree47e9310a0cff869d9ec017dcb2c81876407782c8 /src/uk/ac/ox/cs/pagoda/reasoner/RLUQueryReasoner.java
parent8651164cd632a5db310b457ce32d4fbc97bdc41c (diff)
downloadACQuA-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/reasoner/RLUQueryReasoner.java')
-rw-r--r--src/uk/ac/ox/cs/pagoda/reasoner/RLUQueryReasoner.java135
1 files changed, 0 insertions, 135 deletions
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/RLUQueryReasoner.java b/src/uk/ac/ox/cs/pagoda/reasoner/RLUQueryReasoner.java
deleted file mode 100644
index 368fbb2..0000000
--- a/src/uk/ac/ox/cs/pagoda/reasoner/RLUQueryReasoner.java
+++ /dev/null
@@ -1,135 +0,0 @@
1package uk.ac.ox.cs.pagoda.reasoner;
2
3import org.semanticweb.owlapi.model.OWLOntology;
4import uk.ac.ox.cs.pagoda.multistage.MultiStageQueryEngine;
5import uk.ac.ox.cs.pagoda.owl.EqualitiesEliminator;
6import uk.ac.ox.cs.pagoda.query.AnswerTuples;
7import uk.ac.ox.cs.pagoda.query.QueryRecord;
8import uk.ac.ox.cs.pagoda.query.QueryRecord.Step;
9import uk.ac.ox.cs.pagoda.reasoner.light.BasicQueryEngine;
10import uk.ac.ox.cs.pagoda.rules.DatalogProgram;
11import uk.ac.ox.cs.pagoda.util.Timer;
12import uk.ac.ox.cs.pagoda.util.Utility;
13import uk.ac.ox.cs.pagoda.util.disposable.DisposedException;
14
15class RLUQueryReasoner extends QueryReasoner {
16
17 DatalogProgram program;
18
19 BasicQueryEngine rlLowerStore, rlUpperStore;
20
21 boolean multiStageTag, equalityTag;
22 Timer t = new Timer();
23
24 public RLUQueryReasoner(boolean multiStageTag, boolean considerEqualities) {
25 this.multiStageTag = multiStageTag;
26 this.equalityTag = considerEqualities;
27 rlLowerStore = new BasicQueryEngine("rl-lower-bound");
28 if(!multiStageTag)
29 rlUpperStore = new BasicQueryEngine("rl-upper-bound");
30 else
31 rlUpperStore = new MultiStageQueryEngine("rl-upper-bound", false);
32 }
33
34 @Override
35 public void evaluate(QueryRecord queryRecord) {
36 if(isDisposed()) throw new DisposedException();
37 AnswerTuples ans = null;
38 t.reset();
39 try {
40 ans = rlLowerStore.evaluate(queryRecord.getQueryText(), queryRecord.getAnswerVariables());
41 Utility.logDebug(t.duration());
42 queryRecord.updateLowerBoundAnswers(ans);
43 } finally {
44 if (ans != null) ans.dispose();
45 }
46 queryRecord.addProcessingTime(Step.LOWER_BOUND, t.duration());
47
48 ans = null;
49 t.reset();
50 try {
51 ans = rlUpperStore.evaluate(queryRecord.getQueryText(), queryRecord.getAnswerVariables());
52 Utility.logDebug(t.duration());
53 queryRecord.updateUpperBoundAnswers(ans);
54 } finally {
55 if (ans != null) ans.dispose();
56 }
57 queryRecord.addProcessingTime(Step.UPPER_BOUND, t.duration());
58
59 if(queryRecord.isProcessed())
60 queryRecord.setDifficulty(Step.UPPER_BOUND);
61 }
62
63 @Override
64 public void evaluateUpper(QueryRecord queryRecord) {
65 if(isDisposed()) throw new DisposedException();
66 AnswerTuples ans = null;
67 try {
68 ans = rlUpperStore.evaluate(queryRecord.getQueryText(), queryRecord.getAnswerVariables());
69 Utility.logDebug(t.duration());
70 queryRecord.updateUpperBoundAnswers(ans, true);
71 } finally {
72 if (ans != null) ans.dispose();
73 }
74 }
75
76 @Override
77 public void dispose() {
78 super.dispose();
79 if (rlLowerStore != null) rlLowerStore.dispose();
80 if (rlUpperStore != null) rlUpperStore.dispose();
81 }
82
83 @Override
84 public void loadOntology(OWLOntology o) {
85 if(isDisposed()) throw new DisposedException();
86 if (!equalityTag) {
87 EqualitiesEliminator eliminator = new EqualitiesEliminator(o);
88 o = eliminator.getOutputOntology();
89 eliminator.save();
90 }
91
92 OWLOntology ontology = o;
93 program = new DatalogProgram(ontology);
94 importData(program.getAdditionalDataFile());
95 }
96
97 @Override
98 public boolean preprocess() {
99 if(isDisposed()) throw new DisposedException();
100 String datafile = getImportedData();
101 rlLowerStore.importRDFData("data", datafile);
102 rlLowerStore.materialise("lower program", program.getLower().toString());
103
104 rlUpperStore.importRDFData("data", datafile);
105 rlUpperStore.materialiseRestrictedly(program, null);
106
107 return isConsistent();
108
109 }
110
111 @Override
112 public boolean isConsistent() {
113 if(isDisposed()) throw new DisposedException();
114 String[] X = new String[] { "X" };
115 AnswerTuples ans = null;
116 try {
117 ans = rlLowerStore.evaluate(QueryRecord.botQueryText, X);
118 if (ans.isValid()) return false;
119 } finally {
120 if (ans != null) ans.dispose();
121 }
122
123 ans = null;
124 try {
125 ans = rlUpperStore.evaluate(QueryRecord.botQueryText, X);
126 if (!ans.isValid()) return true;
127 } finally {
128 if (ans != null) ans.dispose();
129 }
130
131 Utility.logDebug("The consistency of the data has not been determined yet.");
132 return true;
133 }
134
135}