diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/main/scala/rsacomb/RSAAxiom.scala | 76 |
1 files changed, 18 insertions, 58 deletions
diff --git a/src/main/scala/rsacomb/RSAAxiom.scala b/src/main/scala/rsacomb/RSAAxiom.scala index f504bbe..3cd9a9d 100644 --- a/src/main/scala/rsacomb/RSAAxiom.scala +++ b/src/main/scala/rsacomb/RSAAxiom.scala | |||
| @@ -20,6 +20,7 @@ import org.semanticweb.owlapi.model.{ | |||
| 20 | OWLClassExpressionVisitorEx | 20 | OWLClassExpressionVisitorEx |
| 21 | } | 21 | } |
| 22 | import org.semanticweb.owlapi.model.OWLObjectProperty | 22 | import org.semanticweb.owlapi.model.OWLObjectProperty |
| 23 | import scala.collection.JavaConverters._ | ||
| 23 | 24 | ||
| 24 | /* Wrapper trait for the implicit class `RSAAxiom`. | 25 | /* Wrapper trait for the implicit class `RSAAxiom`. |
| 25 | */ | 26 | */ |
| @@ -103,68 +104,27 @@ trait RSAAxiom { | |||
| 103 | * of a role if this appears in the axiom (but we will get the role | 104 | * of a role if this appears in the axiom (but we will get the role |
| 104 | * itself instead). | 105 | * itself instead). |
| 105 | */ | 106 | */ |
| 106 | private class RSAAxiomRoleExtractor() | 107 | lazy val objectPropertyExpressionsInSignature |
| 107 | extends OWLAxiomVisitorEx[List[OWLObjectPropertyExpression]] { | 108 | : List[OWLObjectPropertyExpression] = |
| 108 | 109 | axiom match { | |
| 109 | private class RSAExprRoleExtractor() | 110 | case a: OWLSubClassOfAxiom => |
| 110 | extends OWLClassExpressionVisitorEx[ | 111 | rolesInExpr(a.getSubClass) ++ rolesInExpr(a.getSuperClass) |
| 111 | List[OWLObjectPropertyExpression] | 112 | case a: OWLEquivalentClassesAxiom => |
| 112 | ] { | 113 | a.getClassExpressions.asScala.toList.flatMap(rolesInExpr(_)) |
| 113 | override def visit( | 114 | case a: OWLSubObjectPropertyOfAxiom => |
| 114 | expr: OWLObjectSomeValuesFrom | 115 | List(a.getSubProperty, a.getSuperProperty) |
| 115 | ): List[OWLObjectPropertyExpression] = | 116 | case _ => List() |
| 116 | List(expr.getProperty) | ||
| 117 | |||
| 118 | override def visit( | ||
| 119 | expr: OWLObjectMaxCardinality | ||
| 120 | ): List[OWLObjectPropertyExpression] = | ||
| 121 | List(expr.getProperty) | ||
| 122 | |||
| 123 | /* NOTE: this instance of `visit` for `OWLClass` shouldn't be necessary. However | ||
| 124 | * if missing, the code throws a `NullPointerException`. It seems like, for some | ||
| 125 | * reason, `OWLClass` is not really a subinterface of `OWLClassExpression`, as | ||
| 126 | * stated in the JavaDocs. | ||
| 127 | */ | ||
| 128 | override def visit(expr: OWLClass): List[OWLObjectPropertyExpression] = | ||
| 129 | List() | ||
| 130 | |||
| 131 | def doDefault( | ||
| 132 | expr: OWLClassExpression | ||
| 133 | ): List[OWLObjectPropertyExpression] = | ||
| 134 | List() | ||
| 135 | } | ||
| 136 | |||
| 137 | override def visit( | ||
| 138 | axiom: OWLSubClassOfAxiom | ||
| 139 | ): List[OWLObjectPropertyExpression] = { | ||
| 140 | val visitor = new RSAExprRoleExtractor() | ||
| 141 | val sub = axiom.getSubClass.accept(visitor) | ||
| 142 | val sup = axiom.getSuperClass.accept(visitor) | ||
| 143 | sub ++ sup | ||
| 144 | } | 117 | } |
| 145 | 118 | ||
| 146 | override def visit( | 119 | private def rolesInExpr( |
| 147 | axiom: OWLEquivalentClassesAxiom | 120 | expr: OWLClassExpression |
| 148 | ): List[OWLObjectPropertyExpression] = { | 121 | ): List[OWLObjectPropertyExpression] = |
| 149 | // TODO | 122 | expr match { |
| 150 | List() | 123 | case e: OWLObjectSomeValuesFrom => List(e.getProperty) |
| 124 | case e: OWLObjectMaxCardinality => List(e.getProperty) | ||
| 125 | case _ => List() | ||
| 151 | } | 126 | } |
| 152 | 127 | ||
| 153 | override def visit( | ||
| 154 | axiom: OWLSubObjectPropertyOfAxiom | ||
| 155 | ): List[OWLObjectPropertyExpression] = | ||
| 156 | List(axiom.getSubProperty(), axiom.getSuperProperty()) | ||
| 157 | |||
| 158 | def doDefault(axiom: OWLAxiom): List[OWLObjectPropertyExpression] = List() | ||
| 159 | } | ||
| 160 | |||
| 161 | /* Exposed methods */ | ||
| 162 | lazy val objectPropertyExpressionsInSignature | ||
| 163 | : List[OWLObjectPropertyExpression] = { | ||
| 164 | val visitor = new RSAAxiomRoleExtractor() | ||
| 165 | axiom.accept(visitor) | ||
| 166 | } | ||
| 167 | |||
| 168 | lazy val toTriple: Option[(OWLClass, OWLObjectProperty, OWLClass)] = | 128 | lazy val toTriple: Option[(OWLClass, OWLObjectProperty, OWLClass)] = |
| 169 | for { | 129 | for { |
| 170 | subClass <- Some(axiom) collect { case a: OWLSubClassOfAxiom => a } | 130 | subClass <- Some(axiom) collect { case a: OWLSubClassOfAxiom => a } |
