diff options
| author | RncLsn <rnc.lsn@gmail.com> | 2015-06-04 14:37:25 +0100 |
|---|---|---|
| committer | RncLsn <rnc.lsn@gmail.com> | 2015-06-04 14:37:25 +0100 |
| commit | 51cfc39903ae53cbcaba9a9f5c69cac08ae63fa7 (patch) | |
| tree | e877ee54e4cef1d096ef21d6c83fda4e7a912d03 /src | |
| parent | b3ce74df783ebe665182dbd916a7288cff8bc127 (diff) | |
| download | ACQuA-51cfc39903ae53cbcaba9a9f5c69cac08ae63fa7.tar.gz ACQuA-51cfc39903ae53cbcaba9a9f5c69cac08ae63fa7.zip | |
Restored fixed SkolemTermsManager (went lost in some revert).
Diffstat (limited to 'src')
4 files changed, 52 insertions, 54 deletions
diff --git a/src/uk/ac/ox/cs/pagoda/query/QueryRecord.java b/src/uk/ac/ox/cs/pagoda/query/QueryRecord.java index dee2966..7f02741 100644 --- a/src/uk/ac/ox/cs/pagoda/query/QueryRecord.java +++ b/src/uk/ac/ox/cs/pagoda/query/QueryRecord.java | |||
| @@ -707,7 +707,7 @@ public class QueryRecord extends Disposable { | |||
| 707 | UPPER_BOUND, | 707 | UPPER_BOUND, |
| 708 | SIMPLE_UPPER_BOUND, | 708 | SIMPLE_UPPER_BOUND, |
| 709 | LAZY_UPPER_BOUND, | 709 | LAZY_UPPER_BOUND, |
| 710 | L_SKOLEM_UPPER_BOUND, | 710 | SKOLEM_UPPER_BOUND, |
| 711 | EL_LOWER_BOUND, | 711 | EL_LOWER_BOUND, |
| 712 | FRAGMENT, | 712 | FRAGMENT, |
| 713 | FRAGMENT_REFINEMENT, | 713 | FRAGMENT_REFINEMENT, |
diff --git a/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java b/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java index ed6589a..123bd5e 100644 --- a/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java +++ b/src/uk/ac/ox/cs/pagoda/reasoner/MyQueryReasoner.java | |||
| @@ -370,10 +370,10 @@ class MyQueryReasoner extends QueryReasoner { | |||
| 370 | 370 | ||
| 371 | relevantStore.importDataFromABoxOf(relevantSubset); | 371 | relevantStore.importDataFromABoxOf(relevantSubset); |
| 372 | 372 | ||
| 373 | int queryDependentMaxTermDepth = 10; // TODO make it dynamic | 373 | int queryDependentMaxTermDepth = 1; // TODO make it dynamic |
| 374 | int materialisationTag = relevantStore.materialiseSkolemly(relevantProgram, null, | 374 | int materialisationTag = relevantStore.materialiseSkolemly(relevantProgram, null, |
| 375 | queryDependentMaxTermDepth); | 375 | queryDependentMaxTermDepth); |
| 376 | queryRecord.addProcessingTime(Step.L_SKOLEM_UPPER_BOUND, t.duration()); | 376 | queryRecord.addProcessingTime(Step.SKOLEM_UPPER_BOUND, t.duration()); |
| 377 | if(materialisationTag == -1) { | 377 | if(materialisationTag == -1) { |
| 378 | throw new Error("A consistent ontology has turned out to be " + | 378 | throw new Error("A consistent ontology has turned out to be " + |
| 379 | "inconsistent in the Skolemises-relevant-upper-store"); | 379 | "inconsistent in the Skolemises-relevant-upper-store"); |
| @@ -385,7 +385,7 @@ class MyQueryReasoner extends QueryReasoner { | |||
| 385 | 385 | ||
| 386 | boolean isFullyProcessed = queryUpperStore(relevantStore, queryRecord, | 386 | boolean isFullyProcessed = queryUpperStore(relevantStore, queryRecord, |
| 387 | queryRecord.getExtendedQueryText(), | 387 | queryRecord.getExtendedQueryText(), |
| 388 | Step.L_SKOLEM_UPPER_BOUND); | 388 | Step.SKOLEM_UPPER_BOUND); |
| 389 | Utility.logInfo("Semi-Skolemised relevant upper store has been evaluated"); | 389 | Utility.logInfo("Semi-Skolemised relevant upper store has been evaluated"); |
| 390 | return isFullyProcessed; | 390 | return isFullyProcessed; |
| 391 | } | 391 | } |
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 5f6e362..dc2ba8a 100644 --- a/src/uk/ac/ox/cs/pagoda/rules/approximators/LimitedSkolemisationApproximator.java +++ b/src/uk/ac/ox/cs/pagoda/rules/approximators/LimitedSkolemisationApproximator.java | |||
| @@ -18,7 +18,7 @@ import java.util.Collection; | |||
| 18 | * it Skolemises the rule | 18 | * it Skolemises the rule |
| 19 | * if all the terms in the substitution have depth less than a given depth, | 19 | * if all the terms in the substitution have depth less than a given depth, |
| 20 | * otherwise it approximates using an alternative <tt>TupleDependentApproximator</tt>. | 20 | * otherwise it approximates using an alternative <tt>TupleDependentApproximator</tt>. |
| 21 | * */ | 21 | */ |
| 22 | public class LimitedSkolemisationApproximator implements TupleDependentApproximator { | 22 | public class LimitedSkolemisationApproximator implements TupleDependentApproximator { |
| 23 | 23 | ||
| 24 | private static final Atom[] EMPTY_BODY = new Atom[0]; | 24 | private static final Atom[] EMPTY_BODY = new Atom[0]; |
| @@ -41,7 +41,7 @@ public class LimitedSkolemisationApproximator implements TupleDependentApproxima | |||
| 41 | public Collection<DLClause> convert(DLClause clause, | 41 | public Collection<DLClause> convert(DLClause clause, |
| 42 | DLClause originalClause, | 42 | DLClause originalClause, |
| 43 | Collection<Tuple<Individual>> violationTuples) { | 43 | Collection<Tuple<Individual>> violationTuples) { |
| 44 | switch (clause.getHeadLength()) { | 44 | switch(clause.getHeadLength()) { |
| 45 | case 1: | 45 | case 1: |
| 46 | return overApprox(clause, originalClause, violationTuples); | 46 | return overApprox(clause, originalClause, violationTuples); |
| 47 | case 0: | 47 | case 0: |
| @@ -65,7 +65,7 @@ public class LimitedSkolemisationApproximator implements TupleDependentApproxima | |||
| 65 | private Collection<DLClause> overApprox(DLClause clause, DLClause originalClause, Collection<Tuple<Individual>> violationTuples) { | 65 | private Collection<DLClause> overApprox(DLClause clause, DLClause originalClause, Collection<Tuple<Individual>> violationTuples) { |
| 66 | ArrayList<DLClause> result = new ArrayList<>(); | 66 | ArrayList<DLClause> result = new ArrayList<>(); |
| 67 | 67 | ||
| 68 | for (Tuple<Individual> violationTuple : violationTuples) | 68 | for(Tuple<Individual> violationTuple : violationTuples) |
| 69 | if(getMaxDepth(violationTuple) > maxTermDepth) { | 69 | if(getMaxDepth(violationTuple) > maxTermDepth) { |
| 70 | result.addAll(alternativeApproximator.convert(clause, originalClause, null)); | 70 | result.addAll(alternativeApproximator.convert(clause, originalClause, null)); |
| 71 | Utility.logDebug("Approximating maximal individual by a constant in rule:" + originalClause); | 71 | Utility.logDebug("Approximating maximal individual by a constant in rule:" + originalClause); |
| @@ -84,7 +84,7 @@ public class LimitedSkolemisationApproximator implements TupleDependentApproxima | |||
| 84 | 84 | ||
| 85 | // TODO check: strong assumption, the first tuples are the common ones | 85 | // TODO check: strong assumption, the first tuples are the common ones |
| 86 | TupleBuilder<Individual> commonIndividualsBuilder = new TupleBuilder<>(); | 86 | TupleBuilder<Individual> commonIndividualsBuilder = new TupleBuilder<>(); |
| 87 | for (int i = 0; i < commonVars.length; i++) | 87 | for(int i = 0; i < commonVars.length; i++) |
| 88 | commonIndividualsBuilder.append(violationTuple.get(i)); | 88 | commonIndividualsBuilder.append(violationTuple.get(i)); |
| 89 | Tuple<Individual> commonIndividuals = commonIndividualsBuilder.build(); | 89 | Tuple<Individual> commonIndividuals = commonIndividualsBuilder.build(); |
| 90 | 90 | ||
| @@ -96,54 +96,55 @@ public class LimitedSkolemisationApproximator implements TupleDependentApproxima | |||
| 96 | // BEGIN: copy and paste | 96 | // BEGIN: copy and paste |
| 97 | ArrayList<DLClause> ret = new ArrayList<>(); | 97 | ArrayList<DLClause> ret = new ArrayList<>(); |
| 98 | DLPredicate predicate = headAtom.getDLPredicate(); | 98 | DLPredicate predicate = headAtom.getDLPredicate(); |
| 99 | if (predicate instanceof AtLeastConcept) { | 99 | if(predicate instanceof AtLeastConcept) { |
| 100 | AtLeastConcept atLeastConcept = (AtLeastConcept) predicate; | 100 | AtLeastConcept atLeastConcept = (AtLeastConcept) predicate; |
| 101 | LiteralConcept concept = atLeastConcept.getToConcept(); | 101 | LiteralConcept concept = atLeastConcept.getToConcept(); |
| 102 | Role role = atLeastConcept.getOnRole(); | 102 | Role role = atLeastConcept.getOnRole(); |
| 103 | AtomicConcept atomicConcept; | 103 | AtomicConcept atomicConcept; |
| 104 | 104 | ||
| 105 | if (concept instanceof AtomicNegationConcept) { | 105 | if(concept instanceof AtomicNegationConcept) { |
| 106 | // TODO CHECK: is this already in MultiStageUpperProgram? | 106 | // TODO CHECK: is this already in MultiStageUpperProgram? |
| 107 | Atom atom1 = Atom.create(atomicConcept = ((AtomicNegationConcept) concept).getNegatedAtomicConcept(), X); | 107 | Atom atom1 = |
| 108 | Atom.create(atomicConcept = ((AtomicNegationConcept) concept).getNegatedAtomicConcept(), X); | ||
| 108 | Atom atom2 = Atom.create(atomicConcept = OverApproxExist.getNegationConcept(atomicConcept), X); | 109 | Atom atom2 = Atom.create(atomicConcept = OverApproxExist.getNegationConcept(atomicConcept), X); |
| 109 | ret.add(DLClause.create(new Atom[0], new Atom[] {atom1, atom2})); | 110 | ret.add(DLClause.create(new Atom[0], new Atom[]{atom1, atom2})); |
| 110 | } | 111 | } |
| 111 | else { | 112 | else { |
| 112 | atomicConcept = (AtomicConcept) concept; | 113 | atomicConcept = (AtomicConcept) concept; |
| 113 | if (atomicConcept.equals(AtomicConcept.THING)) | 114 | if(atomicConcept.equals(AtomicConcept.THING)) |
| 114 | atomicConcept = null; | 115 | atomicConcept = null; |
| 115 | } | 116 | } |
| 116 | 117 | ||
| 117 | int card = atLeastConcept.getNumber(); | 118 | int card = atLeastConcept.getNumber(); |
| 118 | Individual[] individuals = new Individual[card]; | 119 | Individual[] individuals = new Individual[card]; |
| 119 | SkolemTermsManager termsManager = SkolemTermsManager.getInstance(); | 120 | SkolemTermsManager termsManager = SkolemTermsManager.getInstance(); |
| 120 | for (int i = 0; i < card; ++i) | 121 | for(int i = 0; i < card; ++i) |
| 121 | individuals[i] = termsManager.getFreshIndividual(originalClause, | 122 | individuals[i] = termsManager.getFreshIndividual(originalClause, |
| 122 | offset + i, | 123 | offset + i, |
| 123 | commonIndividuals); | 124 | commonIndividuals); |
| 124 | 125 | ||
| 125 | for (int i = 0; i < card; ++i) { | 126 | for(int i = 0; i < card; ++i) { |
| 126 | if (atomicConcept != null) | 127 | if(atomicConcept != null) |
| 127 | ret.add(DLClause.create(new Atom[] {Atom.create(atomicConcept, individuals[i])}, EMPTY_BODY)); | 128 | ret.add(DLClause.create(new Atom[]{Atom.create(atomicConcept, individuals[i])}, EMPTY_BODY)); |
| 128 | 129 | ||
| 129 | Atom atom = role instanceof AtomicRole ? | 130 | Atom atom = role instanceof AtomicRole ? |
| 130 | Atom.create((AtomicRole) role, commonIndividuals.get(0), individuals[i]) : | 131 | Atom.create((AtomicRole) role, commonIndividuals.get(0), individuals[i]) : |
| 131 | Atom.create(((InverseRole) role).getInverseOf(), individuals[i], commonIndividuals.get(0)); | 132 | Atom.create(((InverseRole) role).getInverseOf(), individuals[i], commonIndividuals.get(0)); |
| 132 | 133 | ||
| 133 | ret.add(DLClause.create(new Atom[] {atom}, EMPTY_BODY)); | 134 | ret.add(DLClause.create(new Atom[]{atom}, EMPTY_BODY)); |
| 134 | } | 135 | } |
| 135 | 136 | ||
| 136 | for (int i = 0; i < card; ++i) | 137 | for(int i = 0; i < card; ++i) |
| 137 | for (int j = i + 1; j < card; ++j) | 138 | for(int j = i + 1; j < card; ++j) |
| 138 | // TODO to be checked ... different as | 139 | // TODO to be checked ... different as |
| 139 | ret.add(DLClause.create(new Atom[] {Atom.create(Inequality.INSTANCE, individuals[i], individuals[j])}, EMPTY_BODY)); | 140 | ret.add(DLClause.create(new Atom[]{Atom.create(Inequality.INSTANCE, individuals[i], individuals[j])}, EMPTY_BODY)); |
| 140 | 141 | ||
| 141 | } | 142 | } |
| 142 | else if (predicate instanceof AtLeastDataRange) { | 143 | else if(predicate instanceof AtLeastDataRange) { |
| 143 | // TODO to be implemented ... | 144 | // TODO to be implemented ... |
| 144 | } | 145 | } |
| 145 | else | 146 | else |
| 146 | ret.add(DLClause.create(new Atom[] {headAtom}, EMPTY_BODY)); | 147 | ret.add(DLClause.create(new Atom[]{headAtom}, EMPTY_BODY)); |
| 147 | 148 | ||
| 148 | return ret; | 149 | return ret; |
| 149 | 150 | ||
diff --git a/src/uk/ac/ox/cs/pagoda/rules/approximators/SkolemTermsManager.java b/src/uk/ac/ox/cs/pagoda/rules/approximators/SkolemTermsManager.java index 368c014..07ad1f9 100644 --- a/src/uk/ac/ox/cs/pagoda/rules/approximators/SkolemTermsManager.java +++ b/src/uk/ac/ox/cs/pagoda/rules/approximators/SkolemTermsManager.java | |||
| @@ -17,13 +17,12 @@ public class SkolemTermsManager { | |||
| 17 | private static SkolemTermsManager skolemTermsManager; | 17 | private static SkolemTermsManager skolemTermsManager; |
| 18 | 18 | ||
| 19 | private int termsCounter = 0; | 19 | private int termsCounter = 0; |
| 20 | private Map<DLClause, Integer> mapClauseToId = new HashMap<>(); | 20 | private Map<DLClause, Integer> clauseToId_map = new HashMap<>(); |
| 21 | private Map<Individual, Integer> mapTermToDepth = new HashMap<>(); | 21 | private Map<Individual, Integer> individualToDepth_map = new HashMap<>(); |
| 22 | private int dependenciesCounter = 0; | 22 | private int dependenciesCounter = 0; |
| 23 | 23 | ||
| 24 | // TODO replace with hashcode. in case of collision you get only a different upper bound model. | 24 | // TODO replace with hashcode. in case of collision you would get only a different upper bound model. |
| 25 | // TODO you can use a cash. | 25 | private Map<Tuple<Individual>, Integer> dependencyToId_map = new HashMap<>(); |
| 26 | private Map<Tuple<Individual>, Integer> mapDependencyToId = new HashMap<>(); | ||
| 27 | 26 | ||
| 28 | private SkolemTermsManager() { | 27 | private SkolemTermsManager() { |
| 29 | } | 28 | } |
| @@ -38,6 +37,11 @@ public class SkolemTermsManager { | |||
| 38 | return -1; | 37 | return -1; |
| 39 | } | 38 | } |
| 40 | 39 | ||
| 40 | /** | ||
| 41 | * Returns the existing unique <tt>SkolemTermsManager</tt> or a new one. | ||
| 42 | * <p> | ||
| 43 | * Indeed the <tt>SkolemTermsManager</tt> is a singleton. | ||
| 44 | */ | ||
| 41 | public static SkolemTermsManager getInstance() { | 45 | public static SkolemTermsManager getInstance() { |
| 42 | if(skolemTermsManager == null) skolemTermsManager = new SkolemTermsManager(); | 46 | if(skolemTermsManager == null) skolemTermsManager = new SkolemTermsManager(); |
| 43 | return skolemTermsManager; | 47 | return skolemTermsManager; |
| @@ -47,21 +51,14 @@ public class SkolemTermsManager { | |||
| 47 | * Get a fresh Individual, unique for the clause, the offset and the dependency. | 51 | * Get a fresh Individual, unique for the clause, the offset and the dependency. |
| 48 | * */ | 52 | * */ |
| 49 | public Individual getFreshIndividual(DLClause originalClause, int offset, Tuple<Individual> dependency) { | 53 | public Individual getFreshIndividual(DLClause originalClause, int offset, Tuple<Individual> dependency) { |
| 50 | if(!mapClauseToId.containsKey(originalClause)) { | 54 | String termId = Integer.toString(mapClauseToId(originalClause) + offset) |
| 51 | mapClauseToId.put(originalClause, termsCounter); | 55 | + "_" + mapDependencyToId(dependency); |
| 52 | termsCounter += noOfExistential(originalClause); | ||
| 53 | } | ||
| 54 | if (!mapDependencyToId.containsKey(dependency)) { | ||
| 55 | mapDependencyToId.put(dependency, dependenciesCounter++); | ||
| 56 | } | ||
| 57 | |||
| 58 | String termId = mapClauseToId.get(originalClause) + offset + "_" + mapDependencyToId(dependency); | ||
| 59 | Individual newIndividual = Individual.create(SKOLEMISED_INDIVIDUAL_PREFIX + termId); | 56 | Individual newIndividual = Individual.create(SKOLEMISED_INDIVIDUAL_PREFIX + termId); |
| 60 | 57 | ||
| 61 | int depth = 0; | 58 | int depth = 0; |
| 62 | for (Individual individual : dependency) | 59 | for (Individual individual : dependency) |
| 63 | depth = Integer.max(depth, mapIndividualToDepth(individual)); | 60 | depth = Integer.max(depth, getDepthOf(individual)); |
| 64 | mapTermToDepth.put(newIndividual, depth); | 61 | individualToDepth_map.put(newIndividual, depth); |
| 65 | 62 | ||
| 66 | return newIndividual; | 63 | return newIndividual; |
| 67 | } | 64 | } |
| @@ -70,14 +67,9 @@ public class SkolemTermsManager { | |||
| 70 | * Get a fresh Individual, unique for the clause and the offset. | 67 | * Get a fresh Individual, unique for the clause and the offset. |
| 71 | * */ | 68 | * */ |
| 72 | public Individual getFreshIndividual(DLClause originalClause, int offset) { | 69 | public Individual getFreshIndividual(DLClause originalClause, int offset) { |
| 73 | if(!mapClauseToId.containsKey(originalClause)) { | 70 | String termId = Integer.toString(mapClauseToId(originalClause) + offset); |
| 74 | mapClauseToId.put(originalClause, termsCounter); | ||
| 75 | termsCounter += noOfExistential(originalClause); | ||
| 76 | } | ||
| 77 | |||
| 78 | String termId = "" + mapClauseToId.get(originalClause) + offset; | ||
| 79 | Individual newIndividual = Individual.create(SKOLEMISED_INDIVIDUAL_PREFIX + termId); | 71 | Individual newIndividual = Individual.create(SKOLEMISED_INDIVIDUAL_PREFIX + termId); |
| 80 | mapTermToDepth.put(newIndividual, 0); | 72 | // individualToDepth_map.put(newIndividual, 0); // TODO REMOVE |
| 81 | 73 | ||
| 82 | return newIndividual; | 74 | return newIndividual; |
| 83 | } | 75 | } |
| @@ -88,24 +80,29 @@ public class SkolemTermsManager { | |||
| 88 | * The term must have been generated by this manager. | 80 | * The term must have been generated by this manager. |
| 89 | * */ | 81 | * */ |
| 90 | public int getDepthOf(Individual individual) { | 82 | public int getDepthOf(Individual individual) { |
| 91 | return mapIndividualToDepth(individual); | 83 | if(individualToDepth_map.containsKey(individual)) return individualToDepth_map.get(individual); |
| 84 | else return 0; | ||
| 92 | } | 85 | } |
| 93 | 86 | ||
| 94 | /** | 87 | /** |
| 95 | * Get the number of individuals generated by this manager. | 88 | * Get the number of individuals generated by this manager. |
| 96 | * */ | 89 | * */ |
| 97 | public int getNumberOfSkolemisedIndividual() { | 90 | public int getNumberOfSkolemisedIndividual() { |
| 98 | return mapTermToDepth.keySet().size(); | 91 | return individualToDepth_map.keySet().size(); |
| 99 | } | 92 | } |
| 100 | 93 | ||
| 101 | private int mapDependencyToId(Tuple<Individual> dependency) { | 94 | private int mapClauseToId(DLClause clause) { |
| 102 | if (mapDependencyToId.containsKey(dependency)) return mapDependencyToId.get(dependency); | 95 | if(!clauseToId_map.containsKey(clause)) { |
| 103 | else return mapDependencyToId.put(dependency, dependenciesCounter++); | 96 | clauseToId_map.put(clause, termsCounter); |
| 97 | termsCounter += noOfExistential(clause); | ||
| 98 | } | ||
| 99 | return clauseToId_map.get(clause); | ||
| 104 | } | 100 | } |
| 105 | 101 | ||
| 106 | private int mapIndividualToDepth(Individual dependency) { | 102 | private int mapDependencyToId(Tuple<Individual> dependency) { |
| 107 | if(mapTermToDepth.containsKey(dependency)) return mapTermToDepth.get(dependency); | 103 | if(!dependencyToId_map.containsKey(dependency)) |
| 108 | else return 0; | 104 | dependencyToId_map.put(dependency, dependenciesCounter++); |
| 105 | return dependencyToId_map.get(dependency); | ||
| 109 | } | 106 | } |
| 110 | 107 | ||
| 111 | private int noOfExistential(DLClause originalClause) { | 108 | private int noOfExistential(DLClause originalClause) { |
