diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/test/scala/rsacomb/FilteringProgramSpecs.scala | 359 |
1 files changed, 246 insertions, 113 deletions
diff --git a/src/test/scala/rsacomb/FilteringProgramSpecs.scala b/src/test/scala/rsacomb/FilteringProgramSpecs.scala index 76ea2d6..027c790 100644 --- a/src/test/scala/rsacomb/FilteringProgramSpecs.scala +++ b/src/test/scala/rsacomb/FilteringProgramSpecs.scala | |||
@@ -1,15 +1,21 @@ | |||
1 | package rsacomb | 1 | package rsacomb |
2 | 2 | ||
3 | import java.io.File | 3 | import java.io.File |
4 | import java.util.{ArrayList => JList} | ||
4 | import org.scalatest.LoneElement | 5 | import org.scalatest.LoneElement |
5 | import org.scalatest.Inspectors | 6 | import org.scalatest.Inspectors |
6 | import org.scalatest.flatspec.AnyFlatSpec | 7 | import org.scalatest.flatspec.AnyFlatSpec |
7 | import org.scalatest.matchers.should.Matchers | 8 | import org.scalatest.matchers.should.Matchers |
8 | 9 | ||
9 | import tech.oxfordsemantic.jrdfox.logic.Variable | 10 | import tech.oxfordsemantic.jrdfox.logic.{Variable, Atom, IRI} |
11 | import tech.oxfordsemantic.jrdfox.logic.{Query, QueryType} | ||
12 | import tech.oxfordsemantic.jrdfox.logic.LogicFormat | ||
10 | import tech.oxfordsemantic.jrdfox.Prefixes | 13 | import tech.oxfordsemantic.jrdfox.Prefixes |
11 | 14 | ||
15 | import scala.collection.JavaConverters._ | ||
16 | |||
12 | import rsacomb.RDFoxUtil._ | 17 | import rsacomb.RDFoxUtil._ |
18 | import tech.oxfordsemantic.jrdfox.logic.Conjunction | ||
13 | 19 | ||
14 | object FilteringProgramSpec { | 20 | object FilteringProgramSpec { |
15 | 21 | ||
@@ -22,116 +28,248 @@ object FilteringProgramSpec { | |||
22 | prefixes.declarePrefix("rdfs:", "http://www.w3.org/2000/01/rdf-schema#") | 28 | prefixes.declarePrefix("rdfs:", "http://www.w3.org/2000/01/rdf-schema#") |
23 | prefixes.declarePrefix("owl:", "http://www.w3.org/2002/07/owl#") | 29 | prefixes.declarePrefix("owl:", "http://www.w3.org/2002/07/owl#") |
24 | 30 | ||
25 | val query0 = parseQuery(""" | 31 | // DEBUG: Quick helper functions |
26 | SELECT ?subj | 32 | def v(v: String): Variable = Variable.create(v) |
27 | WHERE { | 33 | def c(c: String): IRI = IRI.create(":" + c) |
28 | ?subj ?pred ?obj | ||
29 | } | ||
30 | """, prefixes) | ||
31 | 34 | ||
32 | val query1 = parseQuery(""" | 35 | // QUERY 0 |
33 | SELECT * | 36 | |
34 | WHERE { | 37 | // val query0 = parseQuery(""" |
35 | ?w a :Wellbore | 38 | // SELECT ?subj |
36 | } | 39 | // WHERE { |
37 | """, prefixes) | 40 | // ?subj ?pred ?obj |
38 | 41 | // } | |
39 | val query2 = parseQuery( | 42 | // """, prefixes) |
40 | """ | 43 | |
41 | SELECT * | 44 | val query0 = Query.create( |
42 | WHERE { | 45 | QueryType.SELECT, |
43 | ?w a :Wellbore ; | 46 | false, |
44 | :wellboreDocument ?doc . | 47 | List(v("subj")).asJava, |
45 | ?doc :hasURL ?document_hyperlink | 48 | Atom.rdf(v("subj"), v("pred"), v("obj")) |
46 | } | ||
47 | """, | ||
48 | prefixes | ||
49 | ) | 49 | ) |
50 | 50 | ||
51 | val query3 = parseQuery( | 51 | // QUERY 1 |
52 | """ | 52 | |
53 | SELECT ?w ?doc ?document_hyperlink | 53 | // val query1 = parseQuery(""" |
54 | WHERE { | 54 | // SELECT * |
55 | ?w a :Wellbore ; | 55 | // WHERE { |
56 | :wellboreDocument ?doc . | 56 | // ?w a :Wellbore |
57 | ?doc :hasURL ?document_hyperlink | 57 | // } |
58 | } | 58 | // """, prefixes) |
59 | """, | 59 | |
60 | prefixes | 60 | val query1 = Query.create( |
61 | QueryType.SELECT, | ||
62 | false, | ||
63 | List(v("w")).asJava, | ||
64 | Atom.rdf(v("w"), IRI.RDF_TYPE, c("Wellbore")) | ||
61 | ) | 65 | ) |
62 | 66 | ||
63 | val query4 = parseQuery( | 67 | // QUERY 2 |
64 | """ | 68 | |
65 | SELECT ?w ?doc ?document_hyperlink | 69 | // val query2 = parseQuery( |
66 | WHERE { | 70 | // """ |
67 | ?w a :Wellbore ; | 71 | // SELECT * |
68 | :wellboreDocument ?doc . | 72 | // WHERE { |
69 | ?doc :hasURL ?document_hyperlink | 73 | // ?w a :Wellbore ; |
70 | } | 74 | // :wellboreDocument ?doc . |
71 | """, | 75 | // ?doc :hasURL ?document_hyperlink |
72 | prefixes | 76 | // } |
77 | // """, | ||
78 | // prefixes | ||
79 | // ) | ||
80 | |||
81 | val query2 = Query.create( | ||
82 | QueryType.SELECT, | ||
83 | false, | ||
84 | List(v("w"), v("doc"), v("doc"), v("document_hyperlink")).asJava, | ||
85 | Conjunction.create( | ||
86 | Atom.rdf(v("w"), IRI.RDF_TYPE, c("Wellbore")), | ||
87 | Atom.rdf(v("w"), c("wellboreDocument"), v("doc")), | ||
88 | Atom.rdf(v("doc"), c("hasURL"), v("document_hyperlink")) | ||
89 | ) | ||
73 | ) | 90 | ) |
74 | 91 | ||
75 | val query5 = parseQuery( | 92 | // QUERY 3 |
76 | """ | 93 | |
77 | SELECT ?wellbore ?unit_name ?discovery | 94 | // val query3 = parseQuery( |
78 | WHERE { | 95 | // """ |
79 | ?w a :Wellbore ; | 96 | // SELECT ?w ?doc ?document_hyperlink |
80 | :name ?wellbore ; | 97 | // WHERE { |
81 | :hasWellboreInterval ?c_int ; | 98 | // ?w a :Wellbore ; |
82 | :hasWellboreInterval ?f_int . | 99 | // :wellboreDocument ?doc . |
83 | ?c_int :hasUnit ?c_unit . | 100 | // ?doc :hasURL ?document_hyperlink |
84 | ?c_unit :name ?unit_name . | 101 | // } |
85 | ?f_int a :FluidZone ; | 102 | // """, |
86 | :name ?discovery ; | 103 | // prefixes |
87 | :overlapsWellboreInterval ?c_int | 104 | // ) |
88 | } | 105 | |
89 | """, | 106 | val query3 = Query.create( |
90 | prefixes | 107 | QueryType.SELECT, |
108 | false, | ||
109 | List(v("w"), v("doc"), v("document_hyperlink")).asJava, | ||
110 | Conjunction.create( | ||
111 | Atom.rdf(v("w"), IRI.RDF_TYPE, c("Wellbore")), | ||
112 | Atom.rdf(v("w"), c("wellboreDocument"), v("doc")), | ||
113 | Atom.rdf(v("doc"), c("hasURL"), v("document_hyperlink")) | ||
114 | ) | ||
91 | ) | 115 | ) |
92 | 116 | ||
93 | val query6 = parseQuery( | 117 | // QUERY 4 |
94 | """ | 118 | |
95 | SELECT DISTINCT ?wellbore ?content | 119 | // val query4 = parseQuery( |
96 | WHERE { | 120 | // """ |
97 | ?w a :Wellbore ; | 121 | // SELECT ?w ?doc ?document_hyperlink |
98 | :name ?wellbore ; | 122 | // WHERE { |
99 | :hasWellboreInterval ?int . | 123 | // ?w a :Wellbore ; |
100 | ?int a :FluidZone ; | 124 | // :wellboreDocument ?doc . |
101 | :fluidZoneContent ?content | 125 | // ?doc :hasURL ?document_hyperlink |
102 | } | 126 | // } |
103 | """, | 127 | // """, |
104 | prefixes | 128 | // prefixes |
129 | // ) | ||
130 | |||
131 | val query4 = Query.create( | ||
132 | QueryType.SELECT, | ||
133 | false, | ||
134 | List(v("w"), v("doc"), v("document_hyperlink")).asJava, | ||
135 | Conjunction.create( | ||
136 | Atom.rdf(v("w"), IRI.RDF_TYPE, c("Wellbore")), | ||
137 | Atom.rdf(v("w"), c("wellboreDocument"), v("doc")), | ||
138 | Atom.rdf(v("doc"), c("hasURL"), v("document_hyperlink")) | ||
139 | ) | ||
105 | ) | 140 | ) |
106 | 141 | ||
107 | val query7 = parseQuery( | 142 | // QUERY 5 |
108 | """ | 143 | |
109 | SELECT ?wName ?sample ?porosity ?top_depth_md ?bot_depth_md | 144 | // val query5 = parseQuery( |
110 | WHERE { | 145 | // """ |
111 | ?w a :Wellbore ; | 146 | // SELECT ?wellbore ?unit_name ?discovery |
112 | :name ?wName ; | 147 | // WHERE { |
113 | :hasWellboreInterval ?z . | 148 | // ?w a :Wellbore ; |
114 | ?z :hasUnit ?u . | 149 | // :name ?wellbore ; |
115 | ?u :name ?strat_unit_name . | 150 | // :hasWellboreInterval ?c_int ; |
116 | ?wellbore :hasWellboreInterval ?cored_int . | 151 | // :hasWellboreInterval ?f_int . |
117 | ?c :extractedFrom ?cored_int ; | 152 | // ?c_int :hasUnit ?c_unit . |
118 | :hasCoreSample ?sample . | 153 | // ?c_unit :name ?unit_name . |
119 | ?sample :hasDepth ?sample_depth . | 154 | // ?f_int a :FluidZone ; |
120 | ?sample_depth | 155 | // :name ?discovery ; |
121 | :inWellboreInterval ?z . | 156 | // :overlapsWellboreInterval ?c_int |
122 | ?sample :hasPorosity ?p . | 157 | // } |
123 | ?p :valueInStandardUnit ?porosity . | 158 | // """, |
124 | ?z :hasTopDepth ?top . | 159 | // prefixes |
125 | ?top a :MeasuredDepth ; | 160 | // ) |
126 | :valueInStandardUnit ?top_depth_md . | 161 | |
127 | ?z :hasBottomDepth ?bot . | 162 | val query5 = Query.create( |
128 | ?bot a :MeasuredDepth ; | 163 | QueryType.SELECT, |
129 | :valueInStandardUnit ?bot_depth_md | 164 | false, |
130 | } | 165 | List(v("wellbore"), v("unit_name"), v("discovery")).asJava, |
131 | """, | 166 | Conjunction.create( |
132 | prefixes | 167 | Atom.rdf(v("w"), IRI.RDF_TYPE, c("Wellbore")), |
168 | Atom.rdf(v("w"), c("name"), v("wellbore")), | ||
169 | Atom.rdf(v("w"), c("hasWellboreInterval"), v("c_int")), | ||
170 | Atom.rdf(v("w"), c("hasWellboreInterval"), v("f_int")), | ||
171 | Atom.rdf(v("c_int"), c("hasUnit"), v("c_unit")), | ||
172 | Atom.rdf(v("c_unit"), c("name"), v("unit_name")), | ||
173 | Atom.rdf(v("f_int"), IRI.RDF_TYPE, c("FluidZone")), | ||
174 | Atom.rdf(v("f_int"), c("name"), v("discovery")), | ||
175 | Atom.rdf(v("f_int"), c("overlapsWellboreInterval"), v("c_int")) | ||
176 | ) | ||
133 | ) | 177 | ) |
134 | 178 | ||
179 | // QUERY 6 | ||
180 | |||
181 | // val query6 = parseQuery( | ||
182 | // """ | ||
183 | // SELECT DISTINCT ?wellbore ?content | ||
184 | // WHERE { | ||
185 | // ?w a :Wellbore ; | ||
186 | // :name ?wellbore ; | ||
187 | // :hasWellboreInterval ?int . | ||
188 | // ?int a :FluidZone ; | ||
189 | // :fluidZoneContent ?content | ||
190 | // } | ||
191 | // """, | ||
192 | // prefixes | ||
193 | // ) | ||
194 | |||
195 | val query6 = Query.create( | ||
196 | QueryType.SELECT, | ||
197 | true, | ||
198 | List(v("wellbore"), v("content")).asJava, | ||
199 | Conjunction.create( | ||
200 | Atom.rdf(v("w"), IRI.RDF_TYPE, c("Wellbore")), | ||
201 | Atom.rdf(v("w"), c("name"), v("wellbore")), | ||
202 | Atom.rdf(v("w"), c("hasWellboreInterval"), v("int")), | ||
203 | Atom.rdf(v("int"), IRI.RDF_TYPE, c("FluidZone")), | ||
204 | Atom.rdf(v("int"), c("fluidZoneContent"), v("content")) | ||
205 | ) | ||
206 | ) | ||
207 | |||
208 | // QUERY 7 | ||
209 | |||
210 | // val query7 = parseQuery( | ||
211 | // """ | ||
212 | // SELECT ?wName ?sample ?porosity ?top_depth_md ?bot_depth_md | ||
213 | // WHERE { | ||
214 | // ?w a :Wellbore ; | ||
215 | // :name ?wName ; | ||
216 | // :hasWellboreInterval ?z . | ||
217 | // ?z :hasUnit ?u . | ||
218 | // ?u :name ?strat_unit_name . | ||
219 | // ?wellbore :hasWellboreInterval ?cored_int . | ||
220 | // ?c :extractedFrom ?cored_int ; | ||
221 | // :hasCoreSample ?sample . | ||
222 | // ?sample :hasDepth ?sample_depth . | ||
223 | // ?sample_depth | ||
224 | // :inWellboreInterval ?z . | ||
225 | // ?sample :hasPorosity ?p . | ||
226 | // ?p :valueInStandardUnit ?porosity . | ||
227 | // ?z :hasTopDepth ?top . | ||
228 | // ?top a :MeasuredDepth ; | ||
229 | // :valueInStandardUnit ?top_depth_md . | ||
230 | // ?z :hasBottomDepth ?bot . | ||
231 | // ?bot a :MeasuredDepth ; | ||
232 | // :valueInStandardUnit ?bot_depth_md | ||
233 | // } | ||
234 | // """, | ||
235 | // prefixes | ||
236 | // ) | ||
237 | |||
238 | val query7 = Query.create( | ||
239 | QueryType.SELECT, | ||
240 | false, | ||
241 | List( | ||
242 | v("wName"), | ||
243 | v("sample"), | ||
244 | v("porosity"), | ||
245 | v("top_depth_md"), | ||
246 | v("bot_depth_md") | ||
247 | ).asJava, | ||
248 | Conjunction.create( | ||
249 | Atom.rdf(v("w"), IRI.RDF_TYPE, c("Wellbore")), | ||
250 | Atom.rdf(v("w"), c("name"), v("wName")), | ||
251 | Atom.rdf(v("w"), c("hasWellboreInterval"), v("z")), | ||
252 | Atom.rdf(v("z"), c("hasUnit"), v("u")), | ||
253 | Atom.rdf(v("u"), c("name"), v("strat_unit_name")), | ||
254 | Atom.rdf(v("wellbore"), c("hasWellboreInterval"), v("cored_int")), | ||
255 | Atom.rdf(v("c"), c("extractedFrom"), v("cored_int")), | ||
256 | Atom.rdf(v("c"), c("hasCoreSample"), v("sample")), | ||
257 | Atom.rdf(v("sample"), c("hasDepth"), v("sample_depth")), | ||
258 | Atom.rdf(v("sample_depth"), c("inWellboreInterval"), v("z")), | ||
259 | Atom.rdf(v("sample"), c("hasPorosity"), v("p")), | ||
260 | Atom.rdf(v("p"), c("valueInStandardUnit"), v("porosity")), | ||
261 | Atom.rdf(v("z"), c("hasTopDepth"), v("top")), | ||
262 | Atom.rdf(v("top"), IRI.RDF_TYPE, c("MeasuredDepth")), | ||
263 | Atom.rdf(v("top"), c("valueInStandardUnit"), v("top_depth_md")), | ||
264 | Atom.rdf(v("z"), c("hasBottomDepth"), v("bot")), | ||
265 | Atom.rdf(v("bot"), IRI.RDF_TYPE, c("MeasuredDepth")), | ||
266 | Atom.rdf(v("bot"), c("valueInStandardUnit"), v("bot_depth_md")) | ||
267 | ) | ||
268 | ) | ||
269 | |||
270 | val queries = | ||
271 | List(query0, query1, query2, query3, query4, query5, query6, query7) | ||
272 | |||
135 | } | 273 | } |
136 | 274 | ||
137 | class FilteringProgramSpec | 275 | class FilteringProgramSpec |
@@ -142,33 +280,28 @@ class FilteringProgramSpec | |||
142 | 280 | ||
143 | import FilteringProgramSpec._ | 281 | import FilteringProgramSpec._ |
144 | 282 | ||
145 | query0.toString() should "have distinct answer and bounded variables" in { | 283 | "Queries" should "have distinct answer and bounded variables" in { |
146 | val program = new FilteringProgram(query0, List()) | 284 | for (query <- queries) { |
147 | forAll(program.answer) { v => program.bounded should not contain v } | 285 | val program = new FilteringProgram(query, List()) |
148 | forAll(program.bounded) { v => program.answer should not contain v } | 286 | forAll(program.answer) { v => program.bounded should not contain v } |
287 | forAll(program.bounded) { v => program.answer should not contain v } | ||
288 | } | ||
149 | } | 289 | } |
150 | 290 | ||
151 | it should "have {?obj, ?pred} as bounded variables" in { | 291 | query0.toString() should "have {?obj, ?pred} as bounded variables" in { |
152 | val pred = Variable.create("obj") | 292 | val pred = Variable.create("obj") |
153 | val obj = Variable.create("pred") | 293 | val obj = Variable.create("pred") |
154 | val program = new FilteringProgram(query0, List()) | 294 | val program = new FilteringProgram(query0, List()) |
155 | program.bounded should contain theSameElementsAs List(pred, obj) | 295 | program.bounded should contain theSameElementsAs List(pred, obj) |
156 | } | 296 | } |
157 | 297 | ||
158 | query1.toString() should "have distinct answer and bounded variables" in { | 298 | query1.toString() should "have no bounded variable" in { |
159 | val program = new FilteringProgram(query1, List()) | ||
160 | forAll(program.answer) { v => program.bounded should not contain v } | ||
161 | forAll(program.bounded) { v => program.answer should not contain v } | ||
162 | } | ||
163 | |||
164 | it should "have no bounded variable" in { | ||
165 | val program = new FilteringProgram(query1, List()) | 299 | val program = new FilteringProgram(query1, List()) |
166 | program.bounded shouldBe empty | 300 | program.bounded shouldBe empty |
167 | } | 301 | } |
168 | 302 | ||
169 | query2.toString() should "have distinct answer and bounded variables" in { | 303 | query2.toString() should "have no bounded variable" in { |
170 | val program = new FilteringProgram(query2, List()) | 304 | val program = new FilteringProgram(query2, List()) |
171 | forAll(program.answer) { v => program.bounded should not contain v } | 305 | program.bounded shouldBe empty |
172 | forAll(program.bounded) { v => program.answer should not contain v } | ||
173 | } | 306 | } |
174 | } | 307 | } |