blob: 0cf0564b93c89e06185cc860871b61dc2a5e2e2e [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 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));
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 Bingelb6d67812014-08-13 11:37:09 +000059 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 +000060 aqlt = new AqlTree(query);
61 map = aqlt.getRequestMap().get("query").toString();
62 assertEquals(regex1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingele49b4672014-07-16 08:06:56 +000063
64 query = "/.*?Mann.*?/";
Joachim Bingelb6d67812014-08-13 11:37:09 +000065 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 +000066 aqlt = new AqlTree(query);
67 map = aqlt.getRequestMap().get("query").toString();
68 assertEquals(regex2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel019ba5c2014-04-28 14:59:04 +000069 }
70
71 @Test
72 public void testLayers() throws QueryException {
73 query = "cnx/cat=\"NP\"";
Joachim Bingeleee549e2014-04-29 11:15:37 +000074 String layers1 = "{@type=korap:span, foundry=cnx, layer=cat, key=NP, match=match:eq}";
Joachim Bingel019ba5c2014-04-28 14:59:04 +000075 aqlt = new AqlTree(query);
76 map = aqlt.getRequestMap().get("query").toString();
77 assertEquals(layers1.replaceAll(" ", ""), map.replaceAll(" ", ""));
78
79 query = "treetagger/pos=\"NN\"";
Joachim Bingeleee549e2014-04-29 11:15:37 +000080 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 +000081 aqlt = new AqlTree(query);
82 map = aqlt.getRequestMap().get("query").toString();
83 assertEquals(layers2.replaceAll(" ", ""), map.replaceAll(" ", ""));
84 }
85
86 @Test
Joachim Bingel75038792014-05-19 15:12:23 +000087 public void testDirectDeclarationRelations() throws QueryException {
88 query = "node > node";
89 String ddr1 =
90 "{@type=korap:group, operation=operation:relation, operands=[" +
91 "{@type=korap:span}," +
92 "{@type=korap:span}" +
Joachim Bingel62892412014-08-06 15:18:59 +000093 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
Joachim Bingel75038792014-05-19 15:12:23 +000094 "}";
95 aqlt = new AqlTree(query);
96 map = aqlt.getRequestMap().get("query").toString();
97 assertEquals(ddr1.replaceAll(" ", ""), map.replaceAll(" ", ""));
98
99 query = "node > cnx/cat=\"NP\"";
100 String ddr2 =
101 "{@type=korap:group, operation=operation:relation, operands=[" +
102 "{@type=korap:span}," +
103 "{@type=korap:span, foundry=cnx, layer=cat, key=NP, match=match:eq}" +
Joachim Bingel62892412014-08-06 15:18:59 +0000104 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
Joachim Bingel75038792014-05-19 15:12:23 +0000105 "}";
106 aqlt = new AqlTree(query);
107 map = aqlt.getRequestMap().get("query").toString();
108 assertEquals(ddr2.replaceAll(" ", ""), map.replaceAll(" ", ""));
109
110 }
111
112 @Test
Joachim Bingelfc428812014-06-18 14:50:14 +0000113 public void testDefPredicationInversion() throws QueryException {
114 query = " #1 > #2 & cnx/cat=\"VP\" & cnx/cat=\"NP\"";
115 String dom1 =
116 "{@type=korap:group, operation=operation:relation, operands=[" +
117 "{@type=korap:span, foundry=cnx, layer=cat, key=VP, match=match:eq}," +
118 "{@type=korap:span, foundry=cnx, layer=cat, key=NP, match=match:eq}" +
Joachim Bingel62892412014-08-06 15:18:59 +0000119 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
Joachim Bingelfc428812014-06-18 14:50:14 +0000120 "}";
121 aqlt = new AqlTree(query);
122 map = aqlt.getRequestMap().get("query").toString();
123 assertEquals(dom1.replaceAll(" ", ""), map.replaceAll(" ", ""));
124 }
125
126 @Test
Joachim Bingel019ba5c2014-04-28 14:59:04 +0000127 public void testSimpleDominance() throws QueryException {
128 query = "node & node & #2 > #1";
129 String dom1 =
Joachim Bingeld4ae5fd2014-04-29 15:00:16 +0000130 "{@type=korap:group, operation=operation:relation, operands=[" +
Joachim Bingel019ba5c2014-04-28 14:59:04 +0000131 "{@type=korap:span}," +
132 "{@type=korap:span}" +
Joachim Bingel62892412014-08-06 15:18:59 +0000133 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
Joachim Bingeleee549e2014-04-29 11:15:37 +0000134 "}";
Joachim Bingel019ba5c2014-04-28 14:59:04 +0000135 aqlt = new AqlTree(query);
136 map = aqlt.getRequestMap().get("query").toString();
137 assertEquals(dom1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeleee549e2014-04-29 11:15:37 +0000138
139 query = "\"Mann\" & node & #2 > #1";
140 String dom2 =
Joachim Bingeld4ae5fd2014-04-29 15:00:16 +0000141 "{@type=korap:group, operation=operation:relation, operands=[" +
Joachim Bingeleee549e2014-04-29 11:15:37 +0000142 "{@type=korap:span}," +
Joachim Bingelb6d67812014-08-13 11:37:09 +0000143 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" +
Joachim Bingel62892412014-08-06 15:18:59 +0000144 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
Joachim Bingeleee549e2014-04-29 11:15:37 +0000145 "}";
146 aqlt = new AqlTree(query);
147 map = aqlt.getRequestMap().get("query").toString();
148 assertEquals(dom2.replaceAll(" ", ""), map.replaceAll(" ", ""));
149
Joachim Bingeld4ae5fd2014-04-29 15:00:16 +0000150 query = "\"Mann\" & node & #2 >[cat=\"NP\"] #1";
Joachim Bingeleee549e2014-04-29 11:15:37 +0000151 String dom3 =
Joachim Bingeld4ae5fd2014-04-29 15:00:16 +0000152 "{@type=korap:group, operation=operation:relation, operands=[" +
Joachim Bingeleee549e2014-04-29 11:15:37 +0000153 "{@type=korap:span}," +
Joachim Bingelb6d67812014-08-13 11:37:09 +0000154 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" +
Joachim Bingel62892412014-08-06 15:18:59 +0000155 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c, key=NP, match=match:eq}}" +
Joachim Bingeleee549e2014-04-29 11:15:37 +0000156 "}";
157 aqlt = new AqlTree(query);
158 map = aqlt.getRequestMap().get("query").toString();
159 assertEquals(dom3.replaceAll(" ", ""), map.replaceAll(" ", ""));
160
Joachim Bingeld4ae5fd2014-04-29 15:00:16 +0000161 query = "\"Mann\" & node & #2 >@l[cat=\"NP\"] #1";
Joachim Bingeleee549e2014-04-29 11:15:37 +0000162 String dom4 =
Joachim Bingeld4ae5fd2014-04-29 15:00:16 +0000163 "{@type=korap:group, operation=operation:relation, operands=[" +
Joachim Bingeleee549e2014-04-29 11:15:37 +0000164 "{@type=korap:span}," +
Joachim Bingelb6d67812014-08-13 11:37:09 +0000165 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" +
Joachim Bingel62892412014-08-06 15:18:59 +0000166 "], relation={@type=korap:relation, index=0, wrap={@type=korap:term, layer=c, key=NP, match=match:eq}}" +
Joachim Bingeleee549e2014-04-29 11:15:37 +0000167 "}";
168 aqlt = new AqlTree(query);
169 map = aqlt.getRequestMap().get("query").toString();
170 assertEquals(dom4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeld4ae5fd2014-04-29 15:00:16 +0000171
172 query = "\"Mann\" & node & #2 >2,4 #1";
173 String dom5 =
174 "{@type=korap:group, operation=operation:relation, operands=[" +
175 "{@type=korap:span}," +
Joachim Bingelb6d67812014-08-13 11:37:09 +0000176 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" +
Joachim Bingel62892412014-08-06 15:18:59 +0000177 "], 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 +0000178 "}";
179 aqlt = new AqlTree(query);
180 map = aqlt.getRequestMap().get("query").toString();
181 assertEquals(dom5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel019ba5c2014-04-28 14:59:04 +0000182 }
183
Joachim Bingel13421ef2014-05-07 16:22:58 +0000184 @Test
Joachim Bingelca4944e2014-06-13 13:55:10 +0000185 public void testMultipleDominance() throws QueryException {
Joachim Bingel949e3a82014-06-16 13:20:43 +0000186 query = "cat=\"CP\" & cat=\"VP\" & cat=\"NP\" & #1 > #2 > #3";
Joachim Bingelca4944e2014-06-13 13:55:10 +0000187 String dom1 =
188 "{@type=korap:group, operation=operation:relation, operands=[" +
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000189 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
Joachim Bingelfc428812014-06-18 14:50:14 +0000190 "{@type=korap:group, operation=operation:relation, operands=[" +
191 "{@type=korap:span, layer=cat, key=CP, match=match:eq}," +
192 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
193 "{@type=korap:span, layer=cat, key=VP, match=match:eq}" +
194 "]}" +
Joachim Bingel62892412014-08-06 15:18:59 +0000195 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000196 "]}," +
Joachim Bingel949e3a82014-06-16 13:20:43 +0000197 "{@type=korap:span, layer=cat, key=NP, match=match:eq}" +
Joachim Bingel62892412014-08-06 15:18:59 +0000198 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
Joachim Bingelca4944e2014-06-13 13:55:10 +0000199 "}";
200 aqlt = new AqlTree(query);
201 map = aqlt.getRequestMap().get("query").toString();
202 assertEquals(dom1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel949e3a82014-06-16 13:20:43 +0000203
204 query = "cat=\"CP\" & cat=\"VP\" & cat=\"NP\" & cat=\"DP\" & #1 > #2 > #3 > #4";
205 String dom2 =
206 "{@type=korap:group, operation=operation:relation, operands=[" +
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000207 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingel949e3a82014-06-16 13:20:43 +0000208 "{@type=korap:group, operation=operation:relation, operands=[" +
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000209 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
Joachim Bingelfc428812014-06-18 14:50:14 +0000210 "{@type=korap:group, operation=operation:relation, operands=[" +
211 "{@type=korap:span, layer=cat, key=CP, match=match:eq}," +
212 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
213 "{@type=korap:span, layer=cat, key=VP, match=match:eq}" +
214 "]}" +
Joachim Bingel62892412014-08-06 15:18:59 +0000215 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000216 "]}," +
Joachim Bingelfc428812014-06-18 14:50:14 +0000217 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
218 "{@type=korap:span, layer=cat, key=NP, 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 Bingel949e3a82014-06-16 13:20:43 +0000222 "{@type=korap:span, layer=cat, key=DP, match=match:eq}" +
Joachim Bingel62892412014-08-06 15:18:59 +0000223 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
Joachim Bingel949e3a82014-06-16 13:20:43 +0000224 "}";
225 aqlt = new AqlTree(query);
226 map = aqlt.getRequestMap().get("query").toString();
227 assertEquals(dom2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelca4944e2014-06-13 13:55:10 +0000228 }
229
230 @Test
Joachim Bingel13421ef2014-05-07 16:22:58 +0000231 public void testPointingRelations() throws QueryException {
Joachim Bingel62892412014-08-06 15:18:59 +0000232 query = "node & node & #2 ->coref[val=\"true\"] #1";
Joachim Bingel13421ef2014-05-07 16:22:58 +0000233 String dom1 =
234 "{@type=korap:group, operation=operation:relation, operands=[" +
235 "{@type=korap:span}," +
236 "{@type=korap:span}" +
Joachim Bingel62892412014-08-06 15:18:59 +0000237 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=coref, key=true, match=match:eq}}" +
Joachim Bingel13421ef2014-05-07 16:22:58 +0000238 "}";
239 aqlt = new AqlTree(query);
240 map = aqlt.getRequestMap().get("query").toString();
241 assertEquals(dom1.replaceAll(" ", ""), map.replaceAll(" ", ""));
242
Joachim Bingel62892412014-08-06 15:18:59 +0000243 query = "node & node & #2 ->mate/coref[val=\"true\"] #1";
Joachim Bingel639df9c2014-05-12 15:27:00 +0000244 String dom2 =
245 "{@type=korap:group, operation=operation:relation, operands=[" +
246 "{@type=korap:span}," +
247 "{@type=korap:span}" +
Joachim Bingel62892412014-08-06 15:18:59 +0000248 "], relation={@type=korap:relation, wrap={@type=korap:term, foundry=mate, layer=coref, key=true, match=match:eq}}" +
Joachim Bingel639df9c2014-05-12 15:27:00 +0000249 "}";
250 aqlt = new AqlTree(query);
251 map = aqlt.getRequestMap().get("query").toString();
252 assertEquals(dom2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel13421ef2014-05-07 16:22:58 +0000253 }
254
255 @Test
256 public void testSequence() throws QueryException {
257 query = "node & node & #1 . #2";
Joachim Bingelca4944e2014-06-13 13:55:10 +0000258 String seq1 =
Joachim Bingel13421ef2014-05-07 16:22:58 +0000259 "{@type=korap:group, operation=operation:sequence, " +
260 "operands=[" +
261 "{@type=korap:span}," +
262 "{@type=korap:span}" +
263 "], inOrder=true" +
264 "}";
265 aqlt = new AqlTree(query);
266 map = aqlt.getRequestMap().get("query").toString();
Joachim Bingelca4944e2014-06-13 13:55:10 +0000267 assertEquals(seq1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel13421ef2014-05-07 16:22:58 +0000268
269 query = "node & node & #1 .* #2";
Joachim Bingelca4944e2014-06-13 13:55:10 +0000270 String seq2 =
Joachim Bingel75038792014-05-19 15:12:23 +0000271 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel13421ef2014-05-07 16:22:58 +0000272 "{@type=korap:span}," +
273 "{@type=korap:span}" +
274 "], distances=[" +
Joachim Bingel687e4d42014-07-30 09:34:18 +0000275 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0}, min=0}" +
Joachim Bingel13421ef2014-05-07 16:22:58 +0000276 "], inOrder=true" +
277 "}";
278 aqlt = new AqlTree(query);
279 map = aqlt.getRequestMap().get("query").toString();
Joachim Bingelca4944e2014-06-13 13:55:10 +0000280 assertEquals(seq2.replaceAll(" ", ""), map.replaceAll(" ", ""));
281
282 query = "node & node & #1 .2,3 #2";
283 String seq3 =
284 "{@type=korap:group, operation=operation:sequence, operands=[" +
285 "{@type=korap:span}," +
286 "{@type=korap:span}" +
287 "], distances=[" +
Joachim Bingel55020e82014-07-28 14:22:51 +0000288 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=2, max=3}, min=2, max=3}" +
Joachim Bingelca4944e2014-06-13 13:55:10 +0000289 "], inOrder=true" +
290 "}";
291 aqlt = new AqlTree(query);
292 map = aqlt.getRequestMap().get("query").toString();
293 assertEquals(seq3.replaceAll(" ", ""), map.replaceAll(" ", ""));
294
295 }
296
297 @Test
298 public void testMultipleSequence() throws QueryException {
299 query = "tok=\"Sonne\" & tok=\"Mond\" & tok=\"Sterne\" & #1 .0,2 #2 .0,4 #3";
300 String seq4 =
301 "{@type=korap:group, operation=operation:sequence," +
Joachim Bingelfc428812014-06-18 14:50:14 +0000302 "operands=[" +
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000303 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
Joachim Bingelca4944e2014-06-13 13:55:10 +0000304 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel949e3a82014-06-16 13:20:43 +0000305 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sonne, match=match:eq}}," +
Joachim Bingelfc428812014-06-18 14:50:14 +0000306 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
307 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mond, match=match:eq}}" +
308 "]}" +
Joachim Bingel949e3a82014-06-16 13:20:43 +0000309 "], distances=[" +
Joachim Bingel55020e82014-07-28 14:22:51 +0000310 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0, max=2}, min=0, max=2}" +
Joachim Bingelfc428812014-06-18 14:50:14 +0000311 "], inOrder=true}" +
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000312 "]}," +
Joachim Bingelfc428812014-06-18 14:50:14 +0000313 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sterne, match=match:eq}}" +
314 "],distances=[" +
Joachim Bingel55020e82014-07-28 14:22:51 +0000315 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0, max=4}, min=0, max=4}" +
Joachim Bingelfc428812014-06-18 14:50:14 +0000316 "], inOrder=true" +
317 "}";
Joachim Bingelca4944e2014-06-13 13:55:10 +0000318 aqlt = new AqlTree(query);
319 map = aqlt.getRequestMap().get("query").toString();
320 assertEquals(seq4.replaceAll(" ", ""), map.replaceAll(" ", ""));
321
322 query = "node & node & node & #1 . #2 .1,3 #3";
323 String seq5 =
324 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000325 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
Joachim Bingelfc428812014-06-18 14:50:14 +0000326 "{@type=korap:group, operation=operation:sequence, operands=[" +
327 "{@type=korap:span}," +
328 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
329 "{@type=korap:span}" +
330 "]} "+
331 "], inOrder=true}" +
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000332 "]}," +
Joachim Bingel949e3a82014-06-16 13:20:43 +0000333 "{@type=korap:span}" +
334 "], distances=[" +
Joachim Bingel55020e82014-07-28 14:22:51 +0000335 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1, max=3}, min=1, max=3}" +
Joachim Bingel949e3a82014-06-16 13:20:43 +0000336 "], inOrder=true" +
Joachim Bingelca4944e2014-06-13 13:55:10 +0000337 "}";
338 aqlt = new AqlTree(query);
339 map = aqlt.getRequestMap().get("query").toString();
340 assertEquals(seq5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000341
342 query = "tok=\"Sonne\" & tok=\"Mond\" & tok=\"Sterne\" & tok=\"Himmel\" & #1 .0,2 #2 .0,4 #3 . #4";
343 String seq6 =
344 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000345 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000346 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000347 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000348 "{@type=korap:group, operation=operation:sequence, operands=[" +
349 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sonne, match=match:eq}}," +
350 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
351 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mond, match=match:eq}}" +
352 "]}" +
353 "], distances=[" +
Joachim Bingel55020e82014-07-28 14:22:51 +0000354 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0, max=2}, min=0, max=2}" +
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000355 "], inOrder=true}" +
356 "]}," +
357 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
358 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sterne, match=match:eq}}" +
359 "]}" +
360 "],distances=[" +
Joachim Bingel55020e82014-07-28 14:22:51 +0000361 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0, max=4}, min=0, max=4}" +
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000362 "], inOrder=true}" +
363 "]}," +
364 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Himmel, match=match:eq}}" +
365 "], inOrder=true}" ;
366 aqlt = new AqlTree(query);
367 map = aqlt.getRequestMap().get("query").toString();
368 assertEquals(seq6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel75038792014-05-19 15:12:23 +0000369 }
370
371 @Test
Joachim Bingel949e3a82014-06-16 13:20:43 +0000372 public void testMultipleMixedOperators() throws QueryException {
373 query = "tok=\"Sonne\" & tok=\"Mond\" & tok=\"Sterne\" & #1 > #2 .0,4 #3";
374 String seq4 =
Joachim Bingelfc428812014-06-18 14:50:14 +0000375 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000376 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
Joachim Bingelfc428812014-06-18 14:50:14 +0000377 "{@type=korap:group, operation=operation:relation, operands=[" +
378 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sonne, match=match:eq}}," +
379 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
380 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mond, match=match:eq}}" +
381 "]}" +
Joachim Bingel62892412014-08-06 15:18:59 +0000382 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000383 "]}," +
Joachim Bingel949e3a82014-06-16 13:20:43 +0000384 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sterne, match=match:eq}}" +
385 "], distances=[" +
Joachim Bingel55020e82014-07-28 14:22:51 +0000386 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0, max=4}, min=0, max=4}" +
Joachim Bingel949e3a82014-06-16 13:20:43 +0000387 "], inOrder=true" +
388 "}";
389 aqlt = new AqlTree(query);
390 map = aqlt.getRequestMap().get("query").toString();
391 assertEquals(seq4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelfc428812014-06-18 14:50:14 +0000392
393 query = "tok=\"Sonne\" & tok=\"Mond\" & #1 > #2 .0,4 tok=\"Sterne\"";
394 String seq5 =
395 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000396 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
Joachim Bingelfc428812014-06-18 14:50:14 +0000397 "{@type=korap:group, operation=operation:relation, operands=[" +
398 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sonne, match=match:eq}}," +
399 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
400 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mond, match=match:eq}}" +
401 "]}" +
Joachim Bingel62892412014-08-06 15:18:59 +0000402 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000403 "]}," +
Joachim Bingelfc428812014-06-18 14:50:14 +0000404 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sterne, match=match:eq}}" +
405 "], distances=[" +
Joachim Bingel55020e82014-07-28 14:22:51 +0000406 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0, max=4}, min=0, max=4}" +
Joachim Bingelfc428812014-06-18 14:50:14 +0000407 "], inOrder=true" +
408 "}";
409 aqlt = new AqlTree(query);
410 map = aqlt.getRequestMap().get("query").toString();
411 assertEquals(seq5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000412
413 query = "cat=\"NP\" & cat=\"VP\" & cat=\"PP\" & #1 $ #2 > #3";
414 String cp2 =
415 "{@type=korap:group, operation=operation:relation, operands=[" +
416 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
417 "{@type=korap:group, operation=operation:relation, operands=[" +
418 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
419 "{@type=korap:group, operation=operation:relation, operands=[" +
420 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
421 "{@type=korap:span}" +
422 "]}," +
423 "{@type=korap:span, layer=cat, key=NP, match=match:eq}" +
Joachim Bingel62892412014-08-06 15:18:59 +0000424 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000425 "]}," +
426 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
427 "{@type=korap:span, layer=cat, key=VP, match=match:eq}" +
428 "]}" +
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 "}" +
431 "]}," +
432 "{@type=korap:span, layer=cat, key=PP, match=match:eq}" +
Joachim Bingel62892412014-08-06 15:18:59 +0000433 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000434 "}";
435 aqlt = new AqlTree(query);
436 map = aqlt.getRequestMap().get("query").toString();
437 assertEquals(cp2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel949e3a82014-06-16 13:20:43 +0000438 }
Joachim Bingele6d73b12014-09-30 15:34:59 +0000439 /*
440 @Test
441 public void testMultipleOperatorsWithSameOperands() throws QueryException {
442
443 query = "cat=\"NP\" > cat=\"VP\" & #1 _l_ #2";
444 String eq2 =
445 "{@type=korap:group, operation=operation:position, frames=[frame:startswith], sharedClasses=[sharedClasses:includes], operands=[" +
446 "{@type=korap:group, operation=operation:relation, operands=[" +
447 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
448 "{@type=korap:span, layer=cat, key=NP, match=match:eq}" +
449 "]}," +
450 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
451 "{@type=korap:span, layer=cat, key=VP, match=match:eq}" +
452 "]}" +
453 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}," +
454 "{@type=korap:reference, operation=operation:focus, classRef=[2]}" +
455 "]" +
456 "}"; // ???
457 aqlt = new AqlTree(query);
458 map = aqlt.getRequestMap().get("query").toString();
459 assertEquals(eq2.replaceAll(" ", ""), map.replaceAll(" ", ""));
460 }
461 */
Joachim Bingel949e3a82014-06-16 13:20:43 +0000462 @Test
Joachim Bingel75038792014-05-19 15:12:23 +0000463 public void testPositions() throws QueryException {
464 query = "node & node & #2 _=_ #1";
465 String pos1 =
Joachim Bingele6d73b12014-09-30 15:34:59 +0000466 "{@type=korap:group, operation=operation:position, frames=[frame:matches], sharedClasses=[sharedClasses:equals], operands=[" +
Joachim Bingel75038792014-05-19 15:12:23 +0000467 "{@type=korap:span}," +
468 "{@type=korap:span}" +
Joachim Bingele6d73b12014-09-30 15:34:59 +0000469 "], frame=frame:matches}";
Joachim Bingel75038792014-05-19 15:12:23 +0000470 aqlt = new AqlTree(query);
471 map = aqlt.getRequestMap().get("query").toString();
472 assertEquals(pos1.replaceAll(" ", ""), map.replaceAll(" ", ""));
473
Joachim Bingelca4944e2014-06-13 13:55:10 +0000474 query = "node & node & #2 _i_ #1";
475 String pos2 =
Joachim Bingele6d73b12014-09-30 15:34:59 +0000476 "{@type=korap:group, operation=operation:position, frames=[frame:contains], sharedClasses=[sharedClasses:includes], operands=[" +
Joachim Bingelca4944e2014-06-13 13:55:10 +0000477 "{@type=korap:span}," +
478 "{@type=korap:span}" +
479 "], frame=frame:contains" +
480 "}";
481 aqlt = new AqlTree(query);
482 map = aqlt.getRequestMap().get("query").toString();
483 assertEquals(pos2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel75038792014-05-19 15:12:23 +0000484
Joachim Bingelca4944e2014-06-13 13:55:10 +0000485 query = "node & node & #2 _l_ #1";
486 String pos3 =
Joachim Bingele6d73b12014-09-30 15:34:59 +0000487 "{@type=korap:group, operation=operation:position, frames=[frame:startswith], sharedClasses=[sharedClasses:includes], operands=[" +
Joachim Bingelca4944e2014-06-13 13:55:10 +0000488 "{@type=korap:span}," +
489 "{@type=korap:span}" +
Joachim Bingele6d73b12014-09-30 15:34:59 +0000490 "], frame=frame:startswith" +
Joachim Bingelca4944e2014-06-13 13:55:10 +0000491 "}";
492 aqlt = new AqlTree(query);
493 map = aqlt.getRequestMap().get("query").toString();
494 assertEquals(pos3.replaceAll(" ", ""), map.replaceAll(" ", ""));
495
496 query = "node & \"Mann\" & #1 _r_ #2";
Joachim Bingel75038792014-05-19 15:12:23 +0000497 String pos4 =
Joachim Bingele6d73b12014-09-30 15:34:59 +0000498 "{@type=korap:group, operation=operation:position, frames=[frame:endswith], sharedClasses=[sharedClasses:includes], operands=[" +
Joachim Bingel75038792014-05-19 15:12:23 +0000499 "{@type=korap:span}," +
Joachim Bingelb6d67812014-08-13 11:37:09 +0000500 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" +
Joachim Bingele6d73b12014-09-30 15:34:59 +0000501 "], frame=frame:endswith" +
Joachim Bingelca4944e2014-06-13 13:55:10 +0000502 "}";
Joachim Bingel75038792014-05-19 15:12:23 +0000503 aqlt = new AqlTree(query);
504 map = aqlt.getRequestMap().get("query").toString();
505 assertEquals(pos4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel13421ef2014-05-07 16:22:58 +0000506
Joachim Bingelca4944e2014-06-13 13:55:10 +0000507 query = "node & \"Mann\" & #2 _r_ #1";
508 String pos5 =
Joachim Bingele6d73b12014-09-30 15:34:59 +0000509 "{@type=korap:group, operation=operation:position, frames=[frame:endswith], sharedClasses=[sharedClasses:includes], operands=[" +
Joachim Bingelb6d67812014-08-13 11:37:09 +0000510 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}," +
Joachim Bingelca4944e2014-06-13 13:55:10 +0000511 "{@type=korap:span}" +
Joachim Bingele6d73b12014-09-30 15:34:59 +0000512 "], frame=frame:endswith" +
Joachim Bingelca4944e2014-06-13 13:55:10 +0000513 "}";
514 aqlt = new AqlTree(query);
515 map = aqlt.getRequestMap().get("query").toString();
516 assertEquals(pos5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel13421ef2014-05-07 16:22:58 +0000517 }
518
Joachim Bingelca4944e2014-06-13 13:55:10 +0000519 @Test
520 public void testMultiplePredications() throws QueryException {
Joachim Bingel9c3ddb92014-06-23 13:49:58 +0000521 // a noun before a verb before a preposition
Joachim Bingelfc428812014-06-18 14:50:14 +0000522 query = "pos=\"N\" & pos=\"V\" & pos=\"P\" & #1 . #2 & #2 . #3";
Joachim Bingelca4944e2014-06-13 13:55:10 +0000523 String mult1 =
Joachim Bingel9c3ddb92014-06-23 13:49:58 +0000524 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000525 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
Joachim Bingelca4944e2014-06-13 13:55:10 +0000526 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel9c3ddb92014-06-23 13:49:58 +0000527 "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=N, match=match:eq}}," +
528 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
529 "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=V, match=match:eq}}" +
530 "]}" +
531 "], inOrder=true}" +
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000532 "]}," +
Joachim Bingel9c3ddb92014-06-23 13:49:58 +0000533 "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=P, match=match:eq}}" +
534 "], inOrder=true}";
Joachim Bingelca4944e2014-06-13 13:55:10 +0000535 aqlt = new AqlTree(query);
536 map = aqlt.getRequestMap().get("query").toString();
537 assertEquals(mult1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel9c3ddb92014-06-23 13:49:58 +0000538
539 // a noun before a verb before a preposition
540 query = "pos=\"N\" & pos=\"V\" & #1 . #2 & #2 . pos=\"P\"";
541 String mult2 =
542 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000543 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
Joachim Bingel9c3ddb92014-06-23 13:49:58 +0000544 "{@type=korap:group, operation=operation:sequence, operands=[" +
545 "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=N, match=match:eq}}," +
546 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
547 "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=V, match=match:eq}}" +
548 "]}" +
549 "], inOrder=true}" +
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000550 "]}," +
Joachim Bingel9c3ddb92014-06-23 13:49:58 +0000551 "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=P, match=match:eq}}" +
552 "], inOrder=true}";
553 aqlt = new AqlTree(query);
554 map = aqlt.getRequestMap().get("query").toString();
555 assertEquals(mult2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000556
557 query = "pos=\"N\" & pos=\"V\" & pos=\"P\" & #1 > #2 & #1 > #3";
558 String mult3 =
559 "{@type=korap:group, operation=operation:relation, operands=[" +
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000560 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000561 "{@type=korap:group, operation=operation:relation, operands=[" +
562 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
563 "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=N, match=match:eq}}" +
564 "]}," +
565 "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=V, match=match:eq}}" +
Joachim Bingel62892412014-08-06 15:18:59 +0000566 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000567 "]}," +
568 "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=P, match=match:eq}}" +
Joachim Bingel62892412014-08-06 15:18:59 +0000569 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}";
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000570 aqlt = new AqlTree(query);
571 map = aqlt.getRequestMap().get("query").toString();
572 assertEquals(mult3.replaceAll(" ", ""), map.replaceAll(" ", ""));
573
574 query = "cat=\"NP\" & pos=\"V\" & pos=\"P\" & #1 > #2 & #1 > #3 & #2 . #3";
575 String mult4 =
576 "{@type=korap:group, operation=operation:sequence, operands=[" +
577 // 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 +0000578 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000579 "{@type=korap:group, operation=operation:relation, operands=[" +
580 // dominance relation #1 > #2 is reduced to #1, for expressing #1 > #3
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000581 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000582 "{@type=korap:group, operation=operation:relation, operands=[" +
583 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
584 "{@type=korap:span, layer=cat, key=NP, match=match:eq}" +
585 "]}," +
586 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
587 "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=V, match=match:eq}}" +
588 "]}" +
Joachim Bingel62892412014-08-06 15:18:59 +0000589 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000590 "]}," +
591 // establish class 2 around P for later reference
592 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
593 "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=P, match=match:eq}}" +
594 "]}" +
Joachim Bingel62892412014-08-06 15:18:59 +0000595 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000596 "]}," +
597 // refer back to class 2 as second operand
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000598 "{@type=korap:reference, operation=operation:focus, classRef=[2]}" +
Joachim Bingelaee38ae2014-06-25 09:32:56 +0000599 "], inOrder=true}";
600 aqlt = new AqlTree(query);
601 map = aqlt.getRequestMap().get("query").toString();
602 assertEquals(mult4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelca4944e2014-06-13 13:55:10 +0000603 }
Joachim Bingeleee549e2014-04-29 11:15:37 +0000604
Joachim Bingelca4944e2014-06-13 13:55:10 +0000605 @Test
606 public void testUnaryRelations() throws QueryException {
607 query = "node & #1:tokenarity=2";
608 String unary1 =
609 "{@type=korap:span, attr={@type=korap:term, tokenarity={@type=korap:boundary,min=2,max=2}}}";
610 aqlt = new AqlTree(query);
611 map = aqlt.getRequestMap().get("query").toString();
612 assertEquals(unary1.replaceAll(" ", ""), map.replaceAll(" ", ""));
613
614 query = "cnx/cat=\"NP\" & #1:tokenarity=2";
615 String unary2 =
616 "{@type=korap:span, foundry=cnx, layer=cat, key=NP, match=match:eq, attr={@type=korap:term, tokenarity={@type=korap:boundary,min=2,max=2}}}";
617 aqlt = new AqlTree(query);
618 map = aqlt.getRequestMap().get("query").toString();
619 assertEquals(unary2.replaceAll(" ", ""), map.replaceAll(" ", ""));
620
621 query = "cnx/cat=\"NP\" & #1:root";
622 String unary3 =
623 "{@type=korap:span, foundry=cnx, layer=cat, key=NP, match=match:eq, attr={@type=korap:term, root=true}}";
624 aqlt = new AqlTree(query);
625 map = aqlt.getRequestMap().get("query").toString();
626 assertEquals(unary3.replaceAll(" ", ""), map.replaceAll(" ", ""));
627
628 query = "cnx/cat=\"NP\" & node & #1>#2 & #1:tokenarity=2";
629 String unary4 =
630 "{@type=korap:group, operation=operation:relation, operands=[" +
631 "{@type=korap:span, foundry=cnx, layer=cat, key=NP, match=match:eq, attr={@type=korap:term, tokenarity={@type=korap:boundary,min=2,max=2}}}," +
632 "{@type=korap:span}" +
Joachim Bingel62892412014-08-06 15:18:59 +0000633 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
Joachim Bingelca4944e2014-06-13 13:55:10 +0000634 "}";
635 aqlt = new AqlTree(query);
636 map = aqlt.getRequestMap().get("query").toString();
637 assertEquals(unary4.replaceAll(" ", ""), map.replaceAll(" ", ""));
638 }
639
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000640 @Test
641 public void testCommonParent() throws QueryException {
642 query = "cat=\"NP\" & cat=\"VP\" & #1 $ #2";
643 String cp1 =
644 "{@type=korap:group, operation=operation:relation, operands=[" +
645 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
646 "{@type=korap:group, operation=operation:relation, operands=[" +
647 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
648 "{@type=korap:span}" +
649 "]}," +
650 "{@type=korap:span, layer=cat, key=NP, match=match:eq}" +
Joachim Bingel62892412014-08-06 15:18:59 +0000651 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000652 "]}," +
653 "{@type=korap:span, layer=cat, key=VP, match=match:eq}" +
Joachim Bingel62892412014-08-06 15:18:59 +0000654 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000655 "";
656 aqlt = new AqlTree(query);
657 map = aqlt.getRequestMap().get("query").toString();
658 assertEquals(cp1.replaceAll(" ", ""), map.replaceAll(" ", ""));
659
660 query = "cat=\"NP\" & cat=\"VP\" & cat=\"PP\" & #1 $ #2 $ #3";
661 String cp2 =
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}" +
Joachim Bingel62892412014-08-06 15:18:59 +0000671 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000672 "]}," +
673 "{@type=korap:span, layer=cat, key=VP, match=match:eq}" +
Joachim Bingel62892412014-08-06 15:18:59 +0000674 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000675 "}" +
676 "]}," +
677 "{@type=korap:span, layer=cat, key=PP, match=match:eq}" +
Joachim Bingel62892412014-08-06 15:18:59 +0000678 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000679 "}";
680 aqlt = new AqlTree(query);
681 map = aqlt.getRequestMap().get("query").toString();
682 assertEquals(cp2.replaceAll(" ", ""), map.replaceAll(" ", ""));
683
684 query = "cat=\"NP\" & cat=\"VP\" & cat=\"PP\" & cat=\"CP\" & #1 $ #2 $ #3 $ #4";
685 String cp3 =
686 "{@type=korap:group, operation=operation:relation, operands=[" +
687 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
688 "{@type=korap:group, operation=operation:relation, operands=[" +
689 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
690 "{@type=korap:group, operation=operation:relation, operands=[" +
691 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
692 "{@type=korap:group, operation=operation:relation, operands=[" +
693 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
694 "{@type=korap:span}" +
695 "]}," +
696 "{@type=korap:span, layer=cat, key=NP, match=match:eq}" +
Joachim Bingel62892412014-08-06 15:18:59 +0000697 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000698 "]}," +
699 "{@type=korap:span, layer=cat, key=VP, match=match:eq}" +
Joachim Bingel62892412014-08-06 15:18:59 +0000700 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000701 "]}," +
702 "{@type=korap:span, layer=cat, key=PP, match=match:eq}" +
Joachim Bingel62892412014-08-06 15:18:59 +0000703 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" +
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000704 "]}," +
705 "{@type=korap:span, layer=cat, key=CP, match=match:eq}" +
Joachim Bingel62892412014-08-06 15:18:59 +0000706 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" +
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000707 "}" +
708 "";
709 aqlt = new AqlTree(query);
710 map = aqlt.getRequestMap().get("query").toString();
711 assertEquals(cp3.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel1846c8c2014-07-08 14:13:31 +0000712
Joachim Bingele6d73b12014-09-30 15:34:59 +0000713 query = "cat=\"NP\" & cat=\"VP\" & #1 $* #2";
714 String cp4 =
715 "{@type=korap:group, operation=operation:relation, operands=[" +
716 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
717 "{@type=korap:group, operation=operation:relation, operands=[" +
718 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
719 "{@type=korap:span}" +
720 "]}," +
721 "{@type=korap:span, layer=cat, key=NP, match=match:eq}" +
722 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c},boundary={@type=korap:boundary,min=1}}}" +
723 "]}," +
724 "{@type=korap:span, layer=cat, key=VP, match=match:eq}" +
725 "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c},boundary={@type=korap:boundary,min=1}}}" +
726 "";
727 aqlt = new AqlTree(query);
728 map = aqlt.getRequestMap().get("query").toString();
729 assertEquals(cp4.replaceAll(" ", ""), map.replaceAll(" ", ""));
730 }
731
732 /*
733 @Test
734 public void testEqualNotequalValue() throws QueryException {
735 query = "cat=\"NP\" & cat=\"VP\" & #1 == #2";
736 String eq1 =
737 "{}"; // ???
738 aqlt = new AqlTree(query);
739 map = aqlt.getRequestMap().get("query").toString();
740 assertEquals(eq1.replaceAll(" ", ""), map.replaceAll(" ", ""));
741 }
742 */
743
Joachim Bingelca4944e2014-06-13 13:55:10 +0000744}