diff options
Diffstat (limited to 'src/uk/ac/ox/cs/pagoda/tracking/TrackingRuleEncoderWithGap.java')
| -rw-r--r-- | src/uk/ac/ox/cs/pagoda/tracking/TrackingRuleEncoderWithGap.java | 116 |
1 files changed, 0 insertions, 116 deletions
diff --git a/src/uk/ac/ox/cs/pagoda/tracking/TrackingRuleEncoderWithGap.java b/src/uk/ac/ox/cs/pagoda/tracking/TrackingRuleEncoderWithGap.java deleted file mode 100644 index 4ece796..0000000 --- a/src/uk/ac/ox/cs/pagoda/tracking/TrackingRuleEncoderWithGap.java +++ /dev/null | |||
| @@ -1,116 +0,0 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.tracking; | ||
| 2 | |||
| 3 | import org.semanticweb.HermiT.model.*; | ||
| 4 | import org.semanticweb.owlapi.model.IRI; | ||
| 5 | import org.semanticweb.owlapi.model.OWLClass; | ||
| 6 | import org.semanticweb.owlapi.model.OWLObjectProperty; | ||
| 7 | import org.semanticweb.owlapi.model.OWLOntology; | ||
| 8 | import uk.ac.ox.cs.pagoda.hermit.DLClauseHelper; | ||
| 9 | import uk.ac.ox.cs.pagoda.query.GapTupleIterator; | ||
| 10 | import uk.ac.ox.cs.pagoda.reasoner.light.BasicQueryEngine; | ||
| 11 | import uk.ac.ox.cs.pagoda.rules.UpperDatalogProgram; | ||
| 12 | import uk.ac.ox.cs.pagoda.util.Namespace; | ||
| 13 | |||
| 14 | import java.util.Collection; | ||
| 15 | import java.util.HashSet; | ||
| 16 | import java.util.LinkedList; | ||
| 17 | import java.util.Set; | ||
| 18 | |||
| 19 | public class TrackingRuleEncoderWithGap extends TrackingRuleEncoder { | ||
| 20 | |||
| 21 | public TrackingRuleEncoderWithGap(UpperDatalogProgram program, BasicQueryEngine store) { | ||
| 22 | super(program, store); | ||
| 23 | } | ||
| 24 | |||
| 25 | @Override | ||
| 26 | protected String getEqualityRelatedRuleText() { | ||
| 27 | if (equalityRelatedRuleText != null) return equalityRelatedRuleText.replace("_tn", getTrackingPredicate("")); | ||
| 28 | |||
| 29 | Collection<DLClause> equalityRelatedClauses = new LinkedList<DLClause>(); | ||
| 30 | Variable X = Variable.create("X"); | ||
| 31 | AtomicRole trackingSameAs = AtomicRole.create(Namespace.EQUALITY + "_tn"); | ||
| 32 | OWLOntology onto = program.getOntology(); | ||
| 33 | Atom[] headAtom = new Atom[]{Atom.create(trackingSameAs, X, X)}, bodyAtom; | ||
| 34 | for(OWLOntology o : onto.getImportsClosure()) | ||
| 35 | for(OWLClass cls : o.getClassesInSignature()) { | ||
| 36 | String clsIRI = cls.getIRI().toString(); | ||
| 37 | unaryPredicates.add(clsIRI); | ||
| 38 | bodyAtom = new Atom[] { | ||
| 39 | Atom.create(AtomicConcept.create(clsIRI + "_tn"), X), | ||
| 40 | Atom.create(AtomicConcept.create(GapTupleIterator.getGapPredicate(clsIRI)), X)}; | ||
| 41 | equalityRelatedClauses.add(DLClause.create(headAtom, bodyAtom)); | ||
| 42 | } | ||
| 43 | |||
| 44 | Variable Y = Variable.create("Y"); | ||
| 45 | Set<OWLObjectProperty> setOfProperties = new HashSet<OWLObjectProperty>(); | ||
| 46 | for(OWLOntology o : onto.getImportsClosure()) | ||
| 47 | for(OWLObjectProperty prop : o.getObjectPropertiesInSignature()) | ||
| 48 | setOfProperties.add(prop); | ||
| 49 | setOfProperties.add(onto.getOWLOntologyManager() | ||
| 50 | .getOWLDataFactory() | ||
| 51 | .getOWLObjectProperty(IRI.create(Namespace.INEQUALITY))); | ||
| 52 | for(OWLObjectProperty prop : setOfProperties) { | ||
| 53 | String propIRI = prop.getIRI().toString(); | ||
| 54 | binaryPredicates.add(propIRI); | ||
| 55 | AtomicRole trackingRole = AtomicRole.create(propIRI + "_tn"); | ||
| 56 | AtomicRole gapRole = AtomicRole.create(GapTupleIterator.getGapPredicate(propIRI)); | ||
| 57 | // AtomicRole role = AtomicRole.create(propIRI); | ||
| 58 | bodyAtom = new Atom[] { | ||
| 59 | Atom.create(trackingRole, X, Y), | ||
| 60 | Atom.create(gapRole, X, Y)}; | ||
| 61 | equalityRelatedClauses.add(DLClause.create(headAtom, bodyAtom)); | ||
| 62 | |||
| 63 | bodyAtom = new Atom[] { | ||
| 64 | Atom.create(trackingRole, Y, X), | ||
| 65 | Atom.create(gapRole, Y, X)}; | ||
| 66 | equalityRelatedClauses.add(DLClause.create(headAtom, bodyAtom)); | ||
| 67 | } | ||
| 68 | |||
| 69 | equalityRelatedClauses.add( | ||
| 70 | DLClause.create( | ||
| 71 | new Atom[] {Atom.create(trackingSameAs, Y, X)}, | ||
| 72 | new Atom[] {Atom.create(trackingSameAs, X, Y)})); | ||
| 73 | |||
| 74 | equalityRelatedRuleText = DLClauseHelper.toString(equalityRelatedClauses).toString(); | ||
| 75 | return equalityRelatedRuleText.replace("_tn", getTrackingPredicate("")); | ||
| 76 | } | ||
| 77 | |||
| 78 | @Override | ||
| 79 | protected void encodingRule(DLClause clause) { | ||
| 80 | LinkedList<Atom> newHeadAtoms = new LinkedList<Atom>(); | ||
| 81 | newHeadAtoms.add(Atom.create(selected, getIndividual4GeneralRule(clause))); | ||
| 82 | |||
| 83 | Atom headAtom; | ||
| 84 | for (Atom atom: clause.getBodyAtoms()) { | ||
| 85 | headAtom = Atom.create( | ||
| 86 | getTrackingDLPredicate(atom.getDLPredicate()), | ||
| 87 | DLClauseHelper.getArguments(atom)); | ||
| 88 | newHeadAtoms.add(headAtom); | ||
| 89 | } | ||
| 90 | |||
| 91 | DLClause newClause; | ||
| 92 | headAtom = clause.getHeadAtom(0); | ||
| 93 | |||
| 94 | boolean equalityHead = headAtom.getDLPredicate() instanceof Equality || headAtom.getDLPredicate() instanceof AnnotatedEquality; | ||
| 95 | int offset = (equalityHead || (clause.getBodyLength() == 1 && clause.getBodyAtom(0).getDLPredicate().toString().contains("owl:Nothing"))) ? 1 : 2; | ||
| 96 | |||
| 97 | Atom[] newBodyAtoms = new Atom[clause.getBodyLength() + offset]; | ||
| 98 | newBodyAtoms[0] = Atom.create( | ||
| 99 | getTrackingDLPredicate(headAtom.getDLPredicate()), | ||
| 100 | DLClauseHelper.getArguments(headAtom)); | ||
| 101 | |||
| 102 | if (offset == 2) | ||
| 103 | newBodyAtoms[1] = Atom.create( | ||
| 104 | getGapDLPredicate(headAtom.getDLPredicate()), | ||
| 105 | DLClauseHelper.getArguments(headAtom)); | ||
| 106 | |||
| 107 | for (int i = 0; i < clause.getBodyLength(); ++i) | ||
| 108 | newBodyAtoms[i + offset] = clause.getBodyAtom(i); | ||
| 109 | |||
| 110 | for (Atom atom: newHeadAtoms) { | ||
| 111 | newClause = DLClause.create(new Atom[] {atom}, newBodyAtoms); | ||
| 112 | trackingClauses.add(newClause); | ||
| 113 | } | ||
| 114 | |||
| 115 | } | ||
| 116 | } | ||
