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/constraints/UnaryBottom.java | |
| parent | b1ac207612ee8b045244253fb94b866104bc34f2 (diff) | |
| download | ACQuA-9ce65c5a963b03ee97fe9cb6c5aa65a3c04a80a8.tar.gz ACQuA-9ce65c5a963b03ee97fe9cb6c5aa65a3c04a80a8.zip | |
initial version
Diffstat (limited to 'src/uk/ac/ox/cs/pagoda/constraints/UnaryBottom.java')
| -rw-r--r-- | src/uk/ac/ox/cs/pagoda/constraints/UnaryBottom.java | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/src/uk/ac/ox/cs/pagoda/constraints/UnaryBottom.java b/src/uk/ac/ox/cs/pagoda/constraints/UnaryBottom.java new file mode 100644 index 0000000..5339c50 --- /dev/null +++ b/src/uk/ac/ox/cs/pagoda/constraints/UnaryBottom.java | |||
| @@ -0,0 +1,67 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.constraints; | ||
| 2 | |||
| 3 | import java.util.Collection; | ||
| 4 | import java.util.HashSet; | ||
| 5 | import java.util.LinkedList; | ||
| 6 | import java.util.Set; | ||
| 7 | |||
| 8 | import org.semanticweb.HermiT.model.Atom; | ||
| 9 | import org.semanticweb.HermiT.model.AtomicConcept; | ||
| 10 | import org.semanticweb.HermiT.model.DLClause; | ||
| 11 | import org.semanticweb.HermiT.model.Individual; | ||
| 12 | import org.semanticweb.HermiT.model.Term; | ||
| 13 | import org.semanticweb.HermiT.model.Variable; | ||
| 14 | |||
| 15 | public class UnaryBottom implements BottomStrategy { | ||
| 16 | |||
| 17 | @Override | ||
| 18 | public Collection<DLClause> process(Collection<DLClause> clauses) { | ||
| 19 | Collection<DLClause> ret = new LinkedList<DLClause>(); | ||
| 20 | for (DLClause clause: clauses) | ||
| 21 | if (clause.getHeadLength() == 0) { | ||
| 22 | ret.add(DLClause.create(getEmptyHead(pickRepresentative(clause.getBodyAtoms())), clause.getBodyAtoms())); | ||
| 23 | } | ||
| 24 | else | ||
| 25 | ret.add(clause); | ||
| 26 | return ret; | ||
| 27 | } | ||
| 28 | |||
| 29 | protected Term pickRepresentative(Atom[] atoms) { | ||
| 30 | Term rep = null; | ||
| 31 | Set<Variable> vars = new HashSet<Variable>(); | ||
| 32 | for (Atom atom: atoms) { | ||
| 33 | atom.getVariables(vars); | ||
| 34 | for (Variable v: vars) | ||
| 35 | if (rep == null || ((Variable) rep).getName().compareTo(v.getName()) > 0) | ||
| 36 | rep = v; | ||
| 37 | vars.clear(); | ||
| 38 | } | ||
| 39 | if (rep != null) return rep; | ||
| 40 | |||
| 41 | Set<Individual> inds = new HashSet<Individual>(); | ||
| 42 | for (Atom atom: atoms) { | ||
| 43 | atom.getIndividuals(inds); | ||
| 44 | for (Individual i: inds) | ||
| 45 | if (rep == null || ((Individual) rep).getIRI().compareTo(i.getIRI()) > 0) | ||
| 46 | rep = i; | ||
| 47 | inds.clear(); | ||
| 48 | } | ||
| 49 | |||
| 50 | return rep; | ||
| 51 | } | ||
| 52 | |||
| 53 | @Override | ||
| 54 | public boolean isBottomRule(DLClause clause) { | ||
| 55 | return clause.getHeadLength() == 1 && clause.getHeadAtom(0).getDLPredicate().equals(AtomicConcept.NOTHING); | ||
| 56 | } | ||
| 57 | |||
| 58 | public Atom[] getEmptyHead(Term t) { | ||
| 59 | return new Atom[] {Atom.create(AtomicConcept.NOTHING, t)}; | ||
| 60 | } | ||
| 61 | |||
| 62 | @Override | ||
| 63 | public int getBottomNumber() { | ||
| 64 | return 1; | ||
| 65 | } | ||
| 66 | |||
| 67 | } | ||
