blob: f7af8cc8c472b8ef3e940e99c15bec68fc1609c9 [file] [log] [blame]
Joachim Bingel019ba5c2014-04-28 14:59:04 +00001import static org.junit.Assert.*;
2
3import org.junit.Test;
4
5import de.ids_mannheim.korap.query.serialize.AqlTree;
Joachim Bingel019ba5c2014-04-28 14:59:04 +00006import de.ids_mannheim.korap.util.QueryException;
7
8public class AqlTreeTest {
9
10 AqlTree aqlt;
11 String map;
12 private String query;
13
14 private boolean equalsQueryContent(String res, String query) throws QueryException {
15 res = res.replaceAll(" ", "");
16 aqlt = new AqlTree(query);
17 String queryMap = aqlt.getRequestMap().get("query").toString().replaceAll(" ", "");
18 return res.equals(queryMap);
19 }
20
21 @Test
22 public void testContext() throws QueryException {
23 String contextString = "http://ids-mannheim.de/ns/KorAP/json-ld/v0.1/context.jsonld";
24 aqlt = new AqlTree("Test");
25 assertEquals(contextString.replaceAll(" ", ""), aqlt.getRequestMap().get("@context").toString().replaceAll(" ", ""));
26 }
27
28 @Test
29 public void testSingleTokens() throws QueryException {
30 // "Mann"
31 query = "\"Mann\"";
Joachim Bingeleee549e2014-04-29 11:15:37 +000032 String token1 = "{@type=korap:token, wrap={@type=korap:term, key=Mann, match=match:eq}}";
Joachim Bingel019ba5c2014-04-28 14:59:04 +000033 assertTrue(equalsQueryContent(token1, query));
34
35 // [orth!=Frau]
36 query = "tok!=\"Frau\"";
Joachim Bingelca4944e2014-06-13 13:55:10 +000037 String token2 = "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:ne}}";
Joachim Bingel019ba5c2014-04-28 14:59:04 +000038 assertTrue(equalsQueryContent(token2, query));
39
40 // Mann
41 query = "Mann";
42 String token4 = "{@type=korap:span, layer=Mann}";
43 assertTrue(equalsQueryContent(token4, query));
44 }
45
46 @Test
47 public void testSpans() throws QueryException {
48 query = "node";
49 String span1 =
50 "{@type=korap:span}";
51 aqlt = new AqlTree(query);
52 map = aqlt.getRequestMap().get("query").toString();
53 assertEquals(span1.replaceAll(" ", ""), map.replaceAll(" ", ""));
54 }
55
56 @Test
57 public void testRegex() throws QueryException {
58 query = "/Mann/";
Joachim Bingeleee549e2014-04-29 11:15:37 +000059 String regex1 = "{@type=korap:token, wrap={@type=korap:term, type=type:regex, key=Mann, match=match:eq}}";
Joachim Bingel019ba5c2014-04-28 14:59:04 +000060 aqlt = new AqlTree(query);
61 map = aqlt.getRequestMap().get("query").toString();
62 assertEquals(regex1.replaceAll(" ", ""), map.replaceAll(" ", ""));
63 }
64
65 @Test
66 public void testLayers() throws QueryException {
67 query = "cnx/cat=\"NP\"";
Joachim Bingeleee549e2014-04-29 11:15:37 +000068 String layers1 = "{@type=korap:span, foundry=cnx, layer=cat, key=NP, match=match:eq}";
Joachim Bingel019ba5c2014-04-28 14:59:04 +000069 aqlt = new AqlTree(query);
70 map = aqlt.getRequestMap().get("query").toString();
71 assertEquals(layers1.replaceAll(" ", ""), map.replaceAll(" ", ""));
72
73 query = "treetagger/pos=\"NN\"";
Joachim Bingeleee549e2014-04-29 11:15:37 +000074 String layers2 = "{@type=korap:token, wrap={@type=korap:term, foundry=treetagger, layer=pos, key=NN, match=match:eq}}";
Joachim Bingel019ba5c2014-04-28 14:59:04 +000075 aqlt = new AqlTree(query);
76 map = aqlt.getRequestMap().get("query").toString();
77 assertEquals(layers2.replaceAll(" ", ""), map.replaceAll(" ", ""));
78 }
79
80 @Test
Joachim Bingel75038792014-05-19 15:12:23 +000081 public void testDirectDeclarationRelations() throws QueryException {
82 query = "node > node";
83 String ddr1 =
84 "{@type=korap:group, operation=operation:relation, operands=[" +
85 "{@type=korap:span}," +
86 "{@type=korap:span}" +
87 "], relation={@type=korap:treeRelation, reltype=dominance}" +
88 "}";
89 aqlt = new AqlTree(query);
90 map = aqlt.getRequestMap().get("query").toString();
91 assertEquals(ddr1.replaceAll(" ", ""), map.replaceAll(" ", ""));
92
93 query = "node > cnx/cat=\"NP\"";
94 String ddr2 =
95 "{@type=korap:group, operation=operation:relation, operands=[" +
96 "{@type=korap:span}," +
97 "{@type=korap:span, foundry=cnx, layer=cat, key=NP, match=match:eq}" +
98 "], relation={@type=korap:treeRelation, reltype=dominance}" +
99 "}";
100 aqlt = new AqlTree(query);
101 map = aqlt.getRequestMap().get("query").toString();
102 assertEquals(ddr2.replaceAll(" ", ""), map.replaceAll(" ", ""));
103
104 }
105
106 @Test
Joachim Bingel019ba5c2014-04-28 14:59:04 +0000107 public void testSimpleDominance() throws QueryException {
108 query = "node & node & #2 > #1";
109 String dom1 =
Joachim Bingeld4ae5fd2014-04-29 15:00:16 +0000110 "{@type=korap:group, operation=operation:relation, operands=[" +
Joachim Bingel019ba5c2014-04-28 14:59:04 +0000111 "{@type=korap:span}," +
112 "{@type=korap:span}" +
Joachim Bingeld4ae5fd2014-04-29 15:00:16 +0000113 "], relation={@type=korap:treeRelation, reltype=dominance}" +
Joachim Bingeleee549e2014-04-29 11:15:37 +0000114 "}";
Joachim Bingel019ba5c2014-04-28 14:59:04 +0000115 aqlt = new AqlTree(query);
116 map = aqlt.getRequestMap().get("query").toString();
117 assertEquals(dom1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeleee549e2014-04-29 11:15:37 +0000118
119 query = "\"Mann\" & node & #2 > #1";
120 String dom2 =
Joachim Bingeld4ae5fd2014-04-29 15:00:16 +0000121 "{@type=korap:group, operation=operation:relation, operands=[" +
Joachim Bingeleee549e2014-04-29 11:15:37 +0000122 "{@type=korap:span}," +
123 "{@type=korap:token, wrap={@type=korap:term, key=Mann, match=match:eq}}" +
Joachim Bingeld4ae5fd2014-04-29 15:00:16 +0000124 "], relation={@type=korap:treeRelation, reltype=dominance}" +
Joachim Bingeleee549e2014-04-29 11:15:37 +0000125 "}";
126 aqlt = new AqlTree(query);
127 map = aqlt.getRequestMap().get("query").toString();
128 assertEquals(dom2.replaceAll(" ", ""), map.replaceAll(" ", ""));
129
Joachim Bingeld4ae5fd2014-04-29 15:00:16 +0000130 query = "\"Mann\" & node & #2 >[cat=\"NP\"] #1";
Joachim Bingeleee549e2014-04-29 11:15:37 +0000131 String dom3 =
Joachim Bingeld4ae5fd2014-04-29 15:00:16 +0000132 "{@type=korap:group, operation=operation:relation, operands=[" +
Joachim Bingeleee549e2014-04-29 11:15:37 +0000133 "{@type=korap:span}," +
134 "{@type=korap:token, wrap={@type=korap:term, key=Mann, match=match:eq}}" +
Joachim Bingela07b8e72014-05-09 15:06:07 +0000135 "], relation={@type=korap:treeRelation, reltype=dominance, wrap=[{@type=korap:term, layer=cat, key=NP, match=match:eq}]}" +
Joachim Bingeleee549e2014-04-29 11:15:37 +0000136 "}";
137 aqlt = new AqlTree(query);
138 map = aqlt.getRequestMap().get("query").toString();
139 assertEquals(dom3.replaceAll(" ", ""), map.replaceAll(" ", ""));
140
Joachim Bingeld4ae5fd2014-04-29 15:00:16 +0000141 query = "\"Mann\" & node & #2 >@l[cat=\"NP\"] #1";
Joachim Bingeleee549e2014-04-29 11:15:37 +0000142 String dom4 =
Joachim Bingeld4ae5fd2014-04-29 15:00:16 +0000143 "{@type=korap:group, operation=operation:relation, operands=[" +
Joachim Bingeleee549e2014-04-29 11:15:37 +0000144 "{@type=korap:span}," +
145 "{@type=korap:token, wrap={@type=korap:term, key=Mann, match=match:eq}}" +
Joachim Bingela07b8e72014-05-09 15:06:07 +0000146 "], relation={@type=korap:treeRelation, reltype=dominance, index=0, wrap=[{@type=korap:term, layer=cat, key=NP, match=match:eq}]}" +
Joachim Bingeleee549e2014-04-29 11:15:37 +0000147 "}";
148 aqlt = new AqlTree(query);
149 map = aqlt.getRequestMap().get("query").toString();
150 assertEquals(dom4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeld4ae5fd2014-04-29 15:00:16 +0000151
152 query = "\"Mann\" & node & #2 >2,4 #1";
153 String dom5 =
154 "{@type=korap:group, operation=operation:relation, operands=[" +
155 "{@type=korap:span}," +
156 "{@type=korap:token, wrap={@type=korap:term, key=Mann, match=match:eq}}" +
157 "], relation={@type=korap:treeRelation, reltype=dominance, " +
Joachim Bingela07b8e72014-05-09 15:06:07 +0000158 "distance={@type=korap:distance, key=r, min=2, max=4}}" +
Joachim Bingeld4ae5fd2014-04-29 15:00:16 +0000159 "}";
160 aqlt = new AqlTree(query);
161 map = aqlt.getRequestMap().get("query").toString();
162 assertEquals(dom5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel019ba5c2014-04-28 14:59:04 +0000163 }
164
Joachim Bingel13421ef2014-05-07 16:22:58 +0000165 @Test
Joachim Bingelca4944e2014-06-13 13:55:10 +0000166 public void testMultipleDominance() throws QueryException {
Joachim Bingel949e3a82014-06-16 13:20:43 +0000167 query = "cat=\"CP\" & cat=\"VP\" & cat=\"NP\" & #1 > #2 > #3";
Joachim Bingelca4944e2014-06-13 13:55:10 +0000168 String dom1 =
169 "{@type=korap:group, operation=operation:relation, operands=[" +
Joachim Bingelca4944e2014-06-13 13:55:10 +0000170 "{@type=korap:group, operation=operation:relation, operands=[" +
Joachim Bingel949e3a82014-06-16 13:20:43 +0000171 "{@type=korap:span, layer=cat, key=CP, match=match:eq}," +
172 "{@type=korap:span, layer=cat, key=VP, match=match:eq}" +
173 "], relation={@type=korap:treeRelation, reltype=dominance}}," +
174 "{@type=korap:span, layer=cat, key=NP, match=match:eq}" +
Joachim Bingelca4944e2014-06-13 13:55:10 +0000175 "], relation={@type=korap:treeRelation, reltype=dominance}" +
176 "}";
177 aqlt = new AqlTree(query);
178 map = aqlt.getRequestMap().get("query").toString();
179 assertEquals(dom1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel949e3a82014-06-16 13:20:43 +0000180
181 query = "cat=\"CP\" & cat=\"VP\" & cat=\"NP\" & cat=\"DP\" & #1 > #2 > #3 > #4";
182 String dom2 =
183 "{@type=korap:group, operation=operation:relation, operands=[" +
184 "{@type=korap:group, operation=operation:relation, operands=[" +
185 "{@type=korap:group, operation=operation:relation, operands=[" +
186 "{@type=korap:span, layer=cat, key=CP, match=match:eq}," +
187 "{@type=korap:span, layer=cat, key=VP, match=match:eq}" +
188 "], relation={@type=korap:treeRelation, reltype=dominance}}," +
189 "{@type=korap:span, layer=cat, key=NP, match=match:eq}" +
190 "], relation={@type=korap:treeRelation, reltype=dominance}}," +
191 "{@type=korap:span, layer=cat, key=DP, match=match:eq}" +
192 "], relation={@type=korap:treeRelation, reltype=dominance}" +
193 "}";
194 aqlt = new AqlTree(query);
195 map = aqlt.getRequestMap().get("query").toString();
196 assertEquals(dom2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelca4944e2014-06-13 13:55:10 +0000197 }
198
199 @Test
Joachim Bingel13421ef2014-05-07 16:22:58 +0000200 public void testPointingRelations() throws QueryException {
201 query = "node & node & #2 ->label[coref=\"true\"] #1";
202 String dom1 =
203 "{@type=korap:group, operation=operation:relation, operands=[" +
204 "{@type=korap:span}," +
205 "{@type=korap:span}" +
Joachim Bingela07b8e72014-05-09 15:06:07 +0000206 "], relation={@type=korap:relation, reltype=label, wrap=[{@type=korap:term, layer=coref, key=true, match=match:eq}]}" +
Joachim Bingel13421ef2014-05-07 16:22:58 +0000207 "}";
208 aqlt = new AqlTree(query);
209 map = aqlt.getRequestMap().get("query").toString();
210 assertEquals(dom1.replaceAll(" ", ""), map.replaceAll(" ", ""));
211
Joachim Bingel639df9c2014-05-12 15:27:00 +0000212 query = "node & node & #2 ->label[mate/coref=\"true\"] #1";
213 String dom2 =
214 "{@type=korap:group, operation=operation:relation, operands=[" +
215 "{@type=korap:span}," +
216 "{@type=korap:span}" +
217 "], relation={@type=korap:relation, reltype=label, wrap=[{@type=korap:term, foundry=mate, layer=coref, key=true, match=match:eq}]}" +
218 "}";
219 aqlt = new AqlTree(query);
220 map = aqlt.getRequestMap().get("query").toString();
221 assertEquals(dom2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel13421ef2014-05-07 16:22:58 +0000222 }
223
224 @Test
225 public void testSequence() throws QueryException {
226 query = "node & node & #1 . #2";
Joachim Bingelca4944e2014-06-13 13:55:10 +0000227 String seq1 =
Joachim Bingel13421ef2014-05-07 16:22:58 +0000228 "{@type=korap:group, operation=operation:sequence, " +
229 "operands=[" +
230 "{@type=korap:span}," +
231 "{@type=korap:span}" +
232 "], inOrder=true" +
233 "}";
234 aqlt = new AqlTree(query);
235 map = aqlt.getRequestMap().get("query").toString();
Joachim Bingelca4944e2014-06-13 13:55:10 +0000236 assertEquals(seq1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel13421ef2014-05-07 16:22:58 +0000237
238 query = "node & node & #1 .* #2";
Joachim Bingelca4944e2014-06-13 13:55:10 +0000239 String seq2 =
Joachim Bingel75038792014-05-19 15:12:23 +0000240 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel13421ef2014-05-07 16:22:58 +0000241 "{@type=korap:span}," +
242 "{@type=korap:span}" +
243 "], distances=[" +
244 "{@type=korap:distance, key=w, min=0, max=100}" +
245 "], inOrder=true" +
246 "}";
247 aqlt = new AqlTree(query);
248 map = aqlt.getRequestMap().get("query").toString();
Joachim Bingelca4944e2014-06-13 13:55:10 +0000249 assertEquals(seq2.replaceAll(" ", ""), map.replaceAll(" ", ""));
250
251 query = "node & node & #1 .2,3 #2";
252 String seq3 =
253 "{@type=korap:group, operation=operation:sequence, operands=[" +
254 "{@type=korap:span}," +
255 "{@type=korap:span}" +
256 "], distances=[" +
257 "{@type=korap:distance, key=w, min=2, max=3}" +
258 "], inOrder=true" +
259 "}";
260 aqlt = new AqlTree(query);
261 map = aqlt.getRequestMap().get("query").toString();
262 assertEquals(seq3.replaceAll(" ", ""), map.replaceAll(" ", ""));
263
264 }
265
266 @Test
267 public void testMultipleSequence() throws QueryException {
268 query = "tok=\"Sonne\" & tok=\"Mond\" & tok=\"Sterne\" & #1 .0,2 #2 .0,4 #3";
269 String seq4 =
270 "{@type=korap:group, operation=operation:sequence," +
271 "operands=[" +
Joachim Bingelca4944e2014-06-13 13:55:10 +0000272 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel949e3a82014-06-16 13:20:43 +0000273 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sonne, match=match:eq}}," +
274 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mond, match=match:eq}}" +
275 "], distances=[" +
276 "{@type=korap:distance, key=w, min=0, max=2}" +
277 "], inOrder=true}," +
278 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sterne, match=match:eq}}" +
Joachim Bingelca4944e2014-06-13 13:55:10 +0000279 "],distances=[" +
Joachim Bingel949e3a82014-06-16 13:20:43 +0000280 "{@type=korap:distance, key=w, min=0, max=4}" +
Joachim Bingelca4944e2014-06-13 13:55:10 +0000281 "], inOrder=true" +
282 "}";
283 aqlt = new AqlTree(query);
284 map = aqlt.getRequestMap().get("query").toString();
285 assertEquals(seq4.replaceAll(" ", ""), map.replaceAll(" ", ""));
286
287 query = "node & node & node & #1 . #2 .1,3 #3";
288 String seq5 =
289 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelca4944e2014-06-13 13:55:10 +0000290 "{@type=korap:group, operation=operation:sequence, operands=[" +
291 "{@type=korap:span}," +
292 "{@type=korap:span}" +
Joachim Bingel949e3a82014-06-16 13:20:43 +0000293 "], inOrder=true}," +
294 "{@type=korap:span}" +
295 "], distances=[" +
Joachim Bingelca4944e2014-06-13 13:55:10 +0000296 "{@type=korap:distance, key=w, min=1, max=3}" +
Joachim Bingel949e3a82014-06-16 13:20:43 +0000297 "], inOrder=true" +
Joachim Bingelca4944e2014-06-13 13:55:10 +0000298 "}";
299 aqlt = new AqlTree(query);
300 map = aqlt.getRequestMap().get("query").toString();
301 assertEquals(seq5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel75038792014-05-19 15:12:23 +0000302 }
303
304 @Test
Joachim Bingel949e3a82014-06-16 13:20:43 +0000305 public void testMultipleMixedOperators() throws QueryException {
306 query = "tok=\"Sonne\" & tok=\"Mond\" & tok=\"Sterne\" & #1 > #2 .0,4 #3";
307 String seq4 =
308 "{@type=korap:group, operation=operation:sequence," +
309 "operands=[" +
310 "{@type=korap:group, operation=operation:relation, operands=[" +
311 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sonne, match=match:eq}}," +
312 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mond, match=match:eq}}" +
313 "], relation={@type=korap:treeRelation, reltype=dominance}}," +
314 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sterne, match=match:eq}}" +
315 "], distances=[" +
316 "{@type=korap:distance, key=w, min=0, max=4}" +
317 "], inOrder=true" +
318 "}";
319 aqlt = new AqlTree(query);
320 map = aqlt.getRequestMap().get("query").toString();
321 assertEquals(seq4.replaceAll(" ", ""), map.replaceAll(" ", ""));
322 }
323
324 @Test
Joachim Bingel75038792014-05-19 15:12:23 +0000325 public void testPositions() throws QueryException {
326 query = "node & node & #2 _=_ #1";
327 String pos1 =
328 "{@type=korap:group, operation=operation:position, operands=[" +
329 "{@type=korap:span}," +
330 "{@type=korap:span}" +
331 "], frame=frame:matches" +
332 "}";
333 aqlt = new AqlTree(query);
334 map = aqlt.getRequestMap().get("query").toString();
335 assertEquals(pos1.replaceAll(" ", ""), map.replaceAll(" ", ""));
336
Joachim Bingelca4944e2014-06-13 13:55:10 +0000337 query = "node & node & #2 _i_ #1";
338 String pos2 =
339 "{@type=korap:group, operation=operation:position, operands=[" +
340 "{@type=korap:span}," +
341 "{@type=korap:span}" +
342 "], frame=frame:contains" +
343 "}";
344 aqlt = new AqlTree(query);
345 map = aqlt.getRequestMap().get("query").toString();
346 assertEquals(pos2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel75038792014-05-19 15:12:23 +0000347
Joachim Bingelca4944e2014-06-13 13:55:10 +0000348 query = "node & node & #2 _l_ #1";
349 String pos3 =
350 "{@type=korap:group, operation=operation:position, operands=[" +
351 "{@type=korap:span}," +
352 "{@type=korap:span}" +
353 "], inOrder=false, frame=frame:startswith" +
354 "}";
355 aqlt = new AqlTree(query);
356 map = aqlt.getRequestMap().get("query").toString();
357 assertEquals(pos3.replaceAll(" ", ""), map.replaceAll(" ", ""));
358
359 query = "node & \"Mann\" & #1 _r_ #2";
Joachim Bingel75038792014-05-19 15:12:23 +0000360 String pos4 =
Joachim Bingel75038792014-05-19 15:12:23 +0000361 "{@type=korap:group, operation=operation:position, operands=[" +
362 "{@type=korap:span}," +
Joachim Bingelca4944e2014-06-13 13:55:10 +0000363 "{@type=korap:token, wrap={@type=korap:term, key=Mann, match=match:eq}}" +
364 "], inOrder=false, frame=frame:endswith" +
365 "}";
Joachim Bingel75038792014-05-19 15:12:23 +0000366 aqlt = new AqlTree(query);
367 map = aqlt.getRequestMap().get("query").toString();
368 assertEquals(pos4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel13421ef2014-05-07 16:22:58 +0000369
Joachim Bingelca4944e2014-06-13 13:55:10 +0000370 query = "node & \"Mann\" & #2 _r_ #1";
371 String pos5 =
372 "{@type=korap:group, operation=operation:position, operands=[" +
373 "{@type=korap:token, wrap={@type=korap:term, key=Mann, match=match:eq}}," +
374 "{@type=korap:span}" +
375 "], inOrder=false, frame=frame:endswith" +
376 "}";
377 aqlt = new AqlTree(query);
378 map = aqlt.getRequestMap().get("query").toString();
379 assertEquals(pos5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel13421ef2014-05-07 16:22:58 +0000380 }
381
Joachim Bingelca4944e2014-06-13 13:55:10 +0000382 @Test
383 public void testMultiplePredications() throws QueryException {
384 // a noun before a verb before a noun
385 // XXX Warning incorrect serialisation! Need to ensure that the two Vs are identical!
386 // Embed in one sequence!
387 query = "pos=\"N\" & pos=\"V\" & pos=\"N\" & #1 . #2 & #2 . #3";
388 String mult1 =
389 "{@type=korap:group, operation=operation:sequence, operands=[" +
390 "{@type=korap:group, operation=operation:sequence, operands=[" +
391 "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=N, match=match:eq}}," +
392 "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=V, match=match:eq}}" +
393 "], inOrder=true}," +
394 "{@type=korap:group, operation=operation:sequence, operands=[" +
395 "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=V, match=match:eq}}," +
396 "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=N, match=match:eq}}" +
397 "], inOrder=true}" +
398 "], distances=[" +
399 "{@type=korap:distance, key=t, min=0, max=0}" +
400 "]}";
401 aqlt = new AqlTree(query);
402 map = aqlt.getRequestMap().get("query").toString();
403 assertEquals(mult1.replaceAll(" ", ""), map.replaceAll(" ", ""));
404 }
Joachim Bingeleee549e2014-04-29 11:15:37 +0000405
Joachim Bingelca4944e2014-06-13 13:55:10 +0000406 @Test
407 public void testUnaryRelations() throws QueryException {
408 query = "node & #1:tokenarity=2";
409 String unary1 =
410 "{@type=korap:span, attr={@type=korap:term, tokenarity={@type=korap:boundary,min=2,max=2}}}";
411 aqlt = new AqlTree(query);
412 map = aqlt.getRequestMap().get("query").toString();
413 assertEquals(unary1.replaceAll(" ", ""), map.replaceAll(" ", ""));
414
415 query = "cnx/cat=\"NP\" & #1:tokenarity=2";
416 String unary2 =
417 "{@type=korap:span, foundry=cnx, layer=cat, key=NP, match=match:eq, attr={@type=korap:term, tokenarity={@type=korap:boundary,min=2,max=2}}}";
418 aqlt = new AqlTree(query);
419 map = aqlt.getRequestMap().get("query").toString();
420 assertEquals(unary2.replaceAll(" ", ""), map.replaceAll(" ", ""));
421
422 query = "cnx/cat=\"NP\" & #1:root";
423 String unary3 =
424 "{@type=korap:span, foundry=cnx, layer=cat, key=NP, match=match:eq, attr={@type=korap:term, root=true}}";
425 aqlt = new AqlTree(query);
426 map = aqlt.getRequestMap().get("query").toString();
427 assertEquals(unary3.replaceAll(" ", ""), map.replaceAll(" ", ""));
428
429 query = "cnx/cat=\"NP\" & node & #1>#2 & #1:tokenarity=2";
430 String unary4 =
431 "{@type=korap:group, operation=operation:relation, operands=[" +
432 "{@type=korap:span, foundry=cnx, layer=cat, key=NP, match=match:eq, attr={@type=korap:term, tokenarity={@type=korap:boundary,min=2,max=2}}}," +
433 "{@type=korap:span}" +
434 "], relation={@type=korap:treeRelation, reltype=dominance}" +
435 "}";
436 aqlt = new AqlTree(query);
437 map = aqlt.getRequestMap().get("query").toString();
438 assertEquals(unary4.replaceAll(" ", ""), map.replaceAll(" ", ""));
439 }
440
441 // TODO commonparent, commonancestor
442
443}