aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRncLsn <rnc.lsn@gmail.com>2015-08-24 15:54:05 +0100
committerRncLsn <rnc.lsn@gmail.com>2015-08-24 15:54:05 +0100
commit90cb6032058ad3fc16b895922823b5a700121b1b (patch)
tree0aeba79d9df6ea257dd67f5e049d2065f97787ad
parentae9a6bad58019ef18657568e58f49459fbadc49c (diff)
downloadACQuA-90cb6032058ad3fc16b895922823b5a700121b1b.tar.gz
ACQuA-90cb6032058ad3fc16b895922823b5a700121b1b.zip
Incremental Skolemised store (seems completed).
-rw-r--r--src/resources/pagoda.properties6
-rw-r--r--src/uk/ac/ox/cs/pagoda/multistage/MultiStageQueryEngine.java37
-rw-r--r--src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java50
-rw-r--r--src/uk/ac/ox/cs/pagoda/reasoner/light/BasicQueryEngine.java7
-rw-r--r--src/uk/ac/ox/cs/pagoda/util/PagodaProperties.java12
5 files changed, 93 insertions, 19 deletions
diff --git a/src/resources/pagoda.properties b/src/resources/pagoda.properties
index 34b3d7a..aa08593 100644
--- a/src/resources/pagoda.properties
+++ b/src/resources/pagoda.properties
@@ -2,8 +2,12 @@ debug=true
2useAlwaysSimpleUpperBound=false 2useAlwaysSimpleUpperBound=false
3#skolemUpperBound=DISABLED 3#skolemUpperBound=DISABLED
4#skolemUpperBound=BEFORE_SUMMARISATION 4#skolemUpperBound=BEFORE_SUMMARISATION
5skolemUpperBound=AFTER_SUMMARISATION 5skolemUpperBound=BEFORE_SUMMARISATION
6skolemDepth=10 6skolemDepth=10
7
8# seems ok for -Xmx6g
9maxTriplesInSkolemStore=2500000
10
7toCallHermit=true 11toCallHermit=true
8 12
9statisticsDir=/home/alessandro/Dropbox/Oxford/PAGOdA/statistics \ No newline at end of file 13statisticsDir=/home/alessandro/Dropbox/Oxford/PAGOdA/statistics \ No newline at end of file
diff --git a/src/uk/ac/ox/cs/pagoda/multistage/MultiStageQueryEngine.java b/src/uk/ac/ox/cs/pagoda/multistage/MultiStageQueryEngine.java
index f3a78f6..209e1d7 100644
--- a/src/uk/ac/ox/cs/pagoda/multistage/MultiStageQueryEngine.java
+++ b/src/uk/ac/ox/cs/pagoda/multistage/MultiStageQueryEngine.java
@@ -35,7 +35,9 @@ public class MultiStageQueryEngine extends StageQueryEngine {
35 private HashMap<String, List> statistics = new HashMap<>(); 35 private HashMap<String, List> statistics = new HashMap<>();
36 private Set<Tuple<Integer>> oversizedSkolemisedFacts; 36 private Set<Tuple<Integer>> oversizedSkolemisedFacts;
37 private RDFoxTripleManager rdFoxTripleManager; 37 private RDFoxTripleManager rdFoxTripleManager;
38
38 private int lastMaxTermDepth = -1; 39 private int lastMaxTermDepth = -1;
40 private boolean firstCall = true;
39 41
40 public MultiStageQueryEngine(String name, boolean checkValidity) { 42 public MultiStageQueryEngine(String name, boolean checkValidity) {
41 super(name, checkValidity); 43 super(name, checkValidity);
@@ -79,11 +81,12 @@ public class MultiStageQueryEngine extends StageQueryEngine {
79 public int materialiseSkolemly(DatalogProgram dProgram, GapByStore4ID gap, int maxTermDepth) { 81 public int materialiseSkolemly(DatalogProgram dProgram, GapByStore4ID gap, int maxTermDepth) {
80 if(isDisposed()) throw new DisposedException(); 82 if(isDisposed()) throw new DisposedException();
81 83
82 if(maxTermDepth <= lastMaxTermDepth) 84 if(!firstCall && maxTermDepth <= lastMaxTermDepth)
83 throw new IllegalArgumentException("maxTermDepth must be greater than " + lastMaxTermDepth); 85 throw new IllegalArgumentException("maxTermDepth must be greater than " + lastMaxTermDepth);
86 if(firstCall)
87 materialise("lower program", dProgram.getLower().toString());
84 lastMaxTermDepth = maxTermDepth; 88 lastMaxTermDepth = maxTermDepth;
85 89
86 materialise("lower program", dProgram.getLower().toString());
87 Program generalProgram = dProgram.getGeneral(); 90 Program generalProgram = dProgram.getGeneral();
88 LimitedSkolemisationApplication program = 91 LimitedSkolemisationApplication program =
89 new LimitedSkolemisationApplication(generalProgram, 92 new LimitedSkolemisationApplication(generalProgram,
@@ -91,7 +94,9 @@ public class MultiStageQueryEngine extends StageQueryEngine {
91 maxTermDepth); 94 maxTermDepth);
92 rdFoxTripleManager = new RDFoxTripleManager(store, true); 95 rdFoxTripleManager = new RDFoxTripleManager(store, true);
93 Treatment treatment = new Pick4NegativeConceptNaive(this, program, rdFoxTripleManager); 96 Treatment treatment = new Pick4NegativeConceptNaive(this, program, rdFoxTripleManager);
94 return materialise(program, treatment, gap, maxTermDepth); 97 int result = materialise(program, treatment, gap, maxTermDepth);
98 firstCall = false;
99 return result;
95 } 100 }
96 101
97 public int materialise4SpecificQuery(Program generalProgram, QueryRecord record, BottomStrategy upperBottom) { 102 public int materialise4SpecificQuery(Program generalProgram, QueryRecord record, BottomStrategy upperBottom) {
@@ -117,7 +122,11 @@ public class MultiStageQueryEngine extends StageQueryEngine {
117 } 122 }
118 123
119 private int materialise(MultiStageUpperProgram program, Treatment treatment, GapByStore4ID gap, int maxTermDepth) { 124 private int materialise(MultiStageUpperProgram program, Treatment treatment, GapByStore4ID gap, int maxTermDepth) {
120 boolean actuallyCleaned = cleanStoreFromOversizedSkolemisedFacts(); 125 if(!firstCall)
126 cleanStoreFromOversizedSkolemisedFacts();
127
128 boolean isSkolemising = maxTermDepth > 0;
129// boolean isSkolemising = true;
121 130
122 if(gap != null) 131 if(gap != null)
123 treatment.addAdditionalGapTuples(); 132 treatment.addAdditionalGapTuples();
@@ -157,11 +166,11 @@ public class MultiStageQueryEngine extends StageQueryEngine {
157 } 166 }
158 } 167 }
159 else { 168 else {
160 if(!incrementally) { 169 if(!incrementally && firstCall) {
161// store.addRules(new String[] {datalogProgram}); 170// store.addRules(new String[] {datalogProgram});
162 store.importRules(datalogProgram); 171 store.importRules(datalogProgram);
163 } 172 }
164 store.applyReasoning(incrementally || actuallyCleaned); 173 store.applyReasoning(incrementally || !firstCall);
165 } 174 }
166 175
167// Utility.logInfo("The number of sameAs assertions in the current store: " + getSameAsNumber()); 176// Utility.logInfo("The number of sameAs assertions in the current store: " + getSameAsNumber());
@@ -181,15 +190,17 @@ public class MultiStageQueryEngine extends StageQueryEngine {
181 Utility.logDebug("Time to materialise datalog-rules: " + subTimer.duration()); 190 Utility.logDebug("Time to materialise datalog-rules: " + subTimer.duration());
182 191
183 subTimer.reset(); 192 subTimer.reset();
184 if((violations = program.isIntegrated(this, incrementally)) == null || violations.size() == 0) { 193 if((violations = program.isIntegrated(this, !isSkolemising && incrementally)) == null || violations.size() == 0) {
185 store.clearRulesAndMakeFactsExplicit(); 194 if(!isSkolemising)
195 store.clearRulesAndMakeFactsExplicit();
186 Utility.logDebug(name + " store after materialising " + programName + ": " + tripleCount + " (" + (tripleCount - tripleCountBeforeMat) + " new)"); 196 Utility.logDebug(name + " store after materialising " + programName + ": " + tripleCount + " (" + (tripleCount - tripleCountBeforeMat) + " new)");
187 Utility.logDebug(name + " store is DONE for multi-stage materialising in " + t.duration() + " seconds."); 197 Utility.logDebug(name + " store is DONE for multi-stage materialising in " + t.duration() + " seconds.");
188 return isValid() ? 1 : 0; 198 return isValid() ? 1 : 0;
189 } 199 }
190 Utility.logDebug("Time to detect violations: " + subTimer.duration()); 200 Utility.logDebug("Time to detect violations: " + subTimer.duration());
191 201
192// store.makeFactsExplicit(); 202 if(!isSkolemising)
203 store.makeFactsExplicit();
193 subTimer.reset(); 204 subTimer.reset();
194 oldTripleCount = store.getTriplesCount(); 205 oldTripleCount = store.getTriplesCount();
195 206
@@ -274,8 +285,8 @@ public class MultiStageQueryEngine extends StageQueryEngine {
274 result.add(new TupleBuilder<Integer>().append(idTriple[0]).append(idTriple[1]) 285 result.add(new TupleBuilder<Integer>().append(idTriple[0]).append(idTriple[1])
275 .append(idTriple[2]).build()); 286 .append(idTriple[2]).build());
276 } 287 }
277 else if(!(atom.getArgument(0) instanceof Individual)) 288// else if(!(atom.getArgument(0) instanceof Individual))
278 throw new IllegalArgumentException("No individuals: " + atom); 289// throw new IllegalArgumentException("No individuals: " + atom);
279 } 290 }
280 else { 291 else {
281 if((atom.getArgument(0) instanceof Individual && termsManager.getDepthOf((Individual) atom.getArgument(0)) >= maxDepth) 292 if((atom.getArgument(0) instanceof Individual && termsManager.getDepthOf((Individual) atom.getArgument(0)) >= maxDepth)
@@ -284,8 +295,8 @@ public class MultiStageQueryEngine extends StageQueryEngine {
284 result.add(new TupleBuilder<Integer>().append(idTriple[0]).append(idTriple[1]) 295 result.add(new TupleBuilder<Integer>().append(idTriple[0]).append(idTriple[1])
285 .append(idTriple[2]).build()); 296 .append(idTriple[2]).build());
286 } 297 }
287 else if(!(atom.getArgument(0) instanceof Individual) && !(atom.getArgument(1) instanceof Individual)) 298// else if(!(atom.getArgument(0) instanceof Individual) && !(atom.getArgument(1) instanceof Individual))
288 throw new IllegalArgumentException("No individuals: " + atom); 299// throw new IllegalArgumentException("No individuals: " + atom);
289 } 300 }
290 301
291 } 302 }
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java b/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java
index a393474..8a90a26 100644
--- a/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java
+++ b/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java
@@ -2,6 +2,7 @@ package uk.ac.ox.cs.pagoda.reasoner;
2 2
3import org.semanticweb.karma2.profile.ELHOProfile; 3import org.semanticweb.karma2.profile.ELHOProfile;
4import org.semanticweb.owlapi.model.OWLOntology; 4import org.semanticweb.owlapi.model.OWLOntology;
5import uk.ac.ox.cs.JRDFox.JRDFStoreException;
5import uk.ac.ox.cs.pagoda.multistage.MultiStageQueryEngine; 6import uk.ac.ox.cs.pagoda.multistage.MultiStageQueryEngine;
6import uk.ac.ox.cs.pagoda.owl.EqualitiesEliminator; 7import uk.ac.ox.cs.pagoda.owl.EqualitiesEliminator;
7import uk.ac.ox.cs.pagoda.owl.OWLHelper; 8import uk.ac.ox.cs.pagoda.owl.OWLHelper;
@@ -18,6 +19,7 @@ import uk.ac.ox.cs.pagoda.tracking.QueryTracker;
18import uk.ac.ox.cs.pagoda.tracking.TrackingRuleEncoder; 19import uk.ac.ox.cs.pagoda.tracking.TrackingRuleEncoder;
19import uk.ac.ox.cs.pagoda.tracking.TrackingRuleEncoderDisjVar1; 20import uk.ac.ox.cs.pagoda.tracking.TrackingRuleEncoderDisjVar1;
20import uk.ac.ox.cs.pagoda.tracking.TrackingRuleEncoderWithGap; 21import uk.ac.ox.cs.pagoda.tracking.TrackingRuleEncoderWithGap;
22import uk.ac.ox.cs.pagoda.util.ExponentialInterpolation;
21import uk.ac.ox.cs.pagoda.util.PagodaProperties; 23import uk.ac.ox.cs.pagoda.util.PagodaProperties;
22import uk.ac.ox.cs.pagoda.util.Timer; 24import uk.ac.ox.cs.pagoda.util.Timer;
23import uk.ac.ox.cs.pagoda.util.Utility; 25import uk.ac.ox.cs.pagoda.util.Utility;
@@ -25,6 +27,7 @@ import uk.ac.ox.cs.pagoda.util.disposable.DisposedException;
25import uk.ac.ox.cs.pagoda.util.tuples.Tuple; 27import uk.ac.ox.cs.pagoda.util.tuples.Tuple;
26 28
27import java.util.Collection; 29import java.util.Collection;
30import java.util.LinkedList;
28 31
29class MyQueryReasoner extends QueryReasoner { 32class MyQueryReasoner extends QueryReasoner {
30 33
@@ -399,8 +402,32 @@ class MyQueryReasoner extends QueryReasoner {
399 relevantStore.materialise("Mark original individuals", relevantOriginalMarkProgram); 402 relevantStore.materialise("Mark original individuals", relevantOriginalMarkProgram);
400 403
401 boolean isFullyProcessed = false; 404 boolean isFullyProcessed = false;
402 for (int currentMaxTermDepth = 1; 405 LinkedList<Tuple<Long>> lastTwoTriplesCounts = new LinkedList<>();
403 currentMaxTermDepth <= properties.getSkolemDepth() && !isFullyProcessed; currentMaxTermDepth++) { 406 for (int currentMaxTermDepth = 1; !isFullyProcessed; currentMaxTermDepth++) {
407
408 if(currentMaxTermDepth > properties.getSkolemDepth()) {
409 Utility.logInfo("Maximum term depth reached");
410 break;
411 }
412
413 if(lastTwoTriplesCounts.size() == 2) {
414 if(lastTwoTriplesCounts.get(0).get(1).equals(lastTwoTriplesCounts.get(1).get(1)))
415 break;
416
417 ExponentialInterpolation interpolation = new ExponentialInterpolation(lastTwoTriplesCounts.get(0).get(0),
418 lastTwoTriplesCounts.get(0).get(1),
419 lastTwoTriplesCounts.get(1).get(0),
420 lastTwoTriplesCounts.get(1).get(1));
421 double triplesEstimate = interpolation.computeValue(currentMaxTermDepth);
422
423 Utility.logDebug("Estimate of the number of triples:" + triplesEstimate);
424
425 // exit condition if the query is not fully answered
426 if(triplesEstimate > properties.getMaxTriplesInSkolemStore()) {
427 Utility.logInfo("Interrupting Semi-Skolemisation because of triples count limit");
428 break;
429 }
430 }
404 431
405 Utility.logInfo("Trying with maximum depth " + currentMaxTermDepth); 432 Utility.logInfo("Trying with maximum depth " + currentMaxTermDepth);
406 433
@@ -408,18 +435,31 @@ class MyQueryReasoner extends QueryReasoner {
408 currentMaxTermDepth); 435 currentMaxTermDepth);
409 queryRecord.addProcessingTime(Step.SKOLEM_UPPER_BOUND, t.duration()); 436 queryRecord.addProcessingTime(Step.SKOLEM_UPPER_BOUND, t.duration());
410 if(materialisationTag == -1) { 437 if(materialisationTag == -1) {
438 relevantStore.dispose();
411 throw new Error("A consistent ontology has turned out to be " + 439 throw new Error("A consistent ontology has turned out to be " +
412 "inconsistent in the Skolemises-relevant-upper-store"); 440 "inconsistent in the Skolemises-relevant-upper-store");
413 } 441 }
414 else if(materialisationTag != 1) { 442 else if(materialisationTag != 1) {
415 Utility.logInfo("Semi-Skolemised relevant upper store cannot be employed"); 443 Utility.logInfo("Semi-Skolemised relevant upper store cannot be employed");
416 return false; 444 break;
417 } 445 }
418 446
419 Utility.logInfo("Querying semi-Skolemised upper store..."); 447 Utility.logInfo("Querying semi-Skolemised upper store...");
420 isFullyProcessed = queryUpperStore(relevantStore, queryRecord, 448 isFullyProcessed = queryUpperStore(relevantStore, queryRecord,
421 queryRecord.getExtendedQueryText(), 449 queryRecord.getExtendedQueryText(),
422 Step.SKOLEM_UPPER_BOUND); 450 Step.SKOLEM_UPPER_BOUND);
451
452 try {
453 lastTwoTriplesCounts.add
454 (new Tuple<>((long) currentMaxTermDepth, relevantStore.getStoreSize()));
455 } catch (JRDFStoreException e) {
456 e.printStackTrace();
457 break;
458 }
459 if(lastTwoTriplesCounts.size() > 2)
460 lastTwoTriplesCounts.remove();
461
462 Utility.logInfo("Last two triples counts:" + lastTwoTriplesCounts);
423 } 463 }
424 464
425 relevantStore.dispose(); 465 relevantStore.dispose();
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 107d3ca..034827e 100644
--- a/src/uk/ac/ox/cs/pagoda/reasoner/light/BasicQueryEngine.java
+++ b/src/uk/ac/ox/cs/pagoda/reasoner/light/BasicQueryEngine.java
@@ -32,6 +32,13 @@ public class BasicQueryEngine extends RDFoxQueryEngine {
32 parameters.m_useBushy = true; 32 parameters.m_useBushy = true;
33 } 33 }
34 34
35 /***
36 * @return Overall number of triples.
37 */
38 public long getStoreSize() throws JRDFStoreException {
39 return store.getTriplesCount();
40 }
41
35 public void materialiseFoldedly(DatalogProgram dProgram, GapByStore4ID gap) { 42 public void materialiseFoldedly(DatalogProgram dProgram, GapByStore4ID gap) {
36 if(isDisposed()) throw new DisposedException(); 43 if(isDisposed()) throw new DisposedException();
37 if(gap != null) { 44 if(gap != null) {
diff --git a/src/uk/ac/ox/cs/pagoda/util/PagodaProperties.java b/src/uk/ac/ox/cs/pagoda/util/PagodaProperties.java
index 18469ff..0f9ad4e 100644
--- a/src/uk/ac/ox/cs/pagoda/util/PagodaProperties.java
+++ b/src/uk/ac/ox/cs/pagoda/util/PagodaProperties.java
@@ -20,6 +20,7 @@ public class PagodaProperties {
20 private static final int DEFAULT_SKOLEM_DEPTH; 20 private static final int DEFAULT_SKOLEM_DEPTH;
21 private static final boolean DEFAULT_TO_CALL_HERMIT; 21 private static final boolean DEFAULT_TO_CALL_HERMIT;
22 private static final Path DEFAULT_STATISTICS_DIR; 22 private static final Path DEFAULT_STATISTICS_DIR;
23 private static final long DEFAULT_MAX_TRIPLES_IN_SKOLEM_STORE;
23 24
24 public static boolean shellModeDefault = false; 25 public static boolean shellModeDefault = false;
25 private static boolean debug = DEFAULT_DEBUG; 26 private static boolean debug = DEFAULT_DEBUG;
@@ -30,6 +31,7 @@ public class PagodaProperties {
30 int defaultSkolemDepth = 1; 31 int defaultSkolemDepth = 1;
31 boolean toCallHermit = true; 32 boolean toCallHermit = true;
32 Path defaultStatisticsDir = null; 33 Path defaultStatisticsDir = null;
34 long defaultMaxTriplesInSkolemStore = 1000000;
33 35
34 try (InputStream in = PagodaProperties.class.getClassLoader().getResourceAsStream(CONFIG_FILE)) { 36 try (InputStream in = PagodaProperties.class.getClassLoader().getResourceAsStream(CONFIG_FILE)) {
35 Properties config = new Properties(); 37 Properties config = new Properties();
@@ -77,6 +79,10 @@ public class PagodaProperties {
77 defaultSkolemDepth = Integer.parseInt(config.getProperty("skolemDepth")); 79 defaultSkolemDepth = Integer.parseInt(config.getProperty("skolemDepth"));
78 logger.debug("By default the max skolemisation depth is " + defaultSkolemDepth); 80 logger.debug("By default the max skolemisation depth is " + defaultSkolemDepth);
79 } 81 }
82 if (config.containsKey("maxTriplesInSkolemStore")) {
83 defaultMaxTriplesInSkolemStore = Long.parseLong(config.getProperty("maxTriplesInSkolemStore"));
84 logger.debug("By default the maximum number of triples in the Skolem store is " + defaultMaxTriplesInSkolemStore);
85 }
80 86
81 } catch (IOException e) { 87 } catch (IOException e) {
82 e.printStackTrace(); 88 e.printStackTrace();
@@ -86,6 +92,7 @@ public class PagodaProperties {
86 DEFAULT_TO_CALL_HERMIT = toCallHermit; 92 DEFAULT_TO_CALL_HERMIT = toCallHermit;
87 DEFAULT_STATISTICS_DIR = defaultStatisticsDir; 93 DEFAULT_STATISTICS_DIR = defaultStatisticsDir;
88 DEFAULT_SKOLEM_DEPTH = defaultSkolemDepth; 94 DEFAULT_SKOLEM_DEPTH = defaultSkolemDepth;
95 DEFAULT_MAX_TRIPLES_IN_SKOLEM_STORE = defaultMaxTriplesInSkolemStore;
89 } 96 }
90 97
91 String dataPath = null; 98 String dataPath = null;
@@ -108,6 +115,7 @@ public class PagodaProperties {
108 private boolean useAlwaysSimpleUpperBound = DEFAULT_USE_ALWAYS_SIMPLE_UPPER_BOUND; 115 private boolean useAlwaysSimpleUpperBound = DEFAULT_USE_ALWAYS_SIMPLE_UPPER_BOUND;
109 private SkolemUpperBoundOptions skolemUpperBound = DEFAULT_SKOLEM_UPPER_BOUND; 116 private SkolemUpperBoundOptions skolemUpperBound = DEFAULT_SKOLEM_UPPER_BOUND;
110 private Path statisticsDir = DEFAULT_STATISTICS_DIR; 117 private Path statisticsDir = DEFAULT_STATISTICS_DIR;
118 private long maxTriplesInSkolemStore = DEFAULT_MAX_TRIPLES_IN_SKOLEM_STORE;
111 119
112 public PagodaProperties(String path) { 120 public PagodaProperties(String path) {
113 java.util.Properties m_properties = new java.util.Properties(); 121 java.util.Properties m_properties = new java.util.Properties();
@@ -233,4 +241,8 @@ public class PagodaProperties {
233 public void setStatisticsDir(Path statisticsDir) { 241 public void setStatisticsDir(Path statisticsDir) {
234 this.statisticsDir = statisticsDir; 242 this.statisticsDir = statisticsDir;
235 } 243 }
244
245 public long getMaxTriplesInSkolemStore() {
246 return maxTriplesInSkolemStore;
247 }
236} 248}