diff options
| author | Federico Igne <federico.igne@cs.ox.ac.uk> | 2022-05-10 18:17:06 +0100 |
|---|---|---|
| committer | Federico Igne <federico.igne@cs.ox.ac.uk> | 2022-05-11 12:34:47 +0100 |
| commit | 17bd9beaf7f358a44e5bf36a5855fe6727d506dc (patch) | |
| tree | 47e9310a0cff869d9ec017dcb2c81876407782c8 /src/uk/ac/ox/cs/pagoda/tracking/TrackingRuleEncoderDisjVar2.java | |
| parent | 8651164cd632a5db310b457ce32d4fbc97bdc41c (diff) | |
| download | ACQuA-17bd9beaf7f358a44e5bf36a5855fe6727d506dc.tar.gz ACQuA-17bd9beaf7f358a44e5bf36a5855fe6727d506dc.zip | |
[pagoda] Move project to Scala
This commit includes a few changes:
- The repository still uses Maven to manage dependency but it is now a
Scala project.
- The code has been ported from OWLAPI 3.4.10 to 5.1.20
- A proof of concept program using both RSAComb and PAGOdA has been
added.
Diffstat (limited to 'src/uk/ac/ox/cs/pagoda/tracking/TrackingRuleEncoderDisjVar2.java')
| -rw-r--r-- | src/uk/ac/ox/cs/pagoda/tracking/TrackingRuleEncoderDisjVar2.java | 230 |
1 files changed, 0 insertions, 230 deletions
diff --git a/src/uk/ac/ox/cs/pagoda/tracking/TrackingRuleEncoderDisjVar2.java b/src/uk/ac/ox/cs/pagoda/tracking/TrackingRuleEncoderDisjVar2.java deleted file mode 100644 index 7311a86..0000000 --- a/src/uk/ac/ox/cs/pagoda/tracking/TrackingRuleEncoderDisjVar2.java +++ /dev/null | |||
| @@ -1,230 +0,0 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.tracking; | ||
| 2 | |||
| 3 | import org.semanticweb.HermiT.model.*; | ||
| 4 | import uk.ac.ox.cs.pagoda.hermit.DLClauseHelper; | ||
| 5 | import uk.ac.ox.cs.pagoda.multistage.Normalisation; | ||
| 6 | import uk.ac.ox.cs.pagoda.query.QueryRecord; | ||
| 7 | import uk.ac.ox.cs.pagoda.reasoner.light.BasicQueryEngine; | ||
| 8 | import uk.ac.ox.cs.pagoda.rules.UpperDatalogProgram; | ||
| 9 | import uk.ac.ox.cs.pagoda.rules.approximators.OverApproxExist; | ||
| 10 | import uk.ac.ox.cs.pagoda.util.Namespace; | ||
| 11 | |||
| 12 | import java.util.Collection; | ||
| 13 | import java.util.HashSet; | ||
| 14 | import java.util.LinkedList; | ||
| 15 | import java.util.Set; | ||
| 16 | |||
| 17 | public class TrackingRuleEncoderDisjVar2 extends TrackingRuleEncoderWithGap { | ||
| 18 | |||
| 19 | public TrackingRuleEncoderDisjVar2(UpperDatalogProgram program, BasicQueryEngine store) { | ||
| 20 | super(program, store); | ||
| 21 | } | ||
| 22 | |||
| 23 | private Set<DLClause> disjunctiveRules = new HashSet<DLClause>(); | ||
| 24 | |||
| 25 | @Override | ||
| 26 | public boolean encodingRules() { | ||
| 27 | if (ruleEncoded) return false; | ||
| 28 | ruleEncoded = true; | ||
| 29 | |||
| 30 | for (DLClause clause: program.getClauses()) { | ||
| 31 | encodingRule(clause); | ||
| 32 | } | ||
| 33 | |||
| 34 | if (disjunctiveRules.isEmpty()) | ||
| 35 | return true; | ||
| 36 | |||
| 37 | processDisjunctiveRules(); | ||
| 38 | return false; | ||
| 39 | } | ||
| 40 | |||
| 41 | @Override | ||
| 42 | protected void encodingRule(DLClause clause) { | ||
| 43 | DLClause original = program.getCorrespondingClause(clause); | ||
| 44 | if (original.getHeadLength() <= 1) { | ||
| 45 | super.encodingRule(clause); | ||
| 46 | } | ||
| 47 | else { | ||
| 48 | if (!DLClauseHelper.hasSubsetBodyAtoms(clause, original)) | ||
| 49 | super.encodingRule(clause); | ||
| 50 | addDisjunctiveRule(original); | ||
| 51 | } | ||
| 52 | } | ||
| 53 | |||
| 54 | private void processDisjunctiveRules() { | ||
| 55 | for (DLClause clause: disjunctiveRules) | ||
| 56 | encodingDisjunctiveRule(clause); | ||
| 57 | } | ||
| 58 | |||
| 59 | private Atom getAuxiliaryAtom(Atom headAtom) { | ||
| 60 | DLPredicate p = headAtom.getDLPredicate(); | ||
| 61 | if (p instanceof AtLeastConcept) { | ||
| 62 | return Atom.create(generateAuxiliaryRule((AtLeastConcept) p), headAtom.getArgument(0)); | ||
| 63 | } | ||
| 64 | if (p instanceof AtomicConcept) | ||
| 65 | return Atom.create(generateAuxiliaryRule((AtomicConcept) p), headAtom.getArgument(0)); | ||
| 66 | if (p instanceof AtomicRole) | ||
| 67 | return Atom.create(generateAuxiliaryRule((AtomicRole) p), headAtom.getArgument(0), headAtom.getArgument(1)); | ||
| 68 | if (p instanceof Equality || p instanceof AnnotatedEquality) | ||
| 69 | return Atom.create(generateAuxiliaryRule(Equality.INSTANCE), headAtom.getArgument(0), headAtom.getArgument(1)); | ||
| 70 | if (p instanceof Inequality) | ||
| 71 | return Atom.create(generateAuxiliaryRule((Inequality) p), headAtom.getArgument(0), headAtom.getArgument(1)); | ||
| 72 | |||
| 73 | return null; | ||
| 74 | } | ||
| 75 | |||
| 76 | private Atom getGapAtom(Atom headAtom) { | ||
| 77 | DLPredicate p = headAtom.getDLPredicate(); | ||
| 78 | if (p instanceof AtLeastConcept) { | ||
| 79 | return Atom.create(getGapDLPredicate(AtomicConcept.create(Normalisation.getAuxiliaryConcept4Disjunct((AtLeastConcept) p))), headAtom.getArgument(0)); | ||
| 80 | } | ||
| 81 | if (p instanceof AtomicConcept) | ||
| 82 | return Atom.create(getGapDLPredicate(p), headAtom.getArgument(0)); | ||
| 83 | if (p instanceof AtomicRole) | ||
| 84 | return Atom.create(getGapDLPredicate(p), headAtom.getArgument(0), headAtom.getArgument(1)); | ||
| 85 | if (p instanceof Equality || p instanceof AnnotatedEquality) | ||
| 86 | return Atom.create(getGapDLPredicate(Equality.INSTANCE), headAtom.getArgument(0), headAtom.getArgument(1)); | ||
| 87 | if (p instanceof Inequality) | ||
| 88 | return Atom.create(getGapDLPredicate(p), headAtom.getArgument(0), headAtom.getArgument(1)); | ||
| 89 | |||
| 90 | return null; | ||
| 91 | } | ||
| 92 | |||
| 93 | private void encodingDisjunctiveRule(DLClause clause) { | ||
| 94 | int headLength = clause.getHeadLength(); | ||
| 95 | |||
| 96 | Atom[] auxAtoms = new Atom[headLength]; | ||
| 97 | for (int i = 0; i < headLength; ++i) | ||
| 98 | auxAtoms[i] = getAuxiliaryAtom(clause.getHeadAtom(i)); | ||
| 99 | |||
| 100 | Atom[] gapAtoms = new Atom[headLength]; | ||
| 101 | for (int i = 0; i < headLength; ++i) | ||
| 102 | gapAtoms[i] = getGapAtom(clause.getHeadAtom(i)); | ||
| 103 | |||
| 104 | Atom[] bodyAtoms = clause.getBodyAtoms(); | ||
| 105 | |||
| 106 | LinkedList<Atom> newHeadAtoms = new LinkedList<Atom>(); | ||
| 107 | DLPredicate selected = AtomicConcept.create(getSelectedPredicate()); | ||
| 108 | newHeadAtoms.add(Atom.create(selected, getIndividual4GeneralRule(clause))); | ||
| 109 | |||
| 110 | for (Atom atom: bodyAtoms) { | ||
| 111 | Atom newAtom = Atom.create( | ||
| 112 | getTrackingDLPredicate(atom.getDLPredicate()), | ||
| 113 | DLClauseHelper.getArguments(atom)); | ||
| 114 | newHeadAtoms.add(newAtom); | ||
| 115 | } | ||
| 116 | |||
| 117 | DLClause newClause; | ||
| 118 | for (int j = 0; j < headLength; ++j) { | ||
| 119 | Atom[] newBodyAtoms = new Atom[headLength + bodyAtoms.length + 1]; | ||
| 120 | newBodyAtoms[0] = gapAtoms[j]; | ||
| 121 | |||
| 122 | for (int i = 0; i < headLength; ++i) | ||
| 123 | // newBodyAtoms[i] = auxAtoms[i]; | ||
| 124 | newBodyAtoms[i + 1] = auxAtoms[i]; | ||
| 125 | |||
| 126 | for (int i = 0; i < bodyAtoms.length; ++i) | ||
| 127 | // newBodyAtoms[i + headLength] = bodyAtoms[i]; | ||
| 128 | newBodyAtoms[i + headLength + 1] = bodyAtoms[i]; | ||
| 129 | |||
| 130 | for (Atom atom: newHeadAtoms) { | ||
| 131 | newClause = DLClause.create(new Atom[] {atom}, newBodyAtoms); | ||
| 132 | addTrackingClause(newClause); | ||
| 133 | } | ||
| 134 | } | ||
| 135 | } | ||
| 136 | |||
| 137 | private void addTrackingClause(DLClause clause) { | ||
| 138 | trackingClauses.add(clause); | ||
| 139 | } | ||
| 140 | |||
| 141 | private void addDisjunctiveRule(DLClause clause) { | ||
| 142 | disjunctiveRules.add(clause); | ||
| 143 | } | ||
| 144 | |||
| 145 | protected DLPredicate generateAuxiliaryRule(AtLeastConcept p) { | ||
| 146 | AtomicConcept ac = AtomicConcept.create(Normalisation.getAuxiliaryConcept4Disjunct(p)); | ||
| 147 | int num = p.getNumber(); | ||
| 148 | Variable X = Variable.create("X"); | ||
| 149 | Variable[] Ys = new Variable[num]; | ||
| 150 | for (int i = 0; i < num; ++i) Ys[i] = Variable.create("Y" + (i + 1)); | ||
| 151 | Collection<Atom> expandedAtom = new LinkedList<Atom>(); | ||
| 152 | Collection<Atom> representativeAtom = new LinkedList<Atom>(); | ||
| 153 | if (p.getOnRole() instanceof AtomicRole) { | ||
| 154 | AtomicRole r = (AtomicRole) p.getOnRole(); | ||
| 155 | for (int i = 0; i < num; ++i) | ||
| 156 | expandedAtom.add(Atom.create(r, X, Ys[i])); | ||
| 157 | representativeAtom.add(Atom.create(r, X, Ys[0])); | ||
| 158 | } | ||
| 159 | else { | ||
| 160 | AtomicRole r = ((InverseRole) p.getOnRole()).getInverseOf(); | ||
| 161 | for (int i = 0; i < num; ++i) | ||
| 162 | expandedAtom.add(Atom.create(r, Ys[i], X)); | ||
| 163 | representativeAtom.add(Atom.create(r, Ys[0], X)); | ||
| 164 | |||
| 165 | } | ||
| 166 | |||
| 167 | if (num > 1) { | ||
| 168 | representativeAtom.add(Atom.create(Inequality.INSTANCE, Ys[0], Ys[1])); | ||
| 169 | } | ||
| 170 | for (int i = 0; i < num; ++i) | ||
| 171 | for (int j = i + 1; j < num; ++i) | ||
| 172 | expandedAtom.add(Atom.create(Inequality.INSTANCE, Ys[i], Ys[j])); | ||
| 173 | |||
| 174 | if (!p.getToConcept().equals(AtomicConcept.THING)) { | ||
| 175 | AtomicConcept c; | ||
| 176 | if (p.getToConcept() instanceof AtomicConcept) | ||
| 177 | c = (AtomicConcept) p.getToConcept(); | ||
| 178 | else | ||
| 179 | c = OverApproxExist.getNegationConcept(((AtomicNegationConcept) p.getToConcept()).getNegatedAtomicConcept()); | ||
| 180 | for (int i = 0; i < num; ++i) | ||
| 181 | expandedAtom.add(Atom.create(c, Ys[i])); | ||
| 182 | representativeAtom.add(Atom.create(c, Ys[0])); | ||
| 183 | } | ||
| 184 | |||
| 185 | DLPredicate auxPredicate = getTrackingDLPredicate(ac); | ||
| 186 | DLPredicate gapPredicate = getGapDLPredicate(ac); | ||
| 187 | for (Atom atom: representativeAtom) { | ||
| 188 | Atom[] bodyAtoms = new Atom[expandedAtom.size() + 1]; | ||
| 189 | bodyAtoms[0] = getAuxiliaryAtom(atom); | ||
| 190 | int i = 0; | ||
| 191 | for (Atom bodyAtom: expandedAtom) | ||
| 192 | bodyAtoms[++i] = bodyAtom; | ||
| 193 | addTrackingClause(DLClause.create(new Atom[] {Atom.create(auxPredicate, X)}, bodyAtoms)); | ||
| 194 | |||
| 195 | bodyAtoms = new Atom[expandedAtom.size() + 1]; | ||
| 196 | if (atom.getArity() == 1) | ||
| 197 | bodyAtoms[0] = Atom.create(getGapDLPredicate(atom.getDLPredicate()), atom.getArgument(0)); | ||
| 198 | else | ||
| 199 | bodyAtoms[0] = Atom.create(getGapDLPredicate(atom.getDLPredicate()), atom.getArgument(0), atom.getArgument(1)); | ||
| 200 | i = 0; | ||
| 201 | for (Atom bodyAtom: expandedAtom) | ||
| 202 | bodyAtoms[++i] = bodyAtom; | ||
| 203 | addTrackingClause(DLClause.create(new Atom[] {Atom.create(gapPredicate, X)}, bodyAtoms)); | ||
| 204 | } | ||
| 205 | |||
| 206 | return auxPredicate; | ||
| 207 | } | ||
| 208 | |||
| 209 | private DLPredicate generateAuxiliaryRule(AtomicConcept p) { | ||
| 210 | return getTrackingDLPredicate(p); | ||
| 211 | } | ||
| 212 | |||
| 213 | private DLPredicate generateAuxiliaryRule(AtomicRole p) { | ||
| 214 | return getTrackingDLPredicate(p); | ||
| 215 | } | ||
| 216 | |||
| 217 | protected DLPredicate generateAuxiliaryRule(Equality instance) { | ||
| 218 | return getTrackingDLPredicate(AtomicRole.create(Namespace.EQUALITY)); | ||
| 219 | } | ||
| 220 | |||
| 221 | protected DLPredicate generateAuxiliaryRule(Inequality instance) { | ||
| 222 | return getTrackingDLPredicate(AtomicRole.create(Namespace.INEQUALITY)); | ||
| 223 | } | ||
| 224 | |||
| 225 | @Override | ||
| 226 | protected void encodingAtomicQuery(QueryRecord[] botQuerRecords) { | ||
| 227 | encodingAtomicQuery(botQuerRecords, true); | ||
| 228 | } | ||
| 229 | |||
| 230 | } | ||
