diff options
Diffstat (limited to 'src/main/scala/rsacomb/RSAAxiom.scala')
| -rw-r--r-- | src/main/scala/rsacomb/RSAAxiom.scala | 155 |
1 files changed, 0 insertions, 155 deletions
diff --git a/src/main/scala/rsacomb/RSAAxiom.scala b/src/main/scala/rsacomb/RSAAxiom.scala deleted file mode 100644 index 08de5b7..0000000 --- a/src/main/scala/rsacomb/RSAAxiom.scala +++ /dev/null | |||
| @@ -1,155 +0,0 @@ | |||
| 1 | package rsacomb | ||
| 2 | |||
| 3 | /* Java imports */ | ||
| 4 | import org.semanticweb.owlapi.model.{ | ||
| 5 | OWLAxiom, | ||
| 6 | OWLSubClassOfAxiom, | ||
| 7 | OWLEquivalentClassesAxiom | ||
| 8 | } | ||
| 9 | import org.semanticweb.owlapi.model.{ | ||
| 10 | OWLObjectPropertyExpression, | ||
| 11 | OWLSubObjectPropertyOfAxiom, | ||
| 12 | OWLClass, | ||
| 13 | OWLClassExpression, | ||
| 14 | OWLObjectSomeValuesFrom, | ||
| 15 | OWLObjectMaxCardinality | ||
| 16 | } | ||
| 17 | import org.semanticweb.owlapi.model.ClassExpressionType | ||
| 18 | import org.semanticweb.owlapi.model.{ | ||
| 19 | OWLAxiomVisitorEx, | ||
| 20 | OWLClassExpressionVisitorEx | ||
| 21 | } | ||
| 22 | import org.semanticweb.owlapi.model.OWLObjectProperty | ||
| 23 | import scala.collection.JavaConverters._ | ||
| 24 | |||
| 25 | /* Wrapper trait for the implicit class `RSAAxiom`. | ||
| 26 | */ | ||
| 27 | trait RSAAxiom { | ||
| 28 | |||
| 29 | /* Identifies some of the axiom types in a Horn-ALCHOIQ ontology | ||
| 30 | * in normal form. Refer to the paper for more details on the | ||
| 31 | * chosen names. | ||
| 32 | */ | ||
| 33 | private sealed trait RSAAxiomType | ||
| 34 | private object RSAAxiomType { | ||
| 35 | case object T3 extends RSAAxiomType // ∃R.A ⊑ B | ||
| 36 | case object T3top extends RSAAxiomType // ∃R.⊤ ⊑ B | ||
| 37 | case object T4 extends RSAAxiomType // A ⊑ ≤1R.B | ||
| 38 | case object T5 extends RSAAxiomType // A ⊑ ∃R.B | ||
| 39 | } | ||
| 40 | |||
| 41 | object RSAAxiom { | ||
| 42 | |||
| 43 | def hashed( | ||
| 44 | cls1: OWLClass, | ||
| 45 | prop: OWLObjectPropertyExpression, | ||
| 46 | cls2: OWLClass | ||
| 47 | ): String = | ||
| 48 | (cls1, prop, cls2).hashCode.toString | ||
| 49 | |||
| 50 | } | ||
| 51 | |||
| 52 | /* Implements additional features on top of `OWLAxiom` from | ||
| 53 | * the OWLAPI. | ||
| 54 | */ | ||
| 55 | implicit class RSAAxiom(axiom: OWLAxiom) { | ||
| 56 | |||
| 57 | /* Detecting axiom types: | ||
| 58 | * | ||
| 59 | * In order to reason about role unsafety in Horn-ALCHOIQ | ||
| 60 | * ontologies we need to detect and filter axioms by their | ||
| 61 | * "type". | ||
| 62 | * | ||
| 63 | * This is a simple implementation following the Visitor | ||
| 64 | * pattern imposed by the OWLAPI. | ||
| 65 | */ | ||
| 66 | private class RSAAxiomTypeDetector(t: RSAAxiomType) | ||
| 67 | extends OWLAxiomVisitorEx[Boolean] { | ||
| 68 | override def visit(axiom: OWLSubClassOfAxiom): Boolean = { | ||
| 69 | val sub = axiom.getSubClass().getClassExpressionType() | ||
| 70 | val sup = axiom.getSuperClass().getClassExpressionType() | ||
| 71 | t match { | ||
| 72 | case RSAAxiomType.T3top => // ∃R.⊤ ⊑ B | ||
| 73 | axiom.isT3 && axiom | ||
| 74 | .getSubClass() | ||
| 75 | .asInstanceOf[OWLObjectSomeValuesFrom] | ||
| 76 | .getFiller | ||
| 77 | .isOWLThing | ||
| 78 | case RSAAxiomType.T3 => // ∃R.A ⊑ B | ||
| 79 | sub == ClassExpressionType.OBJECT_SOME_VALUES_FROM && sup == ClassExpressionType.OWL_CLASS | ||
| 80 | case RSAAxiomType.T4 => // A ⊑ ≤1R.B | ||
| 81 | sub == ClassExpressionType.OWL_CLASS && sup == ClassExpressionType.OBJECT_MAX_CARDINALITY | ||
| 82 | case RSAAxiomType.T5 => // A ⊑ ∃R.B | ||
| 83 | sub == ClassExpressionType.OWL_CLASS && sup == ClassExpressionType.OBJECT_SOME_VALUES_FROM | ||
| 84 | } | ||
| 85 | } | ||
| 86 | |||
| 87 | override def visit(axiom: OWLEquivalentClassesAxiom): Boolean = { | ||
| 88 | // TODO | ||
| 89 | false | ||
| 90 | } | ||
| 91 | |||
| 92 | def doDefault(axiom: OWLAxiom): Boolean = false | ||
| 93 | } | ||
| 94 | |||
| 95 | private def isOfType(t: RSAAxiomType): Boolean = { | ||
| 96 | val visitor = new RSAAxiomTypeDetector(t) | ||
| 97 | axiom.accept(visitor) | ||
| 98 | } | ||
| 99 | |||
| 100 | /* Exposed methods */ | ||
| 101 | def isT3top: Boolean = isOfType(RSAAxiomType.T3top) | ||
| 102 | def isT3: Boolean = isOfType(RSAAxiomType.T3) | ||
| 103 | def isT4: Boolean = isOfType(RSAAxiomType.T4) | ||
| 104 | def isT5: Boolean = isOfType(RSAAxiomType.T5) | ||
| 105 | |||
| 106 | /* Extracting ObjectPropertyExpressions from axioms | ||
| 107 | * | ||
| 108 | * This extracts all ObjectPropertyExpressions from a given | ||
| 109 | * axiom. While the implementation is generic we use it on axioms | ||
| 110 | * of specific types (see above). | ||
| 111 | * | ||
| 112 | * NOTE: it is not possible to use the `objectPropertyInSignature` | ||
| 113 | * method of `OWLAxiom` because it returns all "role names" involved | ||
| 114 | * in the signature of an axiom. In particular we won't get the inverse | ||
| 115 | * of a role if this appears in the axiom (but we will get the role | ||
| 116 | * itself instead). | ||
| 117 | */ | ||
| 118 | lazy val objectPropertyExpressionsInSignature | ||
| 119 | : List[OWLObjectPropertyExpression] = | ||
| 120 | axiom match { | ||
| 121 | case a: OWLSubClassOfAxiom => | ||
| 122 | rolesInExpr(a.getSubClass) ++ rolesInExpr(a.getSuperClass) | ||
| 123 | case a: OWLEquivalentClassesAxiom => | ||
| 124 | a.getClassExpressions.asScala.toList.flatMap(rolesInExpr(_)) | ||
| 125 | case a: OWLSubObjectPropertyOfAxiom => | ||
| 126 | List(a.getSubProperty, a.getSuperProperty) | ||
| 127 | case _ => List() | ||
| 128 | } | ||
| 129 | |||
| 130 | private def rolesInExpr( | ||
| 131 | expr: OWLClassExpression | ||
| 132 | ): List[OWLObjectPropertyExpression] = | ||
| 133 | expr match { | ||
| 134 | case e: OWLObjectSomeValuesFrom => List(e.getProperty) | ||
| 135 | case e: OWLObjectMaxCardinality => List(e.getProperty) | ||
| 136 | case _ => List() | ||
| 137 | } | ||
| 138 | |||
| 139 | lazy val toTriple: Option[(OWLClass, OWLObjectProperty, OWLClass)] = | ||
| 140 | for { | ||
| 141 | subClass <- Some(axiom) collect { case a: OWLSubClassOfAxiom => a } | ||
| 142 | cls1 <- Some(subClass.getSubClass) collect { case a: OWLClass => a } | ||
| 143 | someValues <- Some(subClass.getSuperClass) collect { | ||
| 144 | case a: OWLObjectSomeValuesFrom => a | ||
| 145 | } | ||
| 146 | prop <- Some(someValues.getProperty) collect { | ||
| 147 | case a: OWLObjectProperty => a | ||
| 148 | } | ||
| 149 | cls2 <- Some(someValues.getFiller) collect { case a: OWLClass => a } | ||
| 150 | } yield (cls1, prop, cls2) | ||
| 151 | |||
| 152 | lazy val hashed: String = (RSAAxiom.hashed _) tupled toTriple.get | ||
| 153 | } | ||
| 154 | |||
| 155 | } // trait RSAAxiom | ||
