diff options
Diffstat (limited to 'src/uk/ac/ox/cs/pagoda/rules/LimitedSkolemisationApproximator.java')
| -rw-r--r-- | src/uk/ac/ox/cs/pagoda/rules/LimitedSkolemisationApproximator.java | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/src/uk/ac/ox/cs/pagoda/rules/LimitedSkolemisationApproximator.java b/src/uk/ac/ox/cs/pagoda/rules/LimitedSkolemisationApproximator.java new file mode 100644 index 0000000..284edd2 --- /dev/null +++ b/src/uk/ac/ox/cs/pagoda/rules/LimitedSkolemisationApproximator.java | |||
| @@ -0,0 +1,72 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.rules; | ||
| 2 | |||
| 3 | import org.semanticweb.HermiT.model.DLClause; | ||
| 4 | import uk.ac.ox.cs.pagoda.multistage.AnswerTupleID; | ||
| 5 | |||
| 6 | import java.util.*; | ||
| 7 | |||
| 8 | /** | ||
| 9 | * Approximates existential rules by a limited form of Skolemisation. | ||
| 10 | * <p> | ||
| 11 | * Given a rule and a grounding substitution, | ||
| 12 | * it Skolemises the rule if | ||
| 13 | * all the terms in the substitution have depth less than a given depth, | ||
| 14 | * otherwise it approximates using an alternative <tt>TupleDependentApproximator</tt>. | ||
| 15 | * | ||
| 16 | * */ | ||
| 17 | public class LimitedSkolemisationApproximator implements TupleDependentApproximator { | ||
| 18 | |||
| 19 | private final int maxTermDepth; | ||
| 20 | private final TupleDependentApproximator alternativeApproximator; | ||
| 21 | |||
| 22 | private Map<AnswerTupleID, Integer> mapIndividualsToDepth; | ||
| 23 | |||
| 24 | public LimitedSkolemisationApproximator(int maxTermDepth) { | ||
| 25 | this(maxTermDepth, new ExistConstantApproximator()); | ||
| 26 | } | ||
| 27 | |||
| 28 | public LimitedSkolemisationApproximator(int maxTermDepth, TupleDependentApproximator alternativeApproximator) { | ||
| 29 | this.maxTermDepth = maxTermDepth; | ||
| 30 | this.alternativeApproximator = alternativeApproximator; | ||
| 31 | this.mapIndividualsToDepth = new HashMap<>(); | ||
| 32 | } | ||
| 33 | |||
| 34 | @Override | ||
| 35 | public Collection<DLClause> convert(DLClause clause, DLClause originalClause, Collection<AnswerTupleID> violationTuples) { | ||
| 36 | switch (clause.getHeadLength()) { | ||
| 37 | case 1: | ||
| 38 | return overApprox(clause, originalClause, violationTuples); | ||
| 39 | case 0: | ||
| 40 | return Arrays.asList(clause); | ||
| 41 | default: | ||
| 42 | ArrayList<DLClause> result = new ArrayList<>(); | ||
| 43 | // TODO implement | ||
| 44 | return result; | ||
| 45 | } | ||
| 46 | |||
| 47 | |||
| 48 | } | ||
| 49 | |||
| 50 | private Collection<DLClause> overApprox(DLClause clause, DLClause originalClause, Collection<AnswerTupleID> violationTuples) { | ||
| 51 | ArrayList<DLClause> result = new ArrayList<>(); | ||
| 52 | |||
| 53 | for (AnswerTupleID violationTuple : violationTuples) | ||
| 54 | if (getDepth(violationTuple) > maxTermDepth) | ||
| 55 | result.addAll(alternativeApproximator.convert(clause, originalClause, null)); | ||
| 56 | else | ||
| 57 | result.add(getInstantiatedSkolemisation(clause, originalClause, violationTuple)); | ||
| 58 | |||
| 59 | return result; | ||
| 60 | } | ||
| 61 | |||
| 62 | |||
| 63 | private DLClause getInstantiatedSkolemisation(DLClause clause, DLClause originalClause, AnswerTupleID violationTuple) { | ||
| 64 | // TODO implement | ||
| 65 | return null; | ||
| 66 | } | ||
| 67 | |||
| 68 | private int getDepth(AnswerTupleID violationTuple) { | ||
| 69 | if (!mapIndividualsToDepth.containsKey(violationTuple)) return 0; | ||
| 70 | return mapIndividualsToDepth.get(violationTuple); | ||
| 71 | } | ||
| 72 | } | ||
