diff options
| author | yzhou <yujiao.zhou@gmail.com> | 2015-04-21 10:34:27 +0100 |
|---|---|---|
| committer | yzhou <yujiao.zhou@gmail.com> | 2015-04-21 10:34:27 +0100 |
| commit | 9ce65c5a963b03ee97fe9cb6c5aa65a3c04a80a8 (patch) | |
| tree | 47511c0fb89dccff0db4b5990522e04f294d795b /src/uk/ac/ox/cs/pagoda/rules/ApproxProgram.java | |
| parent | b1ac207612ee8b045244253fb94b866104bc34f2 (diff) | |
| download | ACQuA-9ce65c5a963b03ee97fe9cb6c5aa65a3c04a80a8.tar.gz ACQuA-9ce65c5a963b03ee97fe9cb6c5aa65a3c04a80a8.zip | |
initial version
Diffstat (limited to 'src/uk/ac/ox/cs/pagoda/rules/ApproxProgram.java')
| -rw-r--r-- | src/uk/ac/ox/cs/pagoda/rules/ApproxProgram.java | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/src/uk/ac/ox/cs/pagoda/rules/ApproxProgram.java b/src/uk/ac/ox/cs/pagoda/rules/ApproxProgram.java new file mode 100644 index 0000000..3b9d6fc --- /dev/null +++ b/src/uk/ac/ox/cs/pagoda/rules/ApproxProgram.java | |||
| @@ -0,0 +1,111 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.rules; | ||
| 2 | |||
| 3 | import java.util.Collection; | ||
| 4 | import java.util.HashMap; | ||
| 5 | import java.util.HashSet; | ||
| 6 | import java.util.Iterator; | ||
| 7 | import java.util.Map; | ||
| 8 | |||
| 9 | import org.semanticweb.HermiT.model.DLClause; | ||
| 10 | import org.semanticweb.owlapi.model.OWLAxiom; | ||
| 11 | import org.semanticweb.owlapi.model.OWLSubPropertyChainOfAxiom; | ||
| 12 | import org.semanticweb.owlapi.model.OWLTransitiveObjectPropertyAxiom; | ||
| 13 | |||
| 14 | import uk.ac.ox.cs.pagoda.owl.OWLHelper; | ||
| 15 | |||
| 16 | public abstract class ApproxProgram extends Program { | ||
| 17 | |||
| 18 | /** | ||
| 19 | * mapping from over-approximated DLClauses to DLClauses from the original ontology | ||
| 20 | */ | ||
| 21 | Map<DLClause, Object> correspondence = new HashMap<DLClause, Object>(); | ||
| 22 | |||
| 23 | protected Approximator m_approx = null; | ||
| 24 | |||
| 25 | protected ApproxProgram() { initApproximator(); } | ||
| 26 | |||
| 27 | protected abstract void initApproximator(); | ||
| 28 | |||
| 29 | @Override | ||
| 30 | public void transform() { | ||
| 31 | super.transform(); | ||
| 32 | Iterator<DLClause> iterClause = transitiveClauses.iterator(); | ||
| 33 | for (Iterator<OWLTransitiveObjectPropertyAxiom> iterAxiom = transitiveAxioms.iterator(); iterAxiom.hasNext(); ) | ||
| 34 | addCorrespondence(iterClause.next(), iterAxiom.next()); | ||
| 35 | |||
| 36 | iterClause = subPropChainClauses.iterator(); | ||
| 37 | for (Iterator<OWLSubPropertyChainOfAxiom> iterAxiom = subPropChainAxioms.iterator(); iterAxiom.hasNext(); ) | ||
| 38 | addCorrespondence(iterClause.next(), iterAxiom.next()); | ||
| 39 | } | ||
| 40 | |||
| 41 | @Override | ||
| 42 | public Collection<DLClause> convert2Clauses(DLClause clause) { | ||
| 43 | Collection<DLClause> ret = botStrategy.process(m_approx.convert(clause, clause)); | ||
| 44 | // OWLAxiom correspondingAxiom = OWLHelper.getOWLAxiom(ontology, clause); | ||
| 45 | for (DLClause newClause: ret) { | ||
| 46 | addCorrespondence(newClause, clause); | ||
| 47 | // addCorrespondence(newClause, correspondingAxiom); | ||
| 48 | } | ||
| 49 | return ret; | ||
| 50 | } | ||
| 51 | |||
| 52 | private void addCorrespondence(DLClause newClause, Object corresponding) { | ||
| 53 | Object object; | ||
| 54 | if ((object = correspondence.get(newClause)) != null) { | ||
| 55 | if (object.equals(corresponding)) | ||
| 56 | return ; | ||
| 57 | |||
| 58 | if (object instanceof DLClause) { | ||
| 59 | DLClause c1 = (DLClause) object; | ||
| 60 | if (c1.getHeadLength() == 1) return ; | ||
| 61 | DLClause c2 = (DLClause) corresponding; | ||
| 62 | if (c2.getHeadLength() == 1) { | ||
| 63 | correspondence.put(newClause, c2); | ||
| 64 | return ; | ||
| 65 | } | ||
| 66 | ClauseSet list = new ClauseSet(c1, c2); | ||
| 67 | correspondence.put(newClause, list); | ||
| 68 | } | ||
| 69 | else if (object instanceof ClauseSet){ | ||
| 70 | ClauseSet list = (ClauseSet) object; | ||
| 71 | list.add((DLClause) corresponding); | ||
| 72 | } | ||
| 73 | } | ||
| 74 | correspondence.put(newClause, corresponding); | ||
| 75 | } | ||
| 76 | |||
| 77 | public OWLAxiom getEquivalentAxiom(DLClause clause) { | ||
| 78 | Object obj = correspondence.get(clause); | ||
| 79 | while (obj != null && obj instanceof DLClause && !obj.equals(clause) && correspondence.containsKey((DLClause) obj)) | ||
| 80 | obj = correspondence.get(clause); | ||
| 81 | if (obj instanceof OWLAxiom) | ||
| 82 | return (OWLAxiom) obj; | ||
| 83 | else if (obj != null) | ||
| 84 | return OWLHelper.getOWLAxiom(ontology, (DLClause) obj); | ||
| 85 | else { | ||
| 86 | return OWLHelper.getOWLAxiom(ontology, clause); | ||
| 87 | } | ||
| 88 | } | ||
| 89 | |||
| 90 | public DLClause getCorrespondingClause(DLClause clause) { | ||
| 91 | Object obj = correspondence.get(clause); | ||
| 92 | if (obj instanceof DLClause) | ||
| 93 | return (DLClause) obj; | ||
| 94 | else | ||
| 95 | return clause; | ||
| 96 | } | ||
| 97 | } | ||
| 98 | |||
| 99 | class ClauseSet extends HashSet<DLClause> { | ||
| 100 | |||
| 101 | public ClauseSet(DLClause first, DLClause second) { | ||
| 102 | add(first); | ||
| 103 | add(second); | ||
| 104 | } | ||
| 105 | |||
| 106 | /** | ||
| 107 | * | ||
| 108 | */ | ||
| 109 | private static final long serialVersionUID = 1L; | ||
| 110 | |||
| 111 | } \ No newline at end of file | ||
