aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFederico Igne <federico.igne@cs.ox.ac.uk>2020-12-07 16:30:26 +0000
committerFederico Igne <federico.igne@cs.ox.ac.uk>2020-12-07 16:30:26 +0000
commit53dbca1f3de8183eefdb0c6b2d0e384f1371e52e (patch)
tree650bdf83d3eca1ba8b8c4eb739f949bd69d21619 /src
parentbbbb61ee13fa258cbed0b502426534afad49b651 (diff)
downloadRSAComb-53dbca1f3de8183eefdb0c6b2d0e384f1371e52e.tar.gz
RSAComb-53dbca1f3de8183eefdb0c6b2d0e384f1371e52e.zip
Change ConjunctiveQuery constructors interface
One of the object constructor was returning an Option. It was weird to have a constructor that would not always return an object.
Diffstat (limited to 'src')
-rw-r--r--src/main/scala/uk/ac/ox/cs/rsacomb/Main.scala2
-rw-r--r--src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala2
-rw-r--r--src/main/scala/uk/ac/ox/cs/rsacomb/sparql/ConjunctiveQuery.scala2
-rw-r--r--src/test/scala/uk/ac/ox/cs/rsacomb/FilteringProgramSpecs.scala8
-rw-r--r--src/test/scala/uk/ac/ox/cs/rsacomb/sparql/ConjunctiveQuerySpec.scala28
5 files changed, 21 insertions, 21 deletions
diff --git a/src/main/scala/uk/ac/ox/cs/rsacomb/Main.scala b/src/main/scala/uk/ac/ox/cs/rsacomb/Main.scala
index d41ca8c..c7ace0f 100644
--- a/src/main/scala/uk/ac/ox/cs/rsacomb/Main.scala
+++ b/src/main/scala/uk/ac/ox/cs/rsacomb/Main.scala
@@ -61,7 +61,7 @@ object RSAComb extends App {
61 source.close() 61 source.close()
62 62
63 /* Compute answers to query */ 63 /* Compute answers to query */
64 val answers = ConjunctiveQuery(query).map(ontology ask _) 64 val answers = ConjunctiveQuery.parse(query).map(ontology ask _)
65 answers map (_.toString) foreach println 65 answers map (_.toString) foreach println
66 } 66 }
67} 67}
diff --git a/src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala b/src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala
index 52d4905..7b4b142 100644
--- a/src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala
+++ b/src/main/scala/uk/ac/ox/cs/rsacomb/RSAOntology.scala
@@ -336,7 +336,7 @@ class RSAOntology(val ontology: OWLOntology) {
336 RSA.Prefixes 336 RSA.Prefixes
337 ) 337 )
338 .map( 338 .map(
339 new ConjunctiveQueryAnswers(query.bcq, _) 339 new ConjunctiveQueryAnswers(query.bcq, query.variables, _)
340 ) 340 )
341 .get 341 .get
342 RDFoxUtil.closeConnection(server, data) 342 RDFoxUtil.closeConnection(server, data)
diff --git a/src/main/scala/uk/ac/ox/cs/rsacomb/sparql/ConjunctiveQuery.scala b/src/main/scala/uk/ac/ox/cs/rsacomb/sparql/ConjunctiveQuery.scala
index 451d1f4..1fb75d7 100644
--- a/src/main/scala/uk/ac/ox/cs/rsacomb/sparql/ConjunctiveQuery.scala
+++ b/src/main/scala/uk/ac/ox/cs/rsacomb/sparql/ConjunctiveQuery.scala
@@ -31,7 +31,7 @@ object ConjunctiveQuery {
31 * @return an [[scala.Option]] containing a ConjunctiveQuery if the 31 * @return an [[scala.Option]] containing a ConjunctiveQuery if the
32 * input query represents one, None is returned otherwise. 32 * input query represents one, None is returned otherwise.
33 */ 33 */
34 def apply( 34 def parse(
35 query: String, 35 query: String,
36 prefixes: Prefixes = new Prefixes() 36 prefixes: Prefixes = new Prefixes()
37 ): Option[ConjunctiveQuery] = 37 ): Option[ConjunctiveQuery] =
diff --git a/src/test/scala/uk/ac/ox/cs/rsacomb/FilteringProgramSpecs.scala b/src/test/scala/uk/ac/ox/cs/rsacomb/FilteringProgramSpecs.scala
index 86e0253..93e312c 100644
--- a/src/test/scala/uk/ac/ox/cs/rsacomb/FilteringProgramSpecs.scala
+++ b/src/test/scala/uk/ac/ox/cs/rsacomb/FilteringProgramSpecs.scala
@@ -66,28 +66,28 @@ class FilteringProgramSpec extends AnyFlatSpec with Matchers {
66 import FilteringProgramSpec._ 66 import FilteringProgramSpec._
67 67
68 "CQ 0" should "generate 27 rules and 3 facts" in { 68 "CQ 0" should "generate 27 rules and 3 facts" in {
69 val cq = ConjunctiveQuery(cq0).get 69 val cq = ConjunctiveQuery.parse(cq0).get
70 val filter = FilteringProgram(cq, constants) 70 val filter = FilteringProgram(cq, constants)
71 filter.facts should have length 3 71 filter.facts should have length 3
72 filter.rules should have length 27 72 filter.rules should have length 27
73 } 73 }
74 74
75 "CQ 1" should "generate 15 rules" in { 75 "CQ 1" should "generate 15 rules" in {
76 val cq = ConjunctiveQuery(cq1).get 76 val cq = ConjunctiveQuery.parse(cq1).get
77 val filter = FilteringProgram(cq, List()) 77 val filter = FilteringProgram(cq, List())
78 filter.facts shouldBe empty 78 filter.facts shouldBe empty
79 filter.rules should have length 15 79 filter.rules should have length 15
80 } 80 }
81 81
82 "CQ 2" should "generate 51 rules" in { 82 "CQ 2" should "generate 51 rules" in {
83 val cq = ConjunctiveQuery(cq2).get 83 val cq = ConjunctiveQuery.parse(cq2).get
84 val filter = FilteringProgram(cq, List()) 84 val filter = FilteringProgram(cq, List())
85 filter.facts shouldBe empty 85 filter.facts shouldBe empty
86 filter.rules should have length 51 86 filter.rules should have length 51
87 } 87 }
88 88
89 "BCQ 0" should "generate 46 rules" in { 89 "BCQ 0" should "generate 46 rules" in {
90 val cq = ConjunctiveQuery(bcq0).get 90 val cq = ConjunctiveQuery.parse(bcq0).get
91 val filter = FilteringProgram(cq, constants) 91 val filter = FilteringProgram(cq, constants)
92 filter.facts should have length 3 92 filter.facts should have length 3
93 filter.rules should have length 43 93 filter.rules should have length 43
diff --git a/src/test/scala/uk/ac/ox/cs/rsacomb/sparql/ConjunctiveQuerySpec.scala b/src/test/scala/uk/ac/ox/cs/rsacomb/sparql/ConjunctiveQuerySpec.scala
index 07e7bfb..7938174 100644
--- a/src/test/scala/uk/ac/ox/cs/rsacomb/sparql/ConjunctiveQuerySpec.scala
+++ b/src/test/scala/uk/ac/ox/cs/rsacomb/sparql/ConjunctiveQuerySpec.scala
@@ -142,35 +142,35 @@ class ConjunctiveQuerySpec
142 import ConjunctiveQuerySpec._ 142 import ConjunctiveQuerySpec._
143 143
144 "A conjunctive query" should "result in a `ConjunctiveQuery` instance" in { 144 "A conjunctive query" should "result in a `ConjunctiveQuery` instance" in {
145 ConjunctiveQuery(cq0) shouldBe defined 145 ConjunctiveQuery.parse(cq0) shouldBe defined
146 } 146 }
147 147
148 "A boolean conjunctive query" should "result in a `ConjunctiveQuery` instance" in { 148 "A boolean conjunctive query" should "result in a `ConjunctiveQuery` instance" in {
149 ConjunctiveQuery(bcq0) shouldBe defined 149 ConjunctiveQuery.parse(bcq0) shouldBe defined
150 } 150 }
151 151
152 "A query with proper SELECT defined" should "not be a BCQ" in { 152 "A query with proper SELECT defined" should "not be a BCQ" in {
153 ConjunctiveQuery(cq0).value should not be 'bcq 153 ConjunctiveQuery.parse(cq0).value should not be 'bcq
154 } 154 }
155 155
156 "A query with a \"*\" SELECT" should "not be a BCQ" in { 156 "A query with a \"*\" SELECT" should "not be a BCQ" in {
157 ConjunctiveQuery(cq1).value should not be 'bcq 157 ConjunctiveQuery.parse(cq1).value should not be 'bcq
158 } 158 }
159 159
160 "An ASK query" should "not be a BCQ" in { 160 "An ASK query" should "not be a BCQ" in {
161 ConjunctiveQuery(bcq0).value shouldBe 'bcq 161 ConjunctiveQuery.parse(bcq0).value shouldBe 'bcq
162 } 162 }
163 163
164 "Queries" should "have distinct answer and bounded variables" in { 164 "Queries" should "have distinct answer and bounded variables" in {
165 for (q <- queries) { 165 for (q <- queries) {
166 val cq = ConjunctiveQuery(q) 166 val cq = ConjunctiveQuery.parse(q)
167 forAll(cq.value.answer) { v => cq.value.bounded should not contain v } 167 forAll(cq.value.answer) { v => cq.value.bounded should not contain v }
168 forAll(cq.value.bounded) { v => cq.value.answer should not contain v } 168 forAll(cq.value.bounded) { v => cq.value.answer should not contain v }
169 } 169 }
170 } 170 }
171 171
172 "CQ0" should "have {?obj, ?pred} as bounded variables" in { 172 "CQ0" should "have {?obj, ?pred} as bounded variables" in {
173 ConjunctiveQuery(cq0).value.bounded should contain theSameElementsAs 173 ConjunctiveQuery.parse(cq0).value.bounded should contain theSameElementsAs
174 List( 174 List(
175 Variable.create("Y"), 175 Variable.create("Y"),
176 Variable.create("Z") 176 Variable.create("Z")
@@ -178,15 +178,15 @@ class ConjunctiveQuerySpec
178 } 178 }
179 179
180 "CQ1" should "have no bounded variable" in { 180 "CQ1" should "have no bounded variable" in {
181 ConjunctiveQuery(cq1).value.bounded shouldBe empty 181 ConjunctiveQuery.parse(cq1).value.bounded shouldBe empty
182 } 182 }
183 183
184 "CQ2" should "have no bounded variable" in { 184 "CQ2" should "have no bounded variable" in {
185 ConjunctiveQuery(cq2).value.bounded shouldBe empty 185 ConjunctiveQuery.parse(cq2).value.bounded shouldBe empty
186 } 186 }
187 187
188 "CQ3" should "have {?w, ?fp} as bounded variables" in { 188 "CQ3" should "have {?w, ?fp} as bounded variables" in {
189 ConjunctiveQuery(cq3).value.bounded should contain theSameElementsAs 189 ConjunctiveQuery.parse(cq3).value.bounded should contain theSameElementsAs
190 List( 190 List(
191 Variable.create("w"), 191 Variable.create("w"),
192 Variable.create("fp") 192 Variable.create("fp")
@@ -194,11 +194,11 @@ class ConjunctiveQuerySpec
194 } 194 }
195 195
196 "CQ4" should "have no bounded variable" in { 196 "CQ4" should "have no bounded variable" in {
197 ConjunctiveQuery(cq4).value.bounded shouldBe empty 197 ConjunctiveQuery.parse(cq4).value.bounded shouldBe empty
198 } 198 }
199 199
200 "CQ5" should "have a non-empty bounded set" in { 200 "CQ5" should "have a non-empty bounded set" in {
201 ConjunctiveQuery(cq5).value.bounded should contain theSameElementsAs 201 ConjunctiveQuery.parse(cq5).value.bounded should contain theSameElementsAs
202 List( 202 List(
203 Variable.create("w"), 203 Variable.create("w"),
204 Variable.create("c_int"), 204 Variable.create("c_int"),
@@ -208,7 +208,7 @@ class ConjunctiveQuerySpec
208 } 208 }
209 209
210 "CQ6" should "have a non-empty bounded set" in { 210 "CQ6" should "have a non-empty bounded set" in {
211 ConjunctiveQuery(cq6).value.bounded should contain theSameElementsAs 211 ConjunctiveQuery.parse(cq6).value.bounded should contain theSameElementsAs
212 List( 212 List(
213 Variable.create("w"), 213 Variable.create("w"),
214 Variable.create("int") 214 Variable.create("int")
@@ -216,7 +216,7 @@ class ConjunctiveQuerySpec
216 } 216 }
217 217
218 "CQ7" should "have a non-empty bounded set" in { 218 "CQ7" should "have a non-empty bounded set" in {
219 ConjunctiveQuery(cq7).value.bounded should contain theSameElementsAs 219 ConjunctiveQuery.parse(cq7).value.bounded should contain theSameElementsAs
220 List( 220 List(
221 Variable.create("w"), 221 Variable.create("w"),
222 Variable.create("z"), 222 Variable.create("z"),