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/org/semanticweb/karma2/profile/ELHOProfile.java | |
| parent | b1ac207612ee8b045244253fb94b866104bc34f2 (diff) | |
| download | ACQuA-9ce65c5a963b03ee97fe9cb6c5aa65a3c04a80a8.tar.gz ACQuA-9ce65c5a963b03ee97fe9cb6c5aa65a3c04a80a8.zip | |
initial version
Diffstat (limited to 'src/org/semanticweb/karma2/profile/ELHOProfile.java')
| -rw-r--r-- | src/org/semanticweb/karma2/profile/ELHOProfile.java | 281 |
1 files changed, 281 insertions, 0 deletions
diff --git a/src/org/semanticweb/karma2/profile/ELHOProfile.java b/src/org/semanticweb/karma2/profile/ELHOProfile.java new file mode 100644 index 0000000..fb68b05 --- /dev/null +++ b/src/org/semanticweb/karma2/profile/ELHOProfile.java | |||
| @@ -0,0 +1,281 @@ | |||
| 1 | package org.semanticweb.karma2.profile; | ||
| 2 | |||
| 3 | import java.util.HashSet; | ||
| 4 | import java.util.Iterator; | ||
| 5 | import java.util.Set; | ||
| 6 | |||
| 7 | import org.semanticweb.owlapi.model.AxiomType; | ||
| 8 | import org.semanticweb.owlapi.model.IRI; | ||
| 9 | import org.semanticweb.owlapi.model.OWLAxiom; | ||
| 10 | import org.semanticweb.owlapi.model.OWLClassExpression; | ||
| 11 | import org.semanticweb.owlapi.model.OWLDataHasValue; | ||
| 12 | import org.semanticweb.owlapi.model.OWLDataIntersectionOf; | ||
| 13 | import org.semanticweb.owlapi.model.OWLDataOneOf; | ||
| 14 | import org.semanticweb.owlapi.model.OWLDataProperty; | ||
| 15 | import org.semanticweb.owlapi.model.OWLDataPropertyAssertionAxiom; | ||
| 16 | import org.semanticweb.owlapi.model.OWLDataPropertyDomainAxiom; | ||
| 17 | import org.semanticweb.owlapi.model.OWLDataPropertyRangeAxiom; | ||
| 18 | import org.semanticweb.owlapi.model.OWLDataSomeValuesFrom; | ||
| 19 | import org.semanticweb.owlapi.model.OWLEquivalentDataPropertiesAxiom; | ||
| 20 | import org.semanticweb.owlapi.model.OWLFunctionalDataPropertyAxiom; | ||
| 21 | import org.semanticweb.owlapi.model.OWLHasKeyAxiom; | ||
| 22 | import org.semanticweb.owlapi.model.OWLNegativeDataPropertyAssertionAxiom; | ||
| 23 | import org.semanticweb.owlapi.model.OWLNegativeObjectPropertyAssertionAxiom; | ||
| 24 | import org.semanticweb.owlapi.model.OWLObjectHasSelf; | ||
| 25 | import org.semanticweb.owlapi.model.OWLObjectMinCardinality; | ||
| 26 | import org.semanticweb.owlapi.model.OWLObjectOneOf; | ||
| 27 | import org.semanticweb.owlapi.model.OWLOntology; | ||
| 28 | import org.semanticweb.owlapi.model.OWLOntologyCreationException; | ||
| 29 | import org.semanticweb.owlapi.model.OWLOntologyManager; | ||
| 30 | import org.semanticweb.owlapi.model.OWLReflexiveObjectPropertyAxiom; | ||
| 31 | import org.semanticweb.owlapi.model.OWLSubDataPropertyOfAxiom; | ||
| 32 | import org.semanticweb.owlapi.model.OWLSubPropertyChainOfAxiom; | ||
| 33 | import org.semanticweb.owlapi.model.OWLTransitiveObjectPropertyAxiom; | ||
| 34 | import org.semanticweb.owlapi.profiles.OWL2ELProfile; | ||
| 35 | import org.semanticweb.owlapi.profiles.OWLProfile; | ||
| 36 | import org.semanticweb.owlapi.profiles.OWLProfileReport; | ||
| 37 | import org.semanticweb.owlapi.profiles.OWLProfileViolation; | ||
| 38 | import org.semanticweb.owlapi.profiles.UseOfDataOneOfWithMultipleLiterals; | ||
| 39 | import org.semanticweb.owlapi.profiles.UseOfIllegalAxiom; | ||
| 40 | import org.semanticweb.owlapi.profiles.UseOfIllegalClassExpression; | ||
| 41 | import org.semanticweb.owlapi.profiles.UseOfObjectOneOfWithMultipleIndividuals; | ||
| 42 | import org.semanticweb.owlapi.util.OWLObjectPropertyManager; | ||
| 43 | import org.semanticweb.owlapi.util.OWLOntologyWalker; | ||
| 44 | import org.semanticweb.owlapi.util.OWLOntologyWalkerVisitor; | ||
| 45 | import uk.ac.ox.cs.pagoda.util.Utility; | ||
| 46 | |||
| 47 | public class ELHOProfile implements OWLProfile { | ||
| 48 | |||
| 49 | public OWLOntology getFragment(OWLOntology ontology) { | ||
| 50 | OWLOntologyManager manager = ontology.getOWLOntologyManager(); | ||
| 51 | OWLOntology elhoOntology = null; | ||
| 52 | try { | ||
| 53 | Utility.logDebug("OntologyID: " + ontology.getOntologyID()); | ||
| 54 | try { | ||
| 55 | String ontologyIRI = ontology.getOntologyID().getOntologyIRI().toString(); | ||
| 56 | if (ontologyIRI.contains(".owl")) | ||
| 57 | ontologyIRI = ontologyIRI.replace(".owl", "-elho.owl"); | ||
| 58 | else | ||
| 59 | ontologyIRI = ontologyIRI + "elho"; | ||
| 60 | elhoOntology = manager.createOntology(IRI.create(ontologyIRI)); | ||
| 61 | } catch (NullPointerException e) { | ||
| 62 | // e.printStackTrace(); | ||
| 63 | elhoOntology = manager.createOntology(); | ||
| 64 | } | ||
| 65 | |||
| 66 | } catch (OWLOntologyCreationException e) { | ||
| 67 | e.printStackTrace(); | ||
| 68 | } | ||
| 69 | for (OWLOntology onto: ontology.getImportsClosure()) | ||
| 70 | manager.addAxioms(elhoOntology, onto.getAxioms()); | ||
| 71 | |||
| 72 | // TODO to be checked ... | ||
| 73 | manager.removeAxioms(elhoOntology, elhoOntology.getAxioms(AxiomType.DIFFERENT_INDIVIDUALS)); | ||
| 74 | |||
| 75 | OWLProfileReport report = checkOntology(elhoOntology); | ||
| 76 | |||
| 77 | for (OWLProfileViolation violation: report.getViolations()) { | ||
| 78 | OWLAxiom axiom = violation.getAxiom(); | ||
| 79 | manager.removeAxiom(elhoOntology, axiom); | ||
| 80 | } | ||
| 81 | Utility.logDebug("ELHO fragment extracted ... "); | ||
| 82 | |||
| 83 | return elhoOntology; | ||
| 84 | } | ||
| 85 | |||
| 86 | @Override | ||
| 87 | public OWLProfileReport checkOntology(OWLOntology ontology) { | ||
| 88 | OWL2ELProfile profile = new OWL2ELProfile(); | ||
| 89 | OWLProfileReport report = profile.checkOntology(ontology); | ||
| 90 | Set<OWLProfileViolation> violations = new HashSet<OWLProfileViolation>(); | ||
| 91 | violations.addAll(report.getViolations()); | ||
| 92 | MyOWLOntologyWalker ontologyWalker = new MyOWLOntologyWalker(ontology.getImportsClosure()); | ||
| 93 | ELHOProfileObjectVisitor visitor = new ELHOProfileObjectVisitor(ontologyWalker, ontology.getOWLOntologyManager()); | ||
| 94 | ontologyWalker.walkStructure(visitor); | ||
| 95 | |||
| 96 | for (Iterator<OWLProfileViolation> iter = violations.iterator(); iter.hasNext(); ) { | ||
| 97 | OWLProfileViolation vio = iter.next(); | ||
| 98 | if (vio instanceof UseOfIllegalClassExpression) { | ||
| 99 | OWLClassExpression exp = ((UseOfIllegalClassExpression) vio).getOWLClassExpression(); | ||
| 100 | if (exp instanceof OWLObjectMinCardinality && ((OWLObjectMinCardinality) exp).getCardinality() == 1) | ||
| 101 | iter.remove(); | ||
| 102 | } | ||
| 103 | } | ||
| 104 | |||
| 105 | violations.addAll(visitor.getProfileViolations()); | ||
| 106 | return new OWLProfileReport(this, violations); | ||
| 107 | } | ||
| 108 | |||
| 109 | @Override | ||
| 110 | public String getName() { | ||
| 111 | return "ELHO"; | ||
| 112 | } | ||
| 113 | |||
| 114 | protected class ELHOProfileObjectVisitor extends OWLOntologyWalkerVisitor<Object> { | ||
| 115 | |||
| 116 | private final OWLOntologyManager man; | ||
| 117 | |||
| 118 | private OWLObjectPropertyManager propertyManager; | ||
| 119 | |||
| 120 | private final Set<OWLProfileViolation> profileViolations = new HashSet<OWLProfileViolation>(); | ||
| 121 | |||
| 122 | public ELHOProfileObjectVisitor(OWLOntologyWalker walker, OWLOntologyManager man) { | ||
| 123 | super(walker); | ||
| 124 | this.man = man; | ||
| 125 | } | ||
| 126 | |||
| 127 | public Set<OWLProfileViolation> getProfileViolations() { | ||
| 128 | return new HashSet<OWLProfileViolation>(profileViolations); | ||
| 129 | } | ||
| 130 | |||
| 131 | @SuppressWarnings("unused") | ||
| 132 | private OWLObjectPropertyManager getPropertyManager() { | ||
| 133 | if (propertyManager == null) { | ||
| 134 | propertyManager = new OWLObjectPropertyManager(man, getCurrentOntology()); | ||
| 135 | } | ||
| 136 | return propertyManager; | ||
| 137 | } | ||
| 138 | |||
| 139 | |||
| 140 | |||
| 141 | @Override | ||
| 142 | public Object visit(OWLDataProperty p) { | ||
| 143 | profileViolations.add(new UseOfIllegalAxiom(getCurrentOntology(), getCurrentAxiom())); | ||
| 144 | return null; | ||
| 145 | } | ||
| 146 | |||
| 147 | |||
| 148 | @Override | ||
| 149 | public Object visit(OWLObjectOneOf desc) { | ||
| 150 | if (desc.getIndividuals().size() != 1) { | ||
| 151 | profileViolations.add(new UseOfObjectOneOfWithMultipleIndividuals(getCurrentOntology(), getCurrentAxiom(), desc)); | ||
| 152 | } | ||
| 153 | return null; | ||
| 154 | } | ||
| 155 | |||
| 156 | @Override | ||
| 157 | public Object visit(OWLDataHasValue desc) { | ||
| 158 | profileViolations.add(new UseOfIllegalClassExpression(getCurrentOntology(), getCurrentAxiom(), desc)); | ||
| 159 | return null; | ||
| 160 | } | ||
| 161 | |||
| 162 | @Override | ||
| 163 | public Object visit(OWLDataSomeValuesFrom desc) { | ||
| 164 | profileViolations.add(new UseOfIllegalClassExpression(getCurrentOntology(), getCurrentAxiom(), desc)); | ||
| 165 | return null; | ||
| 166 | } | ||
| 167 | |||
| 168 | @Override | ||
| 169 | public Object visit(OWLDataIntersectionOf desc) { | ||
| 170 | profileViolations.add(new UseOfIllegalAxiom(getCurrentOntology(), getCurrentAxiom())); | ||
| 171 | return null; | ||
| 172 | } | ||
| 173 | |||
| 174 | @Override | ||
| 175 | public Object visit(OWLSubDataPropertyOfAxiom desc) { | ||
| 176 | profileViolations.add(new UseOfIllegalAxiom(getCurrentOntology(), getCurrentAxiom())); | ||
| 177 | return null; | ||
| 178 | } | ||
| 179 | |||
| 180 | @Override | ||
| 181 | public Object visit(OWLEquivalentDataPropertiesAxiom desc) { | ||
| 182 | profileViolations.add(new UseOfIllegalAxiom(getCurrentOntology(), getCurrentAxiom())); | ||
| 183 | return null; | ||
| 184 | } | ||
| 185 | |||
| 186 | @Override | ||
| 187 | public Object visit(OWLTransitiveObjectPropertyAxiom desc) { | ||
| 188 | profileViolations.add(new UseOfIllegalAxiom(getCurrentOntology(), getCurrentAxiom())); | ||
| 189 | return null; | ||
| 190 | } | ||
| 191 | |||
| 192 | @Override | ||
| 193 | public Object visit(OWLReflexiveObjectPropertyAxiom desc) { | ||
| 194 | profileViolations.add(new UseOfIllegalAxiom(getCurrentOntology(), getCurrentAxiom())); | ||
| 195 | return null; | ||
| 196 | } | ||
| 197 | |||
| 198 | @Override | ||
| 199 | public Object visit(OWLDataPropertyDomainAxiom desc) { | ||
| 200 | profileViolations.add(new UseOfIllegalAxiom(getCurrentOntology(), getCurrentAxiom())); | ||
| 201 | return null; | ||
| 202 | } | ||
| 203 | |||
| 204 | @Override | ||
| 205 | public Object visit(OWLDataPropertyRangeAxiom desc) { | ||
| 206 | profileViolations.add(new UseOfIllegalAxiom(getCurrentOntology(), getCurrentAxiom())); | ||
| 207 | return null; | ||
| 208 | } | ||
| 209 | |||
| 210 | |||
| 211 | |||
| 212 | @Override | ||
| 213 | public Object visit(OWLDataPropertyAssertionAxiom desc) { | ||
| 214 | profileViolations.add(new UseOfIllegalAxiom(getCurrentOntology(), getCurrentAxiom())); | ||
| 215 | return null; | ||
| 216 | } | ||
| 217 | |||
| 218 | @Override | ||
| 219 | public Object visit(OWLNegativeDataPropertyAssertionAxiom desc) { | ||
| 220 | profileViolations.add(new UseOfIllegalAxiom(getCurrentOntology(), getCurrentAxiom())); | ||
| 221 | return null; | ||
| 222 | } | ||
| 223 | |||
| 224 | @Override | ||
| 225 | public Object visit(OWLNegativeObjectPropertyAssertionAxiom desc) { | ||
| 226 | profileViolations.add(new UseOfIllegalAxiom(getCurrentOntology(), getCurrentAxiom())); | ||
| 227 | return null; | ||
| 228 | } | ||
| 229 | |||
| 230 | @Override | ||
| 231 | public Object visit(OWLFunctionalDataPropertyAxiom desc) { | ||
| 232 | profileViolations.add(new UseOfIllegalAxiom(getCurrentOntology(), getCurrentAxiom())); | ||
| 233 | return null; | ||
| 234 | } | ||
| 235 | |||
| 236 | @Override | ||
| 237 | public Object visit(OWLHasKeyAxiom desc) { | ||
| 238 | profileViolations.add(new UseOfIllegalAxiom(getCurrentOntology(), getCurrentAxiom())); | ||
| 239 | return null; | ||
| 240 | } | ||
| 241 | |||
| 242 | |||
| 243 | |||
| 244 | |||
| 245 | @Override | ||
| 246 | public Object visit(OWLObjectHasSelf node) { | ||
| 247 | profileViolations.add(new UseOfIllegalClassExpression(getCurrentOntology(), getCurrentAxiom(), node)); | ||
| 248 | return null; | ||
| 249 | } | ||
| 250 | |||
| 251 | |||
| 252 | @Override | ||
| 253 | public Object visit(OWLDataOneOf node) { | ||
| 254 | profileViolations.add(new UseOfDataOneOfWithMultipleLiterals(getCurrentOntology(), getCurrentAxiom(), node)); | ||
| 255 | return null; | ||
| 256 | } | ||
| 257 | |||
| 258 | |||
| 259 | |||
| 260 | @Override | ||
| 261 | public Object visit(OWLSubPropertyChainOfAxiom axiom) { | ||
| 262 | profileViolations.add(new UseOfIllegalAxiom(getCurrentOntology(), getCurrentAxiom())); | ||
| 263 | |||
| 264 | return null; | ||
| 265 | } | ||
| 266 | |||
| 267 | @Override | ||
| 268 | public Object visit(OWLOntology ontology) { | ||
| 269 | propertyManager = null; | ||
| 270 | return null; | ||
| 271 | } | ||
| 272 | } | ||
| 273 | |||
| 274 | @Override | ||
| 275 | public IRI getIRI() { | ||
| 276 | return null; | ||
| 277 | } | ||
| 278 | |||
| 279 | |||
| 280 | } | ||
| 281 | |||
