aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/rsacomb
diff options
context:
space:
mode:
authorFederico Igne <federico.igne@cs.ox.ac.uk>2020-10-01 19:44:28 +0200
committerFederico Igne <federico.igne@cs.ox.ac.uk>2020-10-01 19:44:28 +0200
commit9ad95a1a08fb441a5594292c20ff2ac38bb8fb4f (patch)
tree310ac6d32472b7345b730617a854d1db2342bf4b /src/main/scala/rsacomb
parent6a29b16dee0592fdeb03b26ff87fd00d57555f78 (diff)
downloadRSAComb-9ad95a1a08fb441a5594292c20ff2ac38bb8fb4f.tar.gz
RSAComb-9ad95a1a08fb441a5594292c20ff2ac38bb8fb4f.zip
Implement method to find conflicting roles
Diffstat (limited to 'src/main/scala/rsacomb')
-rw-r--r--src/main/scala/rsacomb/RSAOntology.scala44
1 files changed, 39 insertions, 5 deletions
diff --git a/src/main/scala/rsacomb/RSAOntology.scala b/src/main/scala/rsacomb/RSAOntology.scala
index 79b8632..26b56d7 100644
--- a/src/main/scala/rsacomb/RSAOntology.scala
+++ b/src/main/scala/rsacomb/RSAOntology.scala
@@ -5,7 +5,10 @@ import java.util.HashMap
5import java.util.stream.{Collectors, Stream} 5import java.util.stream.{Collectors, Stream}
6 6
7import org.semanticweb.owlapi.model.OWLOntology 7import org.semanticweb.owlapi.model.OWLOntology
8import org.semanticweb.owlapi.model.OWLObjectPropertyExpression 8import org.semanticweb.owlapi.model.{
9 OWLObjectProperty,
10 OWLObjectPropertyExpression
11}
9import org.semanticweb.owlapi.model.parameters.Imports 12import org.semanticweb.owlapi.model.parameters.Imports
10import org.semanticweb.owlapi.reasoner.structural.StructuralReasonerFactory 13import org.semanticweb.owlapi.reasoner.structural.StructuralReasonerFactory
11 14
@@ -14,6 +17,7 @@ import tech.oxfordsemantic.jrdfox.logic.{Resource, Rule, Atom, Variable, IRI}
14 17
15/* Scala imports */ 18/* Scala imports */
16import scala.collection.JavaConverters._ 19import scala.collection.JavaConverters._
20import scala.collection.mutable.Set
17import scalax.collection.immutable.Graph 21import scalax.collection.immutable.Graph
18import scalax.collection.GraphEdge.UnDiEdge 22import scalax.collection.GraphEdge.UnDiEdge
19 23
@@ -30,7 +34,7 @@ trait RSAOntology {
30 */ 34 */
31 implicit class RSAOntology(ontology: OWLOntology) extends RSAAxiom { 35 implicit class RSAOntology(ontology: OWLOntology) extends RSAAxiom {
32 36
33 /* TDOO: implement method to retrieve all ontology named individuals 37 /* Retrieve individuals in the original ontology
34 */ 38 */
35 lazy val individuals: List[IRI] = { 39 lazy val individuals: List[IRI] = {
36 ontology 40 ontology
@@ -41,6 +45,17 @@ trait RSAOntology {
41 .toList 45 .toList
42 } 46 }
43 47
48 private lazy val roles: Set[OWLObjectPropertyExpression] =
49 ontology
50 .rboxAxioms(Imports.INCLUDED)
51 .collect(Collectors.toSet())
52 .asScala
53 .flatMap(_.objectPropertyExpressionsInSignature)
54
55 // OWLAPI reasoner for same easier tasks
56 private val reasoner =
57 (new StructuralReasonerFactory()).createReasoner(ontology)
58
44 /* Steps for RSA check 59 /* Steps for RSA check
45 * 1) convert ontology axioms into LP rules 60 * 1) convert ontology axioms into LP rules
46 * 2) call RDFox on the onto and compute materialization 61 * 2) call RDFox on the onto and compute materialization
@@ -126,9 +141,6 @@ trait RSAOntology {
126 } 141 }
127 142
128 lazy val unsafeRoles: List[OWLObjectPropertyExpression] = { 143 lazy val unsafeRoles: List[OWLObjectPropertyExpression] = {
129 // The reasoner is used to check unsafety condition for the ontology roles
130 val factory = new StructuralReasonerFactory()
131 val reasoner = factory.createReasoner(ontology)
132 144
133 val tbox = ontology 145 val tbox = ontology
134 .tboxAxioms(Imports.INCLUDED) 146 .tboxAxioms(Imports.INCLUDED)
@@ -204,6 +216,28 @@ trait RSAOntology {
204 def filteringProgram(query: Query): List[Rule] = 216 def filteringProgram(query: Query): List[Rule] =
205 FilteringProgram(query, individuals).rules 217 FilteringProgram(query, individuals).rules
206 218
219 // TODO: needs testing
220 def confl(
221 role: OWLObjectPropertyExpression
222 ): Set[OWLObjectPropertyExpression] = {
223
224 val invSuperRoles = reasoner
225 .superObjectProperties(role)
226 .collect(Collectors.toSet())
227 .asScala
228 .addOne(role)
229 .map(_.getInverseProperty)
230
231 roles.filter(
232 reasoner
233 .superObjectProperties(_)
234 .collect(Collectors.toSet())
235 .asScala
236 .intersect(invSuperRoles)
237 .nonEmpty
238 )
239 }
240
207 } // implicit class RSAOntology 241 } // implicit class RSAOntology
208 242
209} // trait RSAOntology 243} // trait RSAOntology