blob: faa1cd124d75efd3a0e511094448a486af8c65dd [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 Bingelfc428812014-06-18 14:50:14 +0000107 public void testDefPredicationInversion() throws QueryException {
108 query = " #1 > #2 & cnx/cat=\"VP\" & cnx/cat=\"NP\"";
109 String dom1 =
110 "{@type=korap:group, operation=operation:relation, operands=[" +
111 "{@type=korap:span, foundry=cnx, layer=cat, key=VP, match=match:eq}," +
112 "{@type=korap:span, foundry=cnx, layer=cat, key=NP, match=match:eq}" +
113 "], relation={@type=korap:treeRelation, reltype=dominance}" +
114 "}";
115 aqlt = new AqlTree(query);
116 map = aqlt.getRequestMap().get("query").toString();
117 assertEquals(dom1.replaceAll(" ", ""), map.replaceAll(" ", ""));
118 }
119
120 @Test
Joachim Bingel019ba5c2014-04-28 14:59:04 +0000121 public void testSimpleDominance() throws QueryException {
122 query = "node & node & #2 > #1";
123 String dom1 =
Joachim Bingeld4ae5fd2014-04-29 15:00:16 +0000124 "{@type=korap:group, operation=operation:relation, operands=[" +
Joachim Bingel019ba5c2014-04-28 14:59:04 +0000125 "{@type=korap:span}," +
126 "{@type=korap:span}" +
Joachim Bingeld4ae5fd2014-04-29 15:00:16 +0000127 "], relation={@type=korap:treeRelation, reltype=dominance}" +
Joachim Bingeleee549e2014-04-29 11:15:37 +0000128 "}";
Joachim Bingel019ba5c2014-04-28 14:59:04 +0000129 aqlt = new AqlTree(query);
130 map = aqlt.getRequestMap().get("query").toString();
131 assertEquals(dom1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeleee549e2014-04-29 11:15:37 +0000132
133 query = "\"Mann\" & node & #2 > #1";
134 String dom2 =
Joachim Bingeld4ae5fd2014-04-29 15:00:16 +0000135 "{@type=korap:group, operation=operation:relation, operands=[" +
Joachim Bingeleee549e2014-04-29 11:15:37 +0000136 "{@type=korap:span}," +
137 "{@type=korap:token, wrap={@type=korap:term, key=Mann, match=match:eq}}" +
Joachim Bingeld4ae5fd2014-04-29 15:00:16 +0000138 "], relation={@type=korap:treeRelation, reltype=dominance}" +
Joachim Bingeleee549e2014-04-29 11:15:37 +0000139 "}";
140 aqlt = new AqlTree(query);
141 map = aqlt.getRequestMap().get("query").toString();
142 assertEquals(dom2.replaceAll(" ", ""), map.replaceAll(" ", ""));
143
Joachim Bingeld4ae5fd2014-04-29 15:00:16 +0000144 query = "\"Mann\" & node & #2 >[cat=\"NP\"] #1";
Joachim Bingeleee549e2014-04-29 11:15:37 +0000145 String dom3 =
Joachim Bingeld4ae5fd2014-04-29 15:00:16 +0000146 "{@type=korap:group, operation=operation:relation, operands=[" +
Joachim Bingeleee549e2014-04-29 11:15:37 +0000147 "{@type=korap:span}," +
148 "{@type=korap:token, wrap={@type=korap:term, key=Mann, match=match:eq}}" +
Joachim Bingela07b8e72014-05-09 15:06:07 +0000149 "], relation={@type=korap:treeRelation, reltype=dominance, wrap=[{@type=korap:term, layer=cat, key=NP, match=match:eq}]}" +
Joachim Bingeleee549e2014-04-29 11:15:37 +0000150 "}";
151 aqlt = new AqlTree(query);
152 map = aqlt.getRequestMap().get("query").toString();
153 assertEquals(dom3.replaceAll(" ", ""), map.replaceAll(" ", ""));
154
Joachim Bingeld4ae5fd2014-04-29 15:00:16 +0000155 query = "\"Mann\" & node & #2 >@l[cat=\"NP\"] #1";
Joachim Bingeleee549e2014-04-29 11:15:37 +0000156 String dom4 =
Joachim Bingeld4ae5fd2014-04-29 15:00:16 +0000157 "{@type=korap:group, operation=operation:relation, operands=[" +
Joachim Bingeleee549e2014-04-29 11:15:37 +0000158 "{@type=korap:span}," +
159 "{@type=korap:token, wrap={@type=korap:term, key=Mann, match=match:eq}}" +
Joachim Bingela07b8e72014-05-09 15:06:07 +0000160 "], 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 +0000161 "}";
162 aqlt = new AqlTree(query);
163 map = aqlt.getRequestMap().get("query").toString();
164 assertEquals(dom4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeld4ae5fd2014-04-29 15:00:16 +0000165
166 query = "\"Mann\" & node & #2 >2,4 #1";
167 String dom5 =
168 "{@type=korap:group, operation=operation:relation, operands=[" +
169 "{@type=korap:span}," +
170 "{@type=korap:token, wrap={@type=korap:term, key=Mann, match=match:eq}}" +
171 "], relation={@type=korap:treeRelation, reltype=dominance, " +
Joachim Bingel86195a52014-07-08 14:29:48 +0000172 "boundary={@type=korap:boundary, min=2, max=4}}" +
Joachim Bingeld4ae5fd2014-04-29 15:00:16 +0000173 "}";
174 aqlt = new AqlTree(query);
175 map = aqlt.getRequestMap().get("query").toString();
176 assertEquals(dom5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel019ba5c2014-04-28 14:59:04 +0000177 }
178
Joachim Bingel13421ef2014-05-07 16:22:58 +0000179 @Test
Joachim Bingelca4944e2014-06-13 13:55:10 +0000180 public void testMultipleDominance() throws QueryException {
Joachim Bingel949e3a82014-06-16 13:20:43 +0000181 query = "cat=\"CP\" & cat=\"VP\" & cat=\"NP\" & #1 > #2 > #3";
Joachim Bingelca4944e2014-06-13 13:55:10 +0000182 String dom1 =
183 "{@type=korap:group, operation=operation:relation, operands=[" +
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000184 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
Joachim Bingelfc428812014-06-18 14:50:14 +0000185 "{@type=korap:group, operation=operation:relation, operands=[" +
186 "{@type=korap:span, layer=cat, key=CP, match=match:eq}," +
187 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
188 "{@type=korap:span, layer=cat, key=VP, match=match:eq}" +
189 "]}" +
190 "], relation={@type=korap:treeRelation, reltype=dominance}}" +
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000191 "]}," +
Joachim Bingel949e3a82014-06-16 13:20:43 +0000192 "{@type=korap:span, layer=cat, key=NP, match=match:eq}" +
Joachim Bingelca4944e2014-06-13 13:55:10 +0000193 "], relation={@type=korap:treeRelation, reltype=dominance}" +
194 "}";
195 aqlt = new AqlTree(query);
196 map = aqlt.getRequestMap().get("query").toString();
197 assertEquals(dom1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel949e3a82014-06-16 13:20:43 +0000198
199 query = "cat=\"CP\" & cat=\"VP\" & cat=\"NP\" & cat=\"DP\" & #1 > #2 > #3 > #4";
200 String dom2 =
201 "{@type=korap:group, operation=operation:relation, operands=[" +
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000202 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingel949e3a82014-06-16 13:20:43 +0000203 "{@type=korap:group, operation=operation:relation, operands=[" +
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000204 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
Joachim Bingelfc428812014-06-18 14:50:14 +0000205 "{@type=korap:group, operation=operation:relation, operands=[" +
206 "{@type=korap:span, layer=cat, key=CP, match=match:eq}," +
207 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
208 "{@type=korap:span, layer=cat, key=VP, match=match:eq}" +
209 "]}" +
210 "], relation={@type=korap:treeRelation, reltype=dominance}}" +
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000211 "]}," +
Joachim Bingelfc428812014-06-18 14:50:14 +0000212 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
213 "{@type=korap:span, layer=cat, key=NP, match=match:eq}" +
214 "]}" +
215 "], relation={@type=korap:treeRelation, reltype=dominance}}" +
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000216 "]}," +
Joachim Bingel949e3a82014-06-16 13:20:43 +0000217 "{@type=korap:span, layer=cat, key=DP, match=match:eq}" +
218 "], relation={@type=korap:treeRelation, reltype=dominance}" +
219 "}";
220 aqlt = new AqlTree(query);
221 map = aqlt.getRequestMap().get("query").toString();
222 assertEquals(dom2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelca4944e2014-06-13 13:55:10 +0000223 }
224
225 @Test
Joachim Bingel13421ef2014-05-07 16:22:58 +0000226 public void testPointingRelations() throws QueryException {
227 query = "node & node & #2 ->label[coref=\"true\"] #1";
228 String dom1 =
229 "{@type=korap:group, operation=operation:relation, operands=[" +
230 "{@type=korap:span}," +
231 "{@type=korap:span}" +
Joachim Bingela07b8e72014-05-09 15:06:07 +0000232 "], relation={@type=korap:relation, reltype=label, wrap=[{@type=korap:term, layer=coref, key=true, match=match:eq}]}" +
Joachim Bingel13421ef2014-05-07 16:22:58 +0000233 "}";
234 aqlt = new AqlTree(query);
235 map = aqlt.getRequestMap().get("query").toString();
236 assertEquals(dom1.replaceAll(" ", ""), map.replaceAll(" ", ""));
237
Joachim Bingel639df9c2014-05-12 15:27:00 +0000238 query = "node & node & #2 ->label[mate/coref=\"true\"] #1";
239 String dom2 =
240 "{@type=korap:group, operation=operation:relation, operands=[" +
241 "{@type=korap:span}," +
242 "{@type=korap:span}" +
243 "], relation={@type=korap:relation, reltype=label, wrap=[{@type=korap:term, foundry=mate, layer=coref, key=true, match=match:eq}]}" +
244 "}";
245 aqlt = new AqlTree(query);
246 map = aqlt.getRequestMap().get("query").toString();
247 assertEquals(dom2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel13421ef2014-05-07 16:22:58 +0000248 }
249
250 @Test
251 public void testSequence() throws QueryException {
252 query = "node & node & #1 . #2";
Joachim Bingelca4944e2014-06-13 13:55:10 +0000253 String seq1 =
Joachim Bingel13421ef2014-05-07 16:22:58 +0000254 "{@type=korap:group, operation=operation:sequence, " +
255 "operands=[" +
256 "{@type=korap:span}," +
257 "{@type=korap:span}" +
258 "], inOrder=true" +
259 "}";
260 aqlt = new AqlTree(query);
261 map = aqlt.getRequestMap().get("query").toString();
Joachim Bingelca4944e2014-06-13 13:55:10 +0000262 assertEquals(seq1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel13421ef2014-05-07 16:22:58 +0000263
264 query = "node & node & #1 .* #2";
Joachim Bingelca4944e2014-06-13 13:55:10 +0000265 String seq2 =
Joachim Bingel75038792014-05-19 15:12:23 +0000266 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel13421ef2014-05-07 16:22:58 +0000267 "{@type=korap:span}," +
268 "{@type=korap:span}" +
269 "], distances=[" +
270 "{@type=korap:distance, key=w, min=0, max=100}" +
271 "], inOrder=true" +
272 "}";
273 aqlt = new AqlTree(query);
274 map = aqlt.getRequestMap().get("query").toString();
Joachim Bingelca4944e2014-06-13 13:55:10 +0000275 assertEquals(seq2.replaceAll(" ", ""), map.replaceAll(" ", ""));
276
277 query = "node & node & #1 .2,3 #2";
278 String seq3 =
279 "{@type=korap:group, operation=operation:sequence, operands=[" +
280 "{@type=korap:span}," +
281 "{@type=korap:span}" +
282 "], distances=[" +
283 "{@type=korap:distance, key=w, min=2, max=3}" +
284 "], inOrder=true" +
285 "}";
286 aqlt = new AqlTree(query);
287 map = aqlt.getRequestMap().get("query").toString();
288 assertEquals(seq3.replaceAll(" ", ""), map.replaceAll(" ", ""));
289
290 }
291
292 @Test
293 public void testMultipleSequence() throws QueryException {
294 query = "tok=\"Sonne\" & tok=\"Mond\" & tok=\"Sterne\" & #1 .0,2 #2 .0,4 #3";
295 String seq4 =
296 "{@type=korap:group, operation=operation:sequence," +
Joachim Bingelfc428812014-06-18 14:50:14 +0000297 "operands=[" +
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000298 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
Joachim Bingelca4944e2014-06-13 13:55:10 +0000299 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel949e3a82014-06-16 13:20:43 +0000300 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sonne, match=match:eq}}," +
Joachim Bingelfc428812014-06-18 14:50:14 +0000301 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
302 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mond, match=match:eq}}" +
303 "]}" +
Joachim Bingel949e3a82014-06-16 13:20:43 +0000304 "], distances=[" +
305 "{@type=korap:distance, key=w, min=0, max=2}" +
Joachim Bingelfc428812014-06-18 14:50:14 +0000306 "], inOrder=true}" +
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000307 "]}," +
Joachim Bingelfc428812014-06-18 14:50:14 +0000308 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sterne, match=match:eq}}" +
309 "],distances=[" +
310 "{@type=korap:distance, key=w, min=0, max=4}" +
311 "], inOrder=true" +
312 "}";
Joachim Bingelca4944e2014-06-13 13:55:10 +0000313 aqlt = new AqlTree(query);
314 map = aqlt.getRequestMap().get("query").toString();
315 assertEquals(seq4.replaceAll(" ", ""), map.replaceAll(" ", ""));
316
317 query = "node & node & node & #1 . #2 .1,3 #3";
318 String seq5 =
319 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000320 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
Joachim Bingelfc428812014-06-18 14:50:14 +0000321 "{@type=korap:group, operation=operation:sequence, operands=[" +
322 "{@type=korap:span}," +
323 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
324 "{@type=korap:span}" +
325 "]} "+
326 "], inOrder=true}" +
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000327 "]}," +
Joachim Bingel949e3a82014-06-16 13:20:43 +0000328 "{@type=korap:span}" +
329 "], distances=[" +
Joachim Bingelca4944e2014-06-13 13:55:10 +0000330 "{@type=korap:distance, key=w, min=1, max=3}" +
Joachim Bingel949e3a82014-06-16 13:20:43 +0000331 "], inOrder=true" +
Joachim Bingelca4944e2014-06-13 13:55:10 +0000332 "}";
333 aqlt = new AqlTree(query);
334 map = aqlt.getRequestMap().get("query").toString();
335 assertEquals(seq5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000336
337 query = "tok=\"Sonne\" & tok=\"Mond\" & tok=\"Sterne\" & tok=\"Himmel\" & #1 .0,2 #2 .0,4 #3 . #4";
338 String seq6 =
339 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000340 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000341 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000342 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000343 "{@type=korap:group, operation=operation:sequence, operands=[" +
344 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sonne, match=match:eq}}," +
345 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
346 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mond, match=match:eq}}" +
347 "]}" +
348 "], distances=[" +
349 "{@type=korap:distance, key=w, min=0, max=2}" +
350 "], inOrder=true}" +
351 "]}," +
352 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
353 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sterne, match=match:eq}}" +
354 "]}" +
355 "],distances=[" +
356 "{@type=korap:distance, key=w, min=0, max=4}" +
357 "], inOrder=true}" +
358 "]}," +
359 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Himmel, match=match:eq}}" +
360 "], inOrder=true}" ;
361 aqlt = new AqlTree(query);
362 map = aqlt.getRequestMap().get("query").toString();
363 assertEquals(seq6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel75038792014-05-19 15:12:23 +0000364 }
365
366 @Test
Joachim Bingel949e3a82014-06-16 13:20:43 +0000367 public void testMultipleMixedOperators() throws QueryException {
368 query = "tok=\"Sonne\" & tok=\"Mond\" & tok=\"Sterne\" & #1 > #2 .0,4 #3";
369 String seq4 =
Joachim Bingelfc428812014-06-18 14:50:14 +0000370 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000371 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
Joachim Bingelfc428812014-06-18 14:50:14 +0000372 "{@type=korap:group, operation=operation:relation, operands=[" +
373 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sonne, match=match:eq}}," +
374 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
375 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mond, match=match:eq}}" +
376 "]}" +
377 "], relation={@type=korap:treeRelation, reltype=dominance}}" +
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000378 "]}," +
Joachim Bingel949e3a82014-06-16 13:20:43 +0000379 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sterne, match=match:eq}}" +
380 "], distances=[" +
381 "{@type=korap:distance, key=w, min=0, max=4}" +
382 "], inOrder=true" +
383 "}";
384 aqlt = new AqlTree(query);
385 map = aqlt.getRequestMap().get("query").toString();
386 assertEquals(seq4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelfc428812014-06-18 14:50:14 +0000387
388 query = "tok=\"Sonne\" & tok=\"Mond\" & #1 > #2 .0,4 tok=\"Sterne\"";
389 String seq5 =
390 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000391 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
Joachim Bingelfc428812014-06-18 14:50:14 +0000392 "{@type=korap:group, operation=operation:relation, operands=[" +
393 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sonne, match=match:eq}}," +
394 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
395 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mond, match=match:eq}}" +
396 "]}" +
397 "], relation={@type=korap:treeRelation, reltype=dominance}}" +
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000398 "]}," +
Joachim Bingelfc428812014-06-18 14:50:14 +0000399 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sterne, match=match:eq}}" +
400 "], distances=[" +
401 "{@type=korap:distance, key=w, min=0, max=4}" +
402 "], inOrder=true" +
403 "}";
404 aqlt = new AqlTree(query);
405 map = aqlt.getRequestMap().get("query").toString();
406 assertEquals(seq5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000407
408 query = "cat=\"NP\" & cat=\"VP\" & cat=\"PP\" & #1 $ #2 > #3";
409 String cp2 =
410 "{@type=korap:group, operation=operation:relation, operands=[" +
411 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
412 "{@type=korap:group, operation=operation:relation, operands=[" +
413 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
414 "{@type=korap:group, operation=operation:relation, operands=[" +
415 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
416 "{@type=korap:span}" +
417 "]}," +
418 "{@type=korap:span, layer=cat, key=NP, match=match:eq}" +
419 "], relation={@type=korap:treeRelation, reltype=dominance}}" +
420 "]}," +
421 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
422 "{@type=korap:span, layer=cat, key=VP, match=match:eq}" +
423 "]}" +
424 "], relation={@type=korap:treeRelation, reltype=dominance}" +
425 "}" +
426 "]}," +
427 "{@type=korap:span, layer=cat, key=PP, match=match:eq}" +
428 "], relation={@type=korap:treeRelation, reltype=dominance}" +
429 "}";
430 aqlt = new AqlTree(query);
431 map = aqlt.getRequestMap().get("query").toString();
432 assertEquals(cp2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel949e3a82014-06-16 13:20:43 +0000433 }
434
435 @Test
Joachim Bingel75038792014-05-19 15:12:23 +0000436 public void testPositions() throws QueryException {
437 query = "node & node & #2 _=_ #1";
438 String pos1 =
439 "{@type=korap:group, operation=operation:position, operands=[" +
440 "{@type=korap:span}," +
441 "{@type=korap:span}" +
442 "], frame=frame:matches" +
443 "}";
444 aqlt = new AqlTree(query);
445 map = aqlt.getRequestMap().get("query").toString();
446 assertEquals(pos1.replaceAll(" ", ""), map.replaceAll(" ", ""));
447
Joachim Bingelca4944e2014-06-13 13:55:10 +0000448 query = "node & node & #2 _i_ #1";
449 String pos2 =
450 "{@type=korap:group, operation=operation:position, operands=[" +
451 "{@type=korap:span}," +
452 "{@type=korap:span}" +
453 "], frame=frame:contains" +
454 "}";
455 aqlt = new AqlTree(query);
456 map = aqlt.getRequestMap().get("query").toString();
457 assertEquals(pos2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel75038792014-05-19 15:12:23 +0000458
Joachim Bingelca4944e2014-06-13 13:55:10 +0000459 query = "node & node & #2 _l_ #1";
460 String pos3 =
461 "{@type=korap:group, operation=operation:position, operands=[" +
462 "{@type=korap:span}," +
463 "{@type=korap:span}" +
464 "], inOrder=false, frame=frame:startswith" +
465 "}";
466 aqlt = new AqlTree(query);
467 map = aqlt.getRequestMap().get("query").toString();
468 assertEquals(pos3.replaceAll(" ", ""), map.replaceAll(" ", ""));
469
470 query = "node & \"Mann\" & #1 _r_ #2";
Joachim Bingel75038792014-05-19 15:12:23 +0000471 String pos4 =
Joachim Bingel75038792014-05-19 15:12:23 +0000472 "{@type=korap:group, operation=operation:position, operands=[" +
473 "{@type=korap:span}," +
Joachim Bingelca4944e2014-06-13 13:55:10 +0000474 "{@type=korap:token, wrap={@type=korap:term, key=Mann, match=match:eq}}" +
475 "], inOrder=false, frame=frame:endswith" +
476 "}";
Joachim Bingel75038792014-05-19 15:12:23 +0000477 aqlt = new AqlTree(query);
478 map = aqlt.getRequestMap().get("query").toString();
479 assertEquals(pos4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel13421ef2014-05-07 16:22:58 +0000480
Joachim Bingelca4944e2014-06-13 13:55:10 +0000481 query = "node & \"Mann\" & #2 _r_ #1";
482 String pos5 =
483 "{@type=korap:group, operation=operation:position, operands=[" +
484 "{@type=korap:token, wrap={@type=korap:term, key=Mann, match=match:eq}}," +
485 "{@type=korap:span}" +
486 "], inOrder=false, frame=frame:endswith" +
487 "}";
488 aqlt = new AqlTree(query);
489 map = aqlt.getRequestMap().get("query").toString();
490 assertEquals(pos5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel13421ef2014-05-07 16:22:58 +0000491 }
492
Joachim Bingelca4944e2014-06-13 13:55:10 +0000493 @Test
494 public void testMultiplePredications() throws QueryException {
Joachim Bingel9c3ddb92014-06-23 13:49:58 +0000495 // a noun before a verb before a preposition
Joachim Bingelfc428812014-06-18 14:50:14 +0000496 query = "pos=\"N\" & pos=\"V\" & pos=\"P\" & #1 . #2 & #2 . #3";
Joachim Bingelca4944e2014-06-13 13:55:10 +0000497 String mult1 =
Joachim Bingel9c3ddb92014-06-23 13:49:58 +0000498 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000499 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
Joachim Bingelca4944e2014-06-13 13:55:10 +0000500 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel9c3ddb92014-06-23 13:49:58 +0000501 "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=N, match=match:eq}}," +
502 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
503 "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=V, match=match:eq}}" +
504 "]}" +
505 "], inOrder=true}" +
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000506 "]}," +
Joachim Bingel9c3ddb92014-06-23 13:49:58 +0000507 "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=P, match=match:eq}}" +
508 "], inOrder=true}";
Joachim Bingelca4944e2014-06-13 13:55:10 +0000509 aqlt = new AqlTree(query);
510 map = aqlt.getRequestMap().get("query").toString();
511 assertEquals(mult1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel9c3ddb92014-06-23 13:49:58 +0000512
513 // a noun before a verb before a preposition
514 query = "pos=\"N\" & pos=\"V\" & #1 . #2 & #2 . pos=\"P\"";
515 String mult2 =
516 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000517 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
Joachim Bingel9c3ddb92014-06-23 13:49:58 +0000518 "{@type=korap:group, operation=operation:sequence, operands=[" +
519 "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=N, match=match:eq}}," +
520 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
521 "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=V, match=match:eq}}" +
522 "]}" +
523 "], inOrder=true}" +
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000524 "]}," +
Joachim Bingel9c3ddb92014-06-23 13:49:58 +0000525 "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=P, match=match:eq}}" +
526 "], inOrder=true}";
527 aqlt = new AqlTree(query);
528 map = aqlt.getRequestMap().get("query").toString();
529 assertEquals(mult2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000530
531 query = "pos=\"N\" & pos=\"V\" & pos=\"P\" & #1 > #2 & #1 > #3";
532 String mult3 =
533 "{@type=korap:group, operation=operation:relation, operands=[" +
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000534 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000535 "{@type=korap:group, operation=operation:relation, operands=[" +
536 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
537 "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=N, match=match:eq}}" +
538 "]}," +
539 "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=V, match=match:eq}}" +
540 "], relation={@type=korap:treeRelation, reltype=dominance}}" +
541 "]}," +
542 "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=P, match=match:eq}}" +
543 "], relation={@type=korap:treeRelation, reltype=dominance}}";
544 aqlt = new AqlTree(query);
545 map = aqlt.getRequestMap().get("query").toString();
546 assertEquals(mult3.replaceAll(" ", ""), map.replaceAll(" ", ""));
547
548 query = "cat=\"NP\" & pos=\"V\" & pos=\"P\" & #1 > #2 & #1 > #3 & #2 . #3";
549 String mult4 =
550 "{@type=korap:group, operation=operation:sequence, operands=[" +
551 // reduce dominance relations "#1 > #2 & #1 > #3" to operand #2 in order to make it accessible for #2 . #3 (the last/outermost relation)
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000552 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000553 "{@type=korap:group, operation=operation:relation, operands=[" +
554 // dominance relation #1 > #2 is reduced to #1, for expressing #1 > #3
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000555 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000556 "{@type=korap:group, operation=operation:relation, operands=[" +
557 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
558 "{@type=korap:span, layer=cat, key=NP, match=match:eq}" +
559 "]}," +
560 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
561 "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=V, match=match:eq}}" +
562 "]}" +
563 "], relation={@type=korap:treeRelation, reltype=dominance}}" +
564 "]}," +
565 // establish class 2 around P for later reference
566 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
567 "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=P, match=match:eq}}" +
568 "]}" +
569 "], relation={@type=korap:treeRelation, reltype=dominance}}" +
570 "]}," +
571 // refer back to class 2 as second operand
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000572 "{@type=korap:reference, operation=operation:focus, classRef=[2]}" +
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000573 "], inOrder=true}";
574 aqlt = new AqlTree(query);
575 map = aqlt.getRequestMap().get("query").toString();
576 assertEquals(mult4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelca4944e2014-06-13 13:55:10 +0000577 }
Joachim Bingeleee549e2014-04-29 11:15:37 +0000578
Joachim Bingelca4944e2014-06-13 13:55:10 +0000579 @Test
580 public void testUnaryRelations() throws QueryException {
581 query = "node & #1:tokenarity=2";
582 String unary1 =
583 "{@type=korap:span, attr={@type=korap:term, tokenarity={@type=korap:boundary,min=2,max=2}}}";
584 aqlt = new AqlTree(query);
585 map = aqlt.getRequestMap().get("query").toString();
586 assertEquals(unary1.replaceAll(" ", ""), map.replaceAll(" ", ""));
587
588 query = "cnx/cat=\"NP\" & #1:tokenarity=2";
589 String unary2 =
590 "{@type=korap:span, foundry=cnx, layer=cat, key=NP, match=match:eq, attr={@type=korap:term, tokenarity={@type=korap:boundary,min=2,max=2}}}";
591 aqlt = new AqlTree(query);
592 map = aqlt.getRequestMap().get("query").toString();
593 assertEquals(unary2.replaceAll(" ", ""), map.replaceAll(" ", ""));
594
595 query = "cnx/cat=\"NP\" & #1:root";
596 String unary3 =
597 "{@type=korap:span, foundry=cnx, layer=cat, key=NP, match=match:eq, attr={@type=korap:term, root=true}}";
598 aqlt = new AqlTree(query);
599 map = aqlt.getRequestMap().get("query").toString();
600 assertEquals(unary3.replaceAll(" ", ""), map.replaceAll(" ", ""));
601
602 query = "cnx/cat=\"NP\" & node & #1>#2 & #1:tokenarity=2";
603 String unary4 =
604 "{@type=korap:group, operation=operation:relation, operands=[" +
605 "{@type=korap:span, foundry=cnx, layer=cat, key=NP, match=match:eq, attr={@type=korap:term, tokenarity={@type=korap:boundary,min=2,max=2}}}," +
606 "{@type=korap:span}" +
607 "], relation={@type=korap:treeRelation, reltype=dominance}" +
608 "}";
609 aqlt = new AqlTree(query);
610 map = aqlt.getRequestMap().get("query").toString();
611 assertEquals(unary4.replaceAll(" ", ""), map.replaceAll(" ", ""));
612 }
613
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000614 @Test
615 public void testCommonParent() throws QueryException {
616 query = "cat=\"NP\" & cat=\"VP\" & #1 $ #2";
617 String cp1 =
618 "{@type=korap:group, operation=operation:relation, operands=[" +
619 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
620 "{@type=korap:group, operation=operation:relation, operands=[" +
621 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
622 "{@type=korap:span}" +
623 "]}," +
624 "{@type=korap:span, layer=cat, key=NP, match=match:eq}" +
625 "], relation={@type=korap:treeRelation, reltype=dominance}}" +
626 "]}," +
627 "{@type=korap:span, layer=cat, key=VP, match=match:eq}" +
628 "], relation={@type=korap:treeRelation, reltype=dominance}}" +
629 "";
630 aqlt = new AqlTree(query);
631 map = aqlt.getRequestMap().get("query").toString();
632 assertEquals(cp1.replaceAll(" ", ""), map.replaceAll(" ", ""));
633
634 query = "cat=\"NP\" & cat=\"VP\" & cat=\"PP\" & #1 $ #2 $ #3";
635 String cp2 =
636 "{@type=korap:group, operation=operation:relation, operands=[" +
637 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
638 "{@type=korap:group, operation=operation:relation, operands=[" +
639 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
640 "{@type=korap:group, operation=operation:relation, operands=[" +
641 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
642 "{@type=korap:span}" +
643 "]}," +
644 "{@type=korap:span, layer=cat, key=NP, match=match:eq}" +
645 "], relation={@type=korap:treeRelation, reltype=dominance}}" +
646 "]}," +
647 "{@type=korap:span, layer=cat, key=VP, match=match:eq}" +
648 "], relation={@type=korap:treeRelation, reltype=dominance}" +
649 "}" +
650 "]}," +
651 "{@type=korap:span, layer=cat, key=PP, match=match:eq}" +
652 "], relation={@type=korap:treeRelation, reltype=dominance}" +
653 "}";
654 aqlt = new AqlTree(query);
655 map = aqlt.getRequestMap().get("query").toString();
656 assertEquals(cp2.replaceAll(" ", ""), map.replaceAll(" ", ""));
657
658 query = "cat=\"NP\" & cat=\"VP\" & cat=\"PP\" & cat=\"CP\" & #1 $ #2 $ #3 $ #4";
659 String cp3 =
660 "{@type=korap:group, operation=operation:relation, operands=[" +
661 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
662 "{@type=korap:group, operation=operation:relation, operands=[" +
663 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
664 "{@type=korap:group, operation=operation:relation, operands=[" +
665 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
666 "{@type=korap:group, operation=operation:relation, operands=[" +
667 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
668 "{@type=korap:span}" +
669 "]}," +
670 "{@type=korap:span, layer=cat, key=NP, match=match:eq}" +
671 "], relation={@type=korap:treeRelation, reltype=dominance}}" +
672 "]}," +
673 "{@type=korap:span, layer=cat, key=VP, match=match:eq}" +
674 "], relation={@type=korap:treeRelation, reltype=dominance}}" +
675 "]}," +
676 "{@type=korap:span, layer=cat, key=PP, match=match:eq}" +
677 "], relation={@type=korap:treeRelation, reltype=dominance}}" +
678 "]}," +
679 "{@type=korap:span, layer=cat, key=CP, match=match:eq}" +
680 "], relation={@type=korap:treeRelation, reltype=dominance}" +
681 "}" +
682 "";
683 aqlt = new AqlTree(query);
684 map = aqlt.getRequestMap().get("query").toString();
685 assertEquals(cp3.replaceAll(" ", ""), map.replaceAll(" ", ""));
686 }
687
Joachim Bingelca4944e2014-06-13 13:55:10 +0000688}