blob: e16f8d86122b58e0fd4a0a41f10a988158524cb9 [file] [log] [blame]
Joachim Bingelb5f7bf02014-01-07 16:36:54 +00001import static org.junit.Assert.*;
2
3import org.junit.Test;
4
5import de.ids_mannheim.korap.query.serialize.CosmasTree;
Joachim Bingelb5f7bf02014-01-07 16:36:54 +00006import de.ids_mannheim.korap.util.QueryException;
7
8public class CosmasTreeTest {
9
10 CosmasTree ppt;
11 String map;
12 String query;
13
14 private boolean equalsContent(String str, Object map) {
15 str = str.replaceAll(" ", "");
16 String mapStr = map.toString().replaceAll(" ", "");
17 return str.equals(mapStr);
18 }
19
20 private boolean equalsQueryContent(String res, String query) throws QueryException {
21 res = res.replaceAll(" ", "");
22 ppt = new CosmasTree(query);
23 String queryMap = ppt.getRequestMap().get("query").toString().replaceAll(" ", "");
24 return res.equals(queryMap);
25 }
26
27 @Test
28 public void testContext() throws QueryException {
29 String contextString = "{korap=http://korap.ids-mannheim.de/ns/query, @language=de, operands={@id=korap:operands, @container=@list}, relation={@id=korap:relation, @type=korap:relation#types}, class={@id=korap:class, @type=xsd:integer}, query=korap:query, filter=korap:filter, meta=korap:meta}";
30 ppt = new CosmasTree("Test");
31 assertTrue(equalsContent(contextString, ppt.getRequestMap().get("@context")));
32 }
33
34
35 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +000036 public void testSingleToken() throws QueryException {
Joachim Bingelb5f7bf02014-01-07 16:36:54 +000037 query="der";
38 String single1 =
39 "{@type=korap:token, @value={@type=korap:term, @value=orth:der, relation==}}";
40 ppt = new CosmasTree(query);
41 map = ppt.getRequestMap().get("query").toString();
42 assertEquals(single1.replaceAll(" ", ""), map.replaceAll(" ", ""));
43
44 query="Mann";
45 String single2 =
46 "{@type=korap:token, @value={@type=korap:term, @value=orth:Mann, relation==}}";
47 ppt = new CosmasTree(query);
48 map = ppt.getRequestMap().get("query").toString();
49 assertEquals(single2.replaceAll(" ", ""), map.replaceAll(" ", ""));
50
51 query="&Mann";
52 String single3 =
53 "{@type=korap:token, @value={@type=korap:term, @value=base:Mann, relation==}}";
54 ppt = new CosmasTree(query);
55 map = ppt.getRequestMap().get("query").toString();
56 assertEquals(single3.replaceAll(" ", ""), map.replaceAll(" ", ""));
57 }
58
59 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +000060 public void testSequence() throws QueryException {
Joachim Bingelb5f7bf02014-01-07 16:36:54 +000061 query="der Mann";
62 String seq1 =
63 "{@type=korap:sequence, operands=[" +
64 "{@type=korap:token, @value={@type=korap:term, @value=orth:der, relation==}}," +
65 "{@type=korap:token, @value={@type=korap:term, @value=orth:Mann, relation==}}" +
66 "]}";
67 ppt = new CosmasTree(query);
68 map = ppt.getRequestMap().get("query").toString();
69 assertEquals(seq1.replaceAll(" ", ""), map.replaceAll(" ", ""));
70
Joachim Bingeld5161a12014-01-08 11:15:49 +000071 query="der Mann schläft";
72 String seq2 =
73 "{@type=korap:sequence, operands=[" +
74 "{@type=korap:token, @value={@type=korap:term, @value=orth:der, relation==}}," +
75 "{@type=korap:token, @value={@type=korap:term, @value=orth:Mann, relation==}}," +
76 "{@type=korap:token, @value={@type=korap:term, @value=orth:schläft, relation==}}" +
77 "]}";
78 ppt = new CosmasTree(query);
79 map = ppt.getRequestMap().get("query").toString();
80 assertEquals(seq2.replaceAll(" ", ""), map.replaceAll(" ", ""));
81
82 query="der Mann schläft lang";
83 String seq3 =
84 "{@type=korap:sequence, operands=[" +
85 "{@type=korap:token, @value={@type=korap:term, @value=orth:der, relation==}}," +
86 "{@type=korap:token, @value={@type=korap:term, @value=orth:Mann, relation==}}," +
87 "{@type=korap:token, @value={@type=korap:term, @value=orth:schläft, relation==}}," +
88 "{@type=korap:token, @value={@type=korap:term, @value=orth:lang, relation==}}" +
89 "]}";
90 ppt = new CosmasTree(query);
91 map = ppt.getRequestMap().get("query").toString();
92 assertEquals(seq3.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb5f7bf02014-01-07 16:36:54 +000093 }
94
95 @Test
96 public void testOPOR() throws QueryException {
97 query="Sonne oder Mond";
98 String disj1 =
99 "{@type=korap:group, relation=or, operands=[" +
100 "{@type=korap:token, @value={@type=korap:term, @value=orth:Sonne, relation==}}," +
101 "{@type=korap:token, @value={@type=korap:term, @value=orth:Mond, relation==}}" +
102 "]}";
103 ppt = new CosmasTree(query);
104 map = ppt.getRequestMap().get("query").toString();
105 assertEquals(disj1.replaceAll(" ", ""), map.replaceAll(" ", ""));
106
Joachim Bingeld5161a12014-01-08 11:15:49 +0000107 query="(Sonne scheint) oder Mond";
108 String disj2 =
109 "{@type=korap:group, relation=or, operands=[" +
110 "{@type=korap:sequence, operands=[" +
111 "{@type=korap:token, @value={@type=korap:term, @value=orth:Sonne, relation==}}," +
112 "{@type=korap:token, @value={@type=korap:term, @value=orth:scheint, relation==}}" +
113 "]}," +
114 "{@type=korap:token, @value={@type=korap:term, @value=orth:Mond, relation==}}" +
115 "]}";
116 ppt = new CosmasTree(query);
117 map = ppt.getRequestMap().get("query").toString();
118 assertEquals(disj2.replaceAll(" ", ""), map.replaceAll(" ", ""));
119
120 query="(Sonne scheint) oder (Mond scheint)";
121 String disj3 =
122 "{@type=korap:group, relation=or, operands=[" +
123 "{@type=korap:sequence, operands=[" +
124 "{@type=korap:token, @value={@type=korap:term, @value=orth:Sonne, relation==}}," +
125 "{@type=korap:token, @value={@type=korap:term, @value=orth:scheint, relation==}}" +
126 "]}," +
127 "{@type=korap:sequence, operands=[" +
128 "{@type=korap:token, @value={@type=korap:term, @value=orth:Mond, relation==}}," +
129 "{@type=korap:token, @value={@type=korap:term, @value=orth:scheint, relation==}}" +
130 "]}" +
131 "]}";
132 ppt = new CosmasTree(query);
133 map = ppt.getRequestMap().get("query").toString();
134 assertEquals(disj3.replaceAll(" ", ""), map.replaceAll(" ", ""));
135
136 }
137
138 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000139 public void testOPORAND() throws QueryException {
Joachim Bingeld5161a12014-01-08 11:15:49 +0000140 query="(Sonne oder Mond) und scheint";
141 String orand1 =
142 "{@type=korap:group, relation=and, operands=[" +
143 "{@type=korap:group, relation=or, operands=[" +
144 "{@type=korap:token, @value={@type=korap:term, @value=orth:Sonne, relation==}}," +
145 "{@type=korap:token, @value={@type=korap:term, @value=orth:Mond, relation==}}" +
146 "]}," +
147 "{@type=korap:token, @value={@type=korap:term, @value=orth:scheint, relation==}}" +
148 "]}";
149 ppt = new CosmasTree(query);
150 map = ppt.getRequestMap().get("query").toString();
151 assertEquals(orand1.replaceAll(" ", ""), map.replaceAll(" ", ""));
152
153 query="scheint und (Sonne oder Mond)";
154 String orand2 =
155 "{@type=korap:group, relation=and, operands=[" +
156 "{@type=korap:token, @value={@type=korap:term, @value=orth:scheint, relation==}}," +
157 "{@type=korap:group, relation=or, operands=[" +
158 "{@type=korap:token, @value={@type=korap:term, @value=orth:Sonne, relation==}}," +
159 "{@type=korap:token, @value={@type=korap:term, @value=orth:Mond, relation==}}" +
160 "]}" +
161 "]}";
162 ppt = new CosmasTree(query);
163 map = ppt.getRequestMap().get("query").toString();
164 assertEquals(orand2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000165 }
166
167 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000168 public void testOPPROX() throws QueryException {
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000169 query="Sonne /+w1:4 Mond";
170 String prox1 =
Joachim Bingel87480d02014-01-17 14:07:46 +0000171 "{@type=korap:group, relation=distance, match=operands, @subtype=incl, " +
Joachim Bingel89cceac2014-01-08 15:51:08 +0000172 "constraint=[" +
173 "{@type=korap:distance, measure=w, direction=plus, min=1, max=4}" +
174 "], " +
175 "operands=[" +
176 "{@type=korap:token, @value={@type=korap:term, @value=orth:Sonne, relation==}}," +
177 "{@type=korap:token, @value={@type=korap:term, @value=orth:Mond, relation==}}" +
178 "]" +
179 "}";
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000180 ppt = new CosmasTree(query);
181 map = ppt.getRequestMap().get("query").toString();
182 assertEquals(prox1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel89cceac2014-01-08 15:51:08 +0000183
184 query="Sonne /+w1:4,s0,p1:3 Mond";
185 String prox2 =
Joachim Bingel87480d02014-01-17 14:07:46 +0000186 "{@type=korap:group, relation=distance, match=operands, @subtype=incl, " +
Joachim Bingel89cceac2014-01-08 15:51:08 +0000187 "constraint=[" +
188 "{@type=korap:group, relation=and, operands=[" +
189 "{@type=korap:distance, measure=w, direction=plus, min=1, max=4}," +
190 "{@type=korap:distance, measure=s, direction=both, min=0, max=0}," +
191 "{@type=korap:distance, measure=p, direction=both, min=1, max=3}" +
192 "]}" +
193 "], " +
194 "operands=[" +
195 "{@type=korap:token, @value={@type=korap:term, @value=orth:Sonne, relation==}}," +
196 "{@type=korap:token, @value={@type=korap:term, @value=orth:Mond, relation==}}" +
197 "]" +
198 "}";
199 ppt = new CosmasTree(query);
200 map = ppt.getRequestMap().get("query").toString();
201 assertEquals(prox2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel87480d02014-01-17 14:07:46 +0000202
203 query="Sonne %+w1:4,s0,p1:3 Mond";
204 String prox3 =
205 "{@type=korap:group, relation=distance, match=operands, @subtype=excl, " +
206 "constraint=[" +
207 "{@type=korap:group, relation=and, operands=[" +
208 "{@type=korap:distance, measure=w, direction=plus, min=1, max=4}," +
209 "{@type=korap:distance, measure=s, direction=both, min=0, max=0}," +
210 "{@type=korap:distance, measure=p, direction=both, min=1, max=3}" +
211 "]}" +
212 "], " +
213 "operands=[" +
214 "{@type=korap:token, @value={@type=korap:term, @value=orth:Sonne, relation==}}," +
215 "{@type=korap:token, @value={@type=korap:term, @value=orth:Mond, relation==}}" +
216 "]" +
217 "}";
218 ppt = new CosmasTree(query);
219 map = ppt.getRequestMap().get("query").toString();
220 assertEquals(prox3.replaceAll(" ", ""), map.replaceAll(" ", ""));
221
222 query="Sonne /+w4 Mond";
223 String prox4 =
224 "{@type=korap:group, relation=distance, match=operands, @subtype=incl, " +
225 "constraint=[" +
226 "{@type=korap:distance, measure=w, direction=plus, min=0, max=4}" +
227 "], " +
228 "operands=[" +
229 "{@type=korap:token, @value={@type=korap:term, @value=orth:Sonne, relation==}}," +
230 "{@type=korap:token, @value={@type=korap:term, @value=orth:Mond, relation==}}" +
231 "]" +
232 "}";
233 ppt = new CosmasTree(query);
234 map = ppt.getRequestMap().get("query").toString();
235 assertEquals(prox4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000236
237 query="Sonne /-w4 Mond";
238 String prox5 =
239 "{@type=korap:group, relation=distance, match=operands, @subtype=incl, " +
240 "constraint=[" +
241 "{@type=korap:distance, measure=w, direction=plus, min=0, max=4}" +
242 "], " +
243 "operands=[" +
244 "{@type=korap:token, @value={@type=korap:term, @value=orth:Mond, relation==}}," +
245 "{@type=korap:token, @value={@type=korap:term, @value=orth:Sonne, relation==}}" +
246 "]" +
247 "}";
248 ppt = new CosmasTree(query);
249 map = ppt.getRequestMap().get("query").toString();
250 assertEquals(prox5.replaceAll(" ", ""), map.replaceAll(" ", ""));
251 }
252
253 @Test
254 public void testNestedOPPROX() throws QueryException {
255 query="Sonne /-w4 Mond /+w2 Sterne";
256 String prox6 =
257 "{@type=korap:group, relation=distance, match=operands, @subtype=incl, " +
258 "constraint=[" +
259 "{@type=korap:distance, measure=w, direction=plus, min=0, max=4}" +
260 "], " +
261 "operands=[" +
262 "{@type=korap:group, relation=distance, match=operands, @subtype=incl, " +
263 "constraint=[" +
264 "{@type=korap:distance, measure=w, direction=plus, min=0, max=2}" +
265 "], " +
266 "operands=[" +
267 "{@type=korap:token, @value={@type=korap:term, @value=orth:Mond, relation==}}," +
268 "{@type=korap:token, @value={@type=korap:term, @value=orth:Sterne, relation==}}" +
269 "]}," +
270 "{@type=korap:token, @value={@type=korap:term, @value=orth:Sonne, relation==}}" +
271 "]" +
272 "}";
273 ppt = new CosmasTree(query);
274 map = ppt.getRequestMap().get("query").toString();
275 assertEquals(prox6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000276 }
277
278 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000279 public void testOPIN() throws QueryException {
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000280 query="wegen #IN <s>";
Joachim Bingel3a9f7932014-01-07 17:11:31 +0000281 String opin1 =
Joachim Bingeleecc7652014-01-11 17:21:07 +0000282 "{@type=korap:group, relation=shrink, shrink=1, operands=[" +
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000283 "{@type=korap:group, relation=position, position=contains, operands=[" +
Joachim Bingeleecc7652014-01-11 17:21:07 +0000284 "{@type=korap:elem, @value=s}," +
285 "{@type=korap:group, class=1, operands=[" +
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000286 "{@type=korap:token, @value={@type=korap:term, @value=orth:wegen, relation==}}" +
Joachim Bingeleecc7652014-01-11 17:21:07 +0000287 "]}" +
288 "]}" +
Joachim Bingeld5161a12014-01-08 11:15:49 +0000289 "]}";
290 ppt = new CosmasTree(query);
291 map = ppt.getRequestMap().get("query").toString();
292 assertEquals(opin1.replaceAll(" ", ""), map.replaceAll(" ", ""));
293
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000294 query="wegen #IN(L) <s>";
295 String opin2 =
296 "{@type=korap:group, relation=shrink, shrink=1, operands=[" +
297 "{@type=korap:group, relation=position, position=startswith, operands=[" +
298 "{@type=korap:elem, @value=s}," +
299 "{@type=korap:group, class=1, operands=[" +
300 "{@type=korap:token, @value={@type=korap:term, @value=orth:wegen, relation==}}" +
301 "]}" +
302 "]}" +
303 "]}";
304 ppt = new CosmasTree(query);
305 map = ppt.getRequestMap().get("query").toString();
306 assertEquals(opin2.replaceAll(" ", ""), map.replaceAll(" ", ""));
307
Joachim Bingel87480d02014-01-17 14:07:46 +0000308 query="wegen #IN(%, L) <s>";
309 String opin3 =
310 "{@type=korap:group, relation=shrink, shrink=1, operands=[" +
311 "{@type=korap:group, relation=position, position=startswith, @subtype=excl, operands=[" +
312 "{@type=korap:elem, @value=s}," +
313 "{@type=korap:group, class=1, operands=[" +
314 "{@type=korap:token, @value={@type=korap:term, @value=orth:wegen, relation==}}" +
315 "]}" +
316 "]}" +
317 "]}";
318 ppt = new CosmasTree(query);
319 map = ppt.getRequestMap().get("query").toString();
320 assertEquals(opin3.replaceAll(" ", ""), map.replaceAll(" ", ""));
321
322 query="wegen #IN('FE,ALL,%,MIN') <s>";
323 String opin4 =
324 "{@type=korap:group, relation=shrink, shrink=1, operands=[" +
325 "{@type=korap:group, relation=position, position=ident, range=all, @subtype=excl, grouping=false, operands=[" +
326 "{@type=korap:elem, @value=s}," +
327 "{@type=korap:group, class=1, operands=[" +
328 "{@type=korap:token, @value={@type=korap:term, @value=orth:wegen, relation==}}" +
329 "]}" +
330 "]}" +
331 "]}";
332 ppt = new CosmasTree(query);
333 map = ppt.getRequestMap().get("query").toString();
334 assertEquals(opin4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeld5161a12014-01-08 11:15:49 +0000335 }
336
337 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000338 public void testOPOV() throws QueryException {
Joachim Bingeld5161a12014-01-08 11:15:49 +0000339 query="wegen #OV <s>";
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000340 String opov1 =
341 "{@type=korap:group, relation=shrink, shrink=1, operands=[" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000342 "{@type=korap:group, relation=overlap, position=any, operands=[" +
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000343 "{@type=korap:elem, @value=s}," +
344 "{@type=korap:group, class=1, operands=[" +
345 "{@type=korap:token, @value={@type=korap:term, @value=orth:wegen, relation==}}" +
346 "]}" +
347 "]}" +
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000348 "]}";
349 ppt = new CosmasTree(query);
350 map = ppt.getRequestMap().get("query").toString();
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000351 assertEquals(opov1.replaceAll(" ", ""), map.replaceAll(" ", ""));
352
353 query="wegen #OV(L) <s>";
354 String opov2 =
355 "{@type=korap:group, relation=shrink, shrink=1, operands=[" +
356 "{@type=korap:group, relation=overlap, position=startswith, operands=[" +
357 "{@type=korap:elem, @value=s}," +
358 "{@type=korap:group, class=1, operands=[" +
359 "{@type=korap:token, @value={@type=korap:term, @value=orth:wegen, relation==}}" +
360 "]}" +
361 "]}" +
362 "]}";
363 ppt = new CosmasTree(query);
364 map = ppt.getRequestMap().get("query").toString();
365 assertEquals(opov2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000366 }
367
368 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000369 public void testOPNOT() throws QueryException {
Joachim Bingel3a9f7932014-01-07 17:11:31 +0000370 query="Sonne nicht Mond";
371 String opnot1 =
372 "{@type=korap:group, relation=not, operands=[" +
373 "{@type=korap:token, @value={@type=korap:term, @value=orth:Sonne, relation==}}," +
374 "{@type=korap:token, @value={@type=korap:term, @value=orth:Mond, relation==}}" +
375 "]}";
376 ppt = new CosmasTree(query);
377 map = ppt.getRequestMap().get("query").toString();
378 assertEquals(opnot1.replaceAll(" ", ""), map.replaceAll(" ", ""));
379 }
380
381 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000382 public void testBEG_END() throws QueryException {
Joachim Bingel3a9f7932014-01-07 17:11:31 +0000383 // BEG and END operators
384 // http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/syntax/links.html
385 // http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/syntax/rechts.html
386 // http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/thematische-bsp/bsp-satzlaenge.html
Joachim Bingel87480d02014-01-17 14:07:46 +0000387 query="#BEG(der /w3:5 Mann)";
388 String beg1 =
389 "{@type=korap:group, relation=shrink, shrink=first, operands=[" +
390 "{@type=korap:group, relation=distance, match=operands, @subtype=incl, constraint=[" +
391 "{@type=korap:distance, measure=w, direction=both, min=3, max=5}" +
392 "]," +
393 "operands = [" +
394 "{@type=korap:token, @value={@type=korap:term, @value=orth:der, relation==}}," +
395 "{@type=korap:token, @value={@type=korap:term, @value=orth:Mann, relation==}}" +
396 "]}" +
397 "]}";
398 ppt = new CosmasTree(query);
399 map = ppt.getRequestMap().get("query").toString();
400 assertEquals(beg1.replaceAll(" ", ""), map.replaceAll(" ", ""));
401
402 query="#BEG(der /w3:5 Mann) /+w10 kommt"; // nesting #BEG() in a distance group
403 String beg2 =
404 "{@type=korap:group, relation=distance, match=operands, @subtype=incl, constraint=[" +
405 "{@type=korap:distance, measure=w, direction=plus, min=0, max=10}" +
406 "], operands=[" +
407 "{@type=korap:group, relation=shrink, shrink=first, operands=[" +
408 "{@type=korap:group, relation=distance, match=operands, @subtype=incl, constraint=[" +
409 "{@type=korap:distance, measure=w, direction=both, min=3, max=5}" +
410 "]," +
411 "operands = [" +
412 "{@type=korap:token, @value={@type=korap:term, @value=orth:der, relation==}}," +
413 "{@type=korap:token, @value={@type=korap:term, @value=orth:Mann, relation==}}" +
414 "]}" +
415 "]}," +
416 "{@type=korap:token, @value={@type=korap:term, @value=orth:kommt, relation==}}" +
417 "]}";
418 ppt = new CosmasTree(query);
419 map = ppt.getRequestMap().get("query").toString();
420 assertEquals(beg2.replaceAll(" ", ""), map.replaceAll(" ", ""));
421
422 query="#END(der /w3:5 Mann)";
423 String end1 =
424 "{@type=korap:group, relation=shrink, shrink=last, operands=[" +
425 "{@type=korap:group, relation=distance, match=operands, @subtype=incl, constraint=[" +
426 "{@type=korap:distance, measure=w, direction=both, min=3, max=5}" +
427 "]," +
428 "operands = [" +
429 "{@type=korap:token, @value={@type=korap:term, @value=orth:der, relation==}}," +
430 "{@type=korap:token, @value={@type=korap:term, @value=orth:Mann, relation==}}" +
431 "]}" +
432 "]}";
433 ppt = new CosmasTree(query);
434 map = ppt.getRequestMap().get("query").toString();
435 assertEquals(end1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000436 }
Joachim Bingeld5161a12014-01-08 11:15:49 +0000437
438
439 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000440 public void testELEM() throws QueryException {
Joachim Bingeld5161a12014-01-08 11:15:49 +0000441 // http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/syntax/elem.html
Joachim Bingeleecc7652014-01-11 17:21:07 +0000442 query="#ELEM(S)";
443 String elem1 = "{@type=korap:elem, @value=s}";
444 ppt = new CosmasTree(query);
445 map = ppt.getRequestMap().get("query").toString();
446 assertEquals(elem1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeld5161a12014-01-08 11:15:49 +0000447 }
448
449 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000450 public void testOPALL() throws QueryException {
Joachim Bingel89cceac2014-01-08 15:51:08 +0000451 query="#ALL(gehen /w1:10 voran)";
Joachim Bingele98d0882014-01-21 12:58:54 +0000452 String all1 =
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000453 "{@type=korap:group, relation=distance, match=all, @subtype=incl, " +
454 "constraint=[" +
455 "{@type=korap:distance, measure=w, direction=both, min=1, max=10}" +
456 "], " +
457 "operands=[" +
458 "{@type=korap:token, @value={@type=korap:term, @value=orth:gehen, relation==}}," +
459 "{@type=korap:token, @value={@type=korap:term, @value=orth:voran, relation==}}" +
460 "]" +
461 "}";
Joachim Bingel89cceac2014-01-08 15:51:08 +0000462 ppt = new CosmasTree(query);
463 map = ppt.getRequestMap().get("query").toString();
464 assertEquals(all1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeld5161a12014-01-08 11:15:49 +0000465 }
466
467 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000468 public void testOPNHIT() throws QueryException {
Joachim Bingel89cceac2014-01-08 15:51:08 +0000469 query="#NHIT(gehen /w1:10 voran)";
470 String nhit1 =
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000471 "{@type=korap:group, relation=distance, match=between, @subtype=incl, " +
472 "constraint=[" +
473 "{@type=korap:distance, measure=w, direction=both, min=1, max=10}" +
474 "], " +
475 "operands=[" +
476 "{@type=korap:token, @value={@type=korap:term, @value=orth:gehen, relation==}}," +
477 "{@type=korap:token, @value={@type=korap:term, @value=orth:voran, relation==}}" +
478 "]" +
479 "}";
Joachim Bingel89cceac2014-01-08 15:51:08 +0000480 ppt = new CosmasTree(query);
481 map = ppt.getRequestMap().get("query").toString();
482 assertEquals(nhit1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeld5161a12014-01-08 11:15:49 +0000483 }
484
485 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000486 public void testOPBED() throws QueryException {
Joachim Bingeleecc7652014-01-11 17:21:07 +0000487 query = "#BED(der , sa)";
488 String bed1 =
489 "{@type=korap:group, relation=position, position=startswith, operands=[" +
Joachim Bingele98d0882014-01-21 12:58:54 +0000490 "{@type=korap:elem, @value=s}," +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000491 "{@type=korap:token, @value={@type=korap:term, @value=orth:der, relation==}}" +
Joachim Bingeleecc7652014-01-11 17:21:07 +0000492 "]}";
493 ppt = new CosmasTree(query);
494 map = ppt.getRequestMap().get("query").toString();
495 assertEquals(bed1.replaceAll(" ", ""), map.replaceAll(" ", ""));
496
497 query = "#BED(der Mann , +pe)";
498 String bed2 =
499 "{@type=korap:group, relation=position, position=endswith, operands=[" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000500 "{@type=korap:elem, @value=p}," +
Joachim Bingeleecc7652014-01-11 17:21:07 +0000501 "{@type=korap:sequence, operands=[" +
502 "{@type=korap:token, @value={@type=korap:term, @value=orth:der, relation==}}," +
503 "{@type=korap:token, @value={@type=korap:term, @value=orth:Mann, relation==}}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000504 "]}" +
Joachim Bingeleecc7652014-01-11 17:21:07 +0000505 "]}";
506 ppt = new CosmasTree(query);
507 map = ppt.getRequestMap().get("query").toString();
508 assertEquals(bed2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000509
510 query = "#BED(der Mann , sa,-pa)";
511 String bed3 =
512 "{@type=korap:group, relation=and, operands=[" +
513 "{@type=korap:group, relation=position, position=startswith, operands=[" +
514 "{@type=korap:elem, @value=s}," +
515 "{@type=korap:sequence, operands=[" +
516 "{@type=korap:token, @value={@type=korap:term, @value=orth:der, relation==}}," +
517 "{@type=korap:token, @value={@type=korap:term, @value=orth:Mann, relation==}}" +
518 "]}" +
519 "]}," +
520 "{@type=korap:group, relation=position, position=startswith, @subtype=excl, operands=[" +
521 "{@type=korap:elem, @value=p}," +
522 "{@type=korap:sequence, operands=[" +
523 "{@type=korap:token, @value={@type=korap:term, @value=orth:der, relation==}}," +
524 "{@type=korap:token, @value={@type=korap:term, @value=orth:Mann, relation==}}" +
525 "]}" +
526 "]}" +
527 "]}";
528 ppt = new CosmasTree(query);
529 map = ppt.getRequestMap().get("query").toString();
530 assertEquals(bed3.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeld5161a12014-01-08 11:15:49 +0000531 }
532
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000533}
534