blob: 0d7db7ac42a82894d29768118e58fae688c1e630 [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
Joachim Bingelffd65e32014-01-22 14:22:57 +000059// @Test
60 public void testMORPH() throws QueryException {
61 query="#MORPH(V)";
62 String morph1 =
63 "{@type=korap:token, @value={@type=korap:term, @value=pos:v, relation==}}";
64 ppt = new CosmasTree(query);
65 map = ppt.getRequestMap().get("query").toString();
66 assertEquals(morph1.replaceAll(" ", ""), map.replaceAll(" ", ""));
67 }
68
Joachim Bingelb5f7bf02014-01-07 16:36:54 +000069 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +000070 public void testSequence() throws QueryException {
Joachim Bingelb5f7bf02014-01-07 16:36:54 +000071 query="der Mann";
72 String seq1 =
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 "]}";
77 ppt = new CosmasTree(query);
78 map = ppt.getRequestMap().get("query").toString();
79 assertEquals(seq1.replaceAll(" ", ""), map.replaceAll(" ", ""));
80
Joachim Bingeld5161a12014-01-08 11:15:49 +000081 query="der Mann schläft";
82 String seq2 =
83 "{@type=korap:sequence, operands=[" +
84 "{@type=korap:token, @value={@type=korap:term, @value=orth:der, relation==}}," +
85 "{@type=korap:token, @value={@type=korap:term, @value=orth:Mann, relation==}}," +
86 "{@type=korap:token, @value={@type=korap:term, @value=orth:schläft, relation==}}" +
87 "]}";
88 ppt = new CosmasTree(query);
89 map = ppt.getRequestMap().get("query").toString();
90 assertEquals(seq2.replaceAll(" ", ""), map.replaceAll(" ", ""));
91
92 query="der Mann schläft lang";
93 String seq3 =
94 "{@type=korap:sequence, operands=[" +
95 "{@type=korap:token, @value={@type=korap:term, @value=orth:der, relation==}}," +
96 "{@type=korap:token, @value={@type=korap:term, @value=orth:Mann, relation==}}," +
97 "{@type=korap:token, @value={@type=korap:term, @value=orth:schläft, relation==}}," +
98 "{@type=korap:token, @value={@type=korap:term, @value=orth:lang, relation==}}" +
99 "]}";
100 ppt = new CosmasTree(query);
101 map = ppt.getRequestMap().get("query").toString();
102 assertEquals(seq3.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000103 }
104
105 @Test
106 public void testOPOR() throws QueryException {
107 query="Sonne oder Mond";
108 String disj1 =
109 "{@type=korap:group, relation=or, operands=[" +
110 "{@type=korap:token, @value={@type=korap:term, @value=orth:Sonne, relation==}}," +
111 "{@type=korap:token, @value={@type=korap:term, @value=orth:Mond, relation==}}" +
112 "]}";
113 ppt = new CosmasTree(query);
114 map = ppt.getRequestMap().get("query").toString();
115 assertEquals(disj1.replaceAll(" ", ""), map.replaceAll(" ", ""));
116
Joachim Bingeld5161a12014-01-08 11:15:49 +0000117 query="(Sonne scheint) oder Mond";
118 String disj2 =
119 "{@type=korap:group, relation=or, operands=[" +
120 "{@type=korap:sequence, operands=[" +
121 "{@type=korap:token, @value={@type=korap:term, @value=orth:Sonne, relation==}}," +
122 "{@type=korap:token, @value={@type=korap:term, @value=orth:scheint, relation==}}" +
123 "]}," +
124 "{@type=korap:token, @value={@type=korap:term, @value=orth:Mond, relation==}}" +
125 "]}";
126 ppt = new CosmasTree(query);
127 map = ppt.getRequestMap().get("query").toString();
128 assertEquals(disj2.replaceAll(" ", ""), map.replaceAll(" ", ""));
129
130 query="(Sonne scheint) oder (Mond scheint)";
131 String disj3 =
132 "{@type=korap:group, relation=or, operands=[" +
133 "{@type=korap:sequence, operands=[" +
134 "{@type=korap:token, @value={@type=korap:term, @value=orth:Sonne, relation==}}," +
135 "{@type=korap:token, @value={@type=korap:term, @value=orth:scheint, relation==}}" +
136 "]}," +
137 "{@type=korap:sequence, operands=[" +
138 "{@type=korap:token, @value={@type=korap:term, @value=orth:Mond, relation==}}," +
139 "{@type=korap:token, @value={@type=korap:term, @value=orth:scheint, relation==}}" +
140 "]}" +
141 "]}";
142 ppt = new CosmasTree(query);
143 map = ppt.getRequestMap().get("query").toString();
144 assertEquals(disj3.replaceAll(" ", ""), map.replaceAll(" ", ""));
145
146 }
147
148 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000149 public void testOPORAND() throws QueryException {
Joachim Bingeld5161a12014-01-08 11:15:49 +0000150 query="(Sonne oder Mond) und scheint";
151 String orand1 =
152 "{@type=korap:group, relation=and, operands=[" +
153 "{@type=korap:group, relation=or, operands=[" +
154 "{@type=korap:token, @value={@type=korap:term, @value=orth:Sonne, relation==}}," +
155 "{@type=korap:token, @value={@type=korap:term, @value=orth:Mond, relation==}}" +
156 "]}," +
157 "{@type=korap:token, @value={@type=korap:term, @value=orth:scheint, relation==}}" +
158 "]}";
159 ppt = new CosmasTree(query);
160 map = ppt.getRequestMap().get("query").toString();
161 assertEquals(orand1.replaceAll(" ", ""), map.replaceAll(" ", ""));
162
163 query="scheint und (Sonne oder Mond)";
164 String orand2 =
165 "{@type=korap:group, relation=and, operands=[" +
166 "{@type=korap:token, @value={@type=korap:term, @value=orth:scheint, relation==}}," +
167 "{@type=korap:group, relation=or, operands=[" +
168 "{@type=korap:token, @value={@type=korap:term, @value=orth:Sonne, relation==}}," +
169 "{@type=korap:token, @value={@type=korap:term, @value=orth:Mond, relation==}}" +
170 "]}" +
171 "]}";
172 ppt = new CosmasTree(query);
173 map = ppt.getRequestMap().get("query").toString();
174 assertEquals(orand2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000175 }
176
177 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000178 public void testOPPROX() throws QueryException {
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000179 query="Sonne /+w1:4 Mond";
180 String prox1 =
Joachim Bingel87480d02014-01-17 14:07:46 +0000181 "{@type=korap:group, relation=distance, match=operands, @subtype=incl, " +
Joachim Bingel89cceac2014-01-08 15:51:08 +0000182 "constraint=[" +
183 "{@type=korap:distance, measure=w, direction=plus, min=1, max=4}" +
184 "], " +
185 "operands=[" +
186 "{@type=korap:token, @value={@type=korap:term, @value=orth:Sonne, relation==}}," +
187 "{@type=korap:token, @value={@type=korap:term, @value=orth:Mond, relation==}}" +
188 "]" +
189 "}";
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000190 ppt = new CosmasTree(query);
191 map = ppt.getRequestMap().get("query").toString();
192 assertEquals(prox1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel89cceac2014-01-08 15:51:08 +0000193
194 query="Sonne /+w1:4,s0,p1:3 Mond";
195 String prox2 =
Joachim Bingel87480d02014-01-17 14:07:46 +0000196 "{@type=korap:group, relation=distance, match=operands, @subtype=incl, " +
Joachim Bingel89cceac2014-01-08 15:51:08 +0000197 "constraint=[" +
198 "{@type=korap:group, relation=and, operands=[" +
199 "{@type=korap:distance, measure=w, direction=plus, min=1, max=4}," +
200 "{@type=korap:distance, measure=s, direction=both, min=0, max=0}," +
201 "{@type=korap:distance, measure=p, direction=both, min=1, max=3}" +
202 "]}" +
203 "], " +
204 "operands=[" +
205 "{@type=korap:token, @value={@type=korap:term, @value=orth:Sonne, relation==}}," +
206 "{@type=korap:token, @value={@type=korap:term, @value=orth:Mond, relation==}}" +
207 "]" +
208 "}";
209 ppt = new CosmasTree(query);
210 map = ppt.getRequestMap().get("query").toString();
211 assertEquals(prox2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel87480d02014-01-17 14:07:46 +0000212
213 query="Sonne %+w1:4,s0,p1:3 Mond";
214 String prox3 =
215 "{@type=korap:group, relation=distance, match=operands, @subtype=excl, " +
216 "constraint=[" +
217 "{@type=korap:group, relation=and, operands=[" +
218 "{@type=korap:distance, measure=w, direction=plus, min=1, max=4}," +
219 "{@type=korap:distance, measure=s, direction=both, min=0, max=0}," +
220 "{@type=korap:distance, measure=p, direction=both, min=1, max=3}" +
221 "]}" +
222 "], " +
223 "operands=[" +
224 "{@type=korap:token, @value={@type=korap:term, @value=orth:Sonne, relation==}}," +
225 "{@type=korap:token, @value={@type=korap:term, @value=orth:Mond, relation==}}" +
226 "]" +
227 "}";
228 ppt = new CosmasTree(query);
229 map = ppt.getRequestMap().get("query").toString();
230 assertEquals(prox3.replaceAll(" ", ""), map.replaceAll(" ", ""));
231
232 query="Sonne /+w4 Mond";
233 String prox4 =
234 "{@type=korap:group, relation=distance, match=operands, @subtype=incl, " +
235 "constraint=[" +
236 "{@type=korap:distance, measure=w, direction=plus, min=0, max=4}" +
237 "], " +
238 "operands=[" +
239 "{@type=korap:token, @value={@type=korap:term, @value=orth:Sonne, relation==}}," +
240 "{@type=korap:token, @value={@type=korap:term, @value=orth:Mond, relation==}}" +
241 "]" +
242 "}";
243 ppt = new CosmasTree(query);
244 map = ppt.getRequestMap().get("query").toString();
245 assertEquals(prox4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000246
247 query="Sonne /-w4 Mond";
248 String prox5 =
249 "{@type=korap:group, relation=distance, match=operands, @subtype=incl, " +
250 "constraint=[" +
251 "{@type=korap:distance, measure=w, direction=plus, min=0, max=4}" +
252 "], " +
253 "operands=[" +
254 "{@type=korap:token, @value={@type=korap:term, @value=orth:Mond, relation==}}," +
255 "{@type=korap:token, @value={@type=korap:term, @value=orth:Sonne, relation==}}" +
256 "]" +
257 "}";
258 ppt = new CosmasTree(query);
259 map = ppt.getRequestMap().get("query").toString();
260 assertEquals(prox5.replaceAll(" ", ""), map.replaceAll(" ", ""));
261 }
262
263 @Test
264 public void testNestedOPPROX() throws QueryException {
265 query="Sonne /-w4 Mond /+w2 Sterne";
266 String prox6 =
267 "{@type=korap:group, relation=distance, match=operands, @subtype=incl, " +
268 "constraint=[" +
269 "{@type=korap:distance, measure=w, direction=plus, min=0, max=4}" +
270 "], " +
271 "operands=[" +
272 "{@type=korap:group, relation=distance, match=operands, @subtype=incl, " +
273 "constraint=[" +
274 "{@type=korap:distance, measure=w, direction=plus, min=0, max=2}" +
275 "], " +
276 "operands=[" +
277 "{@type=korap:token, @value={@type=korap:term, @value=orth:Mond, relation==}}," +
278 "{@type=korap:token, @value={@type=korap:term, @value=orth:Sterne, relation==}}" +
279 "]}," +
280 "{@type=korap:token, @value={@type=korap:term, @value=orth:Sonne, relation==}}" +
281 "]" +
282 "}";
283 ppt = new CosmasTree(query);
284 map = ppt.getRequestMap().get("query").toString();
285 assertEquals(prox6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000286 }
287
288 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000289 public void testOPIN() throws QueryException {
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000290 query="wegen #IN <s>";
Joachim Bingel3a9f7932014-01-07 17:11:31 +0000291 String opin1 =
Joachim Bingeleecc7652014-01-11 17:21:07 +0000292 "{@type=korap:group, relation=shrink, shrink=1, operands=[" +
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000293 "{@type=korap:group, relation=position, position=contains, operands=[" +
Joachim Bingelffd65e32014-01-22 14:22:57 +0000294 "{@type=korap:element, @value=s}," +
Joachim Bingeleecc7652014-01-11 17:21:07 +0000295 "{@type=korap:group, class=1, operands=[" +
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000296 "{@type=korap:token, @value={@type=korap:term, @value=orth:wegen, relation==}}" +
Joachim Bingeleecc7652014-01-11 17:21:07 +0000297 "]}" +
298 "]}" +
Joachim Bingeld5161a12014-01-08 11:15:49 +0000299 "]}";
300 ppt = new CosmasTree(query);
301 map = ppt.getRequestMap().get("query").toString();
302 assertEquals(opin1.replaceAll(" ", ""), map.replaceAll(" ", ""));
303
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000304 query="wegen #IN(L) <s>";
305 String opin2 =
306 "{@type=korap:group, relation=shrink, shrink=1, operands=[" +
307 "{@type=korap:group, relation=position, position=startswith, operands=[" +
Joachim Bingelffd65e32014-01-22 14:22:57 +0000308 "{@type=korap:element, @value=s}," +
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000309 "{@type=korap:group, class=1, operands=[" +
310 "{@type=korap:token, @value={@type=korap:term, @value=orth:wegen, relation==}}" +
311 "]}" +
312 "]}" +
313 "]}";
314 ppt = new CosmasTree(query);
315 map = ppt.getRequestMap().get("query").toString();
316 assertEquals(opin2.replaceAll(" ", ""), map.replaceAll(" ", ""));
317
Joachim Bingel87480d02014-01-17 14:07:46 +0000318 query="wegen #IN(%, L) <s>";
319 String opin3 =
320 "{@type=korap:group, relation=shrink, shrink=1, operands=[" +
321 "{@type=korap:group, relation=position, position=startswith, @subtype=excl, operands=[" +
Joachim Bingelffd65e32014-01-22 14:22:57 +0000322 "{@type=korap:element, @value=s}," +
Joachim Bingel87480d02014-01-17 14:07:46 +0000323 "{@type=korap:group, class=1, operands=[" +
324 "{@type=korap:token, @value={@type=korap:term, @value=orth:wegen, relation==}}" +
325 "]}" +
326 "]}" +
327 "]}";
328 ppt = new CosmasTree(query);
329 map = ppt.getRequestMap().get("query").toString();
330 assertEquals(opin3.replaceAll(" ", ""), map.replaceAll(" ", ""));
331
332 query="wegen #IN('FE,ALL,%,MIN') <s>";
333 String opin4 =
334 "{@type=korap:group, relation=shrink, shrink=1, operands=[" +
335 "{@type=korap:group, relation=position, position=ident, range=all, @subtype=excl, grouping=false, operands=[" +
Joachim Bingelffd65e32014-01-22 14:22:57 +0000336 "{@type=korap:element, @value=s}," +
Joachim Bingel87480d02014-01-17 14:07:46 +0000337 "{@type=korap:group, class=1, operands=[" +
338 "{@type=korap:token, @value={@type=korap:term, @value=orth:wegen, relation==}}" +
339 "]}" +
340 "]}" +
341 "]}";
342 ppt = new CosmasTree(query);
343 map = ppt.getRequestMap().get("query").toString();
344 assertEquals(opin4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeld5161a12014-01-08 11:15:49 +0000345 }
346
347 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000348 public void testOPOV() throws QueryException {
Joachim Bingeld5161a12014-01-08 11:15:49 +0000349 query="wegen #OV <s>";
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000350 String opov1 =
351 "{@type=korap:group, relation=shrink, shrink=1, operands=[" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000352 "{@type=korap:group, relation=overlap, position=any, operands=[" +
Joachim Bingelffd65e32014-01-22 14:22:57 +0000353 "{@type=korap:element, @value=s}," +
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000354 "{@type=korap:group, class=1, operands=[" +
355 "{@type=korap:token, @value={@type=korap:term, @value=orth:wegen, relation==}}" +
356 "]}" +
357 "]}" +
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000358 "]}";
359 ppt = new CosmasTree(query);
360 map = ppt.getRequestMap().get("query").toString();
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000361 assertEquals(opov1.replaceAll(" ", ""), map.replaceAll(" ", ""));
362
363 query="wegen #OV(L) <s>";
364 String opov2 =
365 "{@type=korap:group, relation=shrink, shrink=1, operands=[" +
366 "{@type=korap:group, relation=overlap, position=startswith, operands=[" +
Joachim Bingelffd65e32014-01-22 14:22:57 +0000367 "{@type=korap:element, @value=s}," +
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000368 "{@type=korap:group, class=1, operands=[" +
369 "{@type=korap:token, @value={@type=korap:term, @value=orth:wegen, relation==}}" +
370 "]}" +
371 "]}" +
372 "]}";
373 ppt = new CosmasTree(query);
374 map = ppt.getRequestMap().get("query").toString();
375 assertEquals(opov2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000376 }
377
378 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000379 public void testOPNOT() throws QueryException {
Joachim Bingel3a9f7932014-01-07 17:11:31 +0000380 query="Sonne nicht Mond";
381 String opnot1 =
382 "{@type=korap:group, relation=not, operands=[" +
383 "{@type=korap:token, @value={@type=korap:term, @value=orth:Sonne, relation==}}," +
384 "{@type=korap:token, @value={@type=korap:term, @value=orth:Mond, relation==}}" +
385 "]}";
386 ppt = new CosmasTree(query);
387 map = ppt.getRequestMap().get("query").toString();
388 assertEquals(opnot1.replaceAll(" ", ""), map.replaceAll(" ", ""));
389 }
390
391 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000392 public void testBEG_END() throws QueryException {
Joachim Bingel3a9f7932014-01-07 17:11:31 +0000393 // BEG and END operators
394 // http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/syntax/links.html
395 // http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/syntax/rechts.html
396 // http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/thematische-bsp/bsp-satzlaenge.html
Joachim Bingel87480d02014-01-17 14:07:46 +0000397 query="#BEG(der /w3:5 Mann)";
398 String beg1 =
399 "{@type=korap:group, relation=shrink, shrink=first, operands=[" +
400 "{@type=korap:group, relation=distance, match=operands, @subtype=incl, constraint=[" +
401 "{@type=korap:distance, measure=w, direction=both, min=3, max=5}" +
402 "]," +
403 "operands = [" +
404 "{@type=korap:token, @value={@type=korap:term, @value=orth:der, relation==}}," +
405 "{@type=korap:token, @value={@type=korap:term, @value=orth:Mann, relation==}}" +
406 "]}" +
407 "]}";
408 ppt = new CosmasTree(query);
409 map = ppt.getRequestMap().get("query").toString();
410 assertEquals(beg1.replaceAll(" ", ""), map.replaceAll(" ", ""));
411
412 query="#BEG(der /w3:5 Mann) /+w10 kommt"; // nesting #BEG() in a distance group
413 String beg2 =
414 "{@type=korap:group, relation=distance, match=operands, @subtype=incl, constraint=[" +
415 "{@type=korap:distance, measure=w, direction=plus, min=0, max=10}" +
416 "], operands=[" +
417 "{@type=korap:group, relation=shrink, shrink=first, operands=[" +
418 "{@type=korap:group, relation=distance, match=operands, @subtype=incl, constraint=[" +
419 "{@type=korap:distance, measure=w, direction=both, min=3, max=5}" +
420 "]," +
421 "operands = [" +
422 "{@type=korap:token, @value={@type=korap:term, @value=orth:der, relation==}}," +
423 "{@type=korap:token, @value={@type=korap:term, @value=orth:Mann, relation==}}" +
424 "]}" +
425 "]}," +
426 "{@type=korap:token, @value={@type=korap:term, @value=orth:kommt, relation==}}" +
427 "]}";
428 ppt = new CosmasTree(query);
429 map = ppt.getRequestMap().get("query").toString();
430 assertEquals(beg2.replaceAll(" ", ""), map.replaceAll(" ", ""));
431
432 query="#END(der /w3:5 Mann)";
433 String end1 =
434 "{@type=korap:group, relation=shrink, shrink=last, operands=[" +
435 "{@type=korap:group, relation=distance, match=operands, @subtype=incl, constraint=[" +
436 "{@type=korap:distance, measure=w, direction=both, min=3, max=5}" +
437 "]," +
438 "operands = [" +
439 "{@type=korap:token, @value={@type=korap:term, @value=orth:der, relation==}}," +
440 "{@type=korap:token, @value={@type=korap:term, @value=orth:Mann, relation==}}" +
441 "]}" +
442 "]}";
443 ppt = new CosmasTree(query);
444 map = ppt.getRequestMap().get("query").toString();
445 assertEquals(end1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000446 }
Joachim Bingeld5161a12014-01-08 11:15:49 +0000447
448
449 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000450 public void testELEM() throws QueryException {
Joachim Bingeld5161a12014-01-08 11:15:49 +0000451 // http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/syntax/elem.html
Joachim Bingeleecc7652014-01-11 17:21:07 +0000452 query="#ELEM(S)";
Joachim Bingelffd65e32014-01-22 14:22:57 +0000453 String elem1 = "{@type=korap:element, @value=s}";
Joachim Bingeleecc7652014-01-11 17:21:07 +0000454 ppt = new CosmasTree(query);
455 map = ppt.getRequestMap().get("query").toString();
456 assertEquals(elem1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeld5161a12014-01-08 11:15:49 +0000457 }
458
459 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000460 public void testOPALL() throws QueryException {
Joachim Bingel89cceac2014-01-08 15:51:08 +0000461 query="#ALL(gehen /w1:10 voran)";
Joachim Bingele98d0882014-01-21 12:58:54 +0000462 String all1 =
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000463 "{@type=korap:group, relation=distance, match=all, @subtype=incl, " +
464 "constraint=[" +
465 "{@type=korap:distance, measure=w, direction=both, min=1, max=10}" +
466 "], " +
467 "operands=[" +
468 "{@type=korap:token, @value={@type=korap:term, @value=orth:gehen, relation==}}," +
469 "{@type=korap:token, @value={@type=korap:term, @value=orth:voran, relation==}}" +
470 "]" +
471 "}";
Joachim Bingel89cceac2014-01-08 15:51:08 +0000472 ppt = new CosmasTree(query);
473 map = ppt.getRequestMap().get("query").toString();
474 assertEquals(all1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeld5161a12014-01-08 11:15:49 +0000475 }
476
477 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000478 public void testOPNHIT() throws QueryException {
Joachim Bingel89cceac2014-01-08 15:51:08 +0000479 query="#NHIT(gehen /w1:10 voran)";
480 String nhit1 =
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000481 "{@type=korap:group, relation=distance, match=between, @subtype=incl, " +
482 "constraint=[" +
483 "{@type=korap:distance, measure=w, direction=both, min=1, max=10}" +
484 "], " +
485 "operands=[" +
486 "{@type=korap:token, @value={@type=korap:term, @value=orth:gehen, relation==}}," +
487 "{@type=korap:token, @value={@type=korap:term, @value=orth:voran, relation==}}" +
488 "]" +
489 "}";
Joachim Bingel89cceac2014-01-08 15:51:08 +0000490 ppt = new CosmasTree(query);
491 map = ppt.getRequestMap().get("query").toString();
492 assertEquals(nhit1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeld5161a12014-01-08 11:15:49 +0000493 }
494
495 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000496 public void testOPBED() throws QueryException {
Joachim Bingeleecc7652014-01-11 17:21:07 +0000497 query = "#BED(der , sa)";
498 String bed1 =
499 "{@type=korap:group, relation=position, position=startswith, operands=[" +
Joachim Bingelffd65e32014-01-22 14:22:57 +0000500 "{@type=korap:element, @value=s}," +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000501 "{@type=korap:token, @value={@type=korap:term, @value=orth:der, relation==}}" +
Joachim Bingeleecc7652014-01-11 17:21:07 +0000502 "]}";
503 ppt = new CosmasTree(query);
504 map = ppt.getRequestMap().get("query").toString();
505 assertEquals(bed1.replaceAll(" ", ""), map.replaceAll(" ", ""));
506
507 query = "#BED(der Mann , +pe)";
508 String bed2 =
509 "{@type=korap:group, relation=position, position=endswith, operands=[" +
Joachim Bingelffd65e32014-01-22 14:22:57 +0000510 "{@type=korap:element, @value=p}," +
Joachim Bingeleecc7652014-01-11 17:21:07 +0000511 "{@type=korap:sequence, operands=[" +
512 "{@type=korap:token, @value={@type=korap:term, @value=orth:der, relation==}}," +
513 "{@type=korap:token, @value={@type=korap:term, @value=orth:Mann, relation==}}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000514 "]}" +
Joachim Bingeleecc7652014-01-11 17:21:07 +0000515 "]}";
516 ppt = new CosmasTree(query);
517 map = ppt.getRequestMap().get("query").toString();
518 assertEquals(bed2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000519
520 query = "#BED(der Mann , sa,-pa)";
521 String bed3 =
522 "{@type=korap:group, relation=and, operands=[" +
523 "{@type=korap:group, relation=position, position=startswith, operands=[" +
Joachim Bingelffd65e32014-01-22 14:22:57 +0000524 "{@type=korap:element, @value=s}," +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000525 "{@type=korap:sequence, operands=[" +
526 "{@type=korap:token, @value={@type=korap:term, @value=orth:der, relation==}}," +
527 "{@type=korap:token, @value={@type=korap:term, @value=orth:Mann, relation==}}" +
528 "]}" +
529 "]}," +
530 "{@type=korap:group, relation=position, position=startswith, @subtype=excl, operands=[" +
Joachim Bingelffd65e32014-01-22 14:22:57 +0000531 "{@type=korap:element, @value=p}," +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000532 "{@type=korap:sequence, operands=[" +
533 "{@type=korap:token, @value={@type=korap:term, @value=orth:der, relation==}}," +
534 "{@type=korap:token, @value={@type=korap:term, @value=orth:Mann, relation==}}" +
535 "]}" +
536 "]}" +
537 "]}";
538 ppt = new CosmasTree(query);
539 map = ppt.getRequestMap().get("query").toString();
540 assertEquals(bed3.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeld5161a12014-01-08 11:15:49 +0000541 }
542
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000543}
544