aboutsummaryrefslogtreecommitdiff
path: root/src/uk/ac/ox/cs/pagoda/tracking/BottomFragmentManager.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/uk/ac/ox/cs/pagoda/tracking/BottomFragmentManager.java')
-rw-r--r--src/uk/ac/ox/cs/pagoda/tracking/BottomFragmentManager.java100
1 files changed, 100 insertions, 0 deletions
diff --git a/src/uk/ac/ox/cs/pagoda/tracking/BottomFragmentManager.java b/src/uk/ac/ox/cs/pagoda/tracking/BottomFragmentManager.java
new file mode 100644
index 0000000..09915e2
--- /dev/null
+++ b/src/uk/ac/ox/cs/pagoda/tracking/BottomFragmentManager.java
@@ -0,0 +1,100 @@
1package uk.ac.ox.cs.pagoda.tracking;
2
3import java.util.HashSet;
4import java.util.Set;
5
6import org.semanticweb.HermiT.model.AtomicConcept;
7import org.semanticweb.HermiT.model.AtomicRole;
8import org.semanticweb.HermiT.model.DLClause;
9import org.semanticweb.HermiT.model.DLPredicate;
10import org.semanticweb.owlapi.model.OWLAxiom;
11import org.semanticweb.owlapi.model.OWLClass;
12import org.semanticweb.owlapi.model.OWLClassAssertionAxiom;
13import org.semanticweb.owlapi.model.OWLDataProperty;
14import org.semanticweb.owlapi.model.OWLDataPropertyAssertionAxiom;
15import org.semanticweb.owlapi.model.OWLObjectProperty;
16import org.semanticweb.owlapi.model.OWLObjectPropertyAssertionAxiom;
17
18import uk.ac.ox.cs.pagoda.constraints.PredicateDependency;
19import uk.ac.ox.cs.pagoda.query.QueryRecord;
20import uk.ac.ox.cs.pagoda.rules.ApproxProgram;
21import uk.ac.ox.cs.pagoda.rules.GeneralProgram;
22import uk.ac.ox.cs.pagoda.util.Utility;
23
24public class BottomFragmentManager {
25
26 QueryRecord m_record;
27 GeneralProgram m_program;
28 PredicateDependency m_graph;
29
30 public BottomFragmentManager(QueryRecord record) {
31 m_record = record;
32 m_program = new GeneralProgram(record.getRelevantClauses(), record.getRelevantOntology());
33 m_graph = m_program.buildDependencyGraph();
34 }
35
36 public Set<DLClause> relevantClauses(Set<DLClause> disjuntiveRules) {
37 Set<DLClause> relevant = new HashSet<DLClause>();
38 Set<DLClause> now = new HashSet<DLClause>();
39 Set<DLClause> last = new HashSet<DLClause>();
40
41 for (DLClause rule: disjuntiveRules)
42 for (DLPredicate p: m_graph.collectPredicate(rule.getHeadAtoms()))
43 now.addAll(m_graph.pathToBottom(p));
44
45 while (!relevant.containsAll(now)) {
46 relevant.addAll(now);
47 last.clear();
48 last = now;
49 now = new HashSet<DLClause>();
50
51 for (DLClause rule: last) {
52 for (DLPredicate p: m_graph.collectPredicate(rule.getHeadAtoms()))
53 now.addAll(m_graph.pathToBottom(p));
54 for (DLPredicate p: m_graph.collectPredicate(rule.getBodyAtoms()))
55 now.addAll(m_graph.pathTo(p));
56 }
57 }
58
59 Utility.logDebug("There are " + relevant.size() + " clauses in the bottom fragment related to this query.");
60 return relevant;
61 }
62
63 public Set<OWLAxiom> relevantOntology(Set<DLClause> clauses, ApproxProgram upperProgram) {
64 Set<OWLAxiom> axioms = new HashSet<OWLAxiom>();
65 Set<DLPredicate> predicates = new HashSet<DLPredicate>();
66 for (DLClause clause: clauses) {
67 OWLAxiom axiom = upperProgram.getEquivalentAxiom(clause);
68 axioms.add(axiom);
69 predicates.addAll(m_graph.collectPredicate(clause.getHeadAtoms()));
70 predicates.addAll(m_graph.collectPredicate(clause.getBodyAtoms()));
71 }
72
73 int tboxCounter = axioms.size();
74 Utility.logDebug("There are " + tboxCounter + " TBox axioms in the bottom fragment related to this query.");
75 String name;
76 for (OWLAxiom axiom: m_record.getRelevantOntology().getABoxAxioms(true)) {
77 if (axiom instanceof OWLClassAssertionAxiom) {
78 OWLClass cls = (OWLClass) ((OWLClassAssertionAxiom) axiom).getClassExpression();
79 name = cls.getIRI().toString();
80 if (predicates.contains(AtomicConcept.create(name)))
81 axioms.add(axiom);
82 }
83 else if (axiom instanceof OWLObjectPropertyAssertionAxiom) {
84 OWLObjectProperty prop = (OWLObjectProperty) ((OWLObjectPropertyAssertionAxiom) axiom).getProperty();
85 name = prop.getIRI().toString();
86 if (predicates.contains(AtomicRole.create(name)))
87 axioms.add(axiom);
88 }
89 else if (axiom instanceof OWLDataPropertyAssertionAxiom) {
90 OWLDataProperty prop = (OWLDataProperty) ((OWLDataPropertyAssertionAxiom) axiom).getProperty();
91 name = prop.getIRI().toString();
92 if (predicates.contains(AtomicRole.create(name)))
93 axioms.add(axiom);
94 }
95 }
96
97 Utility.logDebug("There are " + (axioms.size() - tboxCounter) + " ABox axioms in the bottom fragment related to this query.");
98 return axioms;
99 }
100}