aboutsummaryrefslogtreecommitdiff
path: root/src/uk/ac/ox/cs
diff options
context:
space:
mode:
authorRncLsn <rnc.lsn@gmail.com>2015-05-19 13:35:52 +0100
committerRncLsn <rnc.lsn@gmail.com>2015-05-19 13:35:52 +0100
commit5d54af2638a53721b414a41356a93686a9616272 (patch)
treee28c64b1887e7e964661d12d96df5b09abd4d9ee /src/uk/ac/ox/cs
parentc7dbc7c61c7094ea4ec49bd630023f23b92fd9d1 (diff)
downloadACQuA-5d54af2638a53721b414a41356a93686a9616272.tar.gz
ACQuA-5d54af2638a53721b414a41356a93686a9616272.zip
Backup before changes in MyQueryReasoner.
Diffstat (limited to 'src/uk/ac/ox/cs')
-rw-r--r--src/uk/ac/ox/cs/pagoda/Pagoda.java64
-rw-r--r--src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java176
-rw-r--r--src/uk/ac/ox/cs/pagoda/reasoner/QueryReasoner.java174
3 files changed, 217 insertions, 197 deletions
diff --git a/src/uk/ac/ox/cs/pagoda/Pagoda.java b/src/uk/ac/ox/cs/pagoda/Pagoda.java
index 3263c03..4ad7678 100644
--- a/src/uk/ac/ox/cs/pagoda/Pagoda.java
+++ b/src/uk/ac/ox/cs/pagoda/Pagoda.java
@@ -9,7 +9,7 @@ import uk.ac.ox.cs.pagoda.util.Utility;
9import java.nio.file.Path; 9import java.nio.file.Path;
10 10
11/** 11/**
12 * The main class 12 * Executable command line user interface.
13 */ 13 */
14public class Pagoda implements Runnable { 14public class Pagoda implements Runnable {
15 15
@@ -19,31 +19,62 @@ public class Pagoda implements Runnable {
19 private static final String OPTION_ANSWER = "a"; 19 private static final String OPTION_ANSWER = "a";
20 private static final String OPTION_CLASSIFY = "c"; 20 private static final String OPTION_CLASSIFY = "c";
21 private static final String OPTION_HERMIT = "f"; 21 private static final String OPTION_HERMIT = "f";
22 private final Properties properties;
23
24 /**
25 * Do not use it
26 * */
27 private Pagoda() {
28 properties = new Properties();
29 }
22 30
23 public static void main(String... args) { 31 public static void main(String... args) {
24 32
25 Options options = new Options(); 33 Options options = new Options();
26 options.addOption(Option.builder(OPTION_ONTOLOGY).argName(OPTION_ONTOLOGY).required().hasArg().desc("The ontology path").build()); 34 options.addOption(Option.builder(OPTION_ONTOLOGY)
35 .argName(OPTION_ONTOLOGY)
36 .required()
37 .hasArg()
38 .desc("The ontology path")
39 .build());
27 options.addOption(Option.builder(OPTION_DATA).argName(OPTION_DATA).hasArg().desc("The data path").build()); 40 options.addOption(Option.builder(OPTION_DATA).argName(OPTION_DATA).hasArg().desc("The data path").build());
28 options.addOption(Option.builder(OPTION_QUERY).argName(OPTION_QUERY).required().hasArg().desc("The query path").build()); 41 options.addOption(Option.builder(OPTION_QUERY)
29 options.addOption(Option.builder(OPTION_ANSWER).argName(OPTION_ANSWER).hasArg().desc("The answer path").build()); 42 .argName(OPTION_QUERY)
30 options.addOption(Option.builder(OPTION_CLASSIFY).argName(OPTION_CLASSIFY).desc("Tell whether to classify").type(Boolean.class).build()); 43 .required()
31 options.addOption(Option.builder(OPTION_HERMIT).argName(OPTION_HERMIT).desc("Tell whether to call Hermit").type(Boolean.class).build()); 44 .hasArg()
45 .desc("The query path")
46 .build());
47 options.addOption(Option.builder(OPTION_ANSWER)
48 .argName(OPTION_ANSWER)
49 .hasArg()
50 .desc("The answer path")
51 .build());
52 options.addOption(Option.builder(OPTION_CLASSIFY)
53 .argName(OPTION_CLASSIFY)
54 .desc("Tell whether to classify")
55 .type(Boolean.class)
56 .build());
57 options.addOption(Option.builder(OPTION_HERMIT)
58 .argName(OPTION_HERMIT)
59 .desc("Tell whether to call Hermit")
60 .type(Boolean.class)
61 .build());
32 62
33 CommandLineParser parser = new DefaultParser(); 63 CommandLineParser parser = new DefaultParser();
34 try { 64 try {
35 CommandLine cmd = parser.parse( options, args ); 65 CommandLine cmd = parser.parse(options, args);
36 PagodaBuilder pagodaBuilder = Pagoda.builder() 66 PagodaBuilder pagodaBuilder = Pagoda.builder()
37 .ontology(cmd.getOptionValue(OPTION_ONTOLOGY)) 67 .ontology(cmd.getOptionValue(OPTION_ONTOLOGY))
38 .query(cmd.getOptionValue(OPTION_QUERY)); 68 .query(cmd.getOptionValue(OPTION_QUERY));
39 if(cmd.hasOption(OPTION_DATA)) pagodaBuilder.data(cmd.getOptionValue(OPTION_DATA)); 69 if(cmd.hasOption(OPTION_DATA)) pagodaBuilder.data(cmd.getOptionValue(OPTION_DATA));
40 if(cmd.hasOption(OPTION_ANSWER)) pagodaBuilder.answer(cmd.getOptionValue(OPTION_ANSWER)); 70 if(cmd.hasOption(OPTION_ANSWER)) pagodaBuilder.answer(cmd.getOptionValue(OPTION_ANSWER));
41 if(cmd.hasOption(OPTION_CLASSIFY)) pagodaBuilder.classify(Boolean.parseBoolean(cmd.getOptionValue(OPTION_CLASSIFY))); 71 if(cmd.hasOption(OPTION_CLASSIFY))
42 if(cmd.hasOption(OPTION_HERMIT)) pagodaBuilder.hermit(Boolean.parseBoolean(cmd.getOptionValue(OPTION_HERMIT))); 72 pagodaBuilder.classify(Boolean.parseBoolean(cmd.getOptionValue(OPTION_CLASSIFY)));
73 if(cmd.hasOption(OPTION_HERMIT))
74 pagodaBuilder.hermit(Boolean.parseBoolean(cmd.getOptionValue(OPTION_HERMIT)));
43 75
44 pagodaBuilder.build().run(); 76 pagodaBuilder.build().run();
45 } 77 } catch(ParseException exp) {
46 catch( ParseException exp ) {
47 HelpFormatter formatter = new HelpFormatter(); 78 HelpFormatter formatter = new HelpFormatter();
48 formatter.printHelp("PAGOdA", options); 79 formatter.printHelp("PAGOdA", options);
49 Utility.logError("Parsing failed. Reason: " + exp.getMessage()); 80 Utility.logError("Parsing failed. Reason: " + exp.getMessage());
@@ -52,15 +83,6 @@ public class Pagoda implements Runnable {
52 } 83 }
53 84
54 /** 85 /**
55 * Do not use it
56 * */
57 private Pagoda() {
58 properties = new Properties();
59 }
60
61 private final Properties properties;
62
63 /**
64 * Get a builder. 86 * Get a builder.
65 * */ 87 * */
66 public static PagodaBuilder builder() { 88 public static PagodaBuilder builder() {
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java b/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java
index 1f435b7..dfbcb4d 100644
--- a/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java
+++ b/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java
@@ -37,21 +37,19 @@ public class MyQueryReasoner extends QueryReasoner {
37 BasicQueryEngine limitedSkolemUpperStore; 37 BasicQueryEngine limitedSkolemUpperStore;
38// boolean[] namedIndividuals_lazyUpper; 38// boolean[] namedIndividuals_lazyUpper;
39 39
40 OWLOntology elho_ontology; 40 OWLOntology elho_ontology;
41 KarmaQueryEngine elLowerStore = null; 41 KarmaQueryEngine elLowerStore = null;
42 42
43 BasicQueryEngine trackingStore = null; 43 BasicQueryEngine trackingStore = null;
44// boolean[] namedIndividuals_tracking; 44// boolean[] namedIndividuals_tracking;
45
46 boolean equalityTag;
47 boolean multiStageTag;
48 TrackingRuleEncoder encoder; 45 TrackingRuleEncoder encoder;
49 Timer t = new Timer(); 46 private boolean equalityTag;
47 private boolean multiStageTag;
48 private Timer t = new Timer();
50 private Collection<String> predicatesWithGap = null; 49 private Collection<String> predicatesWithGap = null;
51 private Boolean satisfiable; 50 private SatisfiabilityStatus satisfiable;
52 private ConsistencyManager consistency = new ConsistencyManager(this); 51 private ConsistencyManager consistency = new ConsistencyManager(this);
53 private boolean useUpperStores = false; 52 private boolean useUpperStores = false;
54
55 public MyQueryReasoner() { 53 public MyQueryReasoner() {
56 setup(true, true); 54 setup(true, true);
57 } 55 }
@@ -59,7 +57,7 @@ public class MyQueryReasoner extends QueryReasoner {
59 public MyQueryReasoner(boolean multiStageTag, boolean considerEqualities) { 57 public MyQueryReasoner(boolean multiStageTag, boolean considerEqualities) {
60 setup(multiStageTag, considerEqualities); 58 setup(multiStageTag, considerEqualities);
61 } 59 }
62 60
63 private BasicQueryEngine getUpperStore(String name, boolean checkValidity) { 61 private BasicQueryEngine getUpperStore(String name, boolean checkValidity) {
64 if (multiStageTag) 62 if (multiStageTag)
65 return new MultiStageQueryEngine(name, checkValidity); 63 return new MultiStageQueryEngine(name, checkValidity);
@@ -69,7 +67,7 @@ public class MyQueryReasoner extends QueryReasoner {
69 } 67 }
70 68
71 public void setup(boolean multiStageTag, boolean considerEqualities) { 69 public void setup(boolean multiStageTag, boolean considerEqualities) {
72 satisfiable = null; 70 satisfiable = SatisfiabilityStatus.UNCHECKED;
73 this.multiStageTag = multiStageTag; 71 this.multiStageTag = multiStageTag;
74 this.equalityTag = considerEqualities; 72 this.equalityTag = considerEqualities;
75 73
@@ -90,7 +88,7 @@ public class MyQueryReasoner extends QueryReasoner {
90 88
91 @Override 89 @Override
92 public void loadOntology(OWLOntology o) { 90 public void loadOntology(OWLOntology o) {
93 if (!equalityTag) { 91 if(!equalityTag) {
94 EqualitiesEliminator eliminator = new EqualitiesEliminator(o); 92 EqualitiesEliminator eliminator = new EqualitiesEliminator(o);
95 o = eliminator.getOutputOntology(); 93 o = eliminator.getOutputOntology();
96 eliminator.save(); 94 eliminator.save();
@@ -103,9 +101,9 @@ public class MyQueryReasoner extends QueryReasoner {
103// program.getGeneral().save(); 101// program.getGeneral().save();
104 102
105 useUpperStores = multiStageTag && !program.getGeneral().isHorn(); 103 useUpperStores = multiStageTag && !program.getGeneral().isHorn();
106 if (useUpperStores) { 104 if(useUpperStores) {
107 lazyUpperStore = getUpperStore("lazy-upper-bound", true); // new MultiStageQueryEngine("lazy-upper-bound", true); // 105 lazyUpperStore = getUpperStore("lazy-upper-bound", true);
108 limitedSkolemUpperStore = getUpperStore("limited-skolem-upper-bound", true); 106 limitedSkolemUpperStore = getUpperStore("limited-skolem-upper-bound", true);
109 } 107 }
110 108
111 importData(program.getAdditionalDataFile()); 109 importData(program.getAdditionalDataFile());
@@ -113,11 +111,11 @@ public class MyQueryReasoner extends QueryReasoner {
113 elho_ontology = new ELHOProfile().getFragment(ontology); 111 elho_ontology = new ELHOProfile().getFragment(ontology);
114 elLowerStore.processOntology(elho_ontology); 112 elLowerStore.processOntology(elho_ontology);
115 } 113 }
116 114
117 public Collection<String> getPredicatesWithGap() { 115 public Collection<String> getPredicatesWithGap() {
118 return predicatesWithGap; 116 return predicatesWithGap;
119 } 117 }
120 118
121 @Override 119 @Override
122 public boolean preprocess() { 120 public boolean preprocess() {
123 t.reset(); 121 t.reset();
@@ -127,7 +125,7 @@ public class MyQueryReasoner extends QueryReasoner {
127 rlLowerStore.importRDFData(name, datafile); 125 rlLowerStore.importRDFData(name, datafile);
128 rlLowerStore.materialise("lower program", program.getLower().toString()); 126 rlLowerStore.materialise("lower program", program.getLower().toString());
129// program.getLower().save(); 127// program.getLower().save();
130 if (!consistency.checkRLLowerBound()) return false; 128 if(!consistency.checkRLLowerBound()) return false;
131 Utility.logInfo("The number of sameAs assertions in RL lower store: " + rlLowerStore.getSameAsNumber()); 129 Utility.logInfo("The number of sameAs assertions in RL lower store: " + rlLowerStore.getSameAsNumber());
132 130
133 String originalMarkProgram = OWLHelper.getOriginalMarkProgram(ontology); 131 String originalMarkProgram = OWLHelper.getOriginalMarkProgram(ontology);
@@ -136,35 +134,35 @@ public class MyQueryReasoner extends QueryReasoner {
136 elLowerStore.materialise("saturate named individuals", originalMarkProgram); 134 elLowerStore.materialise("saturate named individuals", originalMarkProgram);
137 elLowerStore.materialise("lower program", program.getLower().toString()); 135 elLowerStore.materialise("lower program", program.getLower().toString());
138 elLowerStore.initialiseKarma(); 136 elLowerStore.initialiseKarma();
139 if (!consistency.checkELLowerBound()) return false; 137 if(!consistency.checkELLowerBound()) return false;
140 138
141 if (lazyUpperStore != null) { 139 if(lazyUpperStore != null) {
142 lazyUpperStore.importRDFData(name, datafile); 140 lazyUpperStore.importRDFData(name, datafile);
143 lazyUpperStore.materialise("saturate named individuals", originalMarkProgram); 141 lazyUpperStore.materialise("saturate named individuals", originalMarkProgram);
144 int tag = lazyUpperStore.materialiseRestrictedly(program, null); 142 int tag = lazyUpperStore.materialiseRestrictedly(program, null);
145 if (tag != 1) { 143 if(tag != 1) {
146 lazyUpperStore.dispose(); 144 lazyUpperStore.dispose();
147 lazyUpperStore = null; 145 lazyUpperStore = null;
148 } 146 }
149 if (tag == -1) return false; 147 if(tag == -1) return false;
150 } 148 }
151 if (consistency.checkUpper(lazyUpperStore)) { 149 if(consistency.checkUpper(lazyUpperStore)) {
152 satisfiable = true; 150 satisfiable = SatisfiabilityStatus.SATISFIABLE;
153 Utility.logInfo("time for satisfiability checking: " + t.duration()); 151 Utility.logInfo("time for satisfiability checking: " + t.duration());
154 } 152 }
155 153
156 if (limitedSkolemUpperStore != null) { 154 if(limitedSkolemUpperStore != null) {
157 limitedSkolemUpperStore.importRDFData(name, datafile); 155 limitedSkolemUpperStore.importRDFData(name, datafile);
158 limitedSkolemUpperStore.materialise("saturate named individuals", originalMarkProgram); 156 limitedSkolemUpperStore.materialise("saturate named individuals", originalMarkProgram);
159 int tag = limitedSkolemUpperStore.materialiseSkolemly(program, null); 157 int tag = limitedSkolemUpperStore.materialiseSkolemly(program, null);
160 if (tag != 1) { 158 if(tag != 1) {
161 limitedSkolemUpperStore.dispose(); 159 limitedSkolemUpperStore.dispose();
162 limitedSkolemUpperStore = null; 160 limitedSkolemUpperStore = null;
163 } 161 }
164 if (tag == -1) return false; 162 if(tag == -1) return false;
165 } 163 }
166 if (consistency.checkUpper(limitedSkolemUpperStore)) { 164 if(satisfiable == SatisfiabilityStatus.UNCHECKED && consistency.checkUpper(limitedSkolemUpperStore)) {
167 satisfiable = true; 165 satisfiable = SatisfiabilityStatus.SATISFIABLE;
168 Utility.logInfo("time for satisfiability checking: " + t.duration()); 166 Utility.logInfo("time for satisfiability checking: " + t.duration());
169 } 167 }
170 168
@@ -176,7 +174,7 @@ public class MyQueryReasoner extends QueryReasoner {
176 predicatesWithGap = gap.getPredicatesWithGap(); 174 predicatesWithGap = gap.getPredicatesWithGap();
177 gap.clear(); 175 gap.clear();
178 176
179 if (program.getGeneral().isHorn()) 177 if(program.getGeneral().isHorn())
180 encoder = new TrackingRuleEncoderWithGap(program.getUpper(), trackingStore); 178 encoder = new TrackingRuleEncoderWithGap(program.getUpper(), trackingStore);
181 else 179 else
182 encoder = new TrackingRuleEncoderDisjVar1(program.getUpper(), trackingStore); 180 encoder = new TrackingRuleEncoderDisjVar1(program.getUpper(), trackingStore);
@@ -186,21 +184,22 @@ public class MyQueryReasoner extends QueryReasoner {
186 184
187 program.deleteABoxTurtleFile(); 185 program.deleteABoxTurtleFile();
188 186
189 if (!isConsistent()) 187 if(!isConsistent())
190 return false; 188 return false;
191 189
192 consistency.extractBottomFragment(); 190 consistency.extractBottomFragment();
193 consistency.dispose(); 191 consistency.dispose();
192
194 return true; 193 return true;
195 } 194 }
196 195
197 @Override 196 @Override
198 public boolean isConsistent() { 197 public boolean isConsistent() {
199 if (satisfiable == null) { 198 if(satisfiable == SatisfiabilityStatus.UNCHECKED) {
200 satisfiable = consistency.check(); 199 satisfiable = consistency.check() ? SatisfiabilityStatus.SATISFIABLE : SatisfiabilityStatus.UNSATISFIABLE;
201 Utility.logInfo("time for satisfiability checking: " + t.duration()); 200 Utility.logInfo("time for satisfiability checking: " + t.duration());
202 } 201 }
203 return satisfiable; 202 return satisfiable == SatisfiabilityStatus.SATISFIABLE ? true : false;
204 } 203 }
205 204
206 /** 205 /**
@@ -208,8 +207,8 @@ public class MyQueryReasoner extends QueryReasoner {
208 * */ 207 * */
209 private OWLOntology relevantPart(QueryRecord queryRecord) { 208 private OWLOntology relevantPart(QueryRecord queryRecord) {
210 AnswerTuples rlAnswer = null, elAnswer = null; 209 AnswerTuples rlAnswer = null, elAnswer = null;
211 210
212 t.reset(); 211 t.reset();
213 try { 212 try {
214 rlAnswer = rlLowerStore.evaluate(queryRecord.getQueryText(), queryRecord.getAnswerVariables()); 213 rlAnswer = rlLowerStore.evaluate(queryRecord.getQueryText(), queryRecord.getAnswerVariables());
215 Utility.logDebug(t.duration()); 214 Utility.logDebug(t.duration());
@@ -218,11 +217,11 @@ public class MyQueryReasoner extends QueryReasoner {
218 if (rlAnswer != null) rlAnswer.dispose(); 217 if (rlAnswer != null) rlAnswer.dispose();
219 } 218 }
220 queryRecord.addProcessingTime(Step.LowerBound, t.duration()); 219 queryRecord.addProcessingTime(Step.LowerBound, t.duration());
221 220
222 t.reset(); 221 t.reset();
223 BasicQueryEngine upperStore = queryRecord.isBottom() || lazyUpperStore == null ? trackingStore : lazyUpperStore; 222 BasicQueryEngine upperStore = queryRecord.isBottom() || lazyUpperStore == null ? trackingStore : lazyUpperStore;
224 223
225 String[] extendedQuery = queryRecord.getExtendedQueryText(); 224 String[] extendedQuery = queryRecord.getExtendedQueryText();
226 225
227 // TODO why the following??? 226 // TODO why the following???
228 queryUpperBound(upperStore, queryRecord, queryRecord.getQueryText(), queryRecord.getAnswerVariables()); 227 queryUpperBound(upperStore, queryRecord, queryRecord.getQueryText(), queryRecord.getAnswerVariables());
@@ -246,10 +245,10 @@ public class MyQueryReasoner extends QueryReasoner {
246 245
247 queryRecord.addProcessingTime(Step.UpperBound, t.duration()); 246 queryRecord.addProcessingTime(Step.UpperBound, t.duration());
248 if (queryRecord.processed()) { 247 if (queryRecord.processed()) {
249 queryRecord.setDifficulty(Step.UpperBound); 248 queryRecord.setDifficulty(Step.UpperBound);
250 return null; 249 return null;
251 } 250 }
252 251
253 t.reset(); 252 t.reset();
254 try { 253 try {
255 elAnswer = elLowerStore.evaluate(extendedQuery[0], queryRecord.getAnswerVariables(), queryRecord.getLowerBoundAnswers()); 254 elAnswer = elLowerStore.evaluate(extendedQuery[0], queryRecord.getAnswerVariables(), queryRecord.getLowerBoundAnswers());
@@ -261,48 +260,46 @@ public class MyQueryReasoner extends QueryReasoner {
261 queryRecord.addProcessingTime(Step.ELLowerBound, t.duration()); 260 queryRecord.addProcessingTime(Step.ELLowerBound, t.duration());
262 261
263 if (queryRecord.processed()) { 262 if (queryRecord.processed()) {
264 queryRecord.setDifficulty(Step.ELLowerBound); 263 queryRecord.setDifficulty(Step.ELLowerBound);
265 return null; 264 return null;
266 } 265 }
267 266
268 t.reset(); 267 t.reset();
269 268
270 QueryTracker tracker = new QueryTracker(encoder, rlLowerStore, queryRecord); 269 QueryTracker tracker = new QueryTracker(encoder, rlLowerStore, queryRecord);
271 270
272 OWLOntology knowledgebase; 271 OWLOntology knowledgebase;
273 t.reset(); 272 t.reset();
274// if (program.getGeneral().isHorn()) { 273// if (program.getGeneral().isHorn()) {
275// knowledgebase = tracker.extract(lazyUpperStore, consistency.getQueryRecords(), true); 274// knowledgebase = tracker.extract(lazyUpperStore, consistency.getQueryRecords(), true);
276// queryRecord.addProcessingTime(Step.Fragment, t.duration()); 275// queryRecord.addProcessingTime(Step.Fragment, t.duration());
277// return knowledgebase; 276// return knowledgebase;
278// } 277// }
279// else { 278// else {
280 knowledgebase = tracker.extract(trackingStore, consistency.getQueryRecords(), true); 279 knowledgebase = tracker.extract(trackingStore, consistency.getQueryRecords(), true);
281 queryRecord.addProcessingTime(Step.Fragment, t.duration()); 280 queryRecord.addProcessingTime(Step.Fragment, t.duration());
282// } 281// }
283 282
284 if (knowledgebase.isEmpty() || queryRecord.isBottom()) 283 if(knowledgebase.isEmpty() || queryRecord.isBottom())
285 return knowledgebase; 284 return knowledgebase;
286 285
287 if (program.getGeneral().isHorn()) return knowledgebase; 286 if(program.getGeneral().isHorn()) return knowledgebase;
288 287
289// t.reset(); 288// t.reset();
290// if (queryRecord.isHorn() && lazyUpperStore != null) { 289// if (queryRecord.isHorn() && lazyUpperStore != null) {
291//// knowledgebase = tracker.extract(lazyUpperStore, consistency.getQueryRecords(), true); 290//// knowledgebase = tracker.extract(lazyUpperStore, consistency.getQueryRecords(), true);
292// } else if (queryRecord.getArity() < 3) { 291// } else if (queryRecord.getArity() < 3) {
293// IterativeRefinement iterativeRefinement = new IterativeRefinement(queryRecord, tracker, trackingStore, consistency.getQueryRecords()); 292// IterativeRefinement iterativeRefinement = new IterativeRefinement(queryRecord, tracker, trackingStore, consistency.getQueryRecords());
294// knowledgebase = iterativeRefinement.extractWithFullABox(importedData.toString(), program.getUpperBottomStrategy()); 293// knowledgebase = iterativeRefinement.extractWithFullABox(importedData.toString(), program.getUpperBottomStrategy());
295// } 294// }
296// 295//
297// queryRecord.addProcessingTime(Step.FragmentRefinement, t.duration()); 296// queryRecord.addProcessingTime(Step.FragmentRefinement, t.duration());
298// 297//
299// if (knowledgebase == null) 298// if (knowledgebase == null)
300// queryRecord.setDifficulty(Step.FragmentRefinement); 299// queryRecord.setDifficulty(Step.FragmentRefinement);
301
302 return knowledgebase;
303 }
304 300
305// int counter = 0; 301 return knowledgebase;
302 }
306 303
307 private String toJsonKeyValuePair(String key, Object value) { 304 private String toJsonKeyValuePair(String key, Object value) {
308 HashMap<String, Object> map = new HashMap<>(); 305 HashMap<String, Object> map = new HashMap<>();
@@ -310,8 +307,10 @@ public class MyQueryReasoner extends QueryReasoner {
310 return QueryRecord.GsonCreator.getInstance().toJson(map); 307 return QueryRecord.GsonCreator.getInstance().toJson(map);
311 } 308 }
312 309
310// int counter = 0;
311
313 private void queryUpperBound(BasicQueryEngine upperStore, QueryRecord queryRecord, String queryText, String[] answerVariables) { 312 private void queryUpperBound(BasicQueryEngine upperStore, QueryRecord queryRecord, String queryText, String[] answerVariables) {
314 AnswerTuples rlAnswer = null; 313 AnswerTuples rlAnswer = null;
315 try { 314 try {
316 Utility.logDebug(queryText); 315 Utility.logDebug(queryText);
317 rlAnswer = upperStore.evaluate(queryText, answerVariables); 316 rlAnswer = upperStore.evaluate(queryText, answerVariables);
@@ -326,37 +325,38 @@ public class MyQueryReasoner extends QueryReasoner {
326 @Override 325 @Override
327 public void evaluate(QueryRecord queryRecord) { 326 public void evaluate(QueryRecord queryRecord) {
328 OWLOntology knowledgeBase = relevantPart(queryRecord); 327 OWLOntology knowledgeBase = relevantPart(queryRecord);
329 328
330 if (knowledgeBase == null) { 329 if(knowledgeBase == null) {
331 Utility.logDebug("Difficulty of this query: " + queryRecord.getDifficulty()); 330 Utility.logDebug("Difficulty of this query: " + queryRecord.getDifficulty());
332 return ; 331 return;
333 } 332 }
334 333
335 int aBoxCount = knowledgeBase.getABoxAxioms(true).size(); 334 int aBoxCount = knowledgeBase.getABoxAxioms(true).size();
336 Utility.logDebug("ABox axioms: " + aBoxCount + " TBox axioms: " + (knowledgeBase.getAxiomCount() - aBoxCount)); 335 Utility.logDebug("ABox axioms: " + aBoxCount + " TBox axioms: " + (knowledgeBase.getAxiomCount() - aBoxCount));
337// queryRecord.saveRelevantOntology("fragment_query" + queryRecord.getQueryID() + ".owl"); 336// queryRecord.saveRelevantOntology("fragment_query" + queryRecord.getQueryID() + ".owl");
338 337
339 Timer t = new Timer(); 338 Timer t = new Timer();
340 Checker summarisedChecker = new HermitSummaryFilter(queryRecord, properties.getToCallHermiT()); 339 Checker summarisedChecker = new HermitSummaryFilter(queryRecord, properties.getToCallHermiT());
341// int validNumber = 340// int validNumber =
342 summarisedChecker.check(queryRecord.getGapAnswers()); 341 summarisedChecker.check(queryRecord.getGapAnswers());
343 summarisedChecker.dispose(); 342 summarisedChecker.dispose();
344 Utility.logDebug("Total time for full reasoner: " + t.duration()); 343 Utility.logDebug("Total time for full reasoner: " + t.duration());
345// if (validNumber == 0) { 344// if (validNumber == 0) {
346 queryRecord.markAsProcessed(); 345 queryRecord.markAsProcessed();
347 Utility.logDebug("Difficulty of this query: " + queryRecord.getDifficulty()); 346 Utility.logDebug("Difficulty of this query: " + queryRecord.getDifficulty());
348// } 347// }
349 } 348 }
350 349
351 @Override 350 @Override
352 public void evaluateUpper(QueryRecord queryRecord) { 351 public void evaluateUpper(QueryRecord queryRecord) {
353 AnswerTuples rlAnswer = null; 352 AnswerTuples rlAnswer = null;
354 boolean useFull = queryRecord.isBottom() || lazyUpperStore == null; 353 boolean useFull = queryRecord.isBottom() || lazyUpperStore == null;
355 try { 354 try {
356 rlAnswer = (useFull ? trackingStore: lazyUpperStore).evaluate(queryRecord.getQueryText(), queryRecord.getAnswerVariables()); 355 rlAnswer =
357 queryRecord.updateUpperBoundAnswers(rlAnswer, true); 356 (useFull ? trackingStore : lazyUpperStore).evaluate(queryRecord.getQueryText(), queryRecord.getAnswerVariables());
357 queryRecord.updateUpperBoundAnswers(rlAnswer, true);
358 } finally { 358 } finally {
359 if (rlAnswer != null) rlAnswer.dispose(); 359 if(rlAnswer != null) rlAnswer.dispose();
360 } 360 }
361 } 361 }
362 362
@@ -370,4 +370,6 @@ public class MyQueryReasoner extends QueryReasoner {
370 super.dispose(); 370 super.dispose();
371 } 371 }
372 372
373 enum SatisfiabilityStatus {SATISFIABLE, UNSATISFIABLE, UNCHECKED}
374
373} 375}
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/QueryReasoner.java b/src/uk/ac/ox/cs/pagoda/reasoner/QueryReasoner.java
index dfe0c5f..d4f4596 100644
--- a/src/uk/ac/ox/cs/pagoda/reasoner/QueryReasoner.java
+++ b/src/uk/ac/ox/cs/pagoda/reasoner/QueryReasoner.java
@@ -19,24 +19,26 @@ import java.util.Collection;
19 19
20// TODO clean APIs 20// TODO clean APIs
21public abstract class QueryReasoner { 21public abstract class QueryReasoner {
22 22
23 public static final String ImportDataFileSeparator = ";";
24 private static final boolean DEFAULT_MULTI_STAGES = true;
25 private static final boolean DEFAULT_EQUALITIES = true;
26 public boolean fullReasoner = this instanceof MyQueryReasoner;
27 protected StringBuilder importedData = new StringBuilder();
23// protected boolean forSemFacet = false; 28// protected boolean forSemFacet = false;
24 Properties properties; 29 Properties properties;
30 BufferedWriter answerWriter = null;
31 private QueryManager m_queryManager = new QueryManager();
25 32
26 private static boolean defaultMultiStages = true;
27 private static boolean defaultEqualities = true;
28
29 public enum Type { Full, RLU, ELHOU }
30
31 public static QueryReasoner getInstance(Properties p) { 33 public static QueryReasoner getInstance(Properties p) {
32 OWLOntology ontology = OWLHelper.loadOntology(p.getOntologyPath()); 34 OWLOntology ontology = OWLHelper.loadOntology(p.getOntologyPath());
33 QueryReasoner pagoda = getInstance(ontology, p); 35 QueryReasoner pagoda = getInstance(ontology, p);
34 pagoda.properties = p; 36 pagoda.properties = p;
35 pagoda.loadOntology(ontology); 37 pagoda.loadOntology(ontology);
36 pagoda.importData(p.getDataPath()); 38 pagoda.importData(p.getDataPath());
37 if (pagoda.preprocess()) { 39 if (pagoda.preprocess()) {
38 Utility.logInfo("The ontology is consistent!"); 40 Utility.logInfo("The ontology is consistent!");
39 return pagoda; 41 return pagoda;
40 } 42 }
41 else { 43 else {
42 System.out.println("The ontology is inconsistent!"); 44 System.out.println("The ontology is inconsistent!");
@@ -44,60 +46,63 @@ public abstract class QueryReasoner {
44 return null; 46 return null;
45 } 47 }
46 } 48 }
47 49
48 public static QueryReasoner getInstance(OWLOntology o) { 50 public static QueryReasoner getInstance(OWLOntology o) {
49 QueryReasoner pagoda = getInstance(Type.Full, o, defaultMultiStages, defaultEqualities); 51 QueryReasoner pagoda = getInstance(Type.Full, o, DEFAULT_MULTI_STAGES, DEFAULT_EQUALITIES);
50 pagoda.properties = new Properties(); 52 pagoda.properties = new Properties();
51 return pagoda; 53 return pagoda;
52 } 54 }
53 55
54 public void setToClassify(boolean flag) {
55 properties.setToClassify(flag);
56 }
57
58 public void setToCallHermiT(boolean flag) {
59 properties.setToCallHermiT(flag);
60 }
61
62 private static QueryReasoner getInstance(OWLOntology o, Properties p) { 56 private static QueryReasoner getInstance(OWLOntology o, Properties p) {
63 return getInstance(Type.Full, o, defaultMultiStages, defaultEqualities); 57 return getInstance(Type.Full, o, DEFAULT_MULTI_STAGES, DEFAULT_EQUALITIES);
64 } 58 }
65 59
66 public static QueryReasoner getInstance(Type type, OWLOntology o, boolean performMultiStages, boolean considerEqualities) { 60 public static QueryReasoner getInstance(Type type, OWLOntology o, boolean performMultiStages, boolean considerEqualities) {
67// Utility.initialise(); 61// Utility.initialise();
68 QueryReasoner reasoner; 62 QueryReasoner reasoner;
69 if (OWLHelper.isInOWL2RL(o)) reasoner = new RLQueryReasoner(); 63 if (OWLHelper.isInOWL2RL(o)) reasoner = new RLQueryReasoner();
70 else if (OWLHelper.isInELHO(o)) reasoner = new ELHOQueryReasoner(); 64 else if (OWLHelper.isInELHO(o)) reasoner = new ELHOQueryReasoner();
71 else 65 else
72 switch (type) { 66 switch (type) {
73 case RLU: 67 case RLU:
74 reasoner = new RLUQueryReasoner(performMultiStages, considerEqualities); break; 68 reasoner = new RLUQueryReasoner(performMultiStages, considerEqualities);
75 case ELHOU: 69 break;
76 reasoner = new ELHOUQueryReasoner(performMultiStages, considerEqualities); break; 70 case ELHOU:
77 default: 71 reasoner = new ELHOUQueryReasoner(performMultiStages, considerEqualities);
78 reasoner = new MyQueryReasoner(performMultiStages, considerEqualities); 72 break;
73 default:
74 reasoner = new MyQueryReasoner(performMultiStages, considerEqualities);
79 } 75 }
80 return reasoner; 76 return reasoner;
77 }
78
79 public static QueryReasoner getHermiTReasoner(boolean toCheckSatisfiability) {
80 return new HermiTReasoner(toCheckSatisfiability);
81 }
82
83 public void setToClassify(boolean flag) {
84 properties.setToClassify(flag);
85 }
86
87 public void setToCallHermiT(boolean flag) {
88 properties.setToCallHermiT(flag);
81 } 89 }
82
83 public static final String ImportDataFileSeparator = ";";
84 protected StringBuilder importedData = new StringBuilder();
85 90
86 public void importData(String datafile) { 91 public void importData(String datafile) {
87 if (datafile != null && !datafile.equalsIgnoreCase("null")) 92 if (datafile != null && !datafile.equalsIgnoreCase("null"))
88 importData(datafile.split(ImportDataFileSeparator)); 93 importData(datafile.split(ImportDataFileSeparator));
89 } 94 }
90 95
91 public void importData(String[] datafiles) { 96 public void importData(String[] datafiles) {
92 if (datafiles != null) { 97 if (datafiles != null) {
93 for (String datafile: datafiles) { 98 for (String datafile: datafiles) {
94 File file = new File(datafile); 99 File file = new File(datafile);
95 if (file.exists()) { 100 if (file.exists()) {
96 if (file.isFile()) importDataFile(file); 101 if (file.isFile()) importDataFile(file);
97 else importDataDirectory(file); 102 else importDataDirectory(file);
98 } 103 }
99 else { 104 else {
100 Utility.logError("warning: file " + datafile + " doesn't exists."); 105 Utility.logError("warning: file " + datafile + " doesn't exists.");
101 } 106 }
102 } 107 }
103 } 108 }
@@ -115,80 +120,75 @@ public abstract class QueryReasoner {
115 datafile = file.getCanonicalPath(); 120 datafile = file.getCanonicalPath();
116 } catch (IOException e) { 121 } catch (IOException e) {
117 e.printStackTrace(); 122 e.printStackTrace();
118 return ; 123 return;
119 } 124 }
120 importDataFile(datafile); 125 importDataFile(datafile);
121 } 126 }
122 127
123 protected final void importDataFile(String datafile) { 128 protected final void importDataFile(String datafile) {
124 if (importedData.length() == 0) 129 if (importedData.length() == 0)
125 importedData.append(datafile); 130 importedData.append(datafile);
126 else 131 else
127 importedData.append(ImportDataFileSeparator).append(datafile); 132 importedData.append(ImportDataFileSeparator).append(datafile);
128 133
129 } 134 }
130
131 public abstract void loadOntology(OWLOntology ontology);
132
133 public abstract boolean preprocess();
134 135
135 public abstract boolean isConsistent(); 136 public abstract void loadOntology(OWLOntology ontology);
136 137
137 public boolean fullReasoner = this instanceof MyQueryReasoner; 138 public abstract boolean preprocess();
138 139
139 public abstract void evaluate(QueryRecord record); 140 public abstract boolean isConsistent();
140 141
141 public abstract void evaluateUpper(QueryRecord record); 142 public abstract void evaluate(QueryRecord record);
143
144 public abstract void evaluateUpper(QueryRecord record);
142 145
143 public AnswerTuples evaluate(String queryText, boolean forFacetGeneration) { 146 public AnswerTuples evaluate(String queryText, boolean forFacetGeneration) {
144 if (forFacetGeneration) { 147 if (forFacetGeneration) {
145 QueryRecord record = m_queryManager.create(queryText); 148 QueryRecord record = m_queryManager.create(queryText);
146 Utility.logInfo("---------- start evaluating upper bound for Query " + record.getQueryID() + " ----------", queryText); 149 Utility.logInfo("---------- start evaluating upper bound for Query " + record.getQueryID() + " ----------", queryText);
147 if (!record.processed()) 150 if(!record.processed())
148 evaluateUpper(record); 151 evaluateUpper(record);
149// AnswerTuples tuples = record.getUpperBoundAnswers(); 152// AnswerTuples tuples = record.getUpperBoundAnswers();
150// for (AnswerTuple tuple; tuples.isValid(); tuples.moveNext()) { 153// for (AnswerTuple tuple; tuples.isValid(); tuples.moveNext()) {
151// tuple = tuples.getTuple(); 154// tuple = tuples.getTuple();
152// if (tuple.toString().contains("NC")) 155// if (tuple.toString().contains("NC"))
153// System.out.println(tuple.toString()); 156// System.out.println(tuple.toString());
154// } 157// }
155 return record.getUpperBoundAnswers(); 158 return record.getUpperBoundAnswers();
156 } 159 } else
157 else 160 return evaluate(queryText);
158 return evaluate(queryText);
159 } 161 }
160 162
163// public void evaluate(Collection<QueryRecord> queryRecords) {
164// evaluate(queryRecords);
165// }
166
161 public AnswerTuples evaluate(String queryText) { 167 public AnswerTuples evaluate(String queryText) {
162 QueryRecord record = m_queryManager.create(queryText); 168 QueryRecord record = m_queryManager.create(queryText);
163 Utility.logInfo("---------- start evaluating Query " + record.getQueryID() + " ----------", queryText); 169 Utility.logInfo("---------- start evaluating Query " + record.getQueryID() + " ----------", queryText);
164 if (!record.processed()) 170 if(!record.processed())
165 evaluate(record); 171 evaluate(record);
166 AnswerTuples answer = record.getAnswers(); 172 AnswerTuples answer = record.getAnswers();
167 record.dispose(); 173 record.dispose();
168 return answer; 174 return answer;
169 175
170 } 176 }
171 177
172 public void evaluate_shell(String queryText) { 178 public void evaluate_shell(String queryText) {
173 QueryRecord record = m_queryManager.create(queryText); 179 QueryRecord record = m_queryManager.create(queryText);
174 Utility.logInfo("---------- start evaluating Query " + record.getQueryID() + " ----------", queryText); 180 Utility.logInfo("---------- start evaluating Query " + record.getQueryID() + " ----------", queryText);
175 if (!record.processed()) 181 if(!record.processed())
176 evaluate(record); 182 evaluate(record);
177 Utility.logInfo("Answers to this query: ", record.outputSoundAnswerTuple()); 183 Utility.logInfo("Answers to this query: ", record.outputSoundAnswerTuple());
178 record.dispose(); 184 record.dispose();
179 185
180 } 186 }
181 187
182// public void evaluate(Collection<QueryRecord> queryRecords) {
183// evaluate(queryRecords);
184// }
185
186 BufferedWriter answerWriter = null;
187
188 public void evaluate(Collection<QueryRecord> queryRecords) { 188 public void evaluate(Collection<QueryRecord> queryRecords) {
189 if (!isConsistent()) { 189 if (!isConsistent()) {
190 Utility.logDebug("The ontology and dataset is inconsistent."); 190 Utility.logDebug("The ontology and dataset is inconsistent.");
191 return ; 191 return;
192 } 192 }
193 193
194 if(properties.getAnswerPath() != null && answerWriter == null) { 194 if(properties.getAnswerPath() != null && answerWriter == null) {
@@ -199,21 +199,21 @@ public abstract class QueryReasoner {
199 e.printStackTrace(); 199 e.printStackTrace();
200 } 200 }
201 } 201 }
202 202
203 Timer t = new Timer(); 203 Timer t = new Timer();
204 Gson gson = QueryRecord.GsonCreator.getInstance(); 204 Gson gson = QueryRecord.GsonCreator.getInstance();
205 for (QueryRecord record: queryRecords) { 205 for (QueryRecord record: queryRecords) {
206// if (Integer.parseInt(record.getQueryID()) != 218) continue; 206// if (Integer.parseInt(record.getQueryID()) != 218) continue;
207 Utility.logInfo("---------- start evaluating Query " + record.getQueryID() + " ----------", 207 Utility.logInfo("---------- start evaluating Query " + record.getQueryID() + " ----------",
208 record.getQueryText()); 208 record.getQueryText());
209 if (!record.processed()) { 209 if (!record.processed()) {
210 t.reset(); 210 t.reset();
211 if (!record.processed()) 211 if (!record.processed())
212 evaluate(record); 212 evaluate(record);
213 Utility.logInfo("Total time to answer this query: " + t.duration()); 213 Utility.logInfo("Total time to answer this query: " + t.duration());
214 if (!fullReasoner && !record.processed()) { 214 if (!fullReasoner && !record.processed()) {
215 Utility.logInfo("The query has not been fully answered in " + t.duration() + " seconds."); 215 Utility.logInfo("The query has not been fully answered in " + t.duration() + " seconds.");
216 continue; 216 continue;
217 } 217 }
218 } 218 }
219 record.outputAnswerStatistics(); 219 record.outputAnswerStatistics();
@@ -225,7 +225,7 @@ public abstract class QueryReasoner {
225// queryRecords.stream().forEach(record -> Utility.logDebug(gson.toJson(record))); 225// queryRecords.stream().forEach(record -> Utility.logDebug(gson.toJson(record)));
226 queryRecords.stream().forEach(record -> record.dispose()); 226 queryRecords.stream().forEach(record -> record.dispose());
227 } 227 }
228 228
229 public void dispose() { 229 public void dispose() {
230 if (answerWriter != null) { 230 if (answerWriter != null) {
231 try { 231 try {
@@ -235,17 +235,13 @@ public abstract class QueryReasoner {
235 } 235 }
236 } 236 }
237// Utility.cleanup(); 237// Utility.cleanup();
238 } 238 }
239
240 private QueryManager m_queryManager = new QueryManager();
241 239
242 public QueryManager getQueryManager() { 240 public QueryManager getQueryManager() {
243 return m_queryManager; 241 return m_queryManager;
244 } 242 }
245 243
246 244
247 public static QueryReasoner getHermiTReasoner(boolean toCheckSatisfiability) { 245 public enum Type {Full, RLU, ELHOU}
248 return new HermiTReasoner(toCheckSatisfiability);
249 }
250 246
251} 247}