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.scala148
1 files changed, 148 insertions, 0 deletions
diff --git a/src/main/scala/rsacomb/RSAOntology.scala b/src/main/scala/rsacomb/RSAOntology.scala
new file mode 100644
index 0000000..7fc8781
--- /dev/null
+++ b/src/main/scala/rsacomb/RSAOntology.scala
@@ -0,0 +1,148 @@
1package rsacomb
2
3/* Java imports */
4// import java.io.File
5import java.util.stream.{Collectors,Stream}
6
7import org.semanticweb.owlapi.model.OWLOntology
8import org.semanticweb.owlapi.model.OWLObjectPropertyExpression
9// import org.semanticweb.owlapi.model.OWLAxiomVisitorEx
10import org.semanticweb.owlapi.model.parameters.Imports
11// import org.semanticweb.owlapi.reasoner.OWLReasoner
12import org.semanticweb.owlapi.reasoner.structural.StructuralReasonerFactory
13
14import tech.oxfordsemantic.jrdfox.logic.Variable
15
16/* Scala imports */
17import scala.collection.JavaConverters._
18
19/* Local imports */
20// import rsacomb.RSAAxiom
21
22/* Debug only */
23import org.semanticweb.owlapi.dlsyntax.renderer.DLSyntaxObjectRenderer
24
25// import java.util.HashMap
26// import java.util.stream.{Stream,Collectors}
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 {
44
45 implicit class RSAOntology(ontology: OWLOntology) extends RSAAxiom {
46
47 def isRSA: Boolean = {
48
49 /* TODO: Steps for RSA check
50 * 1) convert ontology axioms into LP rules
51 * 2) call RDFox on the onto and compute materialization
52 * 3) build graph from E(x,y) facts
53 * 4) check if the graph is tree-like
54 * ideally this annotates the graph with info about the reasons
55 * why the ontology might not be RSA. This could help a second
56 * step of approximation of an Horn-ALCHOIQ to RSA
57 */
58
59 val tbox =
60 Stream.concat(ontology.tboxAxioms(Imports.INCLUDED), ontology.rboxAxioms(Imports.INCLUDED))
61 .collect(Collectors.toList()).asScala
62 val unsafe = ontology.getUnsafeRoles
63
64 /* DEBUG: print rules in DL syntax */
65 val renderer = new DLSyntaxObjectRenderer()
66 println("\nDL rules:")
67 tbox.foreach(x => println(renderer.render(x)))
68
69 /* Ontology convertion into LP rules */
70 println("\nLP rules:")
71 for {
72 axiom <- tbox
73 visitor = new RDFoxAxiomConverter(Variable.create("x"), SkolemStrategy.ConstantRSA(axiom.toString), unsafe)
74 rule <- axiom.accept(visitor)
75 } yield println(rule)
76
77 /* DEBUG */
78 true
79 }
80
81 def getUnsafeRoles: List[OWLObjectPropertyExpression] = {
82
83 val factory = new StructuralReasonerFactory()
84 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
88 /* DEBUG: print rules in DL syntax */
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
141
142 /* DEBUG */
143 List()
144 }
145
146 } // implicit class RSAOntology
147
148} // trait RSAOntology \ No newline at end of file