From 9ad95a1a08fb441a5594292c20ff2ac38bb8fb4f Mon Sep 17 00:00:00 2001 From: Federico Igne Date: Thu, 1 Oct 2020 19:44:28 +0200 Subject: Implement method to find conflicting roles --- src/main/scala/rsacomb/RSAOntology.scala | 44 ++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 5 deletions(-) (limited to 'src/main/scala/rsacomb') 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 import java.util.stream.{Collectors, Stream} import org.semanticweb.owlapi.model.OWLOntology -import org.semanticweb.owlapi.model.OWLObjectPropertyExpression +import org.semanticweb.owlapi.model.{ + OWLObjectProperty, + OWLObjectPropertyExpression +} import org.semanticweb.owlapi.model.parameters.Imports import org.semanticweb.owlapi.reasoner.structural.StructuralReasonerFactory @@ -14,6 +17,7 @@ import tech.oxfordsemantic.jrdfox.logic.{Resource, Rule, Atom, Variable, IRI} /* Scala imports */ import scala.collection.JavaConverters._ +import scala.collection.mutable.Set import scalax.collection.immutable.Graph import scalax.collection.GraphEdge.UnDiEdge @@ -30,7 +34,7 @@ trait RSAOntology { */ implicit class RSAOntology(ontology: OWLOntology) extends RSAAxiom { - /* TDOO: implement method to retrieve all ontology named individuals + /* Retrieve individuals in the original ontology */ lazy val individuals: List[IRI] = { ontology @@ -41,6 +45,17 @@ trait RSAOntology { .toList } + private lazy val roles: Set[OWLObjectPropertyExpression] = + ontology + .rboxAxioms(Imports.INCLUDED) + .collect(Collectors.toSet()) + .asScala + .flatMap(_.objectPropertyExpressionsInSignature) + + // OWLAPI reasoner for same easier tasks + private val reasoner = + (new StructuralReasonerFactory()).createReasoner(ontology) + /* Steps for RSA check * 1) convert ontology axioms into LP rules * 2) call RDFox on the onto and compute materialization @@ -126,9 +141,6 @@ trait RSAOntology { } lazy val unsafeRoles: List[OWLObjectPropertyExpression] = { - // The reasoner is used to check unsafety condition for the ontology roles - val factory = new StructuralReasonerFactory() - val reasoner = factory.createReasoner(ontology) val tbox = ontology .tboxAxioms(Imports.INCLUDED) @@ -204,6 +216,28 @@ trait RSAOntology { def filteringProgram(query: Query): List[Rule] = FilteringProgram(query, individuals).rules + // TODO: needs testing + def confl( + role: OWLObjectPropertyExpression + ): Set[OWLObjectPropertyExpression] = { + + val invSuperRoles = reasoner + .superObjectProperties(role) + .collect(Collectors.toSet()) + .asScala + .addOne(role) + .map(_.getInverseProperty) + + roles.filter( + reasoner + .superObjectProperties(_) + .collect(Collectors.toSet()) + .asScala + .intersect(invSuperRoles) + .nonEmpty + ) + } + } // implicit class RSAOntology } // trait RSAOntology -- cgit v1.2.3