aboutsummaryrefslogtreecommitdiff
path: root/src/uk/ac/ox/cs/pagoda/constraints/OWLEntityDependency.java
diff options
context:
space:
mode:
authoryzhou <yujiao.zhou@gmail.com>2015-04-21 10:34:27 +0100
committeryzhou <yujiao.zhou@gmail.com>2015-04-21 10:34:27 +0100
commit9ce65c5a963b03ee97fe9cb6c5aa65a3c04a80a8 (patch)
tree47511c0fb89dccff0db4b5990522e04f294d795b /src/uk/ac/ox/cs/pagoda/constraints/OWLEntityDependency.java
parentb1ac207612ee8b045244253fb94b866104bc34f2 (diff)
downloadACQuA-9ce65c5a963b03ee97fe9cb6c5aa65a3c04a80a8.tar.gz
ACQuA-9ce65c5a963b03ee97fe9cb6c5aa65a3c04a80a8.zip
initial version
Diffstat (limited to 'src/uk/ac/ox/cs/pagoda/constraints/OWLEntityDependency.java')
-rw-r--r--src/uk/ac/ox/cs/pagoda/constraints/OWLEntityDependency.java195
1 files changed, 195 insertions, 0 deletions
diff --git a/src/uk/ac/ox/cs/pagoda/constraints/OWLEntityDependency.java b/src/uk/ac/ox/cs/pagoda/constraints/OWLEntityDependency.java
new file mode 100644
index 0000000..60fea28
--- /dev/null
+++ b/src/uk/ac/ox/cs/pagoda/constraints/OWLEntityDependency.java
@@ -0,0 +1,195 @@
1package uk.ac.ox.cs.pagoda.constraints;
2
3import java.util.HashMap;
4import java.util.HashSet;
5import java.util.Map;
6import java.util.Set;
7
8import org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom;
9import org.semanticweb.owlapi.model.OWLAxiom;
10import org.semanticweb.owlapi.model.OWLClass;
11import org.semanticweb.owlapi.model.OWLClassAssertionAxiom;
12import org.semanticweb.owlapi.model.OWLClassExpression;
13import org.semanticweb.owlapi.model.OWLDataPropertyDomainAxiom;
14import org.semanticweb.owlapi.model.OWLDataPropertyRangeAxiom;
15import org.semanticweb.owlapi.model.OWLDeclarationAxiom;
16import org.semanticweb.owlapi.model.OWLDisjointClassesAxiom;
17import org.semanticweb.owlapi.model.OWLEquivalentClassesAxiom;
18import org.semanticweb.owlapi.model.OWLEquivalentObjectPropertiesAxiom;
19import org.semanticweb.owlapi.model.OWLFunctionalObjectPropertyAxiom;
20import org.semanticweb.owlapi.model.OWLInverseFunctionalObjectPropertyAxiom;
21import org.semanticweb.owlapi.model.OWLInverseObjectPropertiesAxiom;
22import org.semanticweb.owlapi.model.OWLLogicalEntity;
23import org.semanticweb.owlapi.model.OWLObject;
24import org.semanticweb.owlapi.model.OWLObjectProperty;
25import org.semanticweb.owlapi.model.OWLObjectPropertyAssertionAxiom;
26import org.semanticweb.owlapi.model.OWLObjectPropertyDomainAxiom;
27import org.semanticweb.owlapi.model.OWLObjectPropertyExpression;
28import org.semanticweb.owlapi.model.OWLObjectPropertyRangeAxiom;
29import org.semanticweb.owlapi.model.OWLOntology;
30import org.semanticweb.owlapi.model.OWLSubClassOfAxiom;
31import org.semanticweb.owlapi.model.OWLSubObjectPropertyOfAxiom;
32import org.semanticweb.owlapi.model.OWLSymmetricObjectPropertyAxiom;
33import org.semanticweb.owlapi.model.OWLTransitiveObjectPropertyAxiom;
34
35import uk.ac.ox.cs.pagoda.MyPrefixes;
36import uk.ac.ox.cs.pagoda.owl.OWLHelper;
37import uk.ac.ox.cs.pagoda.util.Utility;
38
39public class OWLEntityDependency extends DependencyGraph<OWLLogicalEntity> {
40
41 OWLOntology m_ontology;
42 OWLClass m_nothing;
43 Map<String, OWLLogicalEntity> map = new HashMap<String, OWLLogicalEntity>();
44
45 public OWLEntityDependency(OWLOntology ontology) {
46 m_ontology = ontology;
47 m_nothing = ontology.getOWLOntologyManager().getOWLDataFactory().getOWLNothing();
48 build();
49 }
50
51 @Override
52 protected void build() {
53 for (OWLOntology o: m_ontology.getImportsClosure())
54 for (OWLAxiom a: o.getAxioms())
55 if (a instanceof OWLDisjointClassesAxiom)
56 addLinks((OWLDisjointClassesAxiom) a);
57 else if (a instanceof OWLSymmetricObjectPropertyAxiom)
58 addLinks((OWLSymmetricObjectPropertyAxiom) a);
59 else if (a instanceof OWLFunctionalObjectPropertyAxiom)
60 ;
61 else if (a instanceof OWLInverseFunctionalObjectPropertyAxiom)
62 ;
63 else if (a instanceof OWLTransitiveObjectPropertyAxiom)
64 addLinkes((OWLTransitiveObjectPropertyAxiom) a);
65 else if (a instanceof OWLInverseObjectPropertiesAxiom)
66 addLinks((OWLInverseObjectPropertiesAxiom) a);
67 else if (a instanceof OWLSubClassOfAxiom)
68 addLinks((OWLSubClassOfAxiom) a);
69 else if (a instanceof OWLSubObjectPropertyOfAxiom)
70 addLinks((OWLSubObjectPropertyOfAxiom) a);
71 else if (a instanceof OWLEquivalentClassesAxiom)
72 addLinks((OWLEquivalentClassesAxiom) a);
73 else if (a instanceof OWLEquivalentObjectPropertiesAxiom)
74 addLinks((OWLEquivalentObjectPropertiesAxiom) a);
75 else if (a instanceof OWLObjectPropertyDomainAxiom)
76 addLinks((OWLObjectPropertyDomainAxiom) a);
77 else if (a instanceof OWLObjectPropertyRangeAxiom)
78 addLinks((OWLObjectPropertyRangeAxiom) a);
79 else if (a instanceof OWLDataPropertyDomainAxiom)
80 addLinks((OWLDataPropertyDomainAxiom) a);
81 else if (a instanceof OWLDataPropertyRangeAxiom)
82 addLinks((OWLDataPropertyRangeAxiom) a);
83 else if (a instanceof OWLDeclarationAxiom)
84 ;
85 else if (a instanceof OWLAnnotationAssertionAxiom)
86 ;
87 else if (a instanceof OWLClassAssertionAxiom)
88 ;
89 else if (a instanceof OWLObjectPropertyAssertionAxiom)
90 ;
91 else {
92 Utility.logError("Unknowledge OWL Axiom: " + a.getClass().getName() + "\n" + a);
93 }
94// Utility.LOGS.info("DONE\n----------------------------");
95 }
96
97 private void addLinks(OWLDisjointClassesAxiom a) {
98 for (OWLClassExpression exp: a.getClassExpressions())
99 addLinks(exp, m_nothing);
100 }
101
102 private void addLinks(OWLSymmetricObjectPropertyAxiom a) {
103 // TODO Auto-generated method stub
104
105 }
106
107 private void addLinks(OWLInverseObjectPropertiesAxiom a) {
108 // TODO Auto-generated method stub
109
110 }
111
112 private void addLinks(OWLDataPropertyRangeAxiom a) {
113 addLinks(a.getProperty(), a.getRange());
114 }
115
116 private void addLinks(OWLDataPropertyDomainAxiom a) {
117 addLinks(a.getProperty(), a.getDomain());
118 }
119
120 private void addLinks(OWLEquivalentObjectPropertiesAxiom a) {
121 for (OWLObjectPropertyExpression exp1: a.getProperties())
122 for (OWLObjectPropertyExpression exp2: a.getProperties())
123 if(!exp1.equals(exp2))
124 addLinks(exp1, exp2);
125 }
126
127 private void addLinkes(OWLTransitiveObjectPropertyAxiom a) {
128 addLinks(a.getProperty(), a.getProperty());
129 }
130
131 private void addLinks(OWLObjectPropertyRangeAxiom a) {
132 addLinks(a.getProperty(), a.getRange());
133 }
134
135 private void addLinks(OWLObjectPropertyDomainAxiom a) {
136 addLinks(a.getProperty(), a.getDomain());
137
138 }
139
140 private void addLinks(OWLEquivalentClassesAxiom a) {
141 for (OWLClassExpression exp1: a.getClassExpressions())
142 for (OWLClassExpression exp2: a.getClassExpressions())
143 if (!exp1.equals(exp2))
144 addLinks(exp1, exp2);
145 }
146
147 private void addLinks(OWLSubObjectPropertyOfAxiom a) {
148 addLinks(a.getSubProperty(), a.getSuperProperty());
149 }
150
151 private void addLinks(OWLSubClassOfAxiom a) {
152 addLinks(a.getSubClass(), a.getSuperClass());
153
154 }
155
156 private void addLinks(OWLObject body, OWLObject head) {
157 Set<OWLLogicalEntity> bodyEntities = new HashSet<OWLLogicalEntity>();
158 Set<OWLLogicalEntity> headEntities = new HashSet<OWLLogicalEntity>();
159 for (OWLClass c: body.getClassesInSignature()) {
160 bodyEntities.add(c);
161 map.put(c.toStringID(), c);
162 }
163 for (OWLObjectProperty p: body.getObjectPropertiesInSignature()) {
164 bodyEntities.add(p);
165 map.put(p.toStringID(), p);
166 }
167
168 for (OWLClass c: head.getClassesInSignature()) {
169 headEntities.add(c);
170 map.put(c.toStringID(), c);
171 }
172 for (OWLObjectProperty p: head.getObjectPropertiesInSignature()) {
173 headEntities.add(p);
174 map.put(p.toString(), p);
175 }
176
177 for (OWLLogicalEntity subEntity: bodyEntities)
178 for (OWLLogicalEntity superEntity: headEntities)
179 addLink(subEntity, superEntity);
180 }
181
182 public OWLLogicalEntity getLogicalEntity(String iri) {
183 iri = MyPrefixes.PAGOdAPrefixes.expandIRI(iri);
184 return map.get(iri);
185 }
186
187 public static void main(String[] args) {
188 args = ("/users/yzhou/ontologies/uobm/univ-bench-dl.owl").split("\\ ");
189
190 OWLOntology onto = OWLHelper.loadOntology(args[0]);
191 OWLEntityDependency dependency = new OWLEntityDependency(onto);
192 dependency.output();
193 }
194
195}