blob: 24306b53c2f9bf834dac5e05d3af698528356de4 [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
Joachim Bingel11d5b152014-02-11 21:33:47 +000027// @Test
Joachim Bingelb5f7bf02014-01-07 16:36:54 +000028 public void testContext() throws QueryException {
Joachim Bingel11d5b152014-02-11 21:33:47 +000029 String contextString = "{korap = http://ids-mannheim.de/ns/KorAP/json-ld/v0.1/, " +
30 "boundary = korap:boundary/,"+
31 "group = korap:group/,"+
32 "operation = {@id = group:operation/, @type = @id},"+
33 "class = {@id = group:class, @type = xsd:integer},"+
34 "operands = {@id = group:operands, @container = @list},"+
35 "frame = {@id = group:frame/, @type = xsd:integer},"+
36 "classRef = {@id = group:classRef, @type = xsd:integer},"+
37 "spanRef = {@id = group:spanRef, @type = xsd:integer},"+
38 "classRefOp = {@id = group:classRefOp, @type = @id},"+
39 "min = {@id = boundary:min, @type = xsd:integer},"+
40 "max = {@id = boundary:max, @type = xsd:integer},"+
41 "exclude = {@id = group:exclude, @type = xsd:boolean},"+
42 "distances = {@id = group:distances, @container = @list},"+
43 "inOrder = {@id = group:inOrder, @type = xsd:boolean},"+
44 "}";
Joachim Bingelb5f7bf02014-01-07 16:36:54 +000045 ppt = new CosmasTree("Test");
Joachim Bingel11d5b152014-02-11 21:33:47 +000046// assertTrue(equalsContent(contextString, ppt.getRequestMap().get("@context")));
47 assertEquals(contextString.replaceAll(" ", ""), ppt.getRequestMap().get("@context"));
Joachim Bingelb5f7bf02014-01-07 16:36:54 +000048 }
49
50
51 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +000052 public void testSingleToken() throws QueryException {
Joachim Bingelb5f7bf02014-01-07 16:36:54 +000053 query="der";
54 String single1 =
Joachim Bingel11d5b152014-02-11 21:33:47 +000055 "{type=token, key={type=term, key=der, layer=orth, match=eq}}";
Joachim Bingelb5f7bf02014-01-07 16:36:54 +000056 ppt = new CosmasTree(query);
57 map = ppt.getRequestMap().get("query").toString();
58 assertEquals(single1.replaceAll(" ", ""), map.replaceAll(" ", ""));
59
60 query="Mann";
61 String single2 =
Joachim Bingel11d5b152014-02-11 21:33:47 +000062 "{type=token, key={type=term, key=Mann, layer=orth, match=eq}}";
Joachim Bingelb5f7bf02014-01-07 16:36:54 +000063 ppt = new CosmasTree(query);
64 map = ppt.getRequestMap().get("query").toString();
65 assertEquals(single2.replaceAll(" ", ""), map.replaceAll(" ", ""));
66
67 query="&Mann";
68 String single3 =
Joachim Bingel11d5b152014-02-11 21:33:47 +000069 "{type=token, key={type=term, key=Mann, layer=lemma, match=eq}}";
Joachim Bingelb5f7bf02014-01-07 16:36:54 +000070 ppt = new CosmasTree(query);
71 map = ppt.getRequestMap().get("query").toString();
72 assertEquals(single3.replaceAll(" ", ""), map.replaceAll(" ", ""));
73 }
74
Joachim Bingelba9a0ab2014-01-29 10:12:25 +000075 @Test
Joachim Bingel8c640e42014-02-07 16:20:47 +000076 public void testCaseSensitivityFlag() throws QueryException {
77 //TODO ignorieroperator $ http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/syntax/ignorierung.html
78 }
79
80 @Test
Joachim Bingelffd65e32014-01-22 14:22:57 +000081 public void testMORPH() throws QueryException {
82 query="#MORPH(V)";
83 String morph1 =
Joachim Bingel11d5b152014-02-11 21:33:47 +000084 "{type=token, key={type=term, key=V, match=eq}}";
Joachim Bingelffd65e32014-01-22 14:22:57 +000085 ppt = new CosmasTree(query);
86 map = ppt.getRequestMap().get("query").toString();
87 assertEquals(morph1.replaceAll(" ", ""), map.replaceAll(" ", ""));
88 }
89
Joachim Bingelb5f7bf02014-01-07 16:36:54 +000090 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +000091 public void testSequence() throws QueryException {
Joachim Bingelb5f7bf02014-01-07 16:36:54 +000092 query="der Mann";
93 String seq1 =
Joachim Bingel11d5b152014-02-11 21:33:47 +000094 "{type=group, operation=sequence, operands=[" +
95 "{type=token, key={type=term, key=der, layer=orth, match=eq}}," +
96 "{type=token, key={type=term, key=Mann, layer=orth, match=eq}}" +
Joachim Bingelb5f7bf02014-01-07 16:36:54 +000097 "]}";
98 ppt = new CosmasTree(query);
99 map = ppt.getRequestMap().get("query").toString();
100 assertEquals(seq1.replaceAll(" ", ""), map.replaceAll(" ", ""));
101
Joachim Bingeld5161a12014-01-08 11:15:49 +0000102 query="der Mann schläft";
103 String seq2 =
Joachim Bingel11d5b152014-02-11 21:33:47 +0000104 "{type=group, operation=sequence, operands=[" +
105 "{type=token, key={type=term, key=der, layer=orth, match=eq}}," +
106 "{type=token, key={type=term, key=Mann, layer=orth, match=eq}}," +
107 "{type=token, key={type=term, key=schläft, layer=orth, match=eq}}" +
Joachim Bingeld5161a12014-01-08 11:15:49 +0000108 "]}";
109 ppt = new CosmasTree(query);
110 map = ppt.getRequestMap().get("query").toString();
111 assertEquals(seq2.replaceAll(" ", ""), map.replaceAll(" ", ""));
112
113 query="der Mann schläft lang";
114 String seq3 =
Joachim Bingel11d5b152014-02-11 21:33:47 +0000115 "{type=group, operation=sequence, operands=[" +
116 "{type=token, key={type=term, key=der, layer=orth, match=eq}}," +
117 "{type=token, key={type=term, key=Mann, layer=orth, match=eq}}," +
118 "{type=token, key={type=term, key=schläft, layer=orth, match=eq}}," +
119 "{type=token, key={type=term, key=lang, layer=orth, match=eq}}" +
Joachim Bingeld5161a12014-01-08 11:15:49 +0000120 "]}";
121 ppt = new CosmasTree(query);
122 map = ppt.getRequestMap().get("query").toString();
123 assertEquals(seq3.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000124 }
125
126 @Test
127 public void testOPOR() throws QueryException {
128 query="Sonne oder Mond";
129 String disj1 =
Joachim Bingel11d5b152014-02-11 21:33:47 +0000130 "{type=group, operation=or, operands=[" +
131 "{type=token, key={type=term, key=Sonne, layer=orth, match=eq}}," +
132 "{type=token, key={type=term, key=Mond, layer=orth, match=eq}}" +
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000133 "]}";
134 ppt = new CosmasTree(query);
135 map = ppt.getRequestMap().get("query").toString();
136 assertEquals(disj1.replaceAll(" ", ""), map.replaceAll(" ", ""));
137
Joachim Bingeld5161a12014-01-08 11:15:49 +0000138 query="(Sonne scheint) oder Mond";
139 String disj2 =
Joachim Bingel11d5b152014-02-11 21:33:47 +0000140 "{type=group, operation=or, operands=[" +
141 "{type=group, operation=sequence, operands=[" +
142 "{type=token, key={type=term, key=Sonne, layer=orth, match=eq}}," +
143 "{type=token, key={type=term, key=scheint, layer=orth, match=eq}}" +
Joachim Bingeld5161a12014-01-08 11:15:49 +0000144 "]}," +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000145 "{type=token, key={type=term, key=Mond, layer=orth, match=eq}}" +
Joachim Bingeld5161a12014-01-08 11:15:49 +0000146 "]}";
147 ppt = new CosmasTree(query);
148 map = ppt.getRequestMap().get("query").toString();
149 assertEquals(disj2.replaceAll(" ", ""), map.replaceAll(" ", ""));
150
151 query="(Sonne scheint) oder (Mond scheint)";
152 String disj3 =
Joachim Bingel11d5b152014-02-11 21:33:47 +0000153 "{type=group, operation=or, operands=[" +
154 "{type=group, operation=sequence, operands=[" +
155 "{type=token, key={type=term, key=Sonne, layer=orth, match=eq}}," +
156 "{type=token, key={type=term, key=scheint, layer=orth, match=eq}}" +
Joachim Bingeld5161a12014-01-08 11:15:49 +0000157 "]}," +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000158 "{type=group, operation=sequence, operands=[" +
159 "{type=token, key={type=term, key=Mond, layer=orth, match=eq}}," +
160 "{type=token, key={type=term, key=scheint, layer=orth, match=eq}}" +
Joachim Bingeld5161a12014-01-08 11:15:49 +0000161 "]}" +
162 "]}";
163 ppt = new CosmasTree(query);
164 map = ppt.getRequestMap().get("query").toString();
165 assertEquals(disj3.replaceAll(" ", ""), map.replaceAll(" ", ""));
166
167 }
168
169 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000170 public void testOPORAND() throws QueryException {
Joachim Bingeld5161a12014-01-08 11:15:49 +0000171 query="(Sonne oder Mond) und scheint";
172 String orand1 =
Joachim Bingel11d5b152014-02-11 21:33:47 +0000173 "{type=group, operation=and, operands=[" +
174 "{type=group, operation=or, operands=[" +
175 "{type=token, key={type=term, key=Sonne, layer=orth, match=eq}}," +
176 "{type=token, key={type=term, key=Mond, layer=orth, match=eq}}" +
Joachim Bingeld5161a12014-01-08 11:15:49 +0000177 "]}," +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000178 "{type=token, key={type=term, key=scheint, layer=orth, match=eq}}" +
Joachim Bingeld5161a12014-01-08 11:15:49 +0000179 "]}";
180 ppt = new CosmasTree(query);
181 map = ppt.getRequestMap().get("query").toString();
182 assertEquals(orand1.replaceAll(" ", ""), map.replaceAll(" ", ""));
183
184 query="scheint und (Sonne oder Mond)";
185 String orand2 =
Joachim Bingel11d5b152014-02-11 21:33:47 +0000186 "{type=group, operation=and, operands=[" +
187 "{type=token, key={type=term, key=scheint, layer=orth, match=eq}}," +
188 "{type=group, operation=or, operands=[" +
189 "{type=token, key={type=term, key=Sonne, layer=orth, match=eq}}," +
190 "{type=token, key={type=term, key=Mond, layer=orth, match=eq}}" +
Joachim Bingeld5161a12014-01-08 11:15:49 +0000191 "]}" +
192 "]}";
193 ppt = new CosmasTree(query);
194 map = ppt.getRequestMap().get("query").toString();
195 assertEquals(orand2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000196 }
197
198 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000199 public void testOPPROX() throws QueryException {
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000200 query="Sonne /+w1:4 Mond";
201 String prox1 =
Joachim Bingel11d5b152014-02-11 21:33:47 +0000202 "{type=group, operation=sequence, inOrder=true, " +
203 "distances=[" +
204 "{type=distance, measure=w, min=1, max=4}" +
Joachim Bingel89cceac2014-01-08 15:51:08 +0000205 "], " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000206 "operands=[" +
207 "{type=token, key={type=term, key=Sonne, layer=orth, match=eq}}," +
208 "{type=token, key={type=term, key=Mond, layer=orth, match=eq}}" +
Joachim Bingel89cceac2014-01-08 15:51:08 +0000209 "]" +
210 "}";
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000211 ppt = new CosmasTree(query);
212 map = ppt.getRequestMap().get("query").toString();
213 assertEquals(prox1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel89cceac2014-01-08 15:51:08 +0000214
215 query="Sonne /+w1:4,s0,p1:3 Mond";
216 String prox2 =
Joachim Bingel11d5b152014-02-11 21:33:47 +0000217 "{type=group, operation=sequence, inOrder=true, " +
218 "distances=[" +
219 "{type=group, operation=and, operands=[" +
220 "{type=distance, measure=w, min=1, max=4}," +
221 "{type=distance, measure=s, min=0, max=0}," +
222 "{type=distance, measure=p, min=1, max=3}" +
Joachim Bingel89cceac2014-01-08 15:51:08 +0000223 "]}" +
224 "], " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000225 "operands=[" +
226 "{type=token, key={type=term, key=Sonne, layer=orth, match=eq}}," +
227 "{type=token, key={type=term, key=Mond, layer=orth, match=eq}}" +
Joachim Bingel89cceac2014-01-08 15:51:08 +0000228 "]" +
229 "}";
230 ppt = new CosmasTree(query);
231 map = ppt.getRequestMap().get("query").toString();
232 assertEquals(prox2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel87480d02014-01-17 14:07:46 +0000233
234 query="Sonne %+w1:4,s0,p1:3 Mond";
235 String prox3 =
Joachim Bingel11d5b152014-02-11 21:33:47 +0000236 "{type=group, operation=sequence, inOrder=true, " +
237 "distances=[" +
238 "{type=group, operation=and, operands=[" +
239 "{type=distance, measure=w, min=1, max=4, exclude=true}," +
240 "{type=distance, measure=s, min=0, max=0, exclude=true}," +
241 "{type=distance, measure=p, min=1, max=3, exclude=true}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000242 "]}" +
243 "], " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000244 "operands=[" +
245 "{type=token, key={type=term, key=Sonne, layer=orth, match=eq}}," +
246 "{type=token, key={type=term, key=Mond, layer=orth, match=eq}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000247 "]" +
248 "}";
249 ppt = new CosmasTree(query);
250 map = ppt.getRequestMap().get("query").toString();
251 assertEquals(prox3.replaceAll(" ", ""), map.replaceAll(" ", ""));
252
253 query="Sonne /+w4 Mond";
254 String prox4 =
Joachim Bingel11d5b152014-02-11 21:33:47 +0000255 "{type=group, operation=sequence, inOrder=true, " +
256 "distances=[" +
257 "{type=distance, measure=w, min=0, max=4}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000258 "], " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000259 "operands=[" +
260 "{type=token, key={type=term, key=Sonne, layer=orth, match=eq}}," +
261 "{type=token, key={type=term, key=Mond, layer=orth, match=eq}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000262 "]" +
263 "}";
264 ppt = new CosmasTree(query);
265 map = ppt.getRequestMap().get("query").toString();
266 assertEquals(prox4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000267
268 query="Sonne /-w4 Mond";
269 String prox5 =
Joachim Bingel11d5b152014-02-11 21:33:47 +0000270 "{type=group, operation=sequence, inOrder=true, " +
271 "distances=[" +
272 "{type=distance, measure=w, min=0, max=4}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000273 "], " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000274 "operands=[" +
275 "{type=token, key={type=term, key=Mond, layer=orth, match=eq}}," +
276 "{type=token, key={type=term, key=Sonne, layer=orth, match=eq}}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000277 "]" +
278 "}";
279 ppt = new CosmasTree(query);
280 map = ppt.getRequestMap().get("query").toString();
281 assertEquals(prox5.replaceAll(" ", ""), map.replaceAll(" ", ""));
282 }
283
284 @Test
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000285 public void testOPPROXNested() throws QueryException {
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000286 query="Sonne /-w4 Mond /+w2 Sterne";
287 String prox6 =
Joachim Bingel11d5b152014-02-11 21:33:47 +0000288 "{type=group, operation=sequence, inOrder=true, " +
289 "distances=[" +
290 "{type=distance, measure=w, min=0, max=4}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000291 "], " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000292 "operands=[" +
293 "{type=group, operation=sequence, inOrder=true, " +
294 "distances=[" +
295 "{type=distance, measure=w, min=0, max=2}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000296 "], " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000297 "operands=[" +
298 "{type=token, key={type=term, key=Mond, layer=orth, match=eq}}," +
299 "{type=token, key={type=term, key=Sterne, layer=orth, match=eq}}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000300 "]}," +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000301 "{type=token, key={type=term, key=Sonne, layer=orth, match=eq}}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000302 "]" +
303 "}";
304 ppt = new CosmasTree(query);
305 map = ppt.getRequestMap().get("query").toString();
306 assertEquals(prox6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000307 }
308
309 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000310 public void testOPIN() throws QueryException {
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000311 query="wegen #IN <s>";
Joachim Bingel3a9f7932014-01-07 17:11:31 +0000312 String opin1 =
Joachim Bingel11d5b152014-02-11 21:33:47 +0000313 "{type=group, operation=submatch, classRef=1, operands=[" +
314 "{type=group, operation=position, frame=contains, operands=[" +
315 "{type=span, key=s}," +
316 "{type=group, operation=class, class=1, operands=[" +
317 "{type=token, key={type=term, key=wegen, layer=orth, match=eq}}" +
Joachim Bingeleecc7652014-01-11 17:21:07 +0000318 "]}" +
319 "]}" +
Joachim Bingeld5161a12014-01-08 11:15:49 +0000320 "]}";
321 ppt = new CosmasTree(query);
322 map = ppt.getRequestMap().get("query").toString();
323 assertEquals(opin1.replaceAll(" ", ""), map.replaceAll(" ", ""));
324
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000325 query="wegen #IN(L) <s>";
326 String opin2 =
Joachim Bingel11d5b152014-02-11 21:33:47 +0000327 "{type=group, operation=submatch, classRef=1, operands=[" +
328 "{type=group, operation=position, frame=startswith, operands=[" +
329 "{type=span, key=s}," +
330 "{type=group, operation=class, class=1, operands=[" +
331 "{type=token, key={type=term, key=wegen, layer=orth, match=eq}}" +
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000332 "]}" +
333 "]}" +
334 "]}";
335 ppt = new CosmasTree(query);
336 map = ppt.getRequestMap().get("query").toString();
337 assertEquals(opin2.replaceAll(" ", ""), map.replaceAll(" ", ""));
338
Joachim Bingel87480d02014-01-17 14:07:46 +0000339 query="wegen #IN(%, L) <s>";
340 String opin3 =
Joachim Bingel11d5b152014-02-11 21:33:47 +0000341 "{type=group, operation=submatch, classRef=1, operands=[" +
342 "{type=group, operation=position, frame=startswith, exclude=true, operands=[" +
343 "{type=span, key=s}," +
344 "{type=group, operation=class, class=1, operands=[" +
345 "{type=token, key={type=term, key=wegen, layer=orth, match=eq}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000346 "]}" +
347 "]}" +
348 "]}";
349 ppt = new CosmasTree(query);
350 map = ppt.getRequestMap().get("query").toString();
351 assertEquals(opin3.replaceAll(" ", ""), map.replaceAll(" ", ""));
352
353 query="wegen #IN('FE,ALL,%,MIN') <s>";
354 String opin4 =
Joachim Bingel11d5b152014-02-11 21:33:47 +0000355 "{type=group, operation=submatch, classRef=1, operands=[" +
356 "{type=group, operation=position, frame=matches, range=all, exclude=true, grouping=false, operands=[" +
357 "{type=span, key=s}," +
358 "{type=group, operation=class, class=1, operands=[" +
359 "{type=token, key={type=term, key=wegen, layer=orth, match=eq}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000360 "]}" +
361 "]}" +
362 "]}";
363 ppt = new CosmasTree(query);
364 map = ppt.getRequestMap().get("query").toString();
365 assertEquals(opin4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeld5161a12014-01-08 11:15:49 +0000366 }
367
368 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000369 public void testOPOV() throws QueryException {
Joachim Bingeld5161a12014-01-08 11:15:49 +0000370 query="wegen #OV <s>";
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000371 String opov1 =
Joachim Bingel11d5b152014-02-11 21:33:47 +0000372 "{type=group, operation=submatch, classRef=1, operands=[" +
373 "{type=group, operation=position, frame=overlaps, operands=[" +
374 "{type=span, key=s}," +
375 "{type=group, operation=class, class=1, operands=[" +
376 "{type=token, key={type=term, key=wegen, layer=orth, match=eq}}" +
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000377 "]}" +
378 "]}" +
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000379 "]}";
380 ppt = new CosmasTree(query);
381 map = ppt.getRequestMap().get("query").toString();
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000382 assertEquals(opov1.replaceAll(" ", ""), map.replaceAll(" ", ""));
383
384 query="wegen #OV(L) <s>";
385 String opov2 =
Joachim Bingel11d5b152014-02-11 21:33:47 +0000386 "{type=group, operation=submatch, classRef=1, operands=[" +
387 "{type=group, operation=position, frame=overlaps-left, operands=[" +
388 "{type=span, key=s}," +
389 "{type=group, operation=class, class=1, operands=[" +
390 "{type=token, key={type=term, key=wegen, layer=orth, match=eq}}" +
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000391 "]}" +
392 "]}" +
393 "]}";
394 ppt = new CosmasTree(query);
395 map = ppt.getRequestMap().get("query").toString();
396 assertEquals(opov2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000397 }
398
399 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000400 public void testOPNOT() throws QueryException {
Joachim Bingel3a9f7932014-01-07 17:11:31 +0000401 query="Sonne nicht Mond";
402 String opnot1 =
Joachim Bingel11d5b152014-02-11 21:33:47 +0000403 "{type=group, operation=not, operands=[" +
404 "{type=token, key={type=term, key=Sonne, layer=orth, match=eq}}," +
405 "{type=token, key={type=term, key=Mond, layer=orth, match=eq}}" +
Joachim Bingel3a9f7932014-01-07 17:11:31 +0000406 "]}";
407 ppt = new CosmasTree(query);
408 map = ppt.getRequestMap().get("query").toString();
409 assertEquals(opnot1.replaceAll(" ", ""), map.replaceAll(" ", ""));
410 }
411
412 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000413 public void testBEG_END() throws QueryException {
Joachim Bingel3a9f7932014-01-07 17:11:31 +0000414 // BEG and END operators
415 // http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/syntax/links.html
416 // http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/syntax/rechts.html
417 // http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/thematische-bsp/bsp-satzlaenge.html
Joachim Bingel87480d02014-01-17 14:07:46 +0000418 query="#BEG(der /w3:5 Mann)";
419 String beg1 =
Joachim Bingel11d5b152014-02-11 21:33:47 +0000420 "{type=group, operation=submatch, @spanRef=[0,1], operands=[" +
421 "{type=group, operation=sequence, inOrder=false, distances=[" +
422 "{type=distance, measure=w, min=3, max=5}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000423 "]," +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000424 "operands = [" +
425 "{type=token, key={type=term, key=der, layer=orth, match=eq}}," +
426 "{type=token, key={type=term, key=Mann, layer=orth, match=eq}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000427 "]}" +
428 "]}";
429 ppt = new CosmasTree(query);
430 map = ppt.getRequestMap().get("query").toString();
431 assertEquals(beg1.replaceAll(" ", ""), map.replaceAll(" ", ""));
432
433 query="#BEG(der /w3:5 Mann) /+w10 kommt"; // nesting #BEG() in a distance group
434 String beg2 =
Joachim Bingel11d5b152014-02-11 21:33:47 +0000435 "{type=group, operation=sequence, inOrder=true, distances=[" +
436 "{type=distance, measure=w, min=0, max=10}" +
437 "], operands=[" +
438 "{type=group, operation=submatch, @spanRef=[0,1], operands=[" +
439 "{type=group, operation=sequence, inOrder=false, distances=[" +
440 "{type=distance, measure=w, min=3, max=5}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000441 "]," +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000442 "operands = [" +
443 "{type=token, key={type=term, key=der, layer=orth, match=eq}}," +
444 "{type=token, key={type=term, key=Mann, layer=orth, match=eq}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000445 "]}" +
446 "]}," +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000447 "{type=token, key={type=term, key=kommt, layer=orth, match=eq}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000448 "]}";
449 ppt = new CosmasTree(query);
450 map = ppt.getRequestMap().get("query").toString();
451 assertEquals(beg2.replaceAll(" ", ""), map.replaceAll(" ", ""));
452
453 query="#END(der /w3:5 Mann)";
454 String end1 =
Joachim Bingel11d5b152014-02-11 21:33:47 +0000455 "{type=group, operation=submatch, @spanRef=[-1,1], operands=[" +
456 "{type=group, operation=sequence, inOrder=false, distances=[" +
457 "{type=distance, measure=w, min=3, max=5}" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000458 "], " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000459 "operands = [" +
460 "{type=token, key={type=term, key=der, layer=orth, match=eq}}," +
461 "{type=token, key={type=term, key=Mann, layer=orth, match=eq}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000462 "]}" +
463 "]}";
464 ppt = new CosmasTree(query);
465 map = ppt.getRequestMap().get("query").toString();
466 assertEquals(end1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000467 }
Joachim Bingeld5161a12014-01-08 11:15:49 +0000468
469
470 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000471 public void testELEM() throws QueryException {
Joachim Bingeld5161a12014-01-08 11:15:49 +0000472 // http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/syntax/elem.html
Joachim Bingeleecc7652014-01-11 17:21:07 +0000473 query="#ELEM(S)";
Joachim Bingel11d5b152014-02-11 21:33:47 +0000474 String elem1 = "{type=span, key=s}";
Joachim Bingeleecc7652014-01-11 17:21:07 +0000475 ppt = new CosmasTree(query);
476 map = ppt.getRequestMap().get("query").toString();
477 assertEquals(elem1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeld5161a12014-01-08 11:15:49 +0000478 }
479
480 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000481 public void testOPALL() throws QueryException {
Joachim Bingel89cceac2014-01-08 15:51:08 +0000482 query="#ALL(gehen /w1:10 voran)";
Joachim Bingele98d0882014-01-21 12:58:54 +0000483 String all1 =
Joachim Bingel11d5b152014-02-11 21:33:47 +0000484 "{type=group, operation=sequence, inOrder=false, " +
485 "distances=[" +
486 "{type=distance, measure=w, min=1, max=10}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000487 "], " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000488 "operands=[" +
489 "{type=token, key={type=term, key=gehen, layer=orth, match=eq}}," +
490 "{type=token, key={type=term, key=voran, layer=orth, match=eq}}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000491 "]" +
492 "}";
Joachim Bingel89cceac2014-01-08 15:51:08 +0000493 ppt = new CosmasTree(query);
494 map = ppt.getRequestMap().get("query").toString();
495 assertEquals(all1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeld5161a12014-01-08 11:15:49 +0000496 }
497
Joachim Bingel8c640e42014-02-07 16:20:47 +0000498// @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000499 public void testOPNHIT() throws QueryException {
Joachim Bingel89cceac2014-01-08 15:51:08 +0000500 query="#NHIT(gehen /w1:10 voran)";
501 String nhit1 =
Joachim Bingel11d5b152014-02-11 21:33:47 +0000502 "{type=group, operation=sequence, inOrder=false, " +
503 "distances=[" +
504 "{type=distance, measure=w, min=1, max=10}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000505 "], " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000506 "operands=[" +
507 "{type=token, key={type=term, key=gehen, layer=orth, match=eq}}," +
508 "{type=token, key={type=term, key=voran, layer=orth, match=eq}}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000509 "]" +
510 "}";
Joachim Bingel89cceac2014-01-08 15:51:08 +0000511 ppt = new CosmasTree(query);
512 map = ppt.getRequestMap().get("query").toString();
513 assertEquals(nhit1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeld5161a12014-01-08 11:15:49 +0000514 }
515
516 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000517 public void testOPBED() throws QueryException {
Joachim Bingeleecc7652014-01-11 17:21:07 +0000518 query = "#BED(der , sa)";
519 String bed1 =
Joachim Bingel11d5b152014-02-11 21:33:47 +0000520 "{type=group, operation=position, frame=startswith, operands=[" +
521 "{type=span, key=s}," +
522 "{type=token, key={type=term, key=der, layer=orth, match=eq}}" +
Joachim Bingeleecc7652014-01-11 17:21:07 +0000523 "]}";
524 ppt = new CosmasTree(query);
525 map = ppt.getRequestMap().get("query").toString();
526 assertEquals(bed1.replaceAll(" ", ""), map.replaceAll(" ", ""));
527
528 query = "#BED(der Mann , +pe)";
529 String bed2 =
Joachim Bingel11d5b152014-02-11 21:33:47 +0000530 "{type=group, operation=position, frame=endswith, operands=[" +
531 "{type=span, key=p}," +
532 "{type=group, operation=sequence, operands=[" +
533 "{type=token, key={type=term, key=der, layer=orth, match=eq}}," +
534 "{type=token, key={type=term, key=Mann, layer=orth, match=eq}}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000535 "]}" +
Joachim Bingeleecc7652014-01-11 17:21:07 +0000536 "]}";
537 ppt = new CosmasTree(query);
538 map = ppt.getRequestMap().get("query").toString();
539 assertEquals(bed2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000540
541 query = "#BED(der Mann , sa,-pa)";
542 String bed3 =
Joachim Bingel11d5b152014-02-11 21:33:47 +0000543 "{type=group, operation=and, operands=[" +
544 "{type=group, operation=position, frame=startswith, operands=[" +
545 "{type=span, key=s}," +
546 "{type=group, operation=sequence, operands=[" +
547 "{type=token, key={type=term, key=der, layer=orth, match=eq}}," +
548 "{type=token, key={type=term, key=Mann, layer=orth, match=eq}}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000549 "]}" +
550 "]}," +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000551 "{type=group, operation=position, frame=startswith, exclude=true, operands=[" +
552 "{type=span, key=p}," +
553 "{type=group, operation=sequence, operands=[" +
554 "{type=token, key={type=term, key=der, layer=orth, match=eq}}," +
555 "{type=token, key={type=term, key=Mann, layer=orth, match=eq}}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000556 "]}" +
557 "]}" +
558 "]}";
559 ppt = new CosmasTree(query);
560 map = ppt.getRequestMap().get("query").toString();
561 assertEquals(bed3.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeld5161a12014-01-08 11:15:49 +0000562 }
563
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000564}
565