aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFederico Igne <federico.igne@cs.ox.ac.uk>2021-07-20 09:59:52 +0100
committerFederico Igne <federico.igne@cs.ox.ac.uk>2021-07-20 09:59:52 +0100
commitf0d1bfe564853a63128ad139520c9838778a7b61 (patch)
tree217a5529ceec209302f4e7fe0aedf8096cd23edb
parent9c8efc0410487c301b17c8dfb68b843c7dff403e (diff)
downloadRSAComb-f0d1bfe564853a63128ad139520c9838778a7b61.tar.gz
RSAComb-f0d1bfe564853a63128ad139520c9838778a7b61.zip
Add generic Ontology wrapper for common tasks
-rw-r--r--src/main/scala/uk/ac/ox/cs/rsacomb/ontologies/Ontology.scala90
1 files changed, 90 insertions, 0 deletions
diff --git a/src/main/scala/uk/ac/ox/cs/rsacomb/ontologies/Ontology.scala b/src/main/scala/uk/ac/ox/cs/rsacomb/ontologies/Ontology.scala
new file mode 100644
index 0000000..d7e57dd
--- /dev/null
+++ b/src/main/scala/uk/ac/ox/cs/rsacomb/ontologies/Ontology.scala
@@ -0,0 +1,90 @@
1/*
2 * Copyright 2020, 2021 KRR Oxford
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package uk.ac.ox.cs.rsacomb.ontology
18
19import java.io.File
20
21import org.semanticweb.owlapi.apibinding.OWLManager
22import org.semanticweb.owlapi.model.{OWLOntology, OWLAxiom, OWLLogicalAxiom}
23import org.semanticweb.owlapi.model.{OWLObjectPropertyExpression}
24import org.semanticweb.owlapi.reasoner.structural.StructuralReasonerFactory
25
26object Ontology {
27
28 /** Manager instance to interface with OWLAPI */
29 val manager = OWLManager.createOWLOntologyManager()
30 //val factory = manager.getOWLDataFactory()
31
32}
33
34/** A wrapper for
35 */
36class Ontology(val axioms: List[OWLLogicalAxiom], val datafiles: List[File]) {
37
38 /** Extend OWLAxiom functionalities */
39 import uk.ac.ox.cs.rsacomb.implicits.RSAAxiom._
40
41 /** OWLOntology based on input axioms */
42 private val ontology: OWLOntology =
43 Ontology.manager.createOntology((axioms: List[OWLAxiom]).asJava)
44
45 /** OWLAPI internal reasoner for ontology */
46 private val reasoner =
47 (new StructuralReasonerFactory()).createReasoner(ontology)
48
49 /** Unsafe roles in the ontology
50 *
51 * Unsafety conditions are the following:
52 *
53 * 1) For all roles r1 appearing in an axiom of type T5, r1 is unsafe
54 * if there exists a role r2 (different from top) appearing in an
55 * axiom of type T3 and r1 is a subproperty of the inverse of r2.
56 *
57 * 2) For all roles p1 appearing in an axiom of type T5, p1 is unsafe
58 * if there exists a role p2 appearing in an axiom of type T4 and
59 * p1 is a subproperty of either p2 or the inverse of p2.
60 */
61 lazy val unsafe: List[OWLObjectPropertyExpression] = {
62
63 /* Checking for unsafety condition (1) */
64 val unsafe1 = for {
65 axiom <- axioms
66 if axiom.isT5
67 role1 <- axiom.objectPropertyExpressionsInSignature
68 roleSuper = role1 +: reasoner.superObjectProperties(role1)
69 axiom <- axioms
70 if axiom.isT3 && !axiom.isT3top
71 role2 <- axiom.objectPropertyExpressionsInSignature
72 if roleSuper contains role2.getInverseProperty
73 } yield role1
74
75 /* Checking for unsafety condition (2) */
76 val unsafe2 = for {
77 axiom <- axioms
78 if axiom.isT5
79 role1 <- axiom.objectPropertyExpressionsInSignature
80 roleSuper = role1 +: reasoner.superObjectProperties(role1)
81 axiom <- axioms
82 if axiom.isT4
83 role2 <- axiom.objectPropertyExpressionsInSignature
84 if roleSuper.contains(role2) ||
85 roleSuper.contains(role2.getInverseProperty)
86 } yield role1
87
88 unsafe1 ++ unsafe2
89 }
90}