diff options
Diffstat (limited to 'src/main/scala/rsacomb/Main.scala')
-rw-r--r-- | src/main/scala/rsacomb/Main.scala | 54 |
1 files changed, 45 insertions, 9 deletions
diff --git a/src/main/scala/rsacomb/Main.scala b/src/main/scala/rsacomb/Main.scala index 39040fc..596ef33 100644 --- a/src/main/scala/rsacomb/Main.scala +++ b/src/main/scala/rsacomb/Main.scala | |||
@@ -7,6 +7,7 @@ import scala.collection.JavaConverters._ | |||
7 | 7 | ||
8 | import tech.oxfordsemantic.jrdfox.client.UpdateType | 8 | import tech.oxfordsemantic.jrdfox.client.UpdateType |
9 | import tech.oxfordsemantic.jrdfox.logic.sparql.statement.SelectQuery | 9 | import tech.oxfordsemantic.jrdfox.logic.sparql.statement.SelectQuery |
10 | import tech.oxfordsemantic.jrdfox.logic.expression.{IRI, Term} | ||
10 | 11 | ||
11 | /* Local imports */ | 12 | /* Local imports */ |
12 | import rsacomb.RSA._ | 13 | import rsacomb.RSA._ |
@@ -73,23 +74,50 @@ object RSAComb extends App { | |||
73 | // Open connection to RDFox | 74 | // Open connection to RDFox |
74 | val (server, data) = RDFoxUtil.openConnection("AnswerComputation") | 75 | val (server, data) = RDFoxUtil.openConnection("AnswerComputation") |
75 | 76 | ||
76 | // Gather canonical model and filtering rules | 77 | { |
78 | println("\nQuery") | ||
79 | println(query) | ||
80 | } | ||
81 | |||
82 | // Step 1. Computing the canonical model | ||
77 | val canon = ontology.canonicalModel | 83 | val canon = ontology.canonicalModel |
78 | val filter = ontology.filteringProgram(query) | 84 | data.addRules(canon.rules.asJava) |
79 | 85 | ||
80 | { | 86 | { |
81 | println("\nCanonical Model rules:") | 87 | println("\nCanonical Model rules:") |
82 | canon.rules.foreach(println) | 88 | canon.rules.foreach(println) |
83 | println("\nFiltering rules") | ||
84 | filter.rules.foreach(println) | ||
85 | println("\nQuery") | ||
86 | println(query) | ||
87 | } | 89 | } |
88 | 90 | ||
89 | // Add canonical model and filtering rules | 91 | // Step 2. Computing the canonical model |
90 | data.addRules(canon.rules.asJava) | 92 | val nis = { |
93 | val query = | ||
94 | "SELECT ?Y WHERE { ?X internal:EquivTo ?Y ; a internal:NAMED . }" | ||
95 | val cursor = | ||
96 | data.createCursor( | ||
97 | RSA.Prefixes, | ||
98 | query, | ||
99 | new HashMap[String, String]() | ||
100 | ); | ||
101 | var mul = cursor.open() | ||
102 | var iris: List[IRI] = List() | ||
103 | while (mul > 0) { | ||
104 | println(cursor.getResource(0)) | ||
105 | iris = cursor.getResource(0) match { | ||
106 | case iri: IRI => iri :: iris | ||
107 | case _ => iris | ||
108 | } | ||
109 | mul = cursor.advance() | ||
110 | } | ||
111 | iris | ||
112 | } | ||
113 | val filter = ontology.filteringProgram(query, nis) | ||
91 | data.addRules(filter.rules.asJava) | 114 | data.addRules(filter.rules.asJava) |
92 | 115 | ||
116 | { | ||
117 | println("\nFiltering rules") | ||
118 | filter.rules.foreach(println) | ||
119 | } | ||
120 | |||
93 | def retrieveInstances(pred: String, arity: Int): Unit = { | 121 | def retrieveInstances(pred: String, arity: Int): Unit = { |
94 | // Build query | 122 | // Build query |
95 | var query = "SELECT" | 123 | var query = "SELECT" |
@@ -127,6 +155,14 @@ object RSAComb extends App { | |||
127 | 1 | 155 | 1 |
128 | ) | 156 | ) |
129 | 157 | ||
158 | println("\nNAMEDs:") | ||
159 | RDFoxUtil.submitQuery( | ||
160 | data, | ||
161 | RSA.Prefixes, | ||
162 | "SELECT ?X { ?X a internal:NAMED }", | ||
163 | 1 | ||
164 | ) | ||
165 | |||
130 | println("\nNIs:") | 166 | println("\nNIs:") |
131 | RDFoxUtil.submitQuery( | 167 | RDFoxUtil.submitQuery( |
132 | data, | 168 | data, |
@@ -143,7 +179,7 @@ object RSAComb extends App { | |||
143 | RDFoxUtil.submitQuery( | 179 | RDFoxUtil.submitQuery( |
144 | data, | 180 | data, |
145 | RSA.Prefixes, | 181 | RSA.Prefixes, |
146 | "SELECT ?X ?Y { ?X owl:sameAs ?Y }", | 182 | "SELECT ?X ?Y { ?X internal:EquivTo ?Y }", |
147 | 2 | 183 | 2 |
148 | ) | 184 | ) |
149 | 185 | ||