blob: d10b07cbdc23dfb4c7da2af7a39a0541912fc0e5 [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 {
Joachim Bingel832800e2014-10-17 14:46:39 +000023 String contextString = "http://ids-mannheim.de/ns/KorAP/json-ld/v0.2/context.jsonld";
Joachim Bingel019ba5c2014-04-28 14:59:04 +000024 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 Bingelb6d67812014-08-13 11:37:09 +000032 String token1 = "{@type=korap:token, wrap={@type=korap:term, layer=orth, 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));
Joachim Bingelc9c0cf92014-10-02 12:03:59 +000044
45 // tok
46 query = "tok";
47 String token5 = "{@type=korap:token}";
48 assertTrue(equalsQueryContent(token5, query));
Joachim Bingel019ba5c2014-04-28 14:59:04 +000049 }
50
51 @Test
52 public void testSpans() throws QueryException {
53 query = "node";
54 String span1 =
55 "{@type=korap:span}";
56 aqlt = new AqlTree(query);
57 map = aqlt.getRequestMap().get("query").toString();
58 assertEquals(span1.replaceAll(" ", ""), map.replaceAll(" ", ""));
59 }
60
61 @Test
62 public void testRegex() throws QueryException {
63 query = "/Mann/";
Joachim Bingelb6d67812014-08-13 11:37:09 +000064 String regex1 = "{@type=korap:token, wrap={@type=korap:term, layer=orth, type=type:regex, key=Mann, match=match:eq}}";
Joachim Bingel019ba5c2014-04-28 14:59:04 +000065 aqlt = new AqlTree(query);
66 map = aqlt.getRequestMap().get("query").toString();
67 assertEquals(regex1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingele49b4672014-07-16 08:06:56 +000068
69 query = "/.*?Mann.*?/";
Joachim Bingelb6d67812014-08-13 11:37:09 +000070 String regex2 = "{@type=korap:token, wrap={@type=korap:term, layer=orth, type=type:regex, key=.*?Mann.*?, match=match:eq}}";
Joachim Bingele49b4672014-07-16 08:06:56 +000071 aqlt = new AqlTree(query);
72 map = aqlt.getRequestMap().get("query").toString();
73 assertEquals(regex2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel019ba5c2014-04-28 14:59:04 +000074 }
75
76 @Test
77 public void testLayers() throws QueryException {
78 query = "cnx/cat=\"NP\"";
Joachim Bingeleee549e2014-04-29 11:15:37 +000079 String layers1 = "{@type=korap:span, foundry=cnx, layer=cat, key=NP, match=match:eq}";
Joachim Bingel019ba5c2014-04-28 14:59:04 +000080 aqlt = new AqlTree(query);
81 map = aqlt.getRequestMap().get("query").toString();
82 assertEquals(layers1.replaceAll(" ", ""), map.replaceAll(" ", ""));
83
84 query = "treetagger/pos=\"NN\"";
Joachim Bingeleee549e2014-04-29 11:15:37 +000085 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 +000086 aqlt = new AqlTree(query);
87 map = aqlt.getRequestMap().get("query").toString();
88 assertEquals(layers2.replaceAll(" ", ""), map.replaceAll(" ", ""));
89 }
90
91 @Test
Joachim Bingel75038792014-05-19 15:12:23 +000092 public void testDirectDeclarationRelations() throws QueryException {
93 query = "node > node";
94 String ddr1 =
95 "{@type=korap:group, operation=operation:relation, operands=[" +
96 "{@type=korap:span}," +
97 "{@type=korap:span}" +
Joachim Bingel62892412014-08-06 15:18:59 +000098 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
Joachim Bingel75038792014-05-19 15:12:23 +000099 "}";
100 aqlt = new AqlTree(query);
101 map = aqlt.getRequestMap().get("query").toString();
102 assertEquals(ddr1.replaceAll(" ", ""), map.replaceAll(" ", ""));
103
104 query = "node > cnx/cat=\"NP\"";
105 String ddr2 =
106 "{@type=korap:group, operation=operation:relation, operands=[" +
107 "{@type=korap:span}," +
108 "{@type=korap:span, foundry=cnx, layer=cat, key=NP, match=match:eq}" +
Joachim Bingel62892412014-08-06 15:18:59 +0000109 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
Joachim Bingel75038792014-05-19 15:12:23 +0000110 "}";
111 aqlt = new AqlTree(query);
112 map = aqlt.getRequestMap().get("query").toString();
113 assertEquals(ddr2.replaceAll(" ", ""), map.replaceAll(" ", ""));
114
115 }
116
117 @Test
Joachim Bingelfc428812014-06-18 14:50:14 +0000118 public void testDefPredicationInversion() throws QueryException {
119 query = " #1 > #2 & cnx/cat=\"VP\" & cnx/cat=\"NP\"";
120 String dom1 =
121 "{@type=korap:group, operation=operation:relation, operands=[" +
122 "{@type=korap:span, foundry=cnx, layer=cat, key=VP, match=match:eq}," +
123 "{@type=korap:span, foundry=cnx, layer=cat, key=NP, match=match:eq}" +
Joachim Bingel62892412014-08-06 15:18:59 +0000124 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
Joachim Bingelfc428812014-06-18 14:50:14 +0000125 "}";
126 aqlt = new AqlTree(query);
127 map = aqlt.getRequestMap().get("query").toString();
128 assertEquals(dom1.replaceAll(" ", ""), map.replaceAll(" ", ""));
129 }
130
131 @Test
Joachim Bingel019ba5c2014-04-28 14:59:04 +0000132 public void testSimpleDominance() throws QueryException {
133 query = "node & node & #2 > #1";
134 String dom1 =
Joachim Bingeld4ae5fd2014-04-29 15:00:16 +0000135 "{@type=korap:group, operation=operation:relation, operands=[" +
Joachim Bingel019ba5c2014-04-28 14:59:04 +0000136 "{@type=korap:span}," +
137 "{@type=korap:span}" +
Joachim Bingel62892412014-08-06 15:18:59 +0000138 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
Joachim Bingeleee549e2014-04-29 11:15:37 +0000139 "}";
Joachim Bingel019ba5c2014-04-28 14:59:04 +0000140 aqlt = new AqlTree(query);
141 map = aqlt.getRequestMap().get("query").toString();
142 assertEquals(dom1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeleee549e2014-04-29 11:15:37 +0000143
144 query = "\"Mann\" & node & #2 > #1";
145 String dom2 =
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}," +
Joachim Bingelb6d67812014-08-13 11:37:09 +0000148 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" +
Joachim Bingel62892412014-08-06 15:18:59 +0000149 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
Joachim Bingeleee549e2014-04-29 11:15:37 +0000150 "}";
151 aqlt = new AqlTree(query);
152 map = aqlt.getRequestMap().get("query").toString();
153 assertEquals(dom2.replaceAll(" ", ""), map.replaceAll(" ", ""));
154
Joachim Bingeld4ae5fd2014-04-29 15:00:16 +0000155 query = "\"Mann\" & node & #2 >[cat=\"NP\"] #1";
Joachim Bingeleee549e2014-04-29 11:15:37 +0000156 String dom3 =
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}," +
Joachim Bingelb6d67812014-08-13 11:37:09 +0000159 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" +
Joachim Bingel62892412014-08-06 15:18:59 +0000160 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c, 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(dom3.replaceAll(" ", ""), map.replaceAll(" ", ""));
165
Joachim Bingeld4ae5fd2014-04-29 15:00:16 +0000166 query = "\"Mann\" & node & #2 >@l[cat=\"NP\"] #1";
Joachim Bingeleee549e2014-04-29 11:15:37 +0000167 String dom4 =
Joachim Bingeld4ae5fd2014-04-29 15:00:16 +0000168 "{@type=korap:group, operation=operation:relation, operands=[" +
Joachim Bingeleee549e2014-04-29 11:15:37 +0000169 "{@type=korap:span}," +
Joachim Bingelb6d67812014-08-13 11:37:09 +0000170 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" +
Joachim Bingel62892412014-08-06 15:18:59 +0000171 "], relation={@type=korap:relation, index=0, wrap={@type=korap:term, layer=c, key=NP, match=match:eq}}" +
Joachim Bingeleee549e2014-04-29 11:15:37 +0000172 "}";
173 aqlt = new AqlTree(query);
174 map = aqlt.getRequestMap().get("query").toString();
175 assertEquals(dom4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeld4ae5fd2014-04-29 15:00:16 +0000176
177 query = "\"Mann\" & node & #2 >2,4 #1";
178 String dom5 =
179 "{@type=korap:group, operation=operation:relation, operands=[" +
180 "{@type=korap:span}," +
Joachim Bingelb6d67812014-08-13 11:37:09 +0000181 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" +
Joachim Bingel62892412014-08-06 15:18:59 +0000182 "], relation={@type=korap:relation, boundary={@type=korap:boundary, min=2, max=4}, wrap={@type=korap:term, layer=c}}" +
Joachim Bingeld4ae5fd2014-04-29 15:00:16 +0000183 "}";
184 aqlt = new AqlTree(query);
185 map = aqlt.getRequestMap().get("query").toString();
186 assertEquals(dom5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel019ba5c2014-04-28 14:59:04 +0000187 }
188
Joachim Bingel13421ef2014-05-07 16:22:58 +0000189 @Test
Joachim Bingelca4944e2014-06-13 13:55:10 +0000190 public void testMultipleDominance() throws QueryException {
Joachim Bingel949e3a82014-06-16 13:20:43 +0000191 query = "cat=\"CP\" & cat=\"VP\" & cat=\"NP\" & #1 > #2 > #3";
Joachim Bingelca4944e2014-06-13 13:55:10 +0000192 String dom1 =
193 "{@type=korap:group, operation=operation:relation, operands=[" +
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000194 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
Joachim Bingelfc428812014-06-18 14:50:14 +0000195 "{@type=korap:group, operation=operation:relation, operands=[" +
196 "{@type=korap:span, layer=cat, key=CP, match=match:eq}," +
Joachim Bingel832800e2014-10-17 14:46:39 +0000197 "{@type=korap:group, operation=operation:class, class=1024, classOut=1024, operands=[" +
Joachim Bingelfc428812014-06-18 14:50:14 +0000198 "{@type=korap:span, layer=cat, key=VP, match=match:eq}" +
199 "]}" +
Joachim Bingel62892412014-08-06 15:18:59 +0000200 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000201 "]}," +
Joachim Bingel949e3a82014-06-16 13:20:43 +0000202 "{@type=korap:span, layer=cat, key=NP, match=match:eq}" +
Joachim Bingel62892412014-08-06 15:18:59 +0000203 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
Joachim Bingelca4944e2014-06-13 13:55:10 +0000204 "}";
205 aqlt = new AqlTree(query);
206 map = aqlt.getRequestMap().get("query").toString();
207 assertEquals(dom1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel949e3a82014-06-16 13:20:43 +0000208
209 query = "cat=\"CP\" & cat=\"VP\" & cat=\"NP\" & cat=\"DP\" & #1 > #2 > #3 > #4";
210 String dom2 =
211 "{@type=korap:group, operation=operation:relation, operands=[" +
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000212 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingel949e3a82014-06-16 13:20:43 +0000213 "{@type=korap:group, operation=operation:relation, operands=[" +
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000214 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
Joachim Bingelfc428812014-06-18 14:50:14 +0000215 "{@type=korap:group, operation=operation:relation, operands=[" +
216 "{@type=korap:span, layer=cat, key=CP, match=match:eq}," +
Joachim Bingel832800e2014-10-17 14:46:39 +0000217 "{@type=korap:group, operation=operation:class, class=1024, classOut=1024, operands=[" +
Joachim Bingelfc428812014-06-18 14:50:14 +0000218 "{@type=korap:span, layer=cat, key=VP, match=match:eq}" +
219 "]}" +
Joachim Bingel62892412014-08-06 15:18:59 +0000220 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000221 "]}," +
Joachim Bingel832800e2014-10-17 14:46:39 +0000222 "{@type=korap:group, operation=operation:class, class=1025, classOut=1025, operands=[" +
Joachim Bingelfc428812014-06-18 14:50:14 +0000223 "{@type=korap:span, layer=cat, key=NP, match=match:eq}" +
224 "]}" +
Joachim Bingel62892412014-08-06 15:18:59 +0000225 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000226 "]}," +
Joachim Bingel949e3a82014-06-16 13:20:43 +0000227 "{@type=korap:span, layer=cat, key=DP, match=match:eq}" +
Joachim Bingel62892412014-08-06 15:18:59 +0000228 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
Joachim Bingel949e3a82014-06-16 13:20:43 +0000229 "}";
230 aqlt = new AqlTree(query);
231 map = aqlt.getRequestMap().get("query").toString();
232 assertEquals(dom2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelca4944e2014-06-13 13:55:10 +0000233 }
234
235 @Test
Joachim Bingel13421ef2014-05-07 16:22:58 +0000236 public void testPointingRelations() throws QueryException {
Joachim Bingel62892412014-08-06 15:18:59 +0000237 query = "node & node & #2 ->coref[val=\"true\"] #1";
Joachim Bingel13421ef2014-05-07 16:22:58 +0000238 String dom1 =
239 "{@type=korap:group, operation=operation:relation, operands=[" +
240 "{@type=korap:span}," +
241 "{@type=korap:span}" +
Joachim Bingel62892412014-08-06 15:18:59 +0000242 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=coref, key=true, match=match:eq}}" +
Joachim Bingel13421ef2014-05-07 16:22:58 +0000243 "}";
244 aqlt = new AqlTree(query);
245 map = aqlt.getRequestMap().get("query").toString();
246 assertEquals(dom1.replaceAll(" ", ""), map.replaceAll(" ", ""));
247
Joachim Bingel62892412014-08-06 15:18:59 +0000248 query = "node & node & #2 ->mate/coref[val=\"true\"] #1";
Joachim Bingel639df9c2014-05-12 15:27:00 +0000249 String dom2 =
250 "{@type=korap:group, operation=operation:relation, operands=[" +
251 "{@type=korap:span}," +
252 "{@type=korap:span}" +
Joachim Bingel62892412014-08-06 15:18:59 +0000253 "], relation={@type=korap:relation, wrap={@type=korap:term, foundry=mate, layer=coref, key=true, match=match:eq}}" +
Joachim Bingel639df9c2014-05-12 15:27:00 +0000254 "}";
255 aqlt = new AqlTree(query);
256 map = aqlt.getRequestMap().get("query").toString();
257 assertEquals(dom2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel13421ef2014-05-07 16:22:58 +0000258 }
259
260 @Test
261 public void testSequence() throws QueryException {
262 query = "node & node & #1 . #2";
Joachim Bingelca4944e2014-06-13 13:55:10 +0000263 String seq1 =
Joachim Bingel13421ef2014-05-07 16:22:58 +0000264 "{@type=korap:group, operation=operation:sequence, " +
265 "operands=[" +
266 "{@type=korap:span}," +
267 "{@type=korap:span}" +
268 "], inOrder=true" +
269 "}";
270 aqlt = new AqlTree(query);
271 map = aqlt.getRequestMap().get("query").toString();
Joachim Bingelca4944e2014-06-13 13:55:10 +0000272 assertEquals(seq1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel13421ef2014-05-07 16:22:58 +0000273
274 query = "node & node & #1 .* #2";
Joachim Bingelca4944e2014-06-13 13:55:10 +0000275 String seq2 =
Joachim Bingel75038792014-05-19 15:12:23 +0000276 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel13421ef2014-05-07 16:22:58 +0000277 "{@type=korap:span}," +
278 "{@type=korap:span}" +
279 "], distances=[" +
Joachim Bingel687e4d42014-07-30 09:34:18 +0000280 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0}, min=0}" +
Joachim Bingel13421ef2014-05-07 16:22:58 +0000281 "], inOrder=true" +
282 "}";
283 aqlt = new AqlTree(query);
284 map = aqlt.getRequestMap().get("query").toString();
Joachim Bingelca4944e2014-06-13 13:55:10 +0000285 assertEquals(seq2.replaceAll(" ", ""), map.replaceAll(" ", ""));
286
287 query = "node & node & #1 .2,3 #2";
288 String seq3 =
289 "{@type=korap:group, operation=operation:sequence, operands=[" +
290 "{@type=korap:span}," +
291 "{@type=korap:span}" +
292 "], distances=[" +
Joachim Bingel55020e82014-07-28 14:22:51 +0000293 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=2, max=3}, min=2, max=3}" +
Joachim Bingelca4944e2014-06-13 13:55:10 +0000294 "], inOrder=true" +
295 "}";
296 aqlt = new AqlTree(query);
297 map = aqlt.getRequestMap().get("query").toString();
298 assertEquals(seq3.replaceAll(" ", ""), map.replaceAll(" ", ""));
299
300 }
301
302 @Test
303 public void testMultipleSequence() throws QueryException {
304 query = "tok=\"Sonne\" & tok=\"Mond\" & tok=\"Sterne\" & #1 .0,2 #2 .0,4 #3";
305 String seq4 =
306 "{@type=korap:group, operation=operation:sequence," +
Joachim Bingelfc428812014-06-18 14:50:14 +0000307 "operands=[" +
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000308 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
Joachim Bingelca4944e2014-06-13 13:55:10 +0000309 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel949e3a82014-06-16 13:20:43 +0000310 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sonne, match=match:eq}}," +
Joachim Bingel832800e2014-10-17 14:46:39 +0000311 "{@type=korap:group, operation=operation:class, class=1024, classOut=1024, operands=[" +
Joachim Bingelfc428812014-06-18 14:50:14 +0000312 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mond, match=match:eq}}" +
313 "]}" +
Joachim Bingel949e3a82014-06-16 13:20:43 +0000314 "], distances=[" +
Joachim Bingel55020e82014-07-28 14:22:51 +0000315 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0, max=2}, min=0, max=2}" +
Joachim Bingelfc428812014-06-18 14:50:14 +0000316 "], inOrder=true}" +
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000317 "]}," +
Joachim Bingelfc428812014-06-18 14:50:14 +0000318 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sterne, match=match:eq}}" +
319 "],distances=[" +
Joachim Bingel55020e82014-07-28 14:22:51 +0000320 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0, max=4}, min=0, max=4}" +
Joachim Bingelfc428812014-06-18 14:50:14 +0000321 "], inOrder=true" +
322 "}";
Joachim Bingelca4944e2014-06-13 13:55:10 +0000323 aqlt = new AqlTree(query);
324 map = aqlt.getRequestMap().get("query").toString();
325 assertEquals(seq4.replaceAll(" ", ""), map.replaceAll(" ", ""));
326
327 query = "node & node & node & #1 . #2 .1,3 #3";
328 String seq5 =
329 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000330 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
Joachim Bingelfc428812014-06-18 14:50:14 +0000331 "{@type=korap:group, operation=operation:sequence, operands=[" +
332 "{@type=korap:span}," +
Joachim Bingel832800e2014-10-17 14:46:39 +0000333 "{@type=korap:group, operation=operation:class, class=1024, classOut=1024, operands=[" +
Joachim Bingelfc428812014-06-18 14:50:14 +0000334 "{@type=korap:span}" +
335 "]} "+
336 "], inOrder=true}" +
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000337 "]}," +
Joachim Bingel949e3a82014-06-16 13:20:43 +0000338 "{@type=korap:span}" +
339 "], distances=[" +
Joachim Bingel55020e82014-07-28 14:22:51 +0000340 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1, max=3}, min=1, max=3}" +
Joachim Bingel949e3a82014-06-16 13:20:43 +0000341 "], inOrder=true" +
Joachim Bingelca4944e2014-06-13 13:55:10 +0000342 "}";
343 aqlt = new AqlTree(query);
344 map = aqlt.getRequestMap().get("query").toString();
345 assertEquals(seq5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000346
347 query = "tok=\"Sonne\" & tok=\"Mond\" & tok=\"Sterne\" & tok=\"Himmel\" & #1 .0,2 #2 .0,4 #3 . #4";
348 String seq6 =
349 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000350 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000351 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000352 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000353 "{@type=korap:group, operation=operation:sequence, operands=[" +
354 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sonne, match=match:eq}}," +
Joachim Bingel832800e2014-10-17 14:46:39 +0000355 "{@type=korap:group, operation=operation:class, class=1024, classOut=1024, operands=[" +
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000356 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mond, match=match:eq}}" +
357 "]}" +
358 "], distances=[" +
Joachim Bingel55020e82014-07-28 14:22:51 +0000359 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0, max=2}, min=0, max=2}" +
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000360 "], inOrder=true}" +
361 "]}," +
Joachim Bingel832800e2014-10-17 14:46:39 +0000362 "{@type=korap:group, operation=operation:class, class=1025, classOut=1025, operands=[" +
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000363 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sterne, match=match:eq}}" +
364 "]}" +
365 "],distances=[" +
Joachim Bingel55020e82014-07-28 14:22:51 +0000366 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0, max=4}, min=0, max=4}" +
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000367 "], inOrder=true}" +
368 "]}," +
369 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Himmel, match=match:eq}}" +
370 "], inOrder=true}" ;
371 aqlt = new AqlTree(query);
372 map = aqlt.getRequestMap().get("query").toString();
373 assertEquals(seq6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel75038792014-05-19 15:12:23 +0000374 }
375
376 @Test
Joachim Bingel949e3a82014-06-16 13:20:43 +0000377 public void testMultipleMixedOperators() throws QueryException {
378 query = "tok=\"Sonne\" & tok=\"Mond\" & tok=\"Sterne\" & #1 > #2 .0,4 #3";
379 String seq4 =
Joachim Bingelfc428812014-06-18 14:50:14 +0000380 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000381 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
Joachim Bingelfc428812014-06-18 14:50:14 +0000382 "{@type=korap:group, operation=operation:relation, operands=[" +
383 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sonne, match=match:eq}}," +
Joachim Bingel832800e2014-10-17 14:46:39 +0000384 "{@type=korap:group, operation=operation:class, class=1024, classOut=1024, operands=[" +
Joachim Bingelfc428812014-06-18 14:50:14 +0000385 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mond, match=match:eq}}" +
386 "]}" +
Joachim Bingel62892412014-08-06 15:18:59 +0000387 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000388 "]}," +
Joachim Bingel949e3a82014-06-16 13:20:43 +0000389 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sterne, match=match:eq}}" +
390 "], distances=[" +
Joachim Bingel55020e82014-07-28 14:22:51 +0000391 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0, max=4}, min=0, max=4}" +
Joachim Bingel949e3a82014-06-16 13:20:43 +0000392 "], inOrder=true" +
393 "}";
394 aqlt = new AqlTree(query);
395 map = aqlt.getRequestMap().get("query").toString();
396 assertEquals(seq4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelfc428812014-06-18 14:50:14 +0000397
398 query = "tok=\"Sonne\" & tok=\"Mond\" & #1 > #2 .0,4 tok=\"Sterne\"";
399 String seq5 =
400 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000401 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
Joachim Bingelfc428812014-06-18 14:50:14 +0000402 "{@type=korap:group, operation=operation:relation, operands=[" +
403 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sonne, match=match:eq}}," +
Joachim Bingel832800e2014-10-17 14:46:39 +0000404 "{@type=korap:group, operation=operation:class, class=1024, classOut=1024, operands=[" +
Joachim Bingelfc428812014-06-18 14:50:14 +0000405 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mond, match=match:eq}}" +
406 "]}" +
Joachim Bingel62892412014-08-06 15:18:59 +0000407 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000408 "]}," +
Joachim Bingelfc428812014-06-18 14:50:14 +0000409 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sterne, match=match:eq}}" +
410 "], distances=[" +
Joachim Bingel55020e82014-07-28 14:22:51 +0000411 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0, max=4}, min=0, max=4}" +
Joachim Bingelfc428812014-06-18 14:50:14 +0000412 "], inOrder=true" +
413 "}";
414 aqlt = new AqlTree(query);
415 map = aqlt.getRequestMap().get("query").toString();
416 assertEquals(seq5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000417
418 query = "cat=\"NP\" & cat=\"VP\" & cat=\"PP\" & #1 $ #2 > #3";
419 String cp2 =
420 "{@type=korap:group, operation=operation:relation, operands=[" +
421 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
422 "{@type=korap:group, operation=operation:relation, operands=[" +
423 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
424 "{@type=korap:group, operation=operation:relation, operands=[" +
Joachim Bingel832800e2014-10-17 14:46:39 +0000425 "{@type=korap:group, operation=operation:class, class=1024, classOut=1024, operands=[" +
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000426 "{@type=korap:span}" +
427 "]}," +
428 "{@type=korap:span, layer=cat, key=NP, match=match:eq}" +
Joachim Bingel62892412014-08-06 15:18:59 +0000429 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000430 "]}," +
Joachim Bingel832800e2014-10-17 14:46:39 +0000431 "{@type=korap:group, operation=operation:class, class=1025, classOut=1025, operands=[" +
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000432 "{@type=korap:span, layer=cat, key=VP, match=match:eq}" +
433 "]}" +
Joachim Bingel62892412014-08-06 15:18:59 +0000434 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000435 "}" +
436 "]}," +
437 "{@type=korap:span, layer=cat, key=PP, match=match:eq}" +
Joachim Bingel62892412014-08-06 15:18:59 +0000438 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000439 "}";
440 aqlt = new AqlTree(query);
441 map = aqlt.getRequestMap().get("query").toString();
442 assertEquals(cp2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel949e3a82014-06-16 13:20:43 +0000443 }
Joachim Bingele6d73b12014-09-30 15:34:59 +0000444 /*
445 @Test
446 public void testMultipleOperatorsWithSameOperands() throws QueryException {
447
448 query = "cat=\"NP\" > cat=\"VP\" & #1 _l_ #2";
449 String eq2 =
450 "{@type=korap:group, operation=operation:position, frames=[frame:startswith], sharedClasses=[sharedClasses:includes], operands=[" +
451 "{@type=korap:group, operation=operation:relation, operands=[" +
Joachim Bingel832800e2014-10-17 14:46:39 +0000452 "{@type=korap:group, operation=operation:class, class=, classOut=1025, operands=[" +
Joachim Bingele6d73b12014-09-30 15:34:59 +0000453 "{@type=korap:span, layer=cat, key=NP, match=match:eq}" +
454 "]}," +
Joachim Bingel832800e2014-10-17 14:46:39 +0000455 "{@type=korap:group, operation=operation:class, class=, classOut=1025, operands=[" +
Joachim Bingele6d73b12014-09-30 15:34:59 +0000456 "{@type=korap:span, layer=cat, key=VP, match=match:eq}" +
457 "]}" +
458 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}," +
459 "{@type=korap:reference, operation=operation:focus, classRef=[2]}" +
460 "]" +
461 "}"; // ???
462 aqlt = new AqlTree(query);
463 map = aqlt.getRequestMap().get("query").toString();
464 assertEquals(eq2.replaceAll(" ", ""), map.replaceAll(" ", ""));
465 }
466 */
Joachim Bingel949e3a82014-06-16 13:20:43 +0000467 @Test
Joachim Bingel75038792014-05-19 15:12:23 +0000468 public void testPositions() throws QueryException {
469 query = "node & node & #2 _=_ #1";
470 String pos1 =
Joachim Bingele6d73b12014-09-30 15:34:59 +0000471 "{@type=korap:group, operation=operation:position, frames=[frame:matches], sharedClasses=[sharedClasses:equals], operands=[" +
Joachim Bingel75038792014-05-19 15:12:23 +0000472 "{@type=korap:span}," +
473 "{@type=korap:span}" +
Joachim Bingele6d73b12014-09-30 15:34:59 +0000474 "], frame=frame:matches}";
Joachim Bingel75038792014-05-19 15:12:23 +0000475 aqlt = new AqlTree(query);
476 map = aqlt.getRequestMap().get("query").toString();
477 assertEquals(pos1.replaceAll(" ", ""), map.replaceAll(" ", ""));
478
Joachim Bingelca4944e2014-06-13 13:55:10 +0000479 query = "node & node & #2 _i_ #1";
480 String pos2 =
Joachim Bingele6d73b12014-09-30 15:34:59 +0000481 "{@type=korap:group, operation=operation:position, frames=[frame:contains], sharedClasses=[sharedClasses:includes], operands=[" +
Joachim Bingelca4944e2014-06-13 13:55:10 +0000482 "{@type=korap:span}," +
483 "{@type=korap:span}" +
484 "], frame=frame:contains" +
485 "}";
486 aqlt = new AqlTree(query);
487 map = aqlt.getRequestMap().get("query").toString();
488 assertEquals(pos2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel75038792014-05-19 15:12:23 +0000489
Joachim Bingelca4944e2014-06-13 13:55:10 +0000490 query = "node & node & #2 _l_ #1";
491 String pos3 =
Joachim Bingele6d73b12014-09-30 15:34:59 +0000492 "{@type=korap:group, operation=operation:position, frames=[frame:startswith], sharedClasses=[sharedClasses:includes], operands=[" +
Joachim Bingelca4944e2014-06-13 13:55:10 +0000493 "{@type=korap:span}," +
494 "{@type=korap:span}" +
Joachim Bingele6d73b12014-09-30 15:34:59 +0000495 "], frame=frame:startswith" +
Joachim Bingelca4944e2014-06-13 13:55:10 +0000496 "}";
497 aqlt = new AqlTree(query);
498 map = aqlt.getRequestMap().get("query").toString();
499 assertEquals(pos3.replaceAll(" ", ""), map.replaceAll(" ", ""));
500
501 query = "node & \"Mann\" & #1 _r_ #2";
Joachim Bingel75038792014-05-19 15:12:23 +0000502 String pos4 =
Joachim Bingele6d73b12014-09-30 15:34:59 +0000503 "{@type=korap:group, operation=operation:position, frames=[frame:endswith], sharedClasses=[sharedClasses:includes], operands=[" +
Joachim Bingel75038792014-05-19 15:12:23 +0000504 "{@type=korap:span}," +
Joachim Bingelb6d67812014-08-13 11:37:09 +0000505 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" +
Joachim Bingele6d73b12014-09-30 15:34:59 +0000506 "], frame=frame:endswith" +
Joachim Bingelca4944e2014-06-13 13:55:10 +0000507 "}";
Joachim Bingel75038792014-05-19 15:12:23 +0000508 aqlt = new AqlTree(query);
509 map = aqlt.getRequestMap().get("query").toString();
510 assertEquals(pos4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel13421ef2014-05-07 16:22:58 +0000511
Joachim Bingelca4944e2014-06-13 13:55:10 +0000512 query = "node & \"Mann\" & #2 _r_ #1";
513 String pos5 =
Joachim Bingele6d73b12014-09-30 15:34:59 +0000514 "{@type=korap:group, operation=operation:position, frames=[frame:endswith], sharedClasses=[sharedClasses:includes], operands=[" +
Joachim Bingelb6d67812014-08-13 11:37:09 +0000515 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}," +
Joachim Bingelca4944e2014-06-13 13:55:10 +0000516 "{@type=korap:span}" +
Joachim Bingele6d73b12014-09-30 15:34:59 +0000517 "], frame=frame:endswith" +
Joachim Bingelca4944e2014-06-13 13:55:10 +0000518 "}";
519 aqlt = new AqlTree(query);
520 map = aqlt.getRequestMap().get("query").toString();
521 assertEquals(pos5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel13421ef2014-05-07 16:22:58 +0000522 }
523
Joachim Bingelca4944e2014-06-13 13:55:10 +0000524 @Test
525 public void testMultiplePredications() throws QueryException {
Joachim Bingel9c3ddb92014-06-23 13:49:58 +0000526 // a noun before a verb before a preposition
Joachim Bingelfc428812014-06-18 14:50:14 +0000527 query = "pos=\"N\" & pos=\"V\" & pos=\"P\" & #1 . #2 & #2 . #3";
Joachim Bingelca4944e2014-06-13 13:55:10 +0000528 String mult1 =
Joachim Bingel9c3ddb92014-06-23 13:49:58 +0000529 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000530 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
Joachim Bingelca4944e2014-06-13 13:55:10 +0000531 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel9c3ddb92014-06-23 13:49:58 +0000532 "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=N, match=match:eq}}," +
Joachim Bingel832800e2014-10-17 14:46:39 +0000533 "{@type=korap:group, operation=operation:class, class=1024, classOut=1024, operands=[" +
Joachim Bingel9c3ddb92014-06-23 13:49:58 +0000534 "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=V, match=match:eq}}" +
535 "]}" +
536 "], inOrder=true}" +
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000537 "]}," +
Joachim Bingel9c3ddb92014-06-23 13:49:58 +0000538 "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=P, match=match:eq}}" +
539 "], inOrder=true}";
Joachim Bingelca4944e2014-06-13 13:55:10 +0000540 aqlt = new AqlTree(query);
541 map = aqlt.getRequestMap().get("query").toString();
542 assertEquals(mult1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel9c3ddb92014-06-23 13:49:58 +0000543
544 // a noun before a verb before a preposition
545 query = "pos=\"N\" & pos=\"V\" & #1 . #2 & #2 . pos=\"P\"";
546 String mult2 =
547 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000548 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
Joachim Bingel9c3ddb92014-06-23 13:49:58 +0000549 "{@type=korap:group, operation=operation:sequence, operands=[" +
550 "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=N, match=match:eq}}," +
Joachim Bingel832800e2014-10-17 14:46:39 +0000551 "{@type=korap:group, operation=operation:class, class=1024, classOut=1024, operands=[" +
Joachim Bingel9c3ddb92014-06-23 13:49:58 +0000552 "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=V, match=match:eq}}" +
553 "]}" +
554 "], inOrder=true}" +
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000555 "]}," +
Joachim Bingel9c3ddb92014-06-23 13:49:58 +0000556 "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=P, match=match:eq}}" +
557 "], inOrder=true}";
558 aqlt = new AqlTree(query);
559 map = aqlt.getRequestMap().get("query").toString();
560 assertEquals(mult2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000561
562 query = "pos=\"N\" & pos=\"V\" & pos=\"P\" & #1 > #2 & #1 > #3";
563 String mult3 =
564 "{@type=korap:group, operation=operation:relation, operands=[" +
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000565 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000566 "{@type=korap:group, operation=operation:relation, operands=[" +
Joachim Bingel832800e2014-10-17 14:46:39 +0000567 "{@type=korap:group, operation=operation:class, class=1024, classOut=1024, operands=[" +
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000568 "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=N, match=match:eq}}" +
569 "]}," +
570 "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=V, match=match:eq}}" +
Joachim Bingel62892412014-08-06 15:18:59 +0000571 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000572 "]}," +
573 "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=P, match=match:eq}}" +
Joachim Bingel62892412014-08-06 15:18:59 +0000574 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}";
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000575 aqlt = new AqlTree(query);
576 map = aqlt.getRequestMap().get("query").toString();
577 assertEquals(mult3.replaceAll(" ", ""), map.replaceAll(" ", ""));
578
579 query = "cat=\"NP\" & pos=\"V\" & pos=\"P\" & #1 > #2 & #1 > #3 & #2 . #3";
580 String mult4 =
581 "{@type=korap:group, operation=operation:sequence, operands=[" +
582 // 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 +0000583 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000584 "{@type=korap:group, operation=operation:relation, operands=[" +
585 // dominance relation #1 > #2 is reduced to #1, for expressing #1 > #3
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000586 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000587 "{@type=korap:group, operation=operation:relation, operands=[" +
Joachim Bingel832800e2014-10-17 14:46:39 +0000588 "{@type=korap:group, operation=operation:class, class=1024, classOut=1024, operands=[" +
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000589 "{@type=korap:span, layer=cat, key=NP, match=match:eq}" +
590 "]}," +
Joachim Bingel832800e2014-10-17 14:46:39 +0000591 "{@type=korap:group, operation=operation:class, class=1025, classOut=1025, operands=[" +
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000592 "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=V, match=match:eq}}" +
593 "]}" +
Joachim Bingel62892412014-08-06 15:18:59 +0000594 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000595 "]}," +
596 // establish class 2 around P for later reference
Joachim Bingel832800e2014-10-17 14:46:39 +0000597 "{@type=korap:group, operation=operation:class, class=1026, classOut=1026, operands=[" +
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000598 "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=P, match=match:eq}}" +
599 "]}" +
Joachim Bingel62892412014-08-06 15:18:59 +0000600 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000601 "]}," +
602 // refer back to class 2 as second operand
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000603 "{@type=korap:reference, operation=operation:focus, classRef=[2]}" +
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000604 "], inOrder=true}";
605 aqlt = new AqlTree(query);
606 map = aqlt.getRequestMap().get("query").toString();
607 assertEquals(mult4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelca4944e2014-06-13 13:55:10 +0000608 }
Joachim Bingeleee549e2014-04-29 11:15:37 +0000609
Joachim Bingelca4944e2014-06-13 13:55:10 +0000610 @Test
611 public void testUnaryRelations() throws QueryException {
612 query = "node & #1:tokenarity=2";
613 String unary1 =
614 "{@type=korap:span, attr={@type=korap:term, tokenarity={@type=korap:boundary,min=2,max=2}}}";
615 aqlt = new AqlTree(query);
616 map = aqlt.getRequestMap().get("query").toString();
617 assertEquals(unary1.replaceAll(" ", ""), map.replaceAll(" ", ""));
618
619 query = "cnx/cat=\"NP\" & #1:tokenarity=2";
620 String unary2 =
621 "{@type=korap:span, foundry=cnx, layer=cat, key=NP, match=match:eq, attr={@type=korap:term, tokenarity={@type=korap:boundary,min=2,max=2}}}";
622 aqlt = new AqlTree(query);
623 map = aqlt.getRequestMap().get("query").toString();
624 assertEquals(unary2.replaceAll(" ", ""), map.replaceAll(" ", ""));
625
626 query = "cnx/cat=\"NP\" & #1:root";
627 String unary3 =
628 "{@type=korap:span, foundry=cnx, layer=cat, key=NP, match=match:eq, attr={@type=korap:term, root=true}}";
629 aqlt = new AqlTree(query);
630 map = aqlt.getRequestMap().get("query").toString();
631 assertEquals(unary3.replaceAll(" ", ""), map.replaceAll(" ", ""));
632
633 query = "cnx/cat=\"NP\" & node & #1>#2 & #1:tokenarity=2";
634 String unary4 =
635 "{@type=korap:group, operation=operation:relation, operands=[" +
636 "{@type=korap:span, foundry=cnx, layer=cat, key=NP, match=match:eq, attr={@type=korap:term, tokenarity={@type=korap:boundary,min=2,max=2}}}," +
637 "{@type=korap:span}" +
Joachim Bingel62892412014-08-06 15:18:59 +0000638 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
Joachim Bingelca4944e2014-06-13 13:55:10 +0000639 "}";
640 aqlt = new AqlTree(query);
641 map = aqlt.getRequestMap().get("query").toString();
642 assertEquals(unary4.replaceAll(" ", ""), map.replaceAll(" ", ""));
643 }
644
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000645 @Test
646 public void testCommonParent() throws QueryException {
647 query = "cat=\"NP\" & cat=\"VP\" & #1 $ #2";
648 String cp1 =
649 "{@type=korap:group, operation=operation:relation, operands=[" +
650 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
651 "{@type=korap:group, operation=operation:relation, operands=[" +
Joachim Bingel832800e2014-10-17 14:46:39 +0000652 "{@type=korap:group, operation=operation:class, class=1024, classOut=1024, operands=[" +
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000653 "{@type=korap:span}" +
654 "]}," +
655 "{@type=korap:span, layer=cat, key=NP, match=match:eq}" +
Joachim Bingel62892412014-08-06 15:18:59 +0000656 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000657 "]}," +
658 "{@type=korap:span, layer=cat, key=VP, match=match:eq}" +
Joachim Bingel62892412014-08-06 15:18:59 +0000659 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000660 "";
661 aqlt = new AqlTree(query);
662 map = aqlt.getRequestMap().get("query").toString();
663 assertEquals(cp1.replaceAll(" ", ""), map.replaceAll(" ", ""));
664
665 query = "cat=\"NP\" & cat=\"VP\" & cat=\"PP\" & #1 $ #2 $ #3";
666 String cp2 =
667 "{@type=korap:group, operation=operation:relation, operands=[" +
668 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
669 "{@type=korap:group, operation=operation:relation, operands=[" +
670 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
671 "{@type=korap:group, operation=operation:relation, operands=[" +
Joachim Bingel832800e2014-10-17 14:46:39 +0000672 "{@type=korap:group, operation=operation:class, class=1024, classOut=1024, operands=[" +
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000673 "{@type=korap:span}" +
674 "]}," +
675 "{@type=korap:span, layer=cat, key=NP, match=match:eq}" +
Joachim Bingel62892412014-08-06 15:18:59 +0000676 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000677 "]}," +
678 "{@type=korap:span, layer=cat, key=VP, match=match:eq}" +
Joachim Bingel62892412014-08-06 15:18:59 +0000679 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000680 "}" +
681 "]}," +
682 "{@type=korap:span, layer=cat, key=PP, match=match:eq}" +
Joachim Bingel62892412014-08-06 15:18:59 +0000683 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000684 "}";
685 aqlt = new AqlTree(query);
686 map = aqlt.getRequestMap().get("query").toString();
687 assertEquals(cp2.replaceAll(" ", ""), map.replaceAll(" ", ""));
688
689 query = "cat=\"NP\" & cat=\"VP\" & cat=\"PP\" & cat=\"CP\" & #1 $ #2 $ #3 $ #4";
690 String cp3 =
691 "{@type=korap:group, operation=operation:relation, operands=[" +
692 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
693 "{@type=korap:group, operation=operation:relation, operands=[" +
694 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
695 "{@type=korap:group, operation=operation:relation, operands=[" +
696 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
697 "{@type=korap:group, operation=operation:relation, operands=[" +
Joachim Bingel832800e2014-10-17 14:46:39 +0000698 "{@type=korap:group, operation=operation:class, class=1024, classOut=1024, operands=[" +
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000699 "{@type=korap:span}" +
700 "]}," +
701 "{@type=korap:span, layer=cat, key=NP, match=match:eq}" +
Joachim Bingel62892412014-08-06 15:18:59 +0000702 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000703 "]}," +
704 "{@type=korap:span, layer=cat, key=VP, match=match:eq}" +
Joachim Bingel62892412014-08-06 15:18:59 +0000705 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000706 "]}," +
707 "{@type=korap:span, layer=cat, key=PP, match=match:eq}" +
Joachim Bingel62892412014-08-06 15:18:59 +0000708 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000709 "]}," +
710 "{@type=korap:span, layer=cat, key=CP, match=match:eq}" +
Joachim Bingel62892412014-08-06 15:18:59 +0000711 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000712 "}" +
713 "";
714 aqlt = new AqlTree(query);
715 map = aqlt.getRequestMap().get("query").toString();
716 assertEquals(cp3.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000717
Joachim Bingele6d73b12014-09-30 15:34:59 +0000718 query = "cat=\"NP\" & cat=\"VP\" & #1 $* #2";
719 String cp4 =
720 "{@type=korap:group, operation=operation:relation, operands=[" +
721 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
722 "{@type=korap:group, operation=operation:relation, operands=[" +
Joachim Bingel832800e2014-10-17 14:46:39 +0000723 "{@type=korap:group, operation=operation:class, class=1024, classOut=1024, operands=[" +
Joachim Bingele6d73b12014-09-30 15:34:59 +0000724 "{@type=korap:span}" +
725 "]}," +
726 "{@type=korap:span, layer=cat, key=NP, match=match:eq}" +
727 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c},boundary={@type=korap:boundary,min=1}}}" +
728 "]}," +
729 "{@type=korap:span, layer=cat, key=VP, match=match:eq}" +
730 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c},boundary={@type=korap:boundary,min=1}}}" +
731 "";
732 aqlt = new AqlTree(query);
733 map = aqlt.getRequestMap().get("query").toString();
734 assertEquals(cp4.replaceAll(" ", ""), map.replaceAll(" ", ""));
735 }
736
737 /*
738 @Test
739 public void testEqualNotequalValue() throws QueryException {
740 query = "cat=\"NP\" & cat=\"VP\" & #1 == #2";
741 String eq1 =
742 "{}"; // ???
743 aqlt = new AqlTree(query);
744 map = aqlt.getRequestMap().get("query").toString();
745 assertEquals(eq1.replaceAll(" ", ""), map.replaceAll(" ", ""));
746 }
747 */
748
Joachim Bingelca4944e2014-06-13 13:55:10 +0000749}