diff options
Diffstat (limited to 'src/main/scala/rsacomb/RSAAxiom.scala')
| -rw-r--r-- | src/main/scala/rsacomb/RSAAxiom.scala | 154 |
1 files changed, 103 insertions, 51 deletions
diff --git a/src/main/scala/rsacomb/RSAAxiom.scala b/src/main/scala/rsacomb/RSAAxiom.scala index 032b7f9..588c72a 100644 --- a/src/main/scala/rsacomb/RSAAxiom.scala +++ b/src/main/scala/rsacomb/RSAAxiom.scala | |||
| @@ -1,76 +1,64 @@ | |||
| 1 | package rsacomb | 1 | package rsacomb |
| 2 | 2 | ||
| 3 | /* Java imports */ | 3 | /* Java imports */ |
| 4 | // import java.io.File | ||
| 5 | // import java.util.stream.{Collectors,Stream} | ||
| 6 | |||
| 7 | // import org.semanticweb.owlapi.apibinding.OWLManager | ||
| 8 | // import org.semanticweb.owlapi.model.{OWLOntologyManager,OWLOntology} | ||
| 9 | // import org.semanticweb.owlapi.model.{OWLAxiom,OWLObjectPropertyExpression} | ||
| 10 | import org.semanticweb.owlapi.model.{OWLAxiom,OWLSubClassOfAxiom, OWLEquivalentClassesAxiom} | 4 | import org.semanticweb.owlapi.model.{OWLAxiom,OWLSubClassOfAxiom, OWLEquivalentClassesAxiom} |
| 11 | import org.semanticweb.owlapi.model.OWLAxiomVisitorEx | 5 | import org.semanticweb.owlapi.model.{OWLObjectPropertyExpression,OWLClass,OWLClassExpression,OWLObjectSomeValuesFrom,OWLObjectMaxCardinality} |
| 12 | // import org.semanticweb.owlapi.model.parameters.Imports | 6 | import org.semanticweb.owlapi.model.ClassExpressionType |
| 13 | // import org.semanticweb.owlapi.reasoner.OWLReasoner | 7 | import org.semanticweb.owlapi.model.{OWLAxiomVisitorEx,OWLClassExpressionVisitorEx} |
| 14 | // import org.semanticweb.owlapi.reasoner.structural.StructuralReasonerFactory | ||
| 15 | |||
| 16 | // import tech.oxfordsemantic.jrdfox.logic.Variable | ||
| 17 | |||
| 18 | /* Scala imports */ | ||
| 19 | // import scala.collection.JavaConverters._ | ||
| 20 | |||
| 21 | /* Local imports */ | ||
| 22 | // import rsacomb.RSAAxiom | ||
| 23 | |||
| 24 | /* Debug only */ | ||
| 25 | // import org.semanticweb.owlapi.dlsyntax.renderer.DLSyntaxObjectRenderer | ||
| 26 | |||
| 27 | // import java.util.HashMap | ||
| 28 | // import java.util.stream.{Stream,Collectors} | ||
| 29 | |||
| 30 | // import org.semanticweb.owlapi.model.{AxiomType, ClassExpressionType, OWLObjectSomeValuesFrom} | ||
| 31 | // import org.semanticweb.owlapi.model.OWLClassExpression | ||
| 32 | // import org.semanticweb.owlapi.model.IRI | ||
| 33 | // import org.semanticweb.owlapi.reasoner.{OWLReasonerFactory, OWLReasoner} | ||
| 34 | // import uk.ac.manchester.cs.owl.owlapi.OWLObjectPropertyImpl | ||
| 35 | |||
| 36 | // import tech.oxfordsemantic.jrdfox.Prefixes | ||
| 37 | // import tech.oxfordsemantic.jrdfox.client.{ConnectionFactory, ServerConnection, DataStoreConnection} | ||
| 38 | // import tech.oxfordsemantic.jrdfox.client.UpdateType | ||
| 39 | // import tech.oxfordsemantic.jrdfox.logic.{Rule, Atom, Literal, Term, Variable} | ||
| 40 | // import tech.oxfordsemantic.jrdfox.logic.{BuiltinFunctionCall, TupleTableName} | ||
| 41 | // import tech.oxfordsemantic.jrdfox.logic.{LogicFormat} | ||
| 42 | |||
| 43 | |||
| 44 | // import rsacomb.SkolemStrategy | ||
| 45 | //import org.semanticweb.owlapi.model.{OWLAxiom,OWLObjectPropertyExpression} | ||
| 46 | 8 | ||
| 9 | /* Wrapper trait for the implicit class `RSAAxiom`. | ||
| 10 | */ | ||
| 47 | trait RSAAxiom { | 11 | trait RSAAxiom { |
| 48 | 12 | ||
| 49 | sealed trait RSAAxiomType | 13 | /* Identifies some of the axiom types in a Horn-ALCHOIQ ontology |
| 50 | object RSAAxiomType { | 14 | * in normal form. Refer to the paper for more details on the |
| 51 | case object T3 extends RSAAxiomType | 15 | * chosen names. |
| 52 | case object T4 extends RSAAxiomType | 16 | */ |
| 53 | case object T5 extends RSAAxiomType | 17 | private sealed trait RSAAxiomType |
| 18 | private object RSAAxiomType { | ||
| 19 | case object T3 extends RSAAxiomType // ∃R.A ⊑ B | ||
| 20 | case object T4 extends RSAAxiomType // A ⊑ ≤1R.B | ||
| 21 | case object T5 extends RSAAxiomType // A ⊑ ∃R.B | ||
| 54 | } | 22 | } |
| 55 | 23 | ||
| 24 | /* Implements additional features on top of `OWLAxiom` from | ||
| 25 | * the OWLAPI. | ||
| 26 | */ | ||
| 56 | implicit class RSAAxiom(axiom: OWLAxiom) { | 27 | implicit class RSAAxiom(axiom: OWLAxiom) { |
| 57 | 28 | ||
| 29 | /* Detecting axiom types: | ||
| 30 | * | ||
| 31 | * In order to reason about role unsafety in Horn-ALCHOIQ | ||
| 32 | * ontologies we need to detect and filter axioms by their | ||
| 33 | * "type". | ||
| 34 | * | ||
| 35 | * This is a simple implementation following the Visitor | ||
| 36 | * pattern imposed by the OWLAPI. | ||
| 37 | */ | ||
| 58 | private class RSAAxiomTypeDetector(t: RSAAxiomType) | 38 | private class RSAAxiomTypeDetector(t: RSAAxiomType) |
| 59 | extends OWLAxiomVisitorEx[Boolean] | 39 | extends OWLAxiomVisitorEx[Boolean] |
| 60 | { | 40 | { |
| 61 | |||
| 62 | override | 41 | override |
| 63 | def visit(axiom: OWLSubClassOfAxiom): Boolean = { | 42 | def visit(axiom: OWLSubClassOfAxiom): Boolean = { |
| 64 | true | 43 | val sub = axiom.getSubClass().getClassExpressionType() |
| 44 | val sup = axiom.getSuperClass().getClassExpressionType() | ||
| 45 | t match { | ||
| 46 | case RSAAxiomType.T3 => // ∃R.A ⊑ B | ||
| 47 | sub == ClassExpressionType.OBJECT_SOME_VALUES_FROM && sup == ClassExpressionType.OWL_CLASS | ||
| 48 | case RSAAxiomType.T4 => // A ⊑ ≤1R.B | ||
| 49 | sub == ClassExpressionType.OWL_CLASS && sup == ClassExpressionType.OBJECT_MAX_CARDINALITY | ||
| 50 | case RSAAxiomType.T5 => // A ⊑ ∃R.B | ||
| 51 | sub == ClassExpressionType.OWL_CLASS && sup == ClassExpressionType.OBJECT_SOME_VALUES_FROM | ||
| 52 | } | ||
| 65 | } | 53 | } |
| 66 | 54 | ||
| 67 | override | 55 | override |
| 68 | def visit(axiom: OWLEquivalentClassesAxiom): Boolean = { | 56 | def visit(axiom: OWLEquivalentClassesAxiom): Boolean = { |
| 69 | true | 57 | // TODO |
| 58 | false | ||
| 70 | } | 59 | } |
| 71 | 60 | ||
| 72 | def doDefault(axiom : OWLAxiom): Boolean = false | 61 | def doDefault(axiom : OWLAxiom): Boolean = false |
| 73 | |||
| 74 | } | 62 | } |
| 75 | 63 | ||
| 76 | private def isOfType(t: RSAAxiomType): Boolean = { | 64 | private def isOfType(t: RSAAxiomType): Boolean = { |
| @@ -78,9 +66,73 @@ trait RSAAxiom { | |||
| 78 | axiom.accept(visitor) | 66 | axiom.accept(visitor) |
| 79 | } | 67 | } |
| 80 | 68 | ||
| 69 | /* Exposed methods */ | ||
| 81 | def isT3: Boolean = isOfType(RSAAxiomType.T3) | 70 | def isT3: Boolean = isOfType(RSAAxiomType.T3) |
| 82 | def isT4: Boolean = isOfType(RSAAxiomType.T4) | 71 | def isT4: Boolean = isOfType(RSAAxiomType.T4) |
| 83 | def isT5: Boolean = isOfType(RSAAxiomType.T5) | 72 | def isT5: Boolean = isOfType(RSAAxiomType.T5) |
| 73 | |||
| 74 | /* Extracting ObjectPropertyExpressions from axioms | ||
| 75 | * | ||
| 76 | * This extracts all ObjectPropertyExpressions from a given | ||
| 77 | * axiom. While the implementation is generic we use it on axioms | ||
| 78 | * of specific types (see above). | ||
| 79 | * | ||
| 80 | * NOTE: it is not possible to use the `objectPropertyInSignature` | ||
| 81 | * method of `OWLAxiom` because it returns all "role names" involved | ||
| 82 | * in the signature of an axiom. In particular we won't get the inverse | ||
| 83 | * of a role if this appears in the axiom (but we will get the role | ||
| 84 | * itself instead). | ||
| 85 | */ | ||
| 86 | private class RSAAxiomRoleExtractor() | ||
| 87 | extends OWLAxiomVisitorEx[List[OWLObjectPropertyExpression]] | ||
| 88 | { | ||
| 89 | |||
| 90 | private class RSAExprRoleExtractor() | ||
| 91 | extends OWLClassExpressionVisitorEx[List[OWLObjectPropertyExpression]] | ||
| 92 | { | ||
| 93 | override | ||
| 94 | def visit(expr: OWLObjectSomeValuesFrom): List[OWLObjectPropertyExpression] = | ||
| 95 | List(expr.getProperty) | ||
| 96 | |||
| 97 | override | ||
| 98 | def visit(expr: OWLObjectMaxCardinality): List[OWLObjectPropertyExpression] = | ||
| 99 | List(expr.getProperty) | ||
| 100 | |||
| 101 | /* NOTE: this instance of `visit` for `OWLClass` shouldn't be necessary. However | ||
| 102 | * if missing, the code throws a `NullPointerException`. It seems like, for some | ||
| 103 | * reason, `OWLClass` is not really a subinterface of `OWLClassExpression`, as | ||
| 104 | * stated in the JavaDocs. | ||
| 105 | */ | ||
| 106 | override | ||
| 107 | def visit(expr: OWLClass): List[OWLObjectPropertyExpression] = | ||
| 108 | List() | ||
| 109 | |||
| 110 | def doDefault(expr: OWLClassExpression): List[OWLObjectPropertyExpression] = | ||
| 111 | List() | ||
| 112 | } | ||
| 113 | |||
| 114 | override | ||
| 115 | def visit(axiom: OWLSubClassOfAxiom): List[OWLObjectPropertyExpression] = { | ||
| 116 | val visitor = new RSAExprRoleExtractor() | ||
| 117 | val sub = axiom.getSubClass.accept(visitor) | ||
| 118 | val sup = axiom.getSuperClass.accept(visitor) | ||
| 119 | sub ++ sup | ||
| 120 | } | ||
| 121 | |||
| 122 | override | ||
| 123 | def visit(axiom: OWLEquivalentClassesAxiom): List[OWLObjectPropertyExpression] = { | ||
| 124 | // TODO | ||
| 125 | List() | ||
| 126 | } | ||
| 127 | |||
| 128 | def doDefault(axiom : OWLAxiom): List[OWLObjectPropertyExpression] = List() | ||
| 129 | } | ||
| 130 | |||
| 131 | /* Exposed methods */ | ||
| 132 | def objectPropertyExpressionsInSignature: List[OWLObjectPropertyExpression] = { | ||
| 133 | val visitor = new RSAAxiomRoleExtractor() | ||
| 134 | axiom.accept(visitor) | ||
| 135 | } | ||
| 84 | } | 136 | } |
| 85 | 137 | ||
| 86 | } | 138 | } // trait RSAAxiom \ No newline at end of file |
