aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/rsacomb/RSAOntology.scala
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/scala/rsacomb/RSAOntology.scala')
-rw-r--r--src/main/scala/rsacomb/RSAOntology.scala120
1 files changed, 39 insertions, 81 deletions
diff --git a/src/main/scala/rsacomb/RSAOntology.scala b/src/main/scala/rsacomb/RSAOntology.scala
index 7fc8781..474d316 100644
--- a/src/main/scala/rsacomb/RSAOntology.scala
+++ b/src/main/scala/rsacomb/RSAOntology.scala
@@ -1,14 +1,11 @@
1package rsacomb 1package rsacomb
2 2
3/* Java imports */ 3/* Java imports */
4// import java.io.File
5import java.util.stream.{Collectors,Stream} 4import java.util.stream.{Collectors,Stream}
6 5
7import org.semanticweb.owlapi.model.OWLOntology 6import org.semanticweb.owlapi.model.OWLOntology
8import org.semanticweb.owlapi.model.OWLObjectPropertyExpression 7import org.semanticweb.owlapi.model.OWLObjectPropertyExpression
9// import org.semanticweb.owlapi.model.OWLAxiomVisitorEx
10import org.semanticweb.owlapi.model.parameters.Imports 8import org.semanticweb.owlapi.model.parameters.Imports
11// import org.semanticweb.owlapi.reasoner.OWLReasoner
12import org.semanticweb.owlapi.reasoner.structural.StructuralReasonerFactory 9import org.semanticweb.owlapi.reasoner.structural.StructuralReasonerFactory
13 10
14import tech.oxfordsemantic.jrdfox.logic.Variable 11import tech.oxfordsemantic.jrdfox.logic.Variable
@@ -16,32 +13,16 @@ import tech.oxfordsemantic.jrdfox.logic.Variable
16/* Scala imports */ 13/* Scala imports */
17import scala.collection.JavaConverters._ 14import scala.collection.JavaConverters._
18 15
19/* Local imports */
20// import rsacomb.RSAAxiom
21
22/* Debug only */ 16/* Debug only */
23import org.semanticweb.owlapi.dlsyntax.renderer.DLSyntaxObjectRenderer 17import org.semanticweb.owlapi.dlsyntax.renderer.DLSyntaxObjectRenderer
24 18
25// import java.util.HashMap 19/* Wrapper trait for the implicit class `RSAOntology`.
26// import java.util.stream.{Stream,Collectors} 20 */
27
28// import org.semanticweb.owlapi.model.{AxiomType, ClassExpressionType, OWLObjectSomeValuesFrom}
29// import org.semanticweb.owlapi.model.{OWLSubClassOfAxiom, OWLEquivalentClassesAxiom}
30// import org.semanticweb.owlapi.model.OWLClassExpression
31// import org.semanticweb.owlapi.model.IRI
32// import org.semanticweb.owlapi.reasoner.{OWLReasonerFactory, OWLReasoner}
33// import uk.ac.manchester.cs.owl.owlapi.OWLObjectPropertyImpl
34
35// import tech.oxfordsemantic.jrdfox.Prefixes
36// import tech.oxfordsemantic.jrdfox.client.{ConnectionFactory, ServerConnection, DataStoreConnection}
37// import tech.oxfordsemantic.jrdfox.client.UpdateType
38// import tech.oxfordsemantic.jrdfox.logic.{Rule, Atom, Literal, Term, Variable}
39// import tech.oxfordsemantic.jrdfox.logic.{BuiltinFunctionCall, TupleTableName}
40// import tech.oxfordsemantic.jrdfox.logic.{LogicFormat}
41// import rsacomb.SkolemStrategy
42
43trait RSAOntology { 21trait RSAOntology {
44 22
23 /* Implements additional features to reason about RSA ontologies
24 * on top of `OWLOntology` from the OWLAPI.
25 */
45 implicit class RSAOntology(ontology: OWLOntology) extends RSAAxiom { 26 implicit class RSAOntology(ontology: OWLOntology) extends RSAAxiom {
46 27
47 def isRSA: Boolean = { 28 def isRSA: Boolean = {
@@ -79,68 +60,45 @@ trait RSAOntology {
79 } 60 }
80 61
81 def getUnsafeRoles: List[OWLObjectPropertyExpression] = { 62 def getUnsafeRoles: List[OWLObjectPropertyExpression] = {
82 63 // The reasoner is used to check unsafety condition for the ontology roles
83 val factory = new StructuralReasonerFactory() 64 val factory = new StructuralReasonerFactory()
84 val reasoner = factory.createReasoner(ontology) 65 val reasoner = factory.createReasoner(ontology)
85 val tbox = ontology.tboxAxioms(Imports.INCLUDED).collect(Collectors.toList()).asScala
86 val rbox = ontology.rboxAxioms(Imports.INCLUDED).collect(Collectors.toList()).asScala
87 66
88 /* DEBUG: print rules in DL syntax */ 67 val tbox = ontology.tboxAxioms(Imports.INCLUDED).collect(Collectors.toSet()).asScala
89 val renderer = new DLSyntaxObjectRenderer()
90 println("\nT5 axioms:")
91 for {
92 axiom <- tbox
93 if axiom.isT5
94 } yield println(renderer.render(axiom))
95
96 // def isT3(axiom : OWLAxiom) : Boolean = {
97 // println(axiom)
98 // axiom.getAxiomType match {
99 // case AxiomType.SUBCLASS_OF =>
100 // val axiom1 = axiom.asInstanceOf[OWLSubClassOfAxiom]
101 // axiom1.getSubClass().getClassExpressionType() == ClassExpressionType.OBJECT_SOME_VALUES_FROM &&
102 // axiom1.getSuperClass().getClassExpressionType() == ClassExpressionType.OWL_CLASS
103 // case AxiomType.EQUIVALENT_CLASSES => false // TODO
104 // }
105 // }
106
107 // def isT4(axiom : OWLAxiom) : Boolean = {
108 // axiom.getAxiomType match {
109 // case AxiomType.SUBCLASS_OF =>
110 // val axiom1 = axiom.asInstanceOf[OWLSubClassOfAxiom]
111 // axiom1.getSubClass().getClassExpressionType() == ClassExpressionType.OWL_CLASS &&
112 // axiom1.getSuperClass().getClassExpressionType() == ClassExpressionType.OBJECT_MAX_CARDINALITY
113 // case AxiomType.EQUIVALENT_CLASSES => false // TODO
114 // }
115 // }
116
117 // def isT5(axiom : OWLAxiom) : Boolean = {
118 // axiom.getAxiomType match {
119 // case AxiomType.SUBCLASS_OF => {
120 // val axiom1 = axiom.asInstanceOf[OWLSubClassOfAxiom]
121 // axiom1.getSubClass().getClassExpressionType() == ClassExpressionType.OWL_CLASS &&
122 // axiom1.getSuperClass().getClassExpressionType() == ClassExpressionType.OBJECT_SOME_VALUES_FROM
123 // }
124 // case AxiomType.EQUIVALENT_CLASSES => false // TODO
125 // }
126 // }
127
128
129 // println("T3")
130 // for {
131 // axiom <- ontology.tboxAxioms(Imports.INCLUDED)
132 // //role <- axiom.objectPropertiesInSignature()
133 // } yield println(axiom)
134
135 // println("T4")
136 // for {
137 // axiom <- ontology.tboxAxioms(Imports.INCLUDED).filter(isT4)
138 // //role <- axiom.objectPropertiesInSignature()
139 // } yield println(axiom)
140 68
69 /* DEBUG: print rules in DL syntax */
70 //val renderer = new DLSyntaxObjectRenderer()
71
72 /* Checking for (1) unsafety condition:
73 *
74 * For all roles p1 appearing in an axiom of type T5, p1 is unsafe
75 * if there exists a role p2 (different from top) appearing in an axiom
76 * of type T3 and p1 is a subproperty of the inverse of p2.
77 *
78 * TODO: We are not checking whether the class expression on the right in T3
79 * is top. For now we can assume it is always the case.
80 */
81 val unsafe = for {
82 ax1 <- tbox
83 if ax1.isT5
84 p1 <- ax1.objectPropertyExpressionsInSignature
85 sup = p1.getInverseProperty +: reasoner.superObjectProperties(p1).map(_.getInverseProperty).collect(Collectors.toList()).asScala
86 ax2 <- tbox
87 if ax2.isT3
88 p2 <- ax2.objectPropertyExpressionsInSignature
89 if sup.contains(p2)
90 } yield p1
91
92 /* Checking for (2) unsafety condition:
93 *
94 * TODO
95 */
141 96
142 /* DEBUG */ 97 /* TODO: We should be able to avoid this last conversion to List.
143 List() 98 * Maybe we should just move everything to Sets instead of Lists, since
99 * they have a more straightforward conversion from Java collections.
100 */
101 unsafe.toList
144 } 102 }
145 103
146 } // implicit class RSAOntology 104 } // implicit class RSAOntology