aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/rsacomb/Main.scala
diff options
context:
space:
mode:
authorFederico Igne <federico.igne@cs.ox.ac.uk>2020-11-06 17:18:07 +0000
committerFederico Igne <federico.igne@cs.ox.ac.uk>2020-11-06 17:18:07 +0000
commitb721703c349cebd3ffe888d9644f2b85d5a8eeb7 (patch)
treea3845fbf44827ff66fc956c90fe20c1d4be73115 /src/main/scala/rsacomb/Main.scala
parentc6babfd508f65e8b7596a96659214cb43881dadd (diff)
downloadRSAComb-b721703c349cebd3ffe888d9644f2b85d5a8eeb7.tar.gz
RSAComb-b721703c349cebd3ffe888d9644f2b85d5a8eeb7.zip
Rework canonical model computation
This is a first attempt to avoid a bug triggered by the nature of the class RSAOntology and CanonicalModel. An OWLOntology is converted implicitly to an RSAOntology object whenever it is needed. From within the RSAOntology class we used to create a CanonicalModel object (and pass the underling OWLOntology object as a parameter). Inside CanonicalModel we require RSAOntology functionalities from the OWLOntology, triggering a new conversion into RSAOntology (that would compute a new CanonicalModel and so on in a loop). While declaring the CanonicalModel as lazy in RSAOntology could solve the problem, it does not fix the underlying issue of having a class strictly related to RSAOntology as a top level class. As a first attempt we moved CanonicalModel as an object inside RSAOntology.
Diffstat (limited to 'src/main/scala/rsacomb/Main.scala')
-rw-r--r--src/main/scala/rsacomb/Main.scala69
1 files changed, 56 insertions, 13 deletions
diff --git a/src/main/scala/rsacomb/Main.scala b/src/main/scala/rsacomb/Main.scala
index 830f1e0..64343f5 100644
--- a/src/main/scala/rsacomb/Main.scala
+++ b/src/main/scala/rsacomb/Main.scala
@@ -2,6 +2,10 @@ package rsacomb
2 2
3/* Java imports */ 3/* Java imports */
4import java.io.File 4import java.io.File
5import java.util.HashMap
6import scala.collection.JavaConverters._
7
8import tech.oxfordsemantic.jrdfox.client.UpdateType
5 9
6/* Local imports */ 10/* Local imports */
7import rsacomb.RSA._ 11import rsacomb.RSA._
@@ -46,25 +50,64 @@ object RSAComb extends App {
46 * case. 50 * case.
47 */ 51 */
48 52
49 val ontology = RSA.loadOntology(ontoPath) 53 val ontology: RSAOntology = RSA.loadOntology(ontoPath)
50 if (ontology.isRSA) { 54 if (ontology.isRSA) {
51 55
52 /* Build canonical model */
53 //val tboxCanon = rsa.canonicalModel()
54
55 // DEBUG: print program to generate canonical model
56 {
57 ontology.canonicalModel.foreach(println)
58 }
59
60 /* Load query */ 56 /* Load query */
61 val query = RDFoxUtil.parseQuery( 57 val query = RDFoxUtil.parseQuery(
62 "SELECT ?X WHERE {?X ?Y ?Z}" 58 """
59 SELECT ?uno
60 WHERE {
61 ?uno a :D ;
62 :R ?due .
63 ?due :S ?tre .
64 ?tre a :D .
65 }
66 """
63 ) 67 )
64 68
65 val filter = query map { q => ontology.filteringProgram(q) } 69 /* Compute answers to query */
66 70 query match {
67 /* ... */ 71 case Some(query) => {
72 // Open connection to RDFox
73 val (server, data) = RDFoxUtil.openConnection("AnswerComputation")
74
75 // Gather canonical model and filtering rules
76 val canon = ontology.canonicalModel
77 val filter = ontology.filteringProgram(query)
78
79 // Import relevant data
80 data.importData(UpdateType.ADDITION, RSA.Prefixes, ":a a :A .")
81 data.addRules(canon.rules.asJava)
82 data.addRules(filter.rules.asJava)
83
84 // Collect answers to query
85 for ((v, i) <- filter.variables.view.zipWithIndex) {
86 println(s"Variable $i:")
87 val query = s"SELECT ?X ?Y WHERE { ?X internal:Ans_$i ?Y }"
88 val cursor =
89 data.createCursor(
90 RSA.Prefixes,
91 query,
92 new HashMap[String, String]()
93 );
94 var mul = cursor.open()
95 while (mul > 0) {
96 printf(
97 "Ans_%d(%s,%s)",
98 i,
99 cursor.getResource(0),
100 cursor.getResource(1)
101 )
102 mul = cursor.advance()
103 }
104 }
105
106 // Close connection to RDFox
107 RDFoxUtil.closeConnection(server, data)
108 }
109 case None => {}
110 }
68 } 111 }
69} 112}
70 113