blob: 06ea165db095c851b489d0aa9d8547e107b38c2b [file] [log] [blame]
Joachim Bingelf05490a2015-01-23 11:43:52 +00001package de.ids_mannheim.korap.query.serialize;
Joachim Bingel019ba5c2014-04-28 14:59:04 +00002import static org.junit.Assert.*;
3
Joachim Bingel66472b82014-12-04 16:00:05 +00004import java.io.IOException;
5import java.util.ArrayList;
Joachim Bingelba253a72015-01-23 18:28:29 +00006import java.util.Map;
Joachim Bingel66472b82014-12-04 16:00:05 +00007
Joachim Bingel019ba5c2014-04-28 14:59:04 +00008import org.junit.Test;
9
Joachim Bingel66472b82014-12-04 16:00:05 +000010import com.fasterxml.jackson.core.JsonProcessingException;
11import com.fasterxml.jackson.databind.JsonNode;
12import com.fasterxml.jackson.databind.ObjectMapper;
13
14import de.ids_mannheim.korap.query.serialize.QuerySerializer;
Joachim Bingel9f208192015-01-19 18:15:24 +000015import de.ids_mannheim.korap.query.serialize.util.StatusCodes;
Joachim Bingel019ba5c2014-04-28 14:59:04 +000016
Joachim Bingel66472b82014-12-04 16:00:05 +000017/**
18 * Tests for JSON-LD serialization of ANNIS QL queries.
19 * @author Joachim Bingel (bingel@ids-mannheim.de)
20 * @version 1.0
21 */
Joachim Bingel1faf8a52015-01-09 13:17:34 +000022public class AnnisQueryProcessorTest {
Joachim Bingel019ba5c2014-04-28 14:59:04 +000023
Joachim Bingelba253a72015-01-23 18:28:29 +000024 String query;
25 ArrayList<JsonNode> operands;
Joachim Bingel66472b82014-12-04 16:00:05 +000026
Joachim Bingelba253a72015-01-23 18:28:29 +000027 QuerySerializer qs = new QuerySerializer();
28 ObjectMapper mapper = new ObjectMapper();
29 JsonNode res;
Joachim Bingelaee38ae2014-06-25 09:32:56 +000030
Joachim Bingelba253a72015-01-23 18:28:29 +000031 @Test
32 public void testContext() throws JsonProcessingException, IOException {
33 String contextUrl = "http://ids-mannheim.de/ns/KorAP/json-ld/v0.2/context.jsonld";
34 query = "foo";
35 qs.setQuery(query, "annis");
36 res = mapper.readTree(qs.toJSON());
37 assertEquals(contextUrl, res.get("@context").asText());
38 }
Joachim Bingel66472b82014-12-04 16:00:05 +000039
Joachim Bingelba253a72015-01-23 18:28:29 +000040 @Test
41 public void testSingleTokens() throws JsonProcessingException, IOException {
42 query = "\"Mann\"";
43 qs.setQuery(query, "annis");
44 res = mapper.readTree(qs.toJSON());
45 assertEquals("korap:token", res.at("/query/@type").asText());
46 assertEquals("korap:term", res.at("/query/wrap/@type").asText());
47 assertEquals("orth", res.at("/query/wrap/layer").asText());
48 assertEquals("Mann", res.at("/query/wrap/key").asText());
49 assertEquals("match:eq", res.at("/query/wrap/match").asText());
50
51 query = "tok!=\"Frau\"";
52 qs.setQuery(query, "annis");
53 res = mapper.readTree(qs.toJSON());
54 assertEquals("korap:token", res.at("/query/@type").asText());
55 assertEquals("korap:term", res.at("/query/wrap/@type").asText());
56 assertEquals("orth", res.at("/query/wrap/layer").asText());
57 assertEquals("Frau", res.at("/query/wrap/key").asText());
58 assertEquals("match:ne", res.at("/query/wrap/match").asText());
59
60 query = "tok"; // special keyword for token
61 qs.setQuery(query, "annis");
62 res = mapper.readTree(qs.toJSON());
63 assertEquals("korap:token", res.at("/query/@type").asText());
64
65 query = "Mann"; // no special keyword -> defaults to layer name
66 qs.setQuery(query, "annis");
67 res = mapper.readTree(qs.toJSON());
68 assertEquals("korap:span", res.at("/query/@type").asText());
69 assertEquals("Mann", res.at("/query/layer").asText());
70 }
71
72 @Test
73 public void testSpans() throws JsonProcessingException, IOException {
74 query = "node"; // special keyword for general span
75 qs.setQuery(query, "annis");
76 res = mapper.readTree(qs.toJSON());
77 assertEquals("korap:span", res.at("/query/@type").asText());
78
79 query = "cat=\"np\""; // cat is special keyword for spans
80 qs.setQuery(query, "annis");
81 res = mapper.readTree(qs.toJSON());
82 assertEquals("korap:span", res.at("/query/@type").asText());
83 assertEquals("np", res.at("/query/key").asText());
84 assertEquals("c", res.at("/query/layer").asText());
85
86 query = "cat=\"NP\"";
87 qs.setQuery(query, "annis");
88 res = mapper.readTree(qs.toJSON());
89 assertEquals("korap:span", res.at("/query/@type").asText());
90 assertEquals("NP", res.at("/query/key").asText());
91 assertEquals("c", res.at("/query/layer").asText());
92 }
93
94 @Test
95 public void testRegex() throws JsonProcessingException, IOException {
96 query = "/Mann/";
97 qs.setQuery(query, "annis");
98 res = mapper.readTree(qs.toJSON());
99 assertEquals("korap:token", res.at("/query/@type").asText());
100 assertEquals("korap:term", res.at("/query/wrap/@type").asText());
101 assertEquals("type:regex", res.at("/query/wrap/type").asText());
102 assertEquals("orth", res.at("/query/wrap/layer").asText());
103 assertEquals("Mann", res.at("/query/wrap/key").asText());
104 assertEquals("match:eq", res.at("/query/wrap/match").asText());
105
106 query = "/.*?Mann.*?/";
107 qs.setQuery(query, "annis");
108 res = mapper.readTree(qs.toJSON());
109 assertEquals("type:regex", res.at("/query/wrap/type").asText());
110 assertEquals(".*?Mann.*?", res.at("/query/wrap/key").asText());
111 }
112
113 @Test
114 public void testFoundriesLayers() throws JsonProcessingException, IOException {
115 query = "c=\"np\"";
116 qs.setQuery(query, "annis");
117 res = mapper.readTree(qs.toJSON());
118 assertEquals("korap:span", res.at("/query/@type").asText());
119 assertEquals("np", res.at("/query/key").asText());
120 assertEquals("c", res.at("/query/layer").asText());
121
122 query = "cnx/c=\"np\"";
123 qs.setQuery(query, "annis");
124 res = mapper.readTree(qs.toJSON());
125 assertEquals("korap:span", res.at("/query/@type").asText());
126 assertEquals("np", res.at("/query/key").asText());
127 assertEquals("c", res.at("/query/layer").asText());
128 assertEquals("cnx", res.at("/query/foundry").asText());
129
130 query = "tt/pos=\"np\"";
131 qs.setQuery(query, "annis");
132 res = mapper.readTree(qs.toJSON());
133 assertEquals("korap:token", res.at("/query/@type").asText());
134 assertEquals("korap:term", res.at("/query/wrap/@type").asText());
135 assertEquals("np", res.at("/query/wrap/key").asText());
136 assertEquals("p", res.at("/query/wrap/layer").asText());
137 assertEquals("tt", res.at("/query/wrap/foundry").asText());
138 }
139
140 @Test
141 public void testDirectDeclarationRelations() throws JsonProcessingException, IOException {
142 query = "node > node";
143 qs.setQuery(query, "annis");
144 res = mapper.readTree(qs.toJSON());
145 assertEquals("korap:group", res.at("/query/@type").asText());
146 assertEquals("operation:relation", res.at("/query/operation").asText());
147 assertEquals("korap:span", res.at("/query/operands/0/@type").asText());
148 assertEquals("korap:span", res.at("/query/operands/1/@type").asText());
149 assertEquals("korap:relation", res.at("/query/relation/@type").asText());
150 assertEquals("korap:term", res.at("/query/relation/wrap/@type").asText());
151 assertEquals("c", res.at("/query/relation/wrap/layer").asText());
152
153 query = "node > cnx/c=\"np\"";
154 qs.setQuery(query, "annis");
155 res = mapper.readTree(qs.toJSON());
156 assertEquals("korap:group", res.at("/query/@type").asText());
157 assertEquals("operation:relation", res.at("/query/operation").asText());
158 assertEquals("korap:span", res.at("/query/operands/0/@type").asText());
159 assertEquals("korap:span", res.at("/query/operands/1/@type").asText());
160 assertEquals("np", res.at("/query/operands/1/key").asText());
161 assertEquals("c", res.at("/query/operands/1/layer").asText());
162 assertEquals("cnx", res.at("/query/operands/1/foundry").asText());
163 assertEquals("korap:relation", res.at("/query/relation/@type").asText());
164 assertEquals("korap:term", res.at("/query/relation/wrap/@type").asText());
165 assertEquals("c", res.at("/query/relation/wrap/layer").asText());
166
167 query = "cnx/c=\"np\" > node";
168 qs.setQuery(query, "annis");
169 res = mapper.readTree(qs.toJSON());
170 assertEquals(true, res.at("/query/operands/1/key").isMissingNode());
171 assertEquals("np", res.at("/query/operands/0/key").asText());
172
173 query = "cat=/NP/ & cat=/PP/ > #1";
174 qs.setQuery(query, "annis");
175 res = mapper.readTree(qs.toJSON());
176 assertEquals("korap:group", res.at("/query/@type").asText());
177 assertEquals("operation:relation", res.at("/query/operation").asText());
178 assertEquals("korap:span", res.at("/query/operands/0/@type").asText());
179 assertEquals("PP", res.at("/query/operands/0/key").asText());
180 assertEquals("korap:span", res.at("/query/operands/1/@type").asText());
181 assertEquals("NP", res.at("/query/operands/1/key").asText());
182 assertEquals(true, res.at("/query/operands/2").isMissingNode());
183 assertEquals("korap:relation", res.at("/query/relation/@type").asText());
184 assertEquals("korap:term", res.at("/query/relation/wrap/@type").asText());
185 assertEquals("c", res.at("/query/relation/wrap/layer").asText());
186 }
187
188 @Test
189 public void testDefPredicationInversion() throws JsonProcessingException, IOException {
190 query = "#1 > #2 & cnx/cat=\"vp\" & cnx/cat=\"np\"";
191 qs.setQuery(query, "annis");
192 res = mapper.readTree(qs.toJSON());
193 assertEquals("korap:group", res.at("/query/@type").asText());
194 assertEquals("operation:relation", res.at("/query/operation").asText());
195 assertEquals("korap:span", res.at("/query/operands/0/@type").asText());
196 assertEquals("korap:span", res.at("/query/operands/0/@type").asText());
197 assertEquals("vp", res.at("/query/operands/0/key").asText());
198 assertEquals("c", res.at("/query/operands/0/layer").asText());
199 assertEquals("cnx", res.at("/query/operands/0/foundry").asText());
200 assertEquals("korap:span", res.at("/query/operands/1/@type").asText());
201 assertEquals("np", res.at("/query/operands/1/key").asText());
202 assertEquals("c", res.at("/query/operands/1/layer").asText());
203 assertEquals("cnx", res.at("/query/operands/1/foundry").asText());
204 assertEquals("korap:relation", res.at("/query/relation/@type").asText());
205 assertEquals("korap:term", res.at("/query/relation/wrap/@type").asText());
206 assertEquals("c", res.at("/query/relation/wrap/layer").asText());
207 }
208
209 @Test
210 public void testSimpleDominance() throws JsonProcessingException, IOException {
211 query = "node & node & #2 > #1";
212 qs.setQuery(query, "annis");
213 res = mapper.readTree(qs.toJSON());
214 assertEquals("korap:group", res.at("/query/@type").asText());
215 assertEquals("operation:relation", res.at("/query/operation").asText());
216 assertEquals("korap:span", res.at("/query/operands/0/@type").asText());
217 assertEquals("korap:span", res.at("/query/operands/1/@type").asText());
218 assertEquals("korap:relation", res.at("/query/relation/@type").asText());
219 assertEquals("korap:term", res.at("/query/relation/wrap/@type").asText());
220 assertEquals("c", res.at("/query/relation/wrap/layer").asText());
221
222 query = "\"Mann\" & node & #2 > #1";
223 qs.setQuery(query, "annis");
224 res = mapper.readTree(qs.toJSON());
225 assertEquals("korap:group", res.at("/query/@type").asText());
226 assertEquals("operation:relation", res.at("/query/operation").asText());
227 assertEquals("korap:span", res.at("/query/operands/0/@type").asText());
228 assertEquals("korap:token", res.at("/query/operands/1/@type").asText());
229 assertEquals("Mann", res.at("/query/operands/1/wrap/key").asText());
230 assertEquals("korap:relation", res.at("/query/relation/@type").asText());
231 assertEquals("korap:term", res.at("/query/relation/wrap/@type").asText());
232 assertEquals("c", res.at("/query/relation/wrap/layer").asText());
233
234 query = "\"Mann\" & node & #2 >[func=\"SB\"] #1"; //coordinates the func=SB term and requires a "c"-layer term (consituency relation/dominance)
235 qs.setQuery(query, "annis");
236 res = mapper.readTree(qs.toJSON());
237 assertEquals("korap:relation", res.at("/query/relation/@type").asText());
238 assertEquals("korap:termGroup", res.at("/query/relation/wrap/@type").asText());
239 assertEquals("relation:and", res.at("/query/relation/wrap/relation").asText());
240 assertEquals("c", res.at("/query/relation/wrap/operands/1/layer").asText());
241 assertEquals("func", res.at("/query/relation/wrap/operands/0/layer").asText());
242 assertEquals("SB", res.at("/query/relation/wrap/operands/0/key").asText());
243
244 query = "cat=\"S\" & node & #1 >[func=\"SB\" func=\"MO\"] #2"; // quite meaningless (function is subject and modifier), but this is allowed by Annis, however its backend only regards the 1st option
245 qs.setQuery(query, "annis");
246 res = mapper.readTree(qs.toJSON());
247 assertEquals("korap:relation", res.at("/query/relation/@type").asText());
248 assertEquals("korap:termGroup", res.at("/query/relation/wrap/@type").asText());
249 assertEquals("relation:and", res.at("/query/relation/wrap/relation").asText());
250 assertEquals("func", res.at("/query/relation/wrap/operands/0/layer").asText());
251 assertEquals("SB", res.at("/query/relation/wrap/operands/0/key").asText());
252 assertEquals("func", res.at("/query/relation/wrap/operands/1/layer").asText());
253 assertEquals("MO" , res.at("/query/relation/wrap/operands/1/key").asText());
254 assertEquals("c", res.at("/query/relation/wrap/operands/2/layer").asText());
255
256 query = "cat=\"S\" & cat=\"NP\" & #1 >@l #2"; // all sentences starting with NP -> wrap relation in startswith and retrieve 2nd operand with focus
257 qs.setQuery(query, "annis");
258 res = mapper.readTree(qs.toJSON());
259 assertEquals("operation:position", res.at("/query/operation").asText());
260 assertEquals("operation:relation", res.at("/query/operands/0/operation").asText());
261 assertEquals("frames:startswith", res.at("/query/frames/0").asText());
262 assertEquals("korap:span", res.at("/query/operands/0/operands/0/@type").asText());
263 assertEquals("S", res.at("/query/operands/0/operands/0/key").asText());
264 assertEquals("korap:group", res.at("/query/operands/0/operands/1/@type").asText());
265 assertEquals("operation:class", res.at("/query/operands/0/operands/1/operation").asText());
266 assertEquals(129, res.at("/query/operands/0/operands/1/classOut").asInt());
267 assertEquals("korap:span", res.at("/query/operands/0/operands/1/operands/0/@type").asText());
268 assertEquals("NP", res.at("/query/operands/0/operands/1/operands/0/key").asText());
269 assertEquals("korap:reference", res.at("/query/operands/1/@type").asText());
270 assertEquals("operation:focus", res.at("/query/operands/1/operation").asText());
271 assertEquals(129, res.at("/query/operands/1/classRef/0").asInt());
272
273 query = "cat=\"S\" & cat=\"NP\" & #1 >@r #2";
274 qs.setQuery(query, "annis");
275 res = mapper.readTree(qs.toJSON());
276 assertEquals("operation:position", res.at("/query/operation").asText());
277 assertEquals("operation:relation", res.at("/query/operands/0/operation").asText());
278 assertEquals("frames:endswith", res.at("/query/frames/0").asText());
279 assertEquals("korap:span", res.at("/query/operands/0/operands/0/@type").asText());
280 assertEquals("S", res.at("/query/operands/0/operands/0/key").asText());
281 assertEquals("korap:group", res.at("/query/operands/0/operands/1/@type").asText());
282 assertEquals("operation:class", res.at("/query/operands/0/operands/1/operation").asText());
283 assertEquals(129, res.at("/query/operands/0/operands/1/classOut").asInt());
284 assertEquals("korap:span", res.at("/query/operands/0/operands/1/operands/0/@type").asText());
285 assertEquals("NP", res.at("/query/operands/0/operands/1/operands/0/key").asText());
286 assertEquals("korap:reference", res.at("/query/operands/1/@type").asText());
287 assertEquals("operation:focus", res.at("/query/operands/1/operation").asText());
288 assertEquals(129, res.at("/query/operands/1/classRef/0").asInt());
289 }
290
291 @Test
292 public void testIndirectDominance() throws JsonProcessingException, IOException {
293 query = "node & node & #1 >2,4 #2";
294 qs.setQuery(query, "annis");
295 res = mapper.readTree(qs.toJSON());
296 assertEquals("korap:group", res.at("/query/@type").asText());
297 assertEquals("operation:relation", res.at("/query/operation").asText());
298 assertEquals("korap:span", res.at("/query/operands/0/@type").asText());
299 assertEquals("korap:span", res.at("/query/operands/1/@type").asText());
300 assertEquals("korap:relation", res.at("/query/relation/@type").asText());
301 assertEquals(2, res.at("/query/relation/boundary/min").asInt());
302 assertEquals(4, res.at("/query/relation/boundary/max").asInt());
303 assertEquals("korap:term", res.at("/query/relation/wrap/@type").asText());
304 assertEquals("c", res.at("/query/relation/wrap/layer").asText());
305
306 query = "node & node & #1 >* #2";
307 qs.setQuery(query, "annis");
308 res = mapper.readTree(qs.toJSON());
309 assertEquals(0, res.at("/query/relation/boundary/min").asInt());
310 assertEquals(true, res.at("/query/relation/boundary/max").isMissingNode());
311 }
312
313
314 @Test
315 public void testMultipleDominance() throws JsonProcessingException, IOException {
316 query = "cat=\"CP\" & cat=\"VP\" & cat=\"NP\" & #1 > #2 > #3";
317 qs.setQuery(query, "annis");
318 res = mapper.readTree(qs.toJSON());
319 assertEquals("korap:group", res.at("/query/@type").asText());
320 assertEquals("operation:relation", res.at("/query/operation").asText());
321 assertEquals("korap:reference", res.at("/query/operands/0/@type").asText());
322 assertEquals("operation:focus", res.at("/query/operands/0/operation").asText());
323 assertEquals(128, res.at("/query/operands/0/classRef/0").asInt());
324 assertEquals("korap:group", res.at("/query/operands/0/operands/0/@type").asText());
325 assertEquals("operation:relation", res.at("/query/operands/0/operands/0/operation").asText());
326 assertEquals("korap:relation", res.at("/query/operands/0/operands/0/relation/@type").asText());
327 assertEquals("c", res.at("/query/operands/0/operands/0/relation/wrap/layer").asText());
328 assertEquals("korap:span", res.at("/query/operands/0/operands/0/operands/0/@type").asText());
329 assertEquals("c", res.at("/query/operands/0/operands/0/operands/0/layer").asText());
330 assertEquals("CP", res.at("/query/operands/0/operands/0/operands/0/key").asText());
331 assertEquals("korap:group", res.at("/query/operands/0/operands/0/operands/1/@type").asText());
332 assertEquals("operation:class", res.at("/query/operands/0/operands/0/operands/1/operation").asText());
333 assertEquals(128, res.at("/query/operands/0/operands/0/operands/1/classOut").asInt());
334 assertEquals("VP", res.at("/query/operands/0/operands/0/operands/1/operands/0/key").asText());
335 }
336 // query = "cat=\"CP\" & cat=\"VP\" & cat=\"NP\" & #1 > #2 > #3";
337 // String dom1 =
338 // "{@type=korap:group, operation=operation:relation, operands=[" +
339 // "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
340 // "{@type=korap:group, operation=operation:relation, operands=[" +
341 // "{@type=korap:span, layer=cat, key=CP, match=match:eq}," +
342 // "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" +
343 // "{@type=korap:span, layer=cat, key=VP, match=match:eq}" +
344 // "]}" +
345 // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
346 // "]}," +
347 // "{@type=korap:span, layer=cat, key=NP, match=match:eq}" +
348 // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
349 // "}";
350 // aqlt = new AqlTree(query);
351 // map = aqlt.getRequestMap().get("query").toString();
352 // assertEquals(dom1.replaceAll(" ", ""), map.replaceAll(" ", ""));
353 //
354 // query = "cat=\"CP\" & cat=\"VP\" & cat=\"NP\" & cat=\"DP\" & #1 > #2 > #3 > #4";
355 // String dom2 =
356 // "{@type=korap:group, operation=operation:relation, operands=[" +
357 // "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
358 // "{@type=korap:group, operation=operation:relation, operands=[" +
359 // "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
360 // "{@type=korap:group, operation=operation:relation, operands=[" +
361 // "{@type=korap:span, layer=cat, key=CP, match=match:eq}," +
362 // "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" +
363 // "{@type=korap:span, layer=cat, key=VP, match=match:eq}" +
364 // "]}" +
365 // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
366 // "]}," +
367 // "{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +
368 // "{@type=korap:span, layer=cat, key=NP, match=match:eq}" +
369 // "]}" +
370 // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
371 // "]}," +
372 // "{@type=korap:span, layer=cat, key=DP, match=match:eq}" +
373 // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
374 // "}";
375 // aqlt = new AqlTree(query);
376 // map = aqlt.getRequestMap().get("query").toString();
377 // assertEquals(dom2.replaceAll(" ", ""), map.replaceAll(" ", ""));
378 // }
379 //
380 // @Test
381 // public void testPointingRelations() throws Exception {
382 // query = "node & node & #2 ->coref[val=\"true\"] #1";
383 // String dom1 =
384 // "{@type=korap:group, operation=operation:relation, operands=[" +
385 // "{@type=korap:span}," +
386 // "{@type=korap:span}" +
387 // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=coref, key=true, match=match:eq}}" +
388 // "}";
389 // aqlt = new AqlTree(query);
390 // map = aqlt.getRequestMap().get("query").toString();
391 // assertEquals(dom1.replaceAll(" ", ""), map.replaceAll(" ", ""));
392 //
393 // query = "node & node & #2 ->mate/coref[val=\"true\"] #1";
394 // String dom2 =
395 // "{@type=korap:group, operation=operation:relation, operands=[" +
396 // "{@type=korap:span}," +
397 // "{@type=korap:span}" +
398 // "], relation={@type=korap:relation, wrap={@type=korap:term, foundry=mate, layer=coref, key=true, match=match:eq}}" +
399 // "}";
400 // aqlt = new AqlTree(query);
401 // map = aqlt.getRequestMap().get("query").toString();
402 // assertEquals(dom2.replaceAll(" ", ""), map.replaceAll(" ", ""));
403 // }
404 //
405 // @Test
406 // public void testSequence() throws Exception {
407 // query = "node & node & #1 . #2";
408 // String seq1 =
409 // "{@type=korap:group, operation=operation:sequence, " +
410 // "operands=[" +
411 // "{@type=korap:span}," +
412 // "{@type=korap:span}" +
413 // "], inOrder=true" +
414 // "}";
415 // aqlt = new AqlTree(query);
416 // map = aqlt.getRequestMap().get("query").toString();
417 // assertEquals(seq1.replaceAll(" ", ""), map.replaceAll(" ", ""));
418 //
419 // query = "node & node & #1 .* #2";
420 // String seq2 =
421 // "{@type=korap:group, operation=operation:sequence, operands=[" +
422 // "{@type=korap:span}," +
423 // "{@type=korap:span}" +
424 // "], distances=[" +
425 // "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0}, min=0}" +
426 // "], inOrder=true" +
427 // "}";
428 // aqlt = new AqlTree(query);
429 // map = aqlt.getRequestMap().get("query").toString();
430 // assertEquals(seq2.replaceAll(" ", ""), map.replaceAll(" ", ""));
431 //
432 // query = "node & node & #1 .2,3 #2";
433 // String seq3 =
434 // "{@type=korap:group, operation=operation:sequence, operands=[" +
435 // "{@type=korap:span}," +
436 // "{@type=korap:span}" +
437 // "], distances=[" +
438 // "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=2, max=3}, min=2, max=3}" +
439 // "], inOrder=true" +
440 // "}";
441 // aqlt = new AqlTree(query);
442 // map = aqlt.getRequestMap().get("query").toString();
443 // assertEquals(seq3.replaceAll(" ", ""), map.replaceAll(" ", ""));
444 //
445 // }
446 //
447 @Test
448 public void testMultipleSequence() throws Exception {
449 query = "tok=\"a\" & tok=\"b\" & tok=\"c\" & #1 . #2 & #2 . #3";
450 String seq4 =
451 "{@type=korap:group, operation=operation:sequence," +
452 "operands=[" +
453 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
454 "{@type=korap:group, operation=operation:sequence, operands=[" +
455 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sonne, match=match:eq}}," +
456 "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" +
457 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mond, match=match:eq}}" +
458 "]}" +
459 "], distances=[" +
460 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0, max=2}, min=0, max=2}" +
461 "], inOrder=true}" +
462 "]}," +
463 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sterne, match=match:eq}}" +
464 "],distances=[" +
465 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0, max=4}, min=0, max=4}" +
466 "], inOrder=true" +
467 "}";
Joachim Bingel20e06ac2015-01-15 10:31:33 +0000468 qs.setQuery(query, "annis");
469 res = mapper.readTree(qs.toJSON());
470 assertEquals("korap:group", res.at("/query/@type").asText());
471 assertEquals("operation:sequence", res.at("/query/operation").asText());
472 assertEquals("korap:reference", res.at("/query/operands/0/@type").asText());
473 assertEquals(128, res.at("/query/operands/0/classRef/0").asInt());
474 assertEquals(res.at("/query/operands/0/classRef/0").asInt(),
Joachim Bingelba253a72015-01-23 18:28:29 +0000475 res.at("/query/operands/0/operands/0/operands/1/classOut").asInt());
476 }
Joachim Bingel20e06ac2015-01-15 10:31:33 +0000477
Joachim Bingelba253a72015-01-23 18:28:29 +0000478
479 //
480 // query = "node & node & node & #1 . #2 .1,3 #3";
481 // String seq5 =
482 // "{@type=korap:group, operation=operation:sequence, operands=[" +
483 // "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
484 // "{@type=korap:group, operation=operation:sequence, operands=[" +
485 // "{@type=korap:span}," +
486 // "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" +
487 // "{@type=korap:span}" +
488 // "]} "+
489 // "], inOrder=true}" +
490 // "]}," +
491 // "{@type=korap:span}" +
492 // "], distances=[" +
493 // "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1, max=3}, min=1, max=3}" +
494 // "], inOrder=true" +
495 // "}";
496 // aqlt = new AqlTree(query);
497 // map = aqlt.getRequestMap().get("query").toString();
498 // assertEquals(seq5.replaceAll(" ", ""), map.replaceAll(" ", ""));
499 //
500 // query = "tok=\"Sonne\" & tok=\"Mond\" & tok=\"Sterne\" & tok=\"Himmel\" & #1 .0,2 #2 .0,4 #3 . #4";
501 // String seq6 =
502 // "{@type=korap:group, operation=operation:sequence, operands=[" +
503 // "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
504 // "{@type=korap:group, operation=operation:sequence, operands=[" +
505 // "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
506 // "{@type=korap:group, operation=operation:sequence, operands=[" +
507 // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sonne, match=match:eq}}," +
508 // "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" +
509 // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mond, match=match:eq}}" +
510 // "]}" +
511 // "], distances=[" +
512 // "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0, max=2}, min=0, max=2}" +
513 // "], inOrder=true}" +
514 // "]}," +
515 // "{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +
516 // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sterne, match=match:eq}}" +
517 // "]}" +
518 // "],distances=[" +
519 // "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0, max=4}, min=0, max=4}" +
520 // "], inOrder=true}" +
521 // "]}," +
522 // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Himmel, match=match:eq}}" +
523 // "], inOrder=true}" ;
524 // aqlt = new AqlTree(query);
525 // map = aqlt.getRequestMap().get("query").toString();
526 // assertEquals(seq6.replaceAll(" ", ""), map.replaceAll(" ", ""));
527 // }
528 //
529 /**
530 * Tests the (rather difficult) serialization of queries where two subsequent relations
531 * do not share any common operand. Makes it impossible to wrap 2nd relation around 1st.
532 * Must therefore re-order relations (or postpone processing of 2nd).
533 * @throws JsonProcessingException
534 * @throws IOException
535 */
536 @Test
Joachim Bingelc9551b32015-01-19 14:26:58 +0000537 public void testNoSharedOperand() throws JsonProcessingException, IOException {
Joachim Bingelba253a72015-01-23 18:28:29 +0000538 query = "cat=\"A\" & cat=\"B\" & cat=\"C\" & cat=\"D\" & #1 . #2 & #3 . #4 & #1 > #3";
539 // the resulting query should be equivalent to PQ+: focus(2:dominates(focus(1:{1:<A>}<B>),{2:<C>}))<D>
Joachim Bingelc9551b32015-01-19 14:26:58 +0000540 qs.setQuery(query, "annis");
541 res = mapper.readTree(qs.toJSON());
542 assertEquals("korap:group", res.at("/query/@type").asText());
543 assertEquals("operation:sequence", res.at("/query/operation").asText());
544 assertEquals("korap:reference", res.at("/query/operands/0/@type").asText());
545 assertEquals("operation:focus", res.at("/query/operands/0/operation").asText());
546 assertEquals("korap:group", res.at("/query/operands/0/operands/0/@type").asText());
547 assertEquals("operation:relation", res.at("/query/operands/0/operands/0/operation").asText());
548 assertEquals("korap:reference", res.at("/query/operands/0/operands/0/operands/0/@type").asText());
549 assertEquals("operation:focus", res.at("/query/operands/0/operands/0/operands/0/operation").asText());
550 assertEquals("korap:group", res.at("/query/operands/0/operands/0/operands/0/operands/0/@type").asText());
551 assertEquals("operation:sequence", res.at("/query/operands/0/operands/0/operands/0/operands/0/operation").asText());
552 assertEquals("operation:class", res.at("/query/operands/0/operands/0/operands/0/operands/0/operands/0/operation").asText());
553 assertEquals("A", res.at("/query/operands/0/operands/0/operands/0/operands/0/operands/0/operands/0/key").asText());
554 assertEquals("B", res.at("/query/operands/0/operands/0/operands/0/operands/0/operands/1/key").asText());
555 assertEquals("C", res.at("/query/operands/0/operands/0/operands/1/operands/0/key").asText());
556 assertEquals("D", res.at("/query/operands/1/key").asText());
Joachim Bingelba253a72015-01-23 18:28:29 +0000557
Joachim Bingelc9551b32015-01-19 14:26:58 +0000558 query = "cat=\"A\" & cat=\"B\" & cat=\"C\" & cat=\"D\" & cat=\"E\" & cat=\"F\" & #1 . #2 & #3 . #4 & #5 . #6 & #1 > #3 & #3 > #5";
559 // the resulting query should be equivalent to PQ+: focus(3:dominates(focus(2:dominates(focus(1:{1:<A>}<B>),{2:<C>}))<D>,{3:<E>}))<F>
560 qs.setQuery(query, "annis");
561 res = mapper.readTree(qs.toJSON());
562 assertEquals("korap:group", res.at("/query/@type").asText());
563 assertEquals("operation:sequence", res.at("/query/operation").asText());
564 assertEquals("korap:reference", res.at("/query/operands/0/@type").asText());
565 assertEquals("operation:focus", res.at("/query/operands/0/operation").asText());
566 assertEquals("korap:group", res.at("/query/operands/0/operands/0/@type").asText());
567 assertEquals("operation:relation", res.at("/query/operands/0/operands/0/operation").asText());
568 assertEquals("korap:reference", res.at("/query/operands/0/operands/0/operands/0/@type").asText());
569 assertEquals("operation:focus", res.at("/query/operands/0/operands/0/operands/0/operation").asText());
570 assertEquals("korap:group", res.at("/query/operands/0/operands/0/operands/0/operands/0/@type").asText());
571 assertEquals("operation:sequence", res.at("/query/operands/0/operands/0/operands/0/operands/0/operation").asText());
572 assertEquals("operation:class", res.at("/query/operands/0/operands/0/operands/0/operands/0/operands/0/operands/0/operands/0/operands/0/operands/0/operation").asText());
573 assertEquals("A", res.at("/query/operands/0/operands/0/operands/0/operands/0/operands/0/operands/0/operands/0/operands/0/operands/0/operands/0/key").asText());
574 assertEquals("B", res.at("/query/operands/0/operands/0/operands/0/operands/0/operands/0/operands/0/operands/0/operands/0/operands/1/key").asText());
575 assertEquals("C", res.at("/query/operands/0/operands/0/operands/0/operands/0/operands/0/operands/0/operands/1/operands/0/key").asText());
576 assertEquals("D", res.at("/query/operands/0/operands/0/operands/0/operands/0/operands/1/key").asText());
577 assertEquals("E", res.at("/query/operands/0/operands/0/operands/1/operands/0/key").asText());
578 assertEquals("F", res.at("/query/operands/1/key").asText());
Joachim Bingelba253a72015-01-23 18:28:29 +0000579
Joachim Bingel9f208192015-01-19 18:15:24 +0000580 query = "cat=\"A\" & cat=\"B\" & cat=\"C\" & cat=\"D\" & #1 . #2 & #3 . #4";
581 // the resulting query should be equivalent to PQ+: focus(2:dominates(focus(1:{1:<A>}<B>),{2:<C>}))<D>
582 qs.setQuery(query, "annis");
583 res = mapper.readTree(qs.toJSON());
584 assertEquals(true, res.at("/query/@type").isMissingNode());
585 assertEquals(StatusCodes.UNBOUND_ANNIS_RELATION, res.at("/errors/0/0").asInt());
Joachim Bingelc9551b32015-01-19 14:26:58 +0000586 }
Joachim Bingelba253a72015-01-23 18:28:29 +0000587
588 @Test
589 public void testMultipleMixedOperators() throws Exception {
590 query = "tok=\"Sonne\" & tok=\"Mond\" & tok=\"Sterne\" & #1 > #2 .0,4 #3";
591 qs.setQuery(query, "annis");
592 res = mapper.readTree(qs.toJSON());
593 assertEquals("korap:group", res.at("/query/@type").asText());
594 assertEquals("operation:sequence", res.at("/query/operation").asText());
595 assertEquals("korap:reference", res.at("/query/operands/0/@type").asText());
596 assertEquals("operation:focus", res.at("/query/operands/0/operation").asText());
597 assertEquals(128, res.at("/query/operands/0/classRef/0").asInt());
598 assertEquals("korap:group", res.at("/query/operands/0/operands/0/@type").asText());
599 assertEquals("operation:relation", res.at("/query/operands/0/operands/0/operation").asText());
600 assertEquals("korap:token", res.at("/query/operands/0/operands/0/operands/0/@type").asText());
601 assertEquals("Sonne", res.at("/query/operands/0/operands/0/operands/0/wrap/key").asText());
602 assertEquals("korap:group", res.at("/query/operands/0/operands/0/operands/1/@type").asText());
603 assertEquals("operation:class", res.at("/query/operands/0/operands/0/operands/1/operation").asText());
604 assertEquals(128, res.at("/query/operands/0/operands/0/operands/1/classOut").asInt());
605 assertEquals("Mond", res.at("/query/operands/0/operands/0/operands/1/operands/0/wrap/key").asText());
606 assertEquals("Sterne", res.at("/query/operands/1/wrap/key").asText());
607 assertEquals("w", res.at("/query/distances/0/key").asText());
608 assertEquals(0, res.at("/query/distances/0/boundary/min").asInt());
609 assertEquals(4, res.at("/query/distances/0/boundary/max").asInt());
610
611 query = "tok=\"Sonne\" & tok=\"Mond\" & #1 > #2 .0,4 tok=\"Sterne\"";
612 qs.setQuery(query, "annis");
613 res = mapper.readTree(qs.toJSON());
614 assertEquals("korap:group", res.at("/query/@type").asText());
615 assertEquals("operation:sequence", res.at("/query/operation").asText());
616 assertEquals("korap:reference", res.at("/query/operands/0/@type").asText());
617 assertEquals("operation:focus", res.at("/query/operands/0/operation").asText());
618 assertEquals(128, res.at("/query/operands/0/classRef/0").asInt());
619 assertEquals("korap:group", res.at("/query/operands/0/operands/0/@type").asText());
620 assertEquals("operation:relation", res.at("/query/operands/0/operands/0/operation").asText());
621 assertEquals("korap:token", res.at("/query/operands/0/operands/0/operands/0/@type").asText());
622 assertEquals("Sonne", res.at("/query/operands/0/operands/0/operands/0/wrap/key").asText());
623 assertEquals("korap:group", res.at("/query/operands/0/operands/0/operands/1/@type").asText());
624 assertEquals("operation:class", res.at("/query/operands/0/operands/0/operands/1/operation").asText());
625 assertEquals(128, res.at("/query/operands/0/operands/0/operands/1/classOut").asInt());
626 assertEquals("Mond", res.at("/query/operands/0/operands/0/operands/1/operands/0/wrap/key").asText());
627 assertEquals("Sterne", res.at("/query/operands/1/wrap/key").asText());
628 assertEquals("w", res.at("/query/distances/0/key").asText());
629 assertEquals(0, res.at("/query/distances/0/boundary/min").asInt());
630 assertEquals(4, res.at("/query/distances/0/boundary/max").asInt());
631
632 query = "cat=\"NP\" & cat=\"VP\" & cat=\"PP\" & #1 $ #2 > #3";
633 qs.setQuery(query, "annis");
634 res = mapper.readTree(qs.toJSON());
635 assertEquals("korap:group", res.at("/query/@type").asText());
636 assertEquals("operation:relation", res.at("/query/operation").asText());
637 assertEquals("korap:reference", res.at("/query/operands/0/@type").asText());
638 assertEquals("operation:focus", res.at("/query/operands/0/operation").asText());
639 assertEquals(129, res.at("/query/operands/0/classRef/0").asInt());
640 assertEquals("korap:group", res.at("/query/operands/0/operands/0/@type").asText());
641 assertEquals("operation:relation", res.at("/query/operands/0/operands/0/operation").asText());
642 assertEquals("korap:reference", res.at("/query/operands/0/operands/0/operands/0/@type").asText());
643 assertEquals("operation:focus", res.at("/query/operands/0/operands/0/operands/0/operation").asText());
644 assertEquals(128, res.at("/query/operands/0/operands/0/operands/0/classRef/0").asInt());
645 assertEquals("korap:group", res.at("/query/operands/0/operands/0/operands/0/operands/0/@type").asText());
646 assertEquals("operation:relation", res.at("/query/operands/0/operands/0/operands/0/operands/0/operation").asText());
647 assertEquals("operation:class", res.at("/query/operands/0/operands/0/operands/0/operands/0/operands/0/operation").asText());
648 assertEquals(128, res.at("/query/operands/0/operands/0/operands/0/operands/0/operands/0/classOut").asInt());
649 assertEquals("korap:span", res.at("/query/operands/0/operands/0/operands/0/operands/0/operands/0/operands/0/@type").asText());
650 assertEquals("NP", res.at("/query/operands/0/operands/0/operands/0/operands/0/operands/1/key").asText());
651 assertEquals("korap:group", res.at("/query/operands/0/operands/0/operands/1/@type").asText());
652 assertEquals("operation:class", res.at("/query/operands/0/operands/0/operands/1/operation").asText());
653 assertEquals(129, res.at("/query/operands/0/operands/0/operands/1/classOut").asInt());
654 assertEquals("VP", res.at("/query/operands/0/operands/0/operands/1/operands/0/key").asText());
655 assertEquals("PP", res.at("/query/operands/1/key").asText());
656
657 }
658 @Test
659 public void testMultipleOperatorsWithSameOperands() throws Exception {
660 query = "cat=\"NP\" > cat=\"VP\" & #1 _l_ #2";
661 qs.setQuery(query, "annis");
662 res = mapper.readTree(qs.toJSON());
663 assertEquals("korap:group", res.at("/query/@type").asText());
664 assertEquals("operation:position", res.at("/query/operation").asText());
665 assertEquals("frames:startswith", res.at("/query/frames/0").asText());
Joachim Bingelc273a442015-01-26 14:03:51 +0000666 assertEquals("korap:reference", res.at("/query/operands/0/@type").asText());
667 assertEquals("operation:focus", res.at("/query/operands/0/operation").asText());
668 assertEquals(128, res.at("/query/operands/0/classRef/0").asInt());
669 assertEquals("korap:group", res.at("/query/operands/0/operands/0/@type").asText());
670 assertEquals("operation:relation", res.at("/query/operands/0/operands/0/operation").asText());
671 assertEquals("operation:class", res.at("/query/operands/0/operands/0/operands/0/operation").asText());
672 assertEquals(128, res.at("/query/operands/0/operands/0/operands/0/classOut").asInt());
673 assertEquals("korap:span", res.at("/query/operands/0/operands/0/operands/0/operands/0/@type").asText());
674 assertEquals("NP", res.at("/query/operands/0/operands/0/operands/0/operands/0/key").asText());
675 assertEquals("operation:class", res.at("/query/operands/0/operands/0/operands/1/operation").asText());
676 assertEquals(129, res.at("/query/operands/0/operands/0/operands/1/classOut").asInt());
677 assertEquals("VP", res.at("/query/operands/0/operands/0/operands/1/operands/0/key").asText());
Joachim Bingelba253a72015-01-23 18:28:29 +0000678 assertEquals("korap:reference", res.at("/query/operands/1/@type").asText());
Joachim Bingelc273a442015-01-26 14:03:51 +0000679 assertEquals("operation:focus", res.at("/query/operands/1/operation").asText());
680 assertEquals(129, res.at("/query/operands/1/classRef/0").asInt());
681
Joachim Bingelba253a72015-01-23 18:28:29 +0000682 }
Joachim Bingel4acf2462015-01-27 11:49:57 +0000683 @Test
684 public void testPositions() throws Exception {
685 query = "node & node & #1 _=_ #2";
686 qs.setQuery(query, "annis");
687 res = mapper.readTree(qs.toJSON());
688 assertEquals("korap:group", res.at("/query/@type").asText());
689 assertEquals("operation:position", res.at("/query/operation").asText());
690 assertEquals("frames:matches", res.at("/query/frames/0").asText());
691 assertEquals("korap:span", res.at("/query/operands/0/@type").asText());
692 assertEquals("korap:span", res.at("/query/operands/1/@type").asText());
693
694 query = "node & node & #1 _i_ #2";
695 qs.setQuery(query, "annis");
696 res = mapper.readTree(qs.toJSON());
697 assertEquals("frames:contains", res.at("/query/frames/0").asText());
698 assertEquals("korap:span", res.at("/query/operands/0/@type").asText());
699 assertEquals("korap:span", res.at("/query/operands/1/@type").asText());
700
701 query = "node & node & #1 _l_ #2";
702 qs.setQuery(query, "annis");
703 res = mapper.readTree(qs.toJSON());
704 assertEquals("frames:startswith", res.at("/query/frames/0").asText());
705 assertEquals("korap:span", res.at("/query/operands/0/@type").asText());
706 assertEquals("korap:span", res.at("/query/operands/1/@type").asText());
707
708 query = "node & node & #1 _r_ #2";
709 qs.setQuery(query, "annis");
710 res = mapper.readTree(qs.toJSON());
711 assertEquals("frames:endswith", res.at("/query/frames/0").asText());
712 assertEquals("korap:span", res.at("/query/operands/0/@type").asText());
713 assertEquals("korap:span", res.at("/query/operands/1/@type").asText());
714
715 query = "node & \"Mann\" & #1 _r_ #2";
716 qs.setQuery(query, "annis");
717 res = mapper.readTree(qs.toJSON());
718 assertEquals("frames:endswith", res.at("/query/frames/0").asText());
719 assertEquals("korap:span", res.at("/query/operands/0/@type").asText());
720 assertEquals("korap:token", res.at("/query/operands/1/@type").asText());
721 assertEquals("Mann", res.at("/query/operands/1/wrap/key").asText());
722
723 query = "node & \"Mann\" & #2 _r_ #1";
724 qs.setQuery(query, "annis");
725 res = mapper.readTree(qs.toJSON());
726 assertEquals("frames:endswith", res.at("/query/frames/0").asText());
727 assertEquals("korap:span", res.at("/query/operands/1/@type").asText());
728 assertEquals("korap:token", res.at("/query/operands/0/@type").asText());
729 assertEquals("Mann", res.at("/query/operands/0/wrap/key").asText());
730
731 query = "node & cat=\"VP\" & cat=\"NP\" & #1 _r_ #2 & #2 _l_ #3";
732 qs.setQuery(query, "annis");
733 res = mapper.readTree(qs.toJSON());
734 assertEquals("frames:startswith", res.at("/query/frames/0").asText());
735 assertEquals("operation:focus", res.at("/query/operands/0/operation").asText());
736 assertEquals(128, res.at("/query/operands/0/classRef/0").asInt());
737 assertEquals("frames:endswith", res.at("/query/operands/0/operands/0/frames/0").asText());
738 assertEquals("korap:span", res.at("/query/operands/0/operands/0/operands/0/@type").asText());
739 assertEquals("korap:group", res.at("/query/operands/0/operands/0/operands/1/@type").asText());
740 assertEquals("operation:class", res.at("/query/operands/0/operands/0/operands/1/operation").asText());
741 assertEquals(128, res.at("/query/operands/0/operands/0/operands/1/classOut").asInt());
742 assertEquals("VP", res.at("/query/operands/0/operands/0/operands/1/operands/0/key").asText());
743 assertEquals("NP", res.at("/query/operands/1/key").asText());
744
745 query = "node & \"Mann\" & #2 _o_ #1";
746 qs.setQuery(query, "annis");
747 res = mapper.readTree(qs.toJSON());
Joachim Bingel037b79b2015-01-27 12:39:19 +0000748 assertEquals("frames:overlapsLeft", res.at("/query/frames/0").asText());
749 assertEquals("frames:overlapsRight", res.at("/query/frames/1").asText());
750 assertEquals("korap:span", res.at("/query/operands/1/@type").asText());
751 assertEquals("korap:token", res.at("/query/operands/0/@type").asText());
752 assertEquals("Mann", res.at("/query/operands/0/wrap/key").asText());
Joachim Bingel4acf2462015-01-27 11:49:57 +0000753
754 query = "node & \"Mann\" & #2 _ol_ #1";
755 qs.setQuery(query, "annis");
756 res = mapper.readTree(qs.toJSON());
757 assertEquals("frames:overlapsLeft", res.at("/query/frames/0").asText());
Joachim Bingel037b79b2015-01-27 12:39:19 +0000758 assertEquals("korap:span", res.at("/query/operands/1/@type").asText());
759 assertEquals("korap:token", res.at("/query/operands/0/@type").asText());
760 assertEquals("Mann", res.at("/query/operands/0/wrap/key").asText());
Joachim Bingel4acf2462015-01-27 11:49:57 +0000761
762 query = "node & \"Mann\" & #2 _or_ #1";
763 qs.setQuery(query, "annis");
764 res = mapper.readTree(qs.toJSON());
Joachim Bingel037b79b2015-01-27 12:39:19 +0000765 assertEquals("frames:overlapsRight", res.at("/query/frames/0").asText());
766 assertEquals("korap:span", res.at("/query/operands/1/@type").asText());
767 assertEquals("korap:token", res.at("/query/operands/0/@type").asText());
768 assertEquals("Mann", res.at("/query/operands/0/wrap/key").asText());
Joachim Bingel4acf2462015-01-27 11:49:57 +0000769 }
770
771 @Test
772 public void testMultiplePredications() throws Exception {
773 // a noun before a verb before a preposition
774 query = "pos=\"N\" & pos=\"V\" & pos=\"P\" & #1 . #2 & #2 . #3";
775 qs.setQuery(query, "annis");
776 res = mapper.readTree(qs.toJSON());
777 assertEquals("operation:sequence", res.at("/query/operation").asText());
778 assertEquals("operation:focus", res.at("/query/operands/0/operation").asText());
779 assertEquals(128, res.at("/query/operands/0/classRef/0").asInt());
780 assertEquals("operation:sequence", res.at("/query/operands/0/operands/0/operation").asText());
781 assertEquals("korap:token", res.at("/query/operands/0/operands/0/operands/0/@type").asText());
782 assertEquals("p", res.at("/query/operands/0/operands/0/operands/0/wrap/layer").asText());
783 assertEquals("N", res.at("/query/operands/0/operands/0/operands/0/wrap/key").asText());
784 assertEquals("korap:group", res.at("/query/operands/0/operands/0/operands/1/@type").asText());
785 assertEquals("operation:class", res.at("/query/operands/0/operands/0/operands/1/operation").asText());
786 assertEquals(128, res.at("/query/operands/0/operands/0/operands/1/classOut").asInt());
787 assertEquals("V", res.at("/query/operands/0/operands/0/operands/1/operands/0/wrap/key").asText());
788 assertEquals("P", res.at("/query/operands/1/wrap/key").asText());
789
790 query = "pos=\"N\" & pos=\"V\" & #1 . #2 & #2 . pos=\"P\"";
791 qs.setQuery(query, "annis");
792 res = mapper.readTree(qs.toJSON());
793 assertEquals("operation:sequence", res.at("/query/operation").asText());
794 assertEquals("operation:focus", res.at("/query/operands/0/operation").asText());
795 assertEquals(128, res.at("/query/operands/0/classRef/0").asInt());
796 assertEquals("operation:sequence", res.at("/query/operands/0/operands/0/operation").asText());
797 assertEquals("korap:token", res.at("/query/operands/0/operands/0/operands/0/@type").asText());
798 assertEquals("p", res.at("/query/operands/0/operands/0/operands/0/wrap/layer").asText());
799 assertEquals("N", res.at("/query/operands/0/operands/0/operands/0/wrap/key").asText());
800 assertEquals("korap:group", res.at("/query/operands/0/operands/0/operands/1/@type").asText());
801 assertEquals("operation:class", res.at("/query/operands/0/operands/0/operands/1/operation").asText());
802 assertEquals(128, res.at("/query/operands/0/operands/0/operands/1/classOut").asInt());
803 assertEquals("V", res.at("/query/operands/0/operands/0/operands/1/operands/0/wrap/key").asText());
804 assertEquals("P", res.at("/query/operands/1/wrap/key").asText());
Joachim Bingel037b79b2015-01-27 12:39:19 +0000805
806 query = "pos=\"N\" & pos=\"V\" & pos=\"P\" & #1 > #2 & #1 > #3";
807 qs.setQuery(query, "annis");
808 res = mapper.readTree(qs.toJSON());
809 assertEquals("operation:relation", res.at("/query/operation").asText());
810 assertEquals("operation:focus", res.at("/query/operands/0/operation").asText());
811 assertEquals(128, res.at("/query/operands/0/classRef/0").asInt());
812 assertEquals("operation:relation", res.at("/query/operands/0/operands/0/operation").asText());
813 assertEquals("operation:class", res.at("/query/operands/0/operands/0/operands/0/operation").asText());
814 assertEquals(128, res.at("/query/operands/0/operands/0/operands/0/classOut").asInt());
815 assertEquals("N", res.at("/query/operands/0/operands/0/operands/0/operands/0/wrap/key").asText());
816 assertEquals("V", res.at("/query/operands/0/operands/0/operands/1/wrap/key").asText());
817 assertEquals("P", res.at("/query/operands/1/wrap/key").asText());
818
819 query = "cat=\"NP\" & pos=\"V\" & pos=\"P\" & #1 > #2 & #1 > #3 & #2 . #3";
820 qs.setQuery(query, "annis");
821 res = mapper.readTree(qs.toJSON());
822 assertEquals("operation:sequence", res.at("/query/operation").asText());
823 assertEquals("operation:focus", res.at("/query/operands/0/operation").asText());
824 assertEquals(129, res.at("/query/operands/0/classRef/0").asInt());
825 assertEquals("operation:relation", res.at("/query/operands/0/operands/0/operation").asText());
826 assertEquals("operation:focus", res.at("/query/operands/0/operands/0/operands/0/operation").asText());
827 assertEquals(128, res.at("/query/operands/0/operands/0/operands/0/classRef/0").asInt());
828 assertEquals("operation:relation", res.at("/query/operands/0/operands/0/operands/0/operands/0/operation").asText());
829 assertEquals("operation:class", res.at("/query/operands/0/operands/0/operands/0/operands/0/operands/0/operation").asText());
830 assertEquals(128, res.at("/query/operands/0/operands/0/operands/0/operands/0/operands/0/classOut").asInt());
831 assertEquals("NP", res.at("/query/operands/0/operands/0/operands/0/operands/0/operands/0/operands/0/key").asText());
832 assertEquals(129, res.at("/query/operands/0/operands/0/operands/0/operands/0/operands/1/classOut").asInt());
833 assertEquals("V", res.at("/query/operands/0/operands/0/operands/0/operands/0/operands/1/operands/0/wrap/key").asText());
834 assertEquals(130, res.at("/query/operands/0/operands/0/operands/1/classOut").asInt());
835 assertEquals("P", res.at("/query/operands/0/operands/0/operands/1/operands/0/wrap/key").asText());
836 assertEquals("operation:focus", res.at("/query/operands/1/operation").asText());
837 assertEquals(130, res.at("/query/operands/1/classRef/0").asInt());
838 assertEquals(true, res.at("/query/operands/1/operands").isMissingNode());
Joachim Bingel4acf2462015-01-27 11:49:57 +0000839 }
840
Joachim Bingelba253a72015-01-23 18:28:29 +0000841 // query = "cat=\"NP\" & pos=\"V\" & pos=\"P\" & #1 > #2 & #1 > #3 & #2 . #3";
842 // String mult4 =
843 // "{@type=korap:group, operation=operation:sequence, operands=[" +
844 // // reduce dominance relations "#1 > #2 & #1 > #3" to operand #2 in order to make it accessible for #2 . #3 (the last/outermost relation)
845 // "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
846 // "{@type=korap:group, operation=operation:relation, operands=[" +
847 // // dominance relation #1 > #2 is reduced to #1, for expressing #1 > #3
848 // "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
849 // "{@type=korap:group, operation=operation:relation, operands=[" +
850 // "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" +
851 // "{@type=korap:span, layer=cat, key=NP, match=match:eq}" +
852 // "]}," +
853 // "{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +
854 // "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=V, match=match:eq}}" +
855 // "]}" +
856 // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
857 // "]}," +
858 // // establish class 2 around P for later reference
859 // "{@type=korap:group, operation=operation:class, class=130, classOut=130, operands=[" +
860 // "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=P, match=match:eq}}" +
861 // "]}" +
862 // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
863 // "]}," +
864 // // refer back to class 2 as second operand
865 // "{@type=korap:reference, operation=operation:focus, classRef=[2]}" +
866 // "], inOrder=true}";
867 // aqlt = new AqlTree(query);
868 // map = aqlt.getRequestMap().get("query").toString();
869 // assertEquals(mult4.replaceAll(" ", ""), map.replaceAll(" ", ""));
870 // }
871 //
872 // @Test
873 // public void testUnaryRelations() throws Exception {
874 // query = "node & #1:tokenarity=2";
875 // String unary1 =
876 // "{@type=korap:span, attr={@type=korap:term, tokenarity={@type=korap:boundary,min=2,max=2}}}";
877 // aqlt = new AqlTree(query);
878 // map = aqlt.getRequestMap().get("query").toString();
879 // assertEquals(unary1.replaceAll(" ", ""), map.replaceAll(" ", ""));
880 //
881 // query = "cnx/cat=\"NP\" & #1:tokenarity=2";
882 // String unary2 =
883 // "{@type=korap:span, foundry=cnx, layer=cat, key=NP, match=match:eq, attr={@type=korap:term, tokenarity={@type=korap:boundary,min=2,max=2}}}";
884 // aqlt = new AqlTree(query);
885 // map = aqlt.getRequestMap().get("query").toString();
886 // assertEquals(unary2.replaceAll(" ", ""), map.replaceAll(" ", ""));
887 //
888 // query = "cnx/cat=\"NP\" & #1:root";
889 // String unary3 =
890 // "{@type=korap:span, foundry=cnx, layer=cat, key=NP, match=match:eq, attr={@type=korap:term, root=true}}";
891 // aqlt = new AqlTree(query);
892 // map = aqlt.getRequestMap().get("query").toString();
893 // assertEquals(unary3.replaceAll(" ", ""), map.replaceAll(" ", ""));
894 //
895 // query = "cnx/cat=\"NP\" & node & #1>#2 & #1:tokenarity=2";
896 // String unary4 =
897 // "{@type=korap:group, operation=operation:relation, operands=[" +
898 // "{@type=korap:span, foundry=cnx, layer=cat, key=NP, match=match:eq, attr={@type=korap:term, tokenarity={@type=korap:boundary,min=2,max=2}}}," +
899 // "{@type=korap:span}" +
900 // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
901 // "}";
902 // aqlt = new AqlTree(query);
903 // map = aqlt.getRequestMap().get("query").toString();
904 // assertEquals(unary4.replaceAll(" ", ""), map.replaceAll(" ", ""));
905 // }
906 //
907 // @Test
908 // public void testCommonParent() throws Exception {
909 // query = "cat=\"NP\" & cat=\"VP\" & #1 $ #2";
910 // String cp1 =
911 // "{@type=korap:group, operation=operation:relation, operands=[" +
912 // "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
913 // "{@type=korap:group, operation=operation:relation, operands=[" +
914 // "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" +
915 // "{@type=korap:span}" +
916 // "]}," +
917 // "{@type=korap:span, layer=cat, key=NP, match=match:eq}" +
918 // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
919 // "]}," +
920 // "{@type=korap:span, layer=cat, key=VP, match=match:eq}" +
921 // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
922 // "";
923 // aqlt = new AqlTree(query);
924 // map = aqlt.getRequestMap().get("query").toString();
925 // assertEquals(cp1.replaceAll(" ", ""), map.replaceAll(" ", ""));
926 //
927 // query = "cat=\"NP\" & cat=\"VP\" & cat=\"PP\" & #1 $ #2 $ #3";
928 // String cp2 =
929 // "{@type=korap:group, operation=operation:relation, operands=[" +
930 // "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
931 // "{@type=korap:group, operation=operation:relation, operands=[" +
932 // "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
933 // "{@type=korap:group, operation=operation:relation, operands=[" +
934 // "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" +
935 // "{@type=korap:span}" +
936 // "]}," +
937 // "{@type=korap:span, layer=cat, key=NP, match=match:eq}" +
938 // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
939 // "]}," +
940 // "{@type=korap:span, layer=cat, key=VP, match=match:eq}" +
941 // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
942 // "}" +
943 // "]}," +
944 // "{@type=korap:span, layer=cat, key=PP, match=match:eq}" +
945 // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
946 // "}";
947 // aqlt = new AqlTree(query);
948 // map = aqlt.getRequestMap().get("query").toString();
949 // assertEquals(cp2.replaceAll(" ", ""), map.replaceAll(" ", ""));
950 //
951 // query = "cat=\"NP\" & cat=\"VP\" & cat=\"PP\" & cat=\"CP\" & #1 $ #2 $ #3 $ #4";
952 // String cp3 =
953 // "{@type=korap:group, operation=operation:relation, operands=[" +
954 // "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
955 // "{@type=korap:group, operation=operation:relation, operands=[" +
956 // "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
957 // "{@type=korap:group, operation=operation:relation, operands=[" +
958 // "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
959 // "{@type=korap:group, operation=operation:relation, operands=[" +
960 // "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" +
961 // "{@type=korap:span}" +
962 // "]}," +
963 // "{@type=korap:span, layer=cat, key=NP, match=match:eq}" +
964 // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
965 // "]}," +
966 // "{@type=korap:span, layer=cat, key=VP, match=match:eq}" +
967 // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
968 // "]}," +
969 // "{@type=korap:span, layer=cat, key=PP, match=match:eq}" +
970 // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
971 // "]}," +
972 // "{@type=korap:span, layer=cat, key=CP, match=match:eq}" +
973 // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
974 // "}" +
975 // "";
976 // aqlt = new AqlTree(query);
977 // map = aqlt.getRequestMap().get("query").toString();
978 // assertEquals(cp3.replaceAll(" ", ""), map.replaceAll(" ", ""));
979 //
980 // query = "cat=\"NP\" & cat=\"VP\" & #1 $* #2";
981 // String cp4 =
982 // "{@type=korap:group, operation=operation:relation, operands=[" +
983 // "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
984 // "{@type=korap:group, operation=operation:relation, operands=[" +
985 // "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" +
986 // "{@type=korap:span}" +
987 // "]}," +
988 // "{@type=korap:span, layer=cat, key=NP, match=match:eq}" +
989 // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c},boundary={@type=korap:boundary,min=1}}}" +
990 // "]}," +
991 // "{@type=korap:span, layer=cat, key=VP, match=match:eq}" +
992 // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c},boundary={@type=korap:boundary,min=1}}}" +
993 // "";
994 // aqlt = new AqlTree(query);
995 // map = aqlt.getRequestMap().get("query").toString();
996 // assertEquals(cp4.replaceAll(" ", ""), map.replaceAll(" ", ""));
997 // }
998
999 /*
Joachim Bingele6d73b12014-09-30 15:34:59 +00001000 @Test
Joachim Bingel20e06ac2015-01-15 10:31:33 +00001001 public void testEqualNotequalValue() throws Exception {
Joachim Bingele6d73b12014-09-30 15:34:59 +00001002 query = "cat=\"NP\" & cat=\"VP\" & #1 == #2";
1003 String eq1 =
1004 "{}"; // ???
1005 aqlt = new AqlTree(query);
1006 map = aqlt.getRequestMap().get("query").toString();
1007 assertEquals(eq1.replaceAll(" ", ""), map.replaceAll(" ", ""));
1008 }
Joachim Bingelba253a72015-01-23 18:28:29 +00001009 */
1010
Joachim Bingel66472b82014-12-04 16:00:05 +00001011}
Joachim Bingelba253a72015-01-23 18:28:29 +00001012