diff options
| author | RncLsn <rnc.lsn@gmail.com> | 2015-05-13 19:22:07 +0100 |
|---|---|---|
| committer | RncLsn <rnc.lsn@gmail.com> | 2015-05-13 19:22:07 +0100 |
| commit | 6fd8b21066852cbc21e247e7cf0a2f423ebc1658 (patch) | |
| tree | 77b5d7567d0a81cb9593af075f472908f848e445 /src/uk | |
| parent | d0c209780ac209ba20de1ef2ba68551dd3321b3c (diff) | |
| download | ACQuA-6fd8b21066852cbc21e247e7cf0a2f423ebc1658.tar.gz ACQuA-6fd8b21066852cbc21e247e7cf0a2f423ebc1658.zip | |
Fast implementation of all the other things to get something working, but it doesn't.
Diffstat (limited to 'src/uk')
9 files changed, 184 insertions, 61 deletions
diff --git a/src/uk/ac/ox/cs/pagoda/multistage/LimitedSkolemisationApplication.java b/src/uk/ac/ox/cs/pagoda/multistage/LimitedSkolemisationApplication.java index f729158..b548d39 100644 --- a/src/uk/ac/ox/cs/pagoda/multistage/LimitedSkolemisationApplication.java +++ b/src/uk/ac/ox/cs/pagoda/multistage/LimitedSkolemisationApplication.java | |||
| @@ -2,7 +2,6 @@ package uk.ac.ox.cs.pagoda.multistage; | |||
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | import uk.ac.ox.cs.pagoda.constraints.BottomStrategy; | 4 | import uk.ac.ox.cs.pagoda.constraints.BottomStrategy; |
| 5 | import uk.ac.ox.cs.pagoda.rules.ExistConstantApproximator; | ||
| 6 | import uk.ac.ox.cs.pagoda.rules.Program; | 5 | import uk.ac.ox.cs.pagoda.rules.Program; |
| 7 | import uk.ac.ox.cs.pagoda.rules.approximators.LimitedSkolemisationApproximator; | 6 | import uk.ac.ox.cs.pagoda.rules.approximators.LimitedSkolemisationApproximator; |
| 8 | 7 | ||
| @@ -12,6 +11,6 @@ public class LimitedSkolemisationApplication extends RestrictedApplication { | |||
| 12 | 11 | ||
| 13 | public LimitedSkolemisationApplication(Program program, BottomStrategy upperBottom) { | 12 | public LimitedSkolemisationApplication(Program program, BottomStrategy upperBottom) { |
| 14 | super(program, upperBottom); | 13 | super(program, upperBottom); |
| 15 | m_approxExist = new LimitedSkolemisationApproximator(MAX_DEPTH, new ExistConstantApproximator()); | 14 | m_approxExist = new LimitedSkolemisationApproximator(MAX_DEPTH); |
| 16 | } | 15 | } |
| 17 | } | 16 | } |
diff --git a/src/uk/ac/ox/cs/pagoda/multistage/MultiStageQueryEngine.java b/src/uk/ac/ox/cs/pagoda/multistage/MultiStageQueryEngine.java index f0f631a..f80da5f 100644 --- a/src/uk/ac/ox/cs/pagoda/multistage/MultiStageQueryEngine.java +++ b/src/uk/ac/ox/cs/pagoda/multistage/MultiStageQueryEngine.java | |||
| @@ -55,6 +55,18 @@ public class MultiStageQueryEngine extends StageQueryEngine { | |||
| 55 | treatment.dispose(); | 55 | treatment.dispose(); |
| 56 | return ret; | 56 | return ret; |
| 57 | } | 57 | } |
| 58 | |||
| 59 | /** | ||
| 60 | * delta-chase | ||
| 61 | */ | ||
| 62 | @Override | ||
| 63 | public int materialiseSkolemly(DatalogProgram dProgram, GapByStore4ID gap) { | ||
| 64 | materialise("lower program", dProgram.getLower().toString()); | ||
| 65 | Program generalProgram = dProgram.getGeneral(); | ||
| 66 | LimitedSkolemisationApplication program = new LimitedSkolemisationApplication(generalProgram, dProgram.getUpperBottomStrategy()); | ||
| 67 | Treatment treatment = new Pick4NegativeConceptNaive(this, program); | ||
| 68 | return materialise(program, treatment, gap); | ||
| 69 | } | ||
| 58 | 70 | ||
| 59 | private int materialise(MultiStageUpperProgram program, Treatment treatment, GapByStore4ID gap) { | 71 | private int materialise(MultiStageUpperProgram program, Treatment treatment, GapByStore4ID gap) { |
| 60 | if (gap != null) | 72 | if (gap != null) |
diff --git a/src/uk/ac/ox/cs/pagoda/multistage/StageQueryEngine.java b/src/uk/ac/ox/cs/pagoda/multistage/StageQueryEngine.java index 5d2e0d1..84798ce 100644 --- a/src/uk/ac/ox/cs/pagoda/multistage/StageQueryEngine.java +++ b/src/uk/ac/ox/cs/pagoda/multistage/StageQueryEngine.java | |||
| @@ -18,8 +18,10 @@ public abstract class StageQueryEngine extends BasicQueryEngine { | |||
| 18 | 18 | ||
| 19 | public abstract void materialiseFoldedly(DatalogProgram dProgram, GapByStore4ID gap); | 19 | public abstract void materialiseFoldedly(DatalogProgram dProgram, GapByStore4ID gap); |
| 20 | 20 | ||
| 21 | public abstract int materialiseRestrictedly(DatalogProgram dProgram, GapByStore4ID gap); | 21 | public abstract int materialiseRestrictedly(DatalogProgram dProgram, GapByStore4ID gap); |
| 22 | 22 | ||
| 23 | public abstract int materialiseSkolemly(DatalogProgram dProgram, GapByStore4ID gap); | ||
| 24 | |||
| 23 | public void dispose() { | 25 | public void dispose() { |
| 24 | super.dispose(); | 26 | super.dispose(); |
| 25 | } | 27 | } |
diff --git a/src/uk/ac/ox/cs/pagoda/multistage/TwoStageQueryEngine.java b/src/uk/ac/ox/cs/pagoda/multistage/TwoStageQueryEngine.java index b7f989f..29cf23a 100644 --- a/src/uk/ac/ox/cs/pagoda/multistage/TwoStageQueryEngine.java +++ b/src/uk/ac/ox/cs/pagoda/multistage/TwoStageQueryEngine.java | |||
| @@ -1,14 +1,8 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.multistage; | 1 | package uk.ac.ox.cs.pagoda.multistage; |
| 2 | 2 | ||
| 3 | import java.io.FileInputStream; | ||
| 4 | import java.io.FileNotFoundException; | ||
| 5 | import java.io.IOException; | ||
| 6 | import java.util.Collection; | ||
| 7 | |||
| 8 | import org.openrdf.rio.RDFHandlerException; | 3 | import org.openrdf.rio.RDFHandlerException; |
| 9 | import org.openrdf.rio.RDFParseException; | 4 | import org.openrdf.rio.RDFParseException; |
| 10 | import org.openrdf.rio.turtle.TurtleParser; | 5 | import org.openrdf.rio.turtle.TurtleParser; |
| 11 | |||
| 12 | import uk.ac.ox.cs.JRDFox.JRDFStoreException; | 6 | import uk.ac.ox.cs.JRDFox.JRDFStoreException; |
| 13 | import uk.ac.ox.cs.JRDFox.model.Individual; | 7 | import uk.ac.ox.cs.JRDFox.model.Individual; |
| 14 | import uk.ac.ox.cs.pagoda.query.GapByStore4ID; | 8 | import uk.ac.ox.cs.pagoda.query.GapByStore4ID; |
| @@ -17,6 +11,11 @@ import uk.ac.ox.cs.pagoda.rules.DatalogProgram; | |||
| 17 | import uk.ac.ox.cs.pagoda.util.Timer; | 11 | import uk.ac.ox.cs.pagoda.util.Timer; |
| 18 | import uk.ac.ox.cs.pagoda.util.Utility; | 12 | import uk.ac.ox.cs.pagoda.util.Utility; |
| 19 | 13 | ||
| 14 | import java.io.FileInputStream; | ||
| 15 | import java.io.FileNotFoundException; | ||
| 16 | import java.io.IOException; | ||
| 17 | import java.util.Collection; | ||
| 18 | |||
| 20 | public class TwoStageQueryEngine extends StageQueryEngine { | 19 | public class TwoStageQueryEngine extends StageQueryEngine { |
| 21 | 20 | ||
| 22 | IndividualCollector m_collector = new IndividualCollector(); | 21 | IndividualCollector m_collector = new IndividualCollector(); |
| @@ -64,6 +63,11 @@ public class TwoStageQueryEngine extends StageQueryEngine { | |||
| 64 | return program.materialise(); | 63 | return program.materialise(); |
| 65 | } | 64 | } |
| 66 | 65 | ||
| 66 | @Override | ||
| 67 | public int materialiseSkolemly(DatalogProgram dProgram, GapByStore4ID gap) { | ||
| 68 | throw new UnsupportedOperationException("This method is not available in " + getClass()); | ||
| 69 | } | ||
| 70 | |||
| 67 | public void materialise(String programText, GapByStore4ID gap, boolean incrementally) { | 71 | public void materialise(String programText, GapByStore4ID gap, boolean incrementally) { |
| 68 | try { | 72 | try { |
| 69 | if (gap != null) { | 73 | if (gap != null) { |
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/ConsistencyManager.java b/src/uk/ac/ox/cs/pagoda/reasoner/ConsistencyManager.java index 9b862ce..d179d14 100644 --- a/src/uk/ac/ox/cs/pagoda/reasoner/ConsistencyManager.java +++ b/src/uk/ac/ox/cs/pagoda/reasoner/ConsistencyManager.java | |||
| @@ -1,7 +1,5 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.reasoner; | 1 | package uk.ac.ox.cs.pagoda.reasoner; |
| 2 | 2 | ||
| 3 | import java.util.LinkedList; | ||
| 4 | |||
| 5 | import org.semanticweb.HermiT.model.Atom; | 3 | import org.semanticweb.HermiT.model.Atom; |
| 6 | import org.semanticweb.HermiT.model.AtomicConcept; | 4 | import org.semanticweb.HermiT.model.AtomicConcept; |
| 7 | import org.semanticweb.HermiT.model.DLClause; | 5 | import org.semanticweb.HermiT.model.DLClause; |
| @@ -9,7 +7,9 @@ import org.semanticweb.HermiT.model.Variable; | |||
| 9 | import org.semanticweb.owlapi.model.OWLOntology; | 7 | import org.semanticweb.owlapi.model.OWLOntology; |
| 10 | import org.semanticweb.owlapi.model.OWLOntologyCreationException; | 8 | import org.semanticweb.owlapi.model.OWLOntologyCreationException; |
| 11 | import org.semanticweb.owlapi.model.OWLOntologyManager; | 9 | import org.semanticweb.owlapi.model.OWLOntologyManager; |
| 12 | 10 | import uk.ac.ox.cs.JRDFox.JRDFStoreException; | |
| 11 | import uk.ac.ox.cs.JRDFox.store.DataStore; | ||
| 12 | import uk.ac.ox.cs.JRDFox.store.DataStore.UpdateType; | ||
| 13 | import uk.ac.ox.cs.pagoda.hermit.DLClauseHelper; | 13 | import uk.ac.ox.cs.pagoda.hermit.DLClauseHelper; |
| 14 | import uk.ac.ox.cs.pagoda.query.AnswerTuples; | 14 | import uk.ac.ox.cs.pagoda.query.AnswerTuples; |
| 15 | import uk.ac.ox.cs.pagoda.query.QueryManager; | 15 | import uk.ac.ox.cs.pagoda.query.QueryManager; |
| @@ -21,9 +21,8 @@ import uk.ac.ox.cs.pagoda.tracking.QueryTracker; | |||
| 21 | import uk.ac.ox.cs.pagoda.tracking.TrackingRuleEncoder; | 21 | import uk.ac.ox.cs.pagoda.tracking.TrackingRuleEncoder; |
| 22 | import uk.ac.ox.cs.pagoda.util.Timer; | 22 | import uk.ac.ox.cs.pagoda.util.Timer; |
| 23 | import uk.ac.ox.cs.pagoda.util.Utility; | 23 | import uk.ac.ox.cs.pagoda.util.Utility; |
| 24 | import uk.ac.ox.cs.JRDFox.JRDFStoreException; | 24 | |
| 25 | import uk.ac.ox.cs.JRDFox.store.DataStore; | 25 | import java.util.LinkedList; |
| 26 | import uk.ac.ox.cs.JRDFox.store.DataStore.UpdateType; | ||
| 27 | 26 | ||
| 28 | public class ConsistencyManager { | 27 | public class ConsistencyManager { |
| 29 | 28 | ||
| @@ -85,6 +84,23 @@ public class ConsistencyManager { | |||
| 85 | } | 84 | } |
| 86 | return false; | 85 | return false; |
| 87 | } | 86 | } |
| 87 | |||
| 88 | boolean checkSkolemUpper() { | ||
| 89 | if (m_reasoner.limitedSkolemUpperStore != null) { | ||
| 90 | AnswerTuples tuples = null; | ||
| 91 | try { | ||
| 92 | tuples = m_reasoner.limitedSkolemUpperStore.evaluate(fullQueryRecord.getQueryText(), fullQueryRecord.getAnswerVariables()); | ||
| 93 | if (!tuples.isValid()) { | ||
| 94 | Utility.logInfo("There are no contradictions derived in the limited-skolem upper bound materialisation."); | ||
| 95 | return satisfiability(t.duration()); | ||
| 96 | } | ||
| 97 | } | ||
| 98 | finally { | ||
| 99 | if (tuples != null) tuples.dispose(); | ||
| 100 | } | ||
| 101 | } | ||
| 102 | return false; | ||
| 103 | } | ||
| 88 | 104 | ||
| 89 | boolean check() { | 105 | boolean check() { |
| 90 | // if (!checkRLLowerBound()) return false; | 106 | // if (!checkRLLowerBound()) return false; |
| @@ -288,5 +304,6 @@ public class ConsistencyManager { | |||
| 288 | public QueryRecord[] getQueryRecords() { | 304 | public QueryRecord[] getQueryRecords() { |
| 289 | return botQueryRecords; | 305 | return botQueryRecords; |
| 290 | } | 306 | } |
| 291 | 307 | ||
| 308 | |||
| 292 | } | 309 | } |
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java b/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java index 3c0a001..233963e 100644 --- a/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java +++ b/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java | |||
| @@ -49,7 +49,8 @@ public class MyQueryReasoner extends QueryReasoner { | |||
| 49 | private Collection<String> predicatesWithGap = null; | 49 | private Collection<String> predicatesWithGap = null; |
| 50 | private Boolean satisfiable; | 50 | private Boolean satisfiable; |
| 51 | private ConsistencyManager consistency = new ConsistencyManager(this); | 51 | private ConsistencyManager consistency = new ConsistencyManager(this); |
| 52 | 52 | BasicQueryEngine limitedSkolemUpperStore; | |
| 53 | |||
| 53 | public MyQueryReasoner() { | 54 | public MyQueryReasoner() { |
| 54 | setup(true, true); | 55 | setup(true, true); |
| 55 | } | 56 | } |
| @@ -102,10 +103,10 @@ public class MyQueryReasoner extends QueryReasoner { | |||
| 102 | 103 | ||
| 103 | if (multiStageTag && !program.getGeneral().isHorn()) { | 104 | if (multiStageTag && !program.getGeneral().isHorn()) { |
| 104 | lazyUpperStore = getUpperStore("lazy-upper-bound", true); // new MultiStageQueryEngine("lazy-upper-bound", true); // | 105 | lazyUpperStore = getUpperStore("lazy-upper-bound", true); // new MultiStageQueryEngine("lazy-upper-bound", true); // |
| 106 | // TODO CHECK | ||
| 107 | limitedSkolemUpperStore = getUpperStore("limited-skolem-upper-bound", true); | ||
| 105 | } | 108 | } |
| 106 | 109 | ||
| 107 | // TODO add new upper store creation | ||
| 108 | |||
| 109 | importData(program.getAdditionalDataFile()); | 110 | importData(program.getAdditionalDataFile()); |
| 110 | 111 | ||
| 111 | elho_ontology = new ELHOProfile().getFragment(ontology); | 112 | elho_ontology = new ELHOProfile().getFragment(ontology); |
| @@ -151,7 +152,21 @@ public class MyQueryReasoner extends QueryReasoner { | |||
| 151 | Utility.logInfo("time for satisfiability checking: " + t.duration()); | 152 | Utility.logInfo("time for satisfiability checking: " + t.duration()); |
| 152 | } | 153 | } |
| 153 | 154 | ||
| 154 | // TODO add new upper store preprocessing | 155 | // TODO check |
| 156 | if (limitedSkolemUpperStore != null) { | ||
| 157 | limitedSkolemUpperStore.importRDFData(name, datafile); | ||
| 158 | limitedSkolemUpperStore.materialise("saturate named individuals", originalMarkProgram); | ||
| 159 | int tag = limitedSkolemUpperStore.materialiseSkolemly(program, null); | ||
| 160 | if (tag != 1) { | ||
| 161 | limitedSkolemUpperStore.dispose(); | ||
| 162 | limitedSkolemUpperStore = null; | ||
| 163 | } | ||
| 164 | if (tag == -1) return false; | ||
| 165 | } | ||
| 166 | if (consistency.checkSkolemUpper()) { | ||
| 167 | satisfiable = true; | ||
| 168 | Utility.logInfo("time for satisfiability checking: " + t.duration()); | ||
| 169 | } | ||
| 155 | 170 | ||
| 156 | trackingStore.importRDFData(name, datafile); | 171 | trackingStore.importRDFData(name, datafile); |
| 157 | trackingStore.materialise("saturate named individuals", originalMarkProgram); | 172 | trackingStore.materialise("saturate named individuals", originalMarkProgram); |
| @@ -223,6 +238,9 @@ public class MyQueryReasoner extends QueryReasoner { | |||
| 223 | if (!queryRecord.isBottom() && lazyUpperStore != null) { | 238 | if (!queryRecord.isBottom() && lazyUpperStore != null) { |
| 224 | queryUpperBound(trackingStore, queryRecord, queryRecord.getQueryText(), queryRecord.getAnswerVariables()); | 239 | queryUpperBound(trackingStore, queryRecord, queryRecord.getQueryText(), queryRecord.getAnswerVariables()); |
| 225 | } | 240 | } |
| 241 | if (!queryRecord.isBottom() && limitedSkolemUpperStore != null) { | ||
| 242 | queryUpperBound(limitedSkolemUpperStore, queryRecord, queryRecord.getQueryText(), queryRecord.getAnswerVariables()); | ||
| 243 | } | ||
| 226 | // END: trying to intersect | 244 | // END: trying to intersect |
| 227 | 245 | ||
| 228 | queryRecord.addProcessingTime(Step.UpperBound, t.duration()); | 246 | queryRecord.addProcessingTime(Step.UpperBound, t.duration()); |
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 11588ce..5d2e411 100644 --- a/src/uk/ac/ox/cs/pagoda/reasoner/light/BasicQueryEngine.java +++ b/src/uk/ac/ox/cs/pagoda/reasoner/light/BasicQueryEngine.java | |||
| @@ -1,29 +1,21 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.reasoner.light; | 1 | package uk.ac.ox.cs.pagoda.reasoner.light; |
| 2 | 2 | ||
| 3 | import java.util.Arrays; | ||
| 4 | import java.util.Collection; | ||
| 5 | import java.util.HashSet; | ||
| 6 | import java.util.Iterator; | ||
| 7 | import java.util.Set; | ||
| 8 | |||
| 9 | import org.semanticweb.HermiT.model.DLClause; | 3 | import org.semanticweb.HermiT.model.DLClause; |
| 10 | 4 | import uk.ac.ox.cs.JRDFox.JRDFStoreException; | |
| 5 | import uk.ac.ox.cs.JRDFox.store.DataStore; | ||
| 6 | import uk.ac.ox.cs.JRDFox.store.DataStore.UpdateType; | ||
| 7 | import uk.ac.ox.cs.JRDFox.store.Parameters; | ||
| 8 | import uk.ac.ox.cs.JRDFox.store.TripleStatus; | ||
| 9 | import uk.ac.ox.cs.JRDFox.store.TupleIterator; | ||
| 11 | import uk.ac.ox.cs.pagoda.hermit.DLClauseHelper; | 10 | import uk.ac.ox.cs.pagoda.hermit.DLClauseHelper; |
| 12 | import uk.ac.ox.cs.pagoda.query.AnswerTuples; | 11 | import uk.ac.ox.cs.pagoda.query.AnswerTuples; |
| 13 | import uk.ac.ox.cs.pagoda.query.GapByStore4ID; | 12 | import uk.ac.ox.cs.pagoda.query.GapByStore4ID; |
| 14 | import uk.ac.ox.cs.pagoda.rules.DatalogProgram; | 13 | import uk.ac.ox.cs.pagoda.rules.DatalogProgram; |
| 15 | import uk.ac.ox.cs.pagoda.rules.Program; | 14 | import uk.ac.ox.cs.pagoda.rules.Program; |
| 16 | import uk.ac.ox.cs.pagoda.util.ConjunctiveQueryHelper; | 15 | import uk.ac.ox.cs.pagoda.util.*; |
| 17 | import uk.ac.ox.cs.pagoda.util.Namespace; | ||
| 18 | import uk.ac.ox.cs.pagoda.util.Timer; | 16 | import uk.ac.ox.cs.pagoda.util.Timer; |
| 19 | import uk.ac.ox.cs.pagoda.util.UFS; | 17 | |
| 20 | import uk.ac.ox.cs.pagoda.util.Utility; | 18 | import java.util.*; |
| 21 | import uk.ac.ox.cs.JRDFox.JRDFStoreException; | ||
| 22 | import uk.ac.ox.cs.JRDFox.store.DataStore; | ||
| 23 | import uk.ac.ox.cs.JRDFox.store.Parameters; | ||
| 24 | import uk.ac.ox.cs.JRDFox.store.TripleStatus; | ||
| 25 | import uk.ac.ox.cs.JRDFox.store.TupleIterator; | ||
| 26 | import uk.ac.ox.cs.JRDFox.store.DataStore.UpdateType; | ||
| 27 | 19 | ||
| 28 | public class BasicQueryEngine extends RDFoxQueryEngine { | 20 | public class BasicQueryEngine extends RDFoxQueryEngine { |
| 29 | 21 | ||
| @@ -74,6 +66,10 @@ public class BasicQueryEngine extends RDFoxQueryEngine { | |||
| 74 | 66 | ||
| 75 | return 1; | 67 | return 1; |
| 76 | } | 68 | } |
| 69 | |||
| 70 | public int materialiseSkolemly(DatalogProgram dProgram, GapByStore4ID gap) { | ||
| 71 | throw new UnsupportedOperationException(); | ||
| 72 | } | ||
| 77 | 73 | ||
| 78 | @Override | 74 | @Override |
| 79 | public AnswerTuples evaluate(String queryText) { | 75 | public AnswerTuples evaluate(String queryText) { |
| @@ -163,8 +159,7 @@ public class BasicQueryEngine extends RDFoxQueryEngine { | |||
| 163 | instanceTuples = null; | 159 | instanceTuples = null; |
| 164 | try { | 160 | try { |
| 165 | instanceTuples = getDataStore().compileQuery("SELECT ?X ?Z WHERE { ?X " + predicate + " ?Z }", prefixes, parameters); | 161 | instanceTuples = getDataStore().compileQuery("SELECT ?X ?Z WHERE { ?X " + predicate + " ?Z }", prefixes, parameters); |
| 166 | ; | 162 | long totalCount = 0; |
| 167 | long totalCount = 0; | ||
| 168 | for (long multi1 = instanceTuples.open(); multi1 != 0; multi1 = instanceTuples.getNext()) | 163 | for (long multi1 = instanceTuples.open(); multi1 != 0; multi1 = instanceTuples.getNext()) |
| 169 | totalCount += instanceTuples.getMultiplicity(); | 164 | totalCount += instanceTuples.getMultiplicity(); |
| 170 | number.add(predicate + " * " + totalCount); | 165 | number.add(predicate + " * " + totalCount); |
diff --git a/src/uk/ac/ox/cs/pagoda/rules/approximators/LimitedSkolemisationApproximator.java b/src/uk/ac/ox/cs/pagoda/rules/approximators/LimitedSkolemisationApproximator.java index e53ae49..4444c00 100644 --- a/src/uk/ac/ox/cs/pagoda/rules/approximators/LimitedSkolemisationApproximator.java +++ b/src/uk/ac/ox/cs/pagoda/rules/approximators/LimitedSkolemisationApproximator.java | |||
| @@ -1,26 +1,29 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.rules.approximators; | 1 | package uk.ac.ox.cs.pagoda.rules.approximators; |
| 2 | 2 | ||
| 3 | import org.semanticweb.HermiT.model.DLClause; | 3 | import org.semanticweb.HermiT.model.*; |
| 4 | import org.semanticweb.HermiT.model.Individual; | ||
| 5 | import uk.ac.ox.cs.pagoda.multistage.AnswerTupleID; | 4 | import uk.ac.ox.cs.pagoda.multistage.AnswerTupleID; |
| 5 | import uk.ac.ox.cs.pagoda.multistage.MultiStageUpperProgram; | ||
| 6 | import uk.ac.ox.cs.pagoda.rules.ExistConstantApproximator; | 6 | import uk.ac.ox.cs.pagoda.rules.ExistConstantApproximator; |
| 7 | import uk.ac.ox.cs.pagoda.util.tuples.Tuple; | 7 | import uk.ac.ox.cs.pagoda.util.tuples.Tuple; |
| 8 | import uk.ac.ox.cs.pagoda.util.tuples.TupleBuilder; | ||
| 8 | 9 | ||
| 9 | import java.util.*; | 10 | import java.util.*; |
| 10 | 11 | ||
| 11 | /** | 12 | /** |
| 12 | * Approximates existential rules by a limited form of Skolemisation. | 13 | * Approximates existential rules through a limited form of Skolemisation. |
| 13 | * <p> | 14 | * <p> |
| 14 | * Given a rule and a grounding substitution, | 15 | * Given a rule and a ground substitution, |
| 15 | * it Skolemises the rule if | 16 | * it Skolemises the rule |
| 16 | * all the terms in the substitution have depth less than a given depth, | 17 | * if all the terms in the substitution have depth less than a given depth, |
| 17 | * otherwise it approximates using an alternative <tt>TupleDependentApproximator</tt>. | 18 | * otherwise it approximates using an alternative <tt>TupleDependentApproximator</tt>. |
| 18 | * | ||
| 19 | * */ | 19 | * */ |
| 20 | public class LimitedSkolemisationApproximator implements TupleDependentApproximator { | 20 | public class LimitedSkolemisationApproximator implements TupleDependentApproximator { |
| 21 | 21 | ||
| 22 | private static final Atom[] EMPTY_BODY = new Atom[0]; | ||
| 23 | |||
| 22 | private final int maxTermDepth; | 24 | private final int maxTermDepth; |
| 23 | private final TupleDependentApproximator alternativeApproximator; | 25 | private final TupleDependentApproximator alternativeApproximator; |
| 26 | private final SkolemTermsManager skolemTermsManager; | ||
| 24 | 27 | ||
| 25 | private Map<AnswerTupleID, Integer> mapIndividualsToDepth; | 28 | private Map<AnswerTupleID, Integer> mapIndividualsToDepth; |
| 26 | 29 | ||
| @@ -32,19 +35,21 @@ public class LimitedSkolemisationApproximator implements TupleDependentApproxima | |||
| 32 | this.maxTermDepth = maxTermDepth; | 35 | this.maxTermDepth = maxTermDepth; |
| 33 | this.alternativeApproximator = alternativeApproximator; | 36 | this.alternativeApproximator = alternativeApproximator; |
| 34 | this.mapIndividualsToDepth = new HashMap<>(); | 37 | this.mapIndividualsToDepth = new HashMap<>(); |
| 38 | this.skolemTermsManager = SkolemTermsManager.getInstance(); | ||
| 35 | } | 39 | } |
| 36 | 40 | ||
| 37 | @Override | 41 | @Override |
| 38 | public Collection<DLClause> convert(DLClause clause, DLClause originalClause, Collection<Tuple<Individual>> violationTuples) { | 42 | public Collection<DLClause> convert(DLClause clause, |
| 43 | DLClause originalClause, | ||
| 44 | Collection<Tuple<Individual>> violationTuples) { | ||
| 39 | switch (clause.getHeadLength()) { | 45 | switch (clause.getHeadLength()) { |
| 40 | case 1: | 46 | case 1: |
| 41 | return overApprox(clause, originalClause, violationTuples); | 47 | return overApprox(clause, originalClause, violationTuples); |
| 42 | case 0: | 48 | case 0: |
| 43 | return Arrays.asList(clause); | 49 | return Arrays.asList(clause); |
| 44 | default: | 50 | default: |
| 45 | ArrayList<DLClause> result = new ArrayList<>(); | 51 | throw new IllegalArgumentException( |
| 46 | // TODO implement | 52 | "Expected clause with head length < 1, but it is " + clause.getHeadLength()); |
| 47 | return result; | ||
| 48 | } | 53 | } |
| 49 | 54 | ||
| 50 | 55 | ||
| @@ -54,23 +59,94 @@ public class LimitedSkolemisationApproximator implements TupleDependentApproxima | |||
| 54 | ArrayList<DLClause> result = new ArrayList<>(); | 59 | ArrayList<DLClause> result = new ArrayList<>(); |
| 55 | 60 | ||
| 56 | for (Tuple<Individual> violationTuple : violationTuples) | 61 | for (Tuple<Individual> violationTuple : violationTuples) |
| 57 | if (getDepth(violationTuple) > maxTermDepth) | 62 | if (getMaxDepth(violationTuple) > maxTermDepth) |
| 58 | result.addAll(alternativeApproximator.convert(clause, originalClause, null)); | 63 | result.addAll(alternativeApproximator.convert(clause, originalClause, null)); |
| 59 | else | 64 | else |
| 60 | result.add(getGroundSkolemisation(clause, originalClause, violationTuple)); | 65 | result.addAll(getGroundSkolemisation(clause, originalClause, violationTuple)); |
| 61 | 66 | ||
| 62 | return result; | 67 | return result; |
| 63 | } | 68 | } |
| 64 | 69 | ||
| 70 | private static final Variable X = Variable.create("X"); | ||
| 71 | |||
| 72 | private Collection<DLClause> getGroundSkolemisation(DLClause clause, | ||
| 73 | DLClause originalClause, | ||
| 74 | Tuple<Individual> violationTuple) { | ||
| 75 | |||
| 76 | String[] commonVars = MultiStageUpperProgram.getCommonVars(clause); | ||
| 77 | |||
| 78 | // TODO check: strong assumption, the first tuples are the common ones | ||
| 79 | TupleBuilder<Individual> commonIndividualsBuilder = new TupleBuilder<>(); | ||
| 80 | for (int i = 0; i < commonVars.length; i++) | ||
| 81 | commonIndividualsBuilder.add(violationTuple.get(i)); | ||
| 82 | |||
| 83 | Atom headAtom = clause.getHeadAtom(0); | ||
| 84 | Atom[] bodyAtoms = clause.getBodyAtoms(); | ||
| 85 | int offset = OverApproxExist.indexOfExistential(headAtom, originalClause); | ||
| 86 | |||
| 87 | // BEGIN: copy and paste | ||
| 88 | ArrayList<DLClause> ret = new ArrayList<>(); | ||
| 89 | DLPredicate predicate = headAtom.getDLPredicate(); | ||
| 90 | if (predicate instanceof AtLeastConcept) { | ||
| 91 | AtLeastConcept atLeastConcept = (AtLeastConcept) predicate; | ||
| 92 | LiteralConcept concept = atLeastConcept.getToConcept(); | ||
| 93 | Role role = atLeastConcept.getOnRole(); | ||
| 94 | AtomicConcept atomicConcept; | ||
| 95 | |||
| 96 | if (concept instanceof AtomicNegationConcept) { | ||
| 97 | // TODO CHECK: is this already in MultiStageUpperProgram? | ||
| 98 | Atom atom1 = Atom.create(atomicConcept = ((AtomicNegationConcept) concept).getNegatedAtomicConcept(), X); | ||
| 99 | Atom atom2 = Atom.create(atomicConcept = OverApproxExist.getNegationConcept(atomicConcept), X); | ||
| 100 | ret.add(DLClause.create(new Atom[0], new Atom[] {atom1, atom2})); | ||
| 101 | } | ||
| 102 | else { | ||
| 103 | atomicConcept = (AtomicConcept) concept; | ||
| 104 | if (atomicConcept.equals(AtomicConcept.THING)) | ||
| 105 | atomicConcept = null; | ||
| 106 | } | ||
| 107 | |||
| 108 | int card = atLeastConcept.getNumber(); | ||
| 109 | Individual[] individuals = new Individual[card]; | ||
| 110 | SkolemTermsManager termsManager = SkolemTermsManager.getInstance(); | ||
| 111 | for (int i = 0; i < card; ++i) | ||
| 112 | individuals[i] = termsManager.getFreshIndividual(originalClause, | ||
| 113 | offset + i, | ||
| 114 | commonIndividualsBuilder.create()); | ||
| 115 | |||
| 116 | for (int i = 0; i < card; ++i) { | ||
| 117 | if (atomicConcept != null) | ||
| 118 | ret.add(DLClause.create(new Atom[] {Atom.create(atomicConcept, individuals[i])}, EMPTY_BODY)); | ||
| 119 | |||
| 120 | Atom atom = role instanceof AtomicRole ? | ||
| 121 | Atom.create((AtomicRole) role, X, individuals[i]) : | ||
| 122 | Atom.create(((InverseRole) role).getInverseOf(), individuals[i], X); | ||
| 123 | |||
| 124 | ret.add(DLClause.create(new Atom[] {atom}, EMPTY_BODY)); | ||
| 125 | } | ||
| 126 | |||
| 127 | for (int i = 0; i < card; ++i) | ||
| 128 | for (int j = i + 1; j < card; ++j) | ||
| 129 | // TODO to be checked ... different as | ||
| 130 | ret.add(DLClause.create(new Atom[] {Atom.create(Inequality.INSTANCE, individuals[i], individuals[j])}, EMPTY_BODY)); | ||
| 131 | |||
| 132 | } | ||
| 133 | else if (predicate instanceof AtLeastDataRange) { | ||
| 134 | // TODO to be implemented ... | ||
| 135 | } | ||
| 136 | else | ||
| 137 | ret.add(DLClause.create(new Atom[] {headAtom}, EMPTY_BODY)); | ||
| 65 | 138 | ||
| 66 | private DLClause getGroundSkolemisation(DLClause clause, DLClause originalClause, Tuple<Individual> violationTuple) { | 139 | return ret; |
| 67 | // TODO implement | 140 | |
| 68 | // filter the violation tuples appearing on both the sides of the rule | 141 | // END: copy and paste |
| 69 | return null; | ||
| 70 | } | 142 | } |
| 71 | 143 | ||
| 72 | private int getDepth(Tuple<Individual> violationTuple) { | 144 | |
| 73 | if (!mapIndividualsToDepth.containsKey(violationTuple)) return 0; | 145 | public int getMaxDepth(Tuple<Individual> violationTuple) { |
| 74 | return mapIndividualsToDepth.get(violationTuple); | 146 | int maxDepth = 0; |
| 147 | for (Individual individual : violationTuple) | ||
| 148 | maxDepth = Integer.max(maxDepth, skolemTermsManager.getDepth(individual)); | ||
| 149 | |||
| 150 | return maxDepth; | ||
| 75 | } | 151 | } |
| 76 | } | 152 | } |
diff --git a/src/uk/ac/ox/cs/pagoda/rules/approximators/OverApproxExist.java b/src/uk/ac/ox/cs/pagoda/rules/approximators/OverApproxExist.java index d71c472..028568c 100644 --- a/src/uk/ac/ox/cs/pagoda/rules/approximators/OverApproxExist.java +++ b/src/uk/ac/ox/cs/pagoda/rules/approximators/OverApproxExist.java | |||
| @@ -12,7 +12,7 @@ public class OverApproxExist implements Approximator { | |||
| 12 | public static final String negativeSuffix = "_neg"; | 12 | public static final String negativeSuffix = "_neg"; |
| 13 | private static final Variable X = Variable.create("X"); | 13 | private static final Variable X = Variable.create("X"); |
| 14 | 14 | ||
| 15 | private static int indexOfExistential(Atom headAtom, DLClause originalClause) { | 15 | static int indexOfExistential(Atom headAtom, DLClause originalClause) { |
| 16 | if (!(headAtom.getDLPredicate() instanceof AtLeast)) return -1; | 16 | if (!(headAtom.getDLPredicate() instanceof AtLeast)) return -1; |
| 17 | AtLeastConcept alc = (AtLeastConcept) headAtom.getDLPredicate(); | 17 | AtLeastConcept alc = (AtLeastConcept) headAtom.getDLPredicate(); |
| 18 | if (alc.getToConcept() instanceof AtomicConcept) { | 18 | if (alc.getToConcept() instanceof AtomicConcept) { |
