diff options
| author | RncLsn <rnc.lsn@gmail.com> | 2015-05-19 19:06:04 +0100 |
|---|---|---|
| committer | RncLsn <rnc.lsn@gmail.com> | 2015-05-19 19:06:04 +0100 |
| commit | 7a68441a541b12b22587fb53072193e1130049ff (patch) | |
| tree | e05f826da89e73a7f961c505359f4135cca646a8 /src/uk/ac/ox/cs/pagoda/rules | |
| parent | 612729386b645b120f8397a007cd8421986af0ad (diff) | |
| download | ACQuA-7a68441a541b12b22587fb53072193e1130049ff.tar.gz ACQuA-7a68441a541b12b22587fb53072193e1130049ff.zip | |
Deleted unused classes.
Diffstat (limited to 'src/uk/ac/ox/cs/pagoda/rules')
| -rw-r--r-- | src/uk/ac/ox/cs/pagoda/rules/approximators/LimitedSkolemisationApproximator.java | 9 | ||||
| -rw-r--r-- | src/uk/ac/ox/cs/pagoda/rules/approximators/SkolemTermsManager.java | 77 |
2 files changed, 43 insertions, 43 deletions
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 20ae53b..3f1ed7e 100644 --- a/src/uk/ac/ox/cs/pagoda/rules/approximators/LimitedSkolemisationApproximator.java +++ b/src/uk/ac/ox/cs/pagoda/rules/approximators/LimitedSkolemisationApproximator.java | |||
| @@ -1,13 +1,14 @@ | |||
| 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.*; | 3 | import org.semanticweb.HermiT.model.*; |
| 4 | import uk.ac.ox.cs.pagoda.multistage.AnswerTupleID; | ||
| 5 | import uk.ac.ox.cs.pagoda.multistage.MultiStageUpperProgram; | 4 | import uk.ac.ox.cs.pagoda.multistage.MultiStageUpperProgram; |
| 6 | import uk.ac.ox.cs.pagoda.rules.ExistConstantApproximator; | 5 | import uk.ac.ox.cs.pagoda.rules.ExistConstantApproximator; |
| 7 | import uk.ac.ox.cs.pagoda.util.tuples.Tuple; | 6 | import uk.ac.ox.cs.pagoda.util.tuples.Tuple; |
| 8 | import uk.ac.ox.cs.pagoda.util.tuples.TupleBuilder; | 7 | import uk.ac.ox.cs.pagoda.util.tuples.TupleBuilder; |
| 9 | 8 | ||
| 10 | import java.util.*; | 9 | import java.util.ArrayList; |
| 10 | import java.util.Arrays; | ||
| 11 | import java.util.Collection; | ||
| 11 | 12 | ||
| 12 | /** | 13 | /** |
| 13 | * Approximates existential rules through a limited form of Skolemisation. | 14 | * Approximates existential rules through a limited form of Skolemisation. |
| @@ -24,7 +25,6 @@ public class LimitedSkolemisationApproximator implements TupleDependentApproxima | |||
| 24 | private final int maxTermDepth; | 25 | private final int maxTermDepth; |
| 25 | private final TupleDependentApproximator alternativeApproximator; | 26 | private final TupleDependentApproximator alternativeApproximator; |
| 26 | private final SkolemTermsManager skolemTermsManager; | 27 | private final SkolemTermsManager skolemTermsManager; |
| 27 | private Map<AnswerTupleID, Integer> mapIndividualsToDepth; | ||
| 28 | 28 | ||
| 29 | public LimitedSkolemisationApproximator(int maxTermDepth) { | 29 | public LimitedSkolemisationApproximator(int maxTermDepth) { |
| 30 | this(maxTermDepth, new ExistConstantApproximator()); | 30 | this(maxTermDepth, new ExistConstantApproximator()); |
| @@ -33,7 +33,6 @@ public class LimitedSkolemisationApproximator implements TupleDependentApproxima | |||
| 33 | public LimitedSkolemisationApproximator(int maxTermDepth, TupleDependentApproximator alternativeApproximator) { | 33 | public LimitedSkolemisationApproximator(int maxTermDepth, TupleDependentApproximator alternativeApproximator) { |
| 34 | this.maxTermDepth = maxTermDepth; | 34 | this.maxTermDepth = maxTermDepth; |
| 35 | this.alternativeApproximator = alternativeApproximator; | 35 | this.alternativeApproximator = alternativeApproximator; |
| 36 | this.mapIndividualsToDepth = new HashMap<>(); | ||
| 37 | this.skolemTermsManager = SkolemTermsManager.getInstance(); | 36 | this.skolemTermsManager = SkolemTermsManager.getInstance(); |
| 38 | } | 37 | } |
| 39 | 38 | ||
| @@ -144,7 +143,7 @@ public class LimitedSkolemisationApproximator implements TupleDependentApproxima | |||
| 144 | public int getMaxDepth(Tuple<Individual> violationTuple) { | 143 | public int getMaxDepth(Tuple<Individual> violationTuple) { |
| 145 | int maxDepth = 0; | 144 | int maxDepth = 0; |
| 146 | for (Individual individual : violationTuple) | 145 | for (Individual individual : violationTuple) |
| 147 | maxDepth = Integer.max(maxDepth, skolemTermsManager.getDepth(individual)); | 146 | maxDepth = Integer.max(maxDepth, skolemTermsManager.getDepthOf(individual)); |
| 148 | 147 | ||
| 149 | return maxDepth; | 148 | return maxDepth; |
| 150 | } | 149 | } |
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 0c12a27..368c014 100644 --- a/src/uk/ac/ox/cs/pagoda/rules/approximators/SkolemTermsManager.java +++ b/src/uk/ac/ox/cs/pagoda/rules/approximators/SkolemTermsManager.java | |||
| @@ -12,38 +12,56 @@ import java.util.Map; | |||
| 12 | */ | 12 | */ |
| 13 | public class SkolemTermsManager { | 13 | public class SkolemTermsManager { |
| 14 | 14 | ||
| 15 | public static final String skolemisedIndividualPrefix = Namespace.PAGODA_ANONY + "individual"; | 15 | public static final String SKOLEMISED_INDIVIDUAL_PREFIX = Namespace.PAGODA_ANONY + "individual"; |
| 16 | 16 | ||
| 17 | private static SkolemTermsManager skolemTermsManager; | 17 | private static SkolemTermsManager skolemTermsManager; |
| 18 | 18 | ||
| 19 | private int individualCounter = 0; | 19 | private int termsCounter = 0; |
| 20 | private Map<DLClause, Integer> termNumber = new HashMap<>(); | 20 | private Map<DLClause, Integer> mapClauseToId = new HashMap<>(); |
| 21 | private Map<Individual, Integer> mapIndividualToDepth = new HashMap<>(); | 21 | private Map<Individual, Integer> mapTermToDepth = new HashMap<>(); |
| 22 | private int dependenciesCounter = 0; | 22 | private int dependenciesCounter = 0; |
| 23 | 23 | ||
| 24 | // 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 get only a different upper bound model. |
| 25 | // or, better, use perfect hashing (i.e. devise an ad-hoc hash function without collisions) | 25 | // TODO you can use a cash. |
| 26 | private Map<Tuple<Individual>, Integer> mapDependencyToId = new HashMap<>(); | 26 | private Map<Tuple<Individual>, Integer> mapDependencyToId = new HashMap<>(); |
| 27 | 27 | ||
| 28 | private SkolemTermsManager() { | ||
| 29 | } | ||
| 30 | |||
| 31 | public static int indexOfSkolemisedIndividual(Atom atom) { | ||
| 32 | Term t; | ||
| 33 | for(int index = 0; index < atom.getArity(); ++index) { | ||
| 34 | t = atom.getArgument(index); | ||
| 35 | if(t instanceof Individual && ((Individual) t).getIRI().contains(SKOLEMISED_INDIVIDUAL_PREFIX)) | ||
| 36 | return index; | ||
| 37 | } | ||
| 38 | return -1; | ||
| 39 | } | ||
| 40 | |||
| 41 | public static SkolemTermsManager getInstance() { | ||
| 42 | if(skolemTermsManager == null) skolemTermsManager = new SkolemTermsManager(); | ||
| 43 | return skolemTermsManager; | ||
| 44 | } | ||
| 45 | |||
| 28 | /** | 46 | /** |
| 29 | * Get a fresh Individual, unique for the clause, the offset and the dependency. | 47 | * Get a fresh Individual, unique for the clause, the offset and the dependency. |
| 30 | * */ | 48 | * */ |
| 31 | public Individual getFreshIndividual(DLClause originalClause, int offset, Tuple<Individual> dependency) { | 49 | public Individual getFreshIndividual(DLClause originalClause, int offset, Tuple<Individual> dependency) { |
| 32 | if (!termNumber.containsKey(originalClause)) { | 50 | if(!mapClauseToId.containsKey(originalClause)) { |
| 33 | termNumber.put(originalClause, individualCounter); | 51 | mapClauseToId.put(originalClause, termsCounter); |
| 34 | individualCounter += noOfExistential(originalClause); | 52 | termsCounter += noOfExistential(originalClause); |
| 35 | } | 53 | } |
| 36 | if (!mapDependencyToId.containsKey(dependency)) { | 54 | if (!mapDependencyToId.containsKey(dependency)) { |
| 37 | mapDependencyToId.put(dependency, dependenciesCounter++); | 55 | mapDependencyToId.put(dependency, dependenciesCounter++); |
| 38 | } | 56 | } |
| 39 | 57 | ||
| 40 | String termId = termNumber.get(originalClause) + offset + "_" + mapDependencyToId(dependency); | 58 | String termId = mapClauseToId.get(originalClause) + offset + "_" + mapDependencyToId(dependency); |
| 41 | Individual newIndividual = Individual.create(skolemisedIndividualPrefix + termId); | 59 | Individual newIndividual = Individual.create(SKOLEMISED_INDIVIDUAL_PREFIX + termId); |
| 42 | 60 | ||
| 43 | int depth = 0; | 61 | int depth = 0; |
| 44 | for (Individual individual : dependency) | 62 | for (Individual individual : dependency) |
| 45 | depth = Integer.max(depth, mapIndividualToDepth(individual)); | 63 | depth = Integer.max(depth, mapIndividualToDepth(individual)); |
| 46 | mapIndividualToDepth.put(newIndividual, depth); | 64 | mapTermToDepth.put(newIndividual, depth); |
| 47 | 65 | ||
| 48 | return newIndividual; | 66 | return newIndividual; |
| 49 | } | 67 | } |
| @@ -52,14 +70,14 @@ public class SkolemTermsManager { | |||
| 52 | * Get a fresh Individual, unique for the clause and the offset. | 70 | * Get a fresh Individual, unique for the clause and the offset. |
| 53 | * */ | 71 | * */ |
| 54 | public Individual getFreshIndividual(DLClause originalClause, int offset) { | 72 | public Individual getFreshIndividual(DLClause originalClause, int offset) { |
| 55 | if (!termNumber.containsKey(originalClause)) { | 73 | if(!mapClauseToId.containsKey(originalClause)) { |
| 56 | termNumber.put(originalClause, individualCounter); | 74 | mapClauseToId.put(originalClause, termsCounter); |
| 57 | individualCounter += noOfExistential(originalClause); | 75 | termsCounter += noOfExistential(originalClause); |
| 58 | } | 76 | } |
| 59 | 77 | ||
| 60 | String termId = "" + termNumber.get(originalClause) + offset; | 78 | String termId = "" + mapClauseToId.get(originalClause) + offset; |
| 61 | Individual newIndividual = Individual.create(skolemisedIndividualPrefix + termId); | 79 | Individual newIndividual = Individual.create(SKOLEMISED_INDIVIDUAL_PREFIX + termId); |
| 62 | mapIndividualToDepth.put(newIndividual, 0); | 80 | mapTermToDepth.put(newIndividual, 0); |
| 63 | 81 | ||
| 64 | return newIndividual; | 82 | return newIndividual; |
| 65 | } | 83 | } |
| @@ -69,7 +87,7 @@ public class SkolemTermsManager { | |||
| 69 | * <p> | 87 | * <p> |
| 70 | * The term must have been generated by this manager. | 88 | * The term must have been generated by this manager. |
| 71 | * */ | 89 | * */ |
| 72 | public int getDepth(Individual individual) { | 90 | public int getDepthOf(Individual individual) { |
| 73 | return mapIndividualToDepth(individual); | 91 | return mapIndividualToDepth(individual); |
| 74 | } | 92 | } |
| 75 | 93 | ||
| @@ -77,24 +95,7 @@ public class SkolemTermsManager { | |||
| 77 | * Get the number of individuals generated by this manager. | 95 | * Get the number of individuals generated by this manager. |
| 78 | * */ | 96 | * */ |
| 79 | public int getNumberOfSkolemisedIndividual() { | 97 | public int getNumberOfSkolemisedIndividual() { |
| 80 | return mapIndividualToDepth.keySet().size(); | 98 | return mapTermToDepth.keySet().size(); |
| 81 | } | ||
| 82 | |||
| 83 | public static int indexOfSkolemisedIndividual(Atom atom) { | ||
| 84 | Term t; | ||
| 85 | for (int index = 0; index < atom.getArity(); ++index) { | ||
| 86 | t = atom.getArgument(index); | ||
| 87 | if (t instanceof Individual && ((Individual) t).getIRI().contains(skolemisedIndividualPrefix)) return index; | ||
| 88 | } | ||
| 89 | return -1; | ||
| 90 | } | ||
| 91 | |||
| 92 | private SkolemTermsManager() { | ||
| 93 | } | ||
| 94 | |||
| 95 | public static SkolemTermsManager getInstance() { | ||
| 96 | if (skolemTermsManager == null) skolemTermsManager = new SkolemTermsManager(); | ||
| 97 | return skolemTermsManager; | ||
| 98 | } | 99 | } |
| 99 | 100 | ||
| 100 | private int mapDependencyToId(Tuple<Individual> dependency) { | 101 | private int mapDependencyToId(Tuple<Individual> dependency) { |
| @@ -103,7 +104,7 @@ public class SkolemTermsManager { | |||
| 103 | } | 104 | } |
| 104 | 105 | ||
| 105 | private int mapIndividualToDepth(Individual dependency) { | 106 | private int mapIndividualToDepth(Individual dependency) { |
| 106 | if (mapIndividualToDepth.containsKey(dependency)) return mapIndividualToDepth.get(dependency); | 107 | if(mapTermToDepth.containsKey(dependency)) return mapTermToDepth.get(dependency); |
| 107 | else return 0; | 108 | else return 0; |
| 108 | } | 109 | } |
| 109 | 110 | ||
