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/OWLEntityDependency.java | |
| parent | b1ac207612ee8b045244253fb94b866104bc34f2 (diff) | |
| download | ACQuA-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.java | 195 |
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 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.constraints; | ||
| 2 | |||
| 3 | import java.util.HashMap; | ||
| 4 | import java.util.HashSet; | ||
| 5 | import java.util.Map; | ||
| 6 | import java.util.Set; | ||
| 7 | |||
| 8 | import org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom; | ||
| 9 | import org.semanticweb.owlapi.model.OWLAxiom; | ||
| 10 | import org.semanticweb.owlapi.model.OWLClass; | ||
| 11 | import org.semanticweb.owlapi.model.OWLClassAssertionAxiom; | ||
| 12 | import org.semanticweb.owlapi.model.OWLClassExpression; | ||
| 13 | import org.semanticweb.owlapi.model.OWLDataPropertyDomainAxiom; | ||
| 14 | import org.semanticweb.owlapi.model.OWLDataPropertyRangeAxiom; | ||
| 15 | import org.semanticweb.owlapi.model.OWLDeclarationAxiom; | ||
| 16 | import org.semanticweb.owlapi.model.OWLDisjointClassesAxiom; | ||
| 17 | import org.semanticweb.owlapi.model.OWLEquivalentClassesAxiom; | ||
| 18 | import org.semanticweb.owlapi.model.OWLEquivalentObjectPropertiesAxiom; | ||
| 19 | import org.semanticweb.owlapi.model.OWLFunctionalObjectPropertyAxiom; | ||
| 20 | import org.semanticweb.owlapi.model.OWLInverseFunctionalObjectPropertyAxiom; | ||
| 21 | import org.semanticweb.owlapi.model.OWLInverseObjectPropertiesAxiom; | ||
| 22 | import org.semanticweb.owlapi.model.OWLLogicalEntity; | ||
| 23 | import org.semanticweb.owlapi.model.OWLObject; | ||
| 24 | import org.semanticweb.owlapi.model.OWLObjectProperty; | ||
| 25 | import org.semanticweb.owlapi.model.OWLObjectPropertyAssertionAxiom; | ||
| 26 | import org.semanticweb.owlapi.model.OWLObjectPropertyDomainAxiom; | ||
| 27 | import org.semanticweb.owlapi.model.OWLObjectPropertyExpression; | ||
| 28 | import org.semanticweb.owlapi.model.OWLObjectPropertyRangeAxiom; | ||
| 29 | import org.semanticweb.owlapi.model.OWLOntology; | ||
| 30 | import org.semanticweb.owlapi.model.OWLSubClassOfAxiom; | ||
| 31 | import org.semanticweb.owlapi.model.OWLSubObjectPropertyOfAxiom; | ||
| 32 | import org.semanticweb.owlapi.model.OWLSymmetricObjectPropertyAxiom; | ||
| 33 | import org.semanticweb.owlapi.model.OWLTransitiveObjectPropertyAxiom; | ||
| 34 | |||
| 35 | import uk.ac.ox.cs.pagoda.MyPrefixes; | ||
| 36 | import uk.ac.ox.cs.pagoda.owl.OWLHelper; | ||
| 37 | import uk.ac.ox.cs.pagoda.util.Utility; | ||
| 38 | |||
| 39 | public 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 | } | ||
