blob: 2cbdce0d4c22d772e09643fcea41854833a082a5 [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
Joachim Bingel2daf9862014-02-12 10:18:54 +000010 CosmasTree ct;
Joachim Bingelb5f7bf02014-01-07 16:36:54 +000011 String map;
12 String query;
13
Joachim Bingelb5f7bf02014-01-07 16:36:54 +000014
Joachim Bingel81812632014-02-18 08:55:22 +000015 @Test
Joachim Bingelb5f7bf02014-01-07 16:36:54 +000016 public void testContext() throws QueryException {
Joachim Bingel81812632014-02-18 08:55:22 +000017 String contextString = "http://ids-mannheim.de/ns/KorAP/json-ld/v0.1/context.jsonld";
Joachim Bingel2daf9862014-02-12 10:18:54 +000018 ct = new CosmasTree("Test");
19 assertEquals(contextString.replaceAll(" ", ""), ct.getRequestMap().get("@context").toString().replaceAll(" ", ""));
Joachim Bingelb5f7bf02014-01-07 16:36:54 +000020 }
21
22
23 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +000024 public void testSingleToken() throws QueryException {
Joachim Bingelb5f7bf02014-01-07 16:36:54 +000025 query="der";
26 String single1 =
Joachim Bingelee3b21d2014-02-12 12:34:59 +000027 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}";
Joachim Bingel2daf9862014-02-12 10:18:54 +000028 ct = new CosmasTree(query);
29 map = ct.getRequestMap().get("query").toString();
Joachim Bingelb5f7bf02014-01-07 16:36:54 +000030 assertEquals(single1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Michael Hanlbaf1a5e2014-05-15 19:51:40 +000031
Joachim Bingelb5f7bf02014-01-07 16:36:54 +000032 query="Mann";
33 String single2 =
Joachim Bingelee3b21d2014-02-12 12:34:59 +000034 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}";
Joachim Bingel2daf9862014-02-12 10:18:54 +000035 ct = new CosmasTree(query);
36 map = ct.getRequestMap().get("query").toString();
Joachim Bingelb5f7bf02014-01-07 16:36:54 +000037 assertEquals(single2.replaceAll(" ", ""), map.replaceAll(" ", ""));
38
39 query="&Mann";
40 String single3 =
Joachim Bingelee3b21d2014-02-12 12:34:59 +000041 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}";
Joachim Bingel2daf9862014-02-12 10:18:54 +000042 ct = new CosmasTree(query);
43 map = ct.getRequestMap().get("query").toString();
Joachim Bingelb5f7bf02014-01-07 16:36:54 +000044 assertEquals(single3.replaceAll(" ", ""), map.replaceAll(" ", ""));
45 }
46
Joachim Bingelba9a0ab2014-01-29 10:12:25 +000047 @Test
Joachim Bingel8c640e42014-02-07 16:20:47 +000048 public void testCaseSensitivityFlag() throws QueryException {
Joachim Bingel0207d5e2014-02-12 14:18:41 +000049 query="$deutscher";
50 String cs1 =
51 "{@type=korap:token, wrap={@type=korap:term, caseInsensitive=true, key=deutscher, layer=orth, match=match:eq}}";
52 ct = new CosmasTree(query);
53 map = ct.getRequestMap().get("query").toString();
54 assertEquals(cs1.replaceAll(" ", ""), map.replaceAll(" ", ""));
55
56 query="$deutscher Bundestag";
57 String cs2 =
58 "{@type=korap:group, operation=operation:sequence, operands=[" +
59 "{@type=korap:token, wrap={@type=korap:term, caseInsensitive=true, key=deutscher, layer=orth, match=match:eq}}," +
60 "{@type=korap:token, wrap={@type=korap:term, key=Bundestag, layer=orth, match=match:eq}}" +
61 "]}";
62 ct = new CosmasTree(query);
63 map = ct.getRequestMap().get("query").toString();
64 assertEquals(cs2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel8c640e42014-02-07 16:20:47 +000065 }
66
67 @Test
Joachim Bingelffd65e32014-01-22 14:22:57 +000068 public void testMORPH() throws QueryException {
69 query="#MORPH(V)";
70 String morph1 =
Joachim Bingel0207d5e2014-02-12 14:18:41 +000071 "{@type=korap:token, wrap={@type=korap:term, key=V, layer=pos, match=match:eq}}";
Joachim Bingel2daf9862014-02-12 10:18:54 +000072 ct = new CosmasTree(query);
73 map = ct.getRequestMap().get("query").toString();
Joachim Bingelffd65e32014-01-22 14:22:57 +000074 assertEquals(morph1.replaceAll(" ", ""), map.replaceAll(" ", ""));
75 }
76
Joachim Bingelb5f7bf02014-01-07 16:36:54 +000077 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +000078 public void testSequence() throws QueryException {
Joachim Bingelb5f7bf02014-01-07 16:36:54 +000079 query="der Mann";
80 String seq1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +000081 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +000082 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
83 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
Joachim Bingelb5f7bf02014-01-07 16:36:54 +000084 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +000085 ct = new CosmasTree(query);
86 map = ct.getRequestMap().get("query").toString();
Joachim Bingelb5f7bf02014-01-07 16:36:54 +000087 assertEquals(seq1.replaceAll(" ", ""), map.replaceAll(" ", ""));
88
Joachim Bingeld5161a12014-01-08 11:15:49 +000089 query="der Mann schläft";
90 String seq2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +000091 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +000092 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
93 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}," +
94 "{@type=korap:token, wrap={@type=korap:term, key=schläft, layer=orth, match=match:eq}}" +
Joachim Bingeld5161a12014-01-08 11:15:49 +000095 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +000096 ct = new CosmasTree(query);
97 map = ct.getRequestMap().get("query").toString();
Joachim Bingeld5161a12014-01-08 11:15:49 +000098 assertEquals(seq2.replaceAll(" ", ""), map.replaceAll(" ", ""));
99
100 query="der Mann schläft lang";
101 String seq3 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000102 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000103 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
104 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}," +
105 "{@type=korap:token, wrap={@type=korap:term, key=schläft, layer=orth, match=match:eq}}," +
106 "{@type=korap:token, wrap={@type=korap:term, key=lang, layer=orth, match=match:eq}}" +
Joachim Bingeld5161a12014-01-08 11:15:49 +0000107 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000108 ct = new CosmasTree(query);
109 map = ct.getRequestMap().get("query").toString();
Joachim Bingeld5161a12014-01-08 11:15:49 +0000110 assertEquals(seq3.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000111 }
112
113 @Test
114 public void testOPOR() throws QueryException {
115 query="Sonne oder Mond";
116 String disj1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000117 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000118 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}," +
119 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000120 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000121 ct = new CosmasTree(query);
122 map = ct.getRequestMap().get("query").toString();
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000123 assertEquals(disj1.replaceAll(" ", ""), map.replaceAll(" ", ""));
124
Joachim Bingeld5161a12014-01-08 11:15:49 +0000125 query="(Sonne scheint) oder Mond";
126 String disj2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000127 "{@type=korap:group, operation=operation:or, operands=[" +
128 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000129 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}," +
130 "{@type=korap:token, wrap={@type=korap:term, key=scheint, layer=orth, match=match:eq}}" +
Joachim Bingeld5161a12014-01-08 11:15:49 +0000131 "]}," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000132 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
Joachim Bingeld5161a12014-01-08 11:15:49 +0000133 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000134 ct = new CosmasTree(query);
135 map = ct.getRequestMap().get("query").toString();
Joachim Bingeld5161a12014-01-08 11:15:49 +0000136 assertEquals(disj2.replaceAll(" ", ""), map.replaceAll(" ", ""));
137
138 query="(Sonne scheint) oder (Mond scheint)";
139 String disj3 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000140 "{@type=korap:group, operation=operation:or, operands=[" +
141 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000142 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}," +
143 "{@type=korap:token, wrap={@type=korap:term, key=scheint, layer=orth, match=match:eq}}" +
Joachim Bingeld5161a12014-01-08 11:15:49 +0000144 "]}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000145 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000146 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}," +
147 "{@type=korap:token, wrap={@type=korap:term, key=scheint, layer=orth, match=match:eq}}" +
Joachim Bingeld5161a12014-01-08 11:15:49 +0000148 "]}" +
149 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000150 ct = new CosmasTree(query);
151 map = ct.getRequestMap().get("query").toString();
Joachim Bingeld5161a12014-01-08 11:15:49 +0000152 assertEquals(disj3.replaceAll(" ", ""), map.replaceAll(" ", ""));
153
154 }
155
156 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000157 public void testOPORAND() throws QueryException {
Joachim Bingeld5161a12014-01-08 11:15:49 +0000158 query="(Sonne oder Mond) und scheint";
159 String orand1 =
Joachim Bingelb7a59792014-02-14 13:52:29 +0000160 "{@type=korap:group, operation=operation:sequence, distances=[" +
161 "{@type=korap:distance, key=t, min=0, max=0}" +
162 "], operands=[" +
163 "{@type=korap:group, operation=operation:or, operands=[" +
164 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}," +
165 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
166 "]}," +
167 "{@type=korap:token, wrap={@type=korap:term, key=scheint, layer=orth, match=match:eq}}" +
Joachim Bingeld5161a12014-01-08 11:15:49 +0000168 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000169 ct = new CosmasTree(query);
170 map = ct.getRequestMap().get("query").toString();
Joachim Bingeld5161a12014-01-08 11:15:49 +0000171 assertEquals(orand1.replaceAll(" ", ""), map.replaceAll(" ", ""));
172
173 query="scheint und (Sonne oder Mond)";
174 String orand2 =
Joachim Bingelb7a59792014-02-14 13:52:29 +0000175 "{@type=korap:group, operation=operation:sequence, distances=[" +
176 "{@type=korap:distance, key=t, min=0, max=0}" +
177 "], operands=[" +
178 "{@type=korap:token, wrap={@type=korap:term, key=scheint, layer=orth, match=match:eq}}," +
179 "{@type=korap:group, operation=operation:or, operands=[" +
180 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}," +
181 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
Joachim Bingeld5161a12014-01-08 11:15:49 +0000182 "]}" +
183 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000184 ct = new CosmasTree(query);
185 map = ct.getRequestMap().get("query").toString();
Joachim Bingeld5161a12014-01-08 11:15:49 +0000186 assertEquals(orand2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel92f9c9c2014-06-25 15:01:17 +0000187
188 query="Regen und scheint und (Sonne oder Mond)";
189 String orand3 =
190 "{@type=korap:group, operation=operation:sequence, distances=[" +
191 "{@type=korap:distance, key=t, min=0, max=0}" +
192 "], operands=[" +
193 "{@type=korap:token, wrap={@type=korap:term, key=Regen, layer=orth, match=match:eq}}," +
194 "{@type=korap:group, operation=operation:sequence, distances=[" +
195 "{@type=korap:distance, key=t, min=0, max=0}" +
196 "], operands=[" +
197 "{@type=korap:token, wrap={@type=korap:term, key=scheint, layer=orth, match=match:eq}}," +
198 "{@type=korap:group, operation=operation:or, operands=[" +
199 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}," +
200 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
201 "]}" +
202 "]}" +
203 "]}";
204 ct = new CosmasTree(query);
205 map = ct.getRequestMap().get("query").toString();
206 assertEquals(orand3.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000207 }
208
209 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000210 public void testOPPROX() throws QueryException {
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000211 query="Sonne /+w1:4 Mond";
212 String prox1 =
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000213 "{@type=korap:group, operation=operation:sequence, " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000214 "operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000215 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}," +
216 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000217 "], inOrder=true, " +
218 "distances=[" +
219 "{@type=korap:distance, key=w, min=1, max=4}" +
Joachim Bingel89cceac2014-01-08 15:51:08 +0000220 "]" +
221 "}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000222 ct = new CosmasTree(query);
223 map = ct.getRequestMap().get("query").toString();
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000224 assertEquals(prox1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel89cceac2014-01-08 15:51:08 +0000225
226 query="Sonne /+w1:4,s0,p1:3 Mond";
227 String prox2 =
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000228 "{@type=korap:group, operation=operation:sequence, " +
229 "operands=[" +
230 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}," +
231 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
232 "], inOrder=true, " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000233 "distances=[" +
Joachim Bingelcd7b7252014-02-13 08:49:14 +0000234 "{@type=korap:distance, key=w, min=1, max=4}," +
235 "{@type=korap:distance, key=s, min=0, max=0}," +
236 "{@type=korap:distance, key=p, min=1, max=3}" +
Joachim Bingel89cceac2014-01-08 15:51:08 +0000237 "]" +
238 "}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000239 ct = new CosmasTree(query);
240 map = ct.getRequestMap().get("query").toString();
Joachim Bingel89cceac2014-01-08 15:51:08 +0000241 assertEquals(prox2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel87480d02014-01-17 14:07:46 +0000242
243 query="Sonne %+w1:4,s0,p1:3 Mond";
244 String prox3 =
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000245 "{@type=korap:group, operation=operation:sequence, " +
246 "operands=[" +
247 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}," +
248 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
249 "], inOrder=true, " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000250 "distances=[" +
Joachim Bingelcd7b7252014-02-13 08:49:14 +0000251 "{@type=korap:distance, key=w, min=1, max=4, exclude=true}," +
252 "{@type=korap:distance, key=s, min=0, max=0, exclude=true}," +
253 "{@type=korap:distance, key=p, min=1, max=3, exclude=true}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000254 "]" +
255 "}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000256 ct = new CosmasTree(query);
257 map = ct.getRequestMap().get("query").toString();
Joachim Bingel87480d02014-01-17 14:07:46 +0000258 assertEquals(prox3.replaceAll(" ", ""), map.replaceAll(" ", ""));
259
260 query="Sonne /+w4 Mond";
261 String prox4 =
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000262 "{@type=korap:group, operation=operation:sequence, " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000263 "operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000264 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}," +
265 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000266 "], inOrder=true, " +
267 "distances=[" +
268 "{@type=korap:distance, key=w, min=0, max=4}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000269 "]" +
270 "}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000271 ct = new CosmasTree(query);
272 map = ct.getRequestMap().get("query").toString();
Joachim Bingel87480d02014-01-17 14:07:46 +0000273 assertEquals(prox4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000274
275 query="Sonne /-w4 Mond";
276 String prox5 =
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000277 "{@type=korap:group, operation=operation:sequence, " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000278 "operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000279 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}," +
280 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000281 "], inOrder=true, " +
282 "distances=[" +
283 "{@type=korap:distance, key=w, min=0, max=4}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000284 "]" +
285 "}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000286 ct = new CosmasTree(query);
287 map = ct.getRequestMap().get("query").toString();
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000288 assertEquals(prox5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000289
290 query="Sonne /w4 Mond";
291 String prox6 =
292 "{@type=korap:group, operation=operation:sequence, " +
293 "operands=[" +
294 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}," +
295 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
296 "], inOrder=false, " +
297 "distances=[" +
298 "{@type=korap:distance, key=w, min=0, max=4}" +
299 "]" +
300 "}";
301 ct = new CosmasTree(query);
302 map = ct.getRequestMap().get("query").toString();
303 assertEquals(prox6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000304 }
305
306 @Test
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000307 public void testOPPROXNested() throws QueryException {
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000308 query="Sonne /-w4 Mond /+w2 Sterne";
309 String prox6 =
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000310 "{@type=korap:group, operation=operation:sequence, " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000311 "operands=[" +
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000312 "{@type=korap:group, operation=operation:sequence, " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000313 "operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000314 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}," +
315 "{@type=korap:token, wrap={@type=korap:term, key=Sterne, layer=orth, match=match:eq}}" +
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000316 "], inOrder=true, " +
317 "distances=[" +
318 "{@type=korap:distance, key=w, min=0, max=2}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000319 "]}," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000320 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000321 "], inOrder=true, " +
322 "distances=[" +
323 "{@type=korap:distance, key=w, min=0, max=4}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000324 "]" +
325 "}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000326 ct = new CosmasTree(query);
327 map = ct.getRequestMap().get("query").toString();
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000328 assertEquals(prox6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000329 }
330
331 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000332 public void testOPIN() throws QueryException {
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000333 query="wegen #IN <s>";
Joachim Bingel3a9f7932014-01-07 17:11:31 +0000334 String opin1 =
Joachim Bingel0de1b412014-07-02 14:51:48 +0000335 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000336 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
337 "{@type=korap:span, key=s}," +
338 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000339 "{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
Joachim Bingeleecc7652014-01-11 17:21:07 +0000340 "]}" +
341 "]}" +
Joachim Bingeld5161a12014-01-08 11:15:49 +0000342 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000343 ct = new CosmasTree(query);
344 map = ct.getRequestMap().get("query").toString();
Joachim Bingeld5161a12014-01-08 11:15:49 +0000345 assertEquals(opin1.replaceAll(" ", ""), map.replaceAll(" ", ""));
346
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000347 query="wegen #IN(L) <s>"; //wrap an *excluded* matches-position around a startwith-position constraint in order to
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000348 String opin2 =
Joachim Bingel0de1b412014-07-02 14:51:48 +0000349 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000350 "{@type=korap:group, operation=operation:position, frame=frame:matches, operands=[" +
351 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
352 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
353 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
354 "{@type=korap:span, key=s}" +
355 "]}," +
356 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
357 "{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
358 "]}" +
359 "]}" +
360 "]}," +
361 "{@type=korap:reference, operation=operation:focus, classRef=[2]}" +
362 "], exclude=true}" +
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000363 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000364 ct = new CosmasTree(query);
365 map = ct.getRequestMap().get("query").toString();
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000366 assertEquals(opin2.replaceAll(" ", ""), map.replaceAll(" ", ""));
367
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000368
369 query="wegen #IN(F) <s>";
370 String opin3=
371 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
372 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
373 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
374 "{@type=korap:group, operation=operation:position, frame=frame:endswith, operands=[" +
375 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
376 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
377 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
378 "{@type=korap:span, key=s}" +
379 "]}," +
380 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
381 "{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
382 "]}" +
383 "]}" +
384 "]}," +
385 "{@type=korap:reference, operation=operation:focus, classRef=[2]}" +
386 "]}" +
387 "]}," +
388 "{@type=korap:reference, operation=operation:focus, classRef=[2]}" +
389 "]}" +
390 "]}" +
391 "";
392 ct = new CosmasTree(query);
393 map = ct.getRequestMap().get("query").toString();
394 assertEquals(opin3.replaceAll(" ", ""), map.replaceAll(" ", ""));
395
396 query="wegen #IN(FI) <s>";
397 String opin4=
398 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
399 "{@type=korap:group, operation=operation:position, frame=frame:matches, operands=[" +
400 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
401 "{@type=korap:group, operation=operation:position, frame=frame:endswith, operands=[" +
402 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
403 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
404 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
405 "{@type=korap:span, key=s}" +
406 "]}," +
407 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
408 "{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
409 "]}" +
410 "]}" +
411 "]}," +
412 "{@type=korap:reference, operation=operation:focus, classRef=[2]}" +
413 "]}" +
414 "]}," +
415 "{@type=korap:reference, operation=operation:focus, classRef=[2]}" +
416 "], exclude=true}" +
417 "]}" +
418 "";
419 ct = new CosmasTree(query);
420 map = ct.getRequestMap().get("query").toString();
421 assertEquals(opin4.replaceAll(" ", ""), map.replaceAll(" ", ""));
422
423 query="wegen #IN(FE) <s>";
424 String opin5=
425 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
426 "{@type=korap:group, operation=operation:position, frame=frame:matches, operands=[" +
427 "{@type=korap:span, key=s}," +
428 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
429 "{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
430 "]}" +
431 "]}" +
432 "]}" +
433 "";
434 ct = new CosmasTree(query);
435 map = ct.getRequestMap().get("query").toString();
436 assertEquals(opin5.replaceAll(" ", ""), map.replaceAll(" ", ""));
437
Joachim Bingel87480d02014-01-17 14:07:46 +0000438 query="wegen #IN(%, L) <s>";
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000439 String opin6 =
Joachim Bingel0de1b412014-07-02 14:51:48 +0000440 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
441 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000442 "{@type=korap:span, key=s}," +
443 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000444 "{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000445 "]}" +
Joachim Bingel0de1b412014-07-02 14:51:48 +0000446 "], exclude=true}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000447 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000448 ct = new CosmasTree(query);
449 map = ct.getRequestMap().get("query").toString();
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000450 assertEquals(opin6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel87480d02014-01-17 14:07:46 +0000451
452 query="wegen #IN('FE,ALL,%,MIN') <s>";
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000453 String opin7 =
Joachim Bingel0de1b412014-07-02 14:51:48 +0000454 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
455 "{@type=korap:group, operation=operation:position, frame=frame:matches, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000456 "{@type=korap:span, key=s}," +
457 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000458 "{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000459 "]}" +
Joachim Bingel0de1b412014-07-02 14:51:48 +0000460 "], range=all, exclude=true, grouping=false}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000461 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000462 ct = new CosmasTree(query);
463 map = ct.getRequestMap().get("query").toString();
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000464 assertEquals(opin7.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeld5161a12014-01-08 11:15:49 +0000465 }
466
467 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000468 public void testOPOV() throws QueryException {
Joachim Bingeld5161a12014-01-08 11:15:49 +0000469 query="wegen #OV <s>";
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000470 String opov1 =
Joachim Bingel0de1b412014-07-02 14:51:48 +0000471 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000472 "{@type=korap:group, operation=operation:position, frame=frame:overlaps, operands=[" +
473 "{@type=korap:span, key=s}," +
474 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000475 "{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000476 "]}" +
477 "]}" +
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000478 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000479 ct = new CosmasTree(query);
480 map = ct.getRequestMap().get("query").toString();
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000481 assertEquals(opov1.replaceAll(" ", ""), map.replaceAll(" ", ""));
482
483 query="wegen #OV(L) <s>";
484 String opov2 =
Joachim Bingel0de1b412014-07-02 14:51:48 +0000485 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000486 "{@type=korap:group, operation=operation:position, frame=frame:overlapsLeft, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000487 "{@type=korap:span, key=s}," +
488 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000489 "{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000490 "]}" +
491 "]}" +
492 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000493 ct = new CosmasTree(query);
494 map = ct.getRequestMap().get("query").toString();
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000495 assertEquals(opov2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000496
497 query="wegen #OV(F) <s>";
498 String opov3=
499 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
500 "{@type=korap:group, operation=operation:position, frame=frame:endswith, operands=[" +
501 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
502 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
503 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
504 "{@type=korap:span, key=s}" +
505 "]}," +
506 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
507 "{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
508 "]}" +
509 "]}" +
510 "]}," +
511 "{@type=korap:reference, operation=operation:focus, classRef=[2]}" +
512 "]}" +
513 "]}" +
514 "";
515 ct = new CosmasTree(query);
516 map = ct.getRequestMap().get("query").toString();
517 assertEquals(opov3.replaceAll(" ", ""), map.replaceAll(" ", ""));
518
519 query="wegen #OV(FI) <s>";
520 String opov4=
521 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
522 "{@type=korap:group, operation=operation:position, frame=frame:matches, operands=[" +
523 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
524 "{@type=korap:group, operation=operation:position, frame=frame:endswith, operands=[" +
525 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
526 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
527 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
528 "{@type=korap:span, key=s}" +
529 "]}," +
530 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
531 "{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
532 "]}" +
533 "]}" +
534 "]}," +
535 "{@type=korap:reference, operation=operation:focus, classRef=[2]}" +
536 "]}" +
537 "]}," +
538 "{@type=korap:reference, operation=operation:focus, classRef=[2]}" +
539 "], exclude=true}" +
540 "]}" +
541 "";
542 ct = new CosmasTree(query);
543 map = ct.getRequestMap().get("query").toString();
544 assertEquals(opov4.replaceAll(" ", ""), map.replaceAll(" ", ""));
545
546 query="wegen #OV(FE) <s>";
547 String opov5=
548 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
549 "{@type=korap:group, operation=operation:position, frame=frame:matches, operands=[" +
550 "{@type=korap:span, key=s}," +
551 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
552 "{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
553 "]}" +
554 "]}" +
555 "]}" +
556 "";
557 ct = new CosmasTree(query);
558 map = ct.getRequestMap().get("query").toString();
559 assertEquals(opov5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000560 }
561
562 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000563 public void testOPNOT() throws QueryException {
Joachim Bingel3a9f7932014-01-07 17:11:31 +0000564 query="Sonne nicht Mond";
565 String opnot1 =
Joachim Bingelb7a59792014-02-14 13:52:29 +0000566 "{@type=korap:group, operation=operation:sequence, distances=[" +
567 "{@type=korap:distance, key=t, min=0, max=0, exclude=true}" +
568 "], operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000569 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}," +
570 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
Joachim Bingel3a9f7932014-01-07 17:11:31 +0000571 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000572 ct = new CosmasTree(query);
573 map = ct.getRequestMap().get("query").toString();
Joachim Bingel3a9f7932014-01-07 17:11:31 +0000574 assertEquals(opnot1.replaceAll(" ", ""), map.replaceAll(" ", ""));
575 }
576
577 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000578 public void testBEG_END() throws QueryException {
Joachim Bingel3a9f7932014-01-07 17:11:31 +0000579 // BEG and END operators
580 // http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/syntax/links.html
581 // http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/syntax/rechts.html
582 // http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/thematische-bsp/bsp-satzlaenge.html
Joachim Bingel87480d02014-01-17 14:07:46 +0000583 query="#BEG(der /w3:5 Mann)";
584 String beg1 =
Joachim Bingel0de1b412014-07-02 14:51:48 +0000585 "{@type=korap:reference, operation=operation:focus, spanRef=[0,1], operands=[" +
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000586 "{@type=korap:group, operation=operation:sequence," +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000587 "operands = [" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000588 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
589 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000590 "], inOrder=false, distances=[" +
591 "{@type=korap:distance, key=w, min=3, max=5}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000592 "]}" +
593 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000594 ct = new CosmasTree(query);
595 map = ct.getRequestMap().get("query").toString();
Joachim Bingel87480d02014-01-17 14:07:46 +0000596 assertEquals(beg1.replaceAll(" ", ""), map.replaceAll(" ", ""));
597
598 query="#BEG(der /w3:5 Mann) /+w10 kommt"; // nesting #BEG() in a distance group
599 String beg2 =
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000600 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0de1b412014-07-02 14:51:48 +0000601 "{@type=korap:reference, operation=operation:focus, spanRef=[0,1], operands=[" +
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000602 "{@type=korap:group, operation=operation:sequence," +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000603 "operands = [" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000604 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
605 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000606 "], inOrder=false, distances=[" +
607 "{@type=korap:distance, key=w, min=3, max=5}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000608 "]}" +
609 "]}," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000610 "{@type=korap:token, wrap={@type=korap:term, key=kommt, layer=orth, match=match:eq}}" +
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000611 "], inOrder=true, distances=[" +
612 "{@type=korap:distance, key=w, min=0, max=10}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000613 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000614 ct = new CosmasTree(query);
615 map = ct.getRequestMap().get("query").toString();
Joachim Bingel87480d02014-01-17 14:07:46 +0000616 assertEquals(beg2.replaceAll(" ", ""), map.replaceAll(" ", ""));
617
618 query="#END(der /w3:5 Mann)";
619 String end1 =
Joachim Bingel0de1b412014-07-02 14:51:48 +0000620 "{@type=korap:reference, operation=operation:focus, spanRef=[-1,1], operands=[" +
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000621 "{@type=korap:group, operation=operation:sequence, " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000622 "operands = [" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000623 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
624 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000625 "], inOrder=false, distances=[" +
626 "{@type=korap:distance, key=w, min=3, max=5}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000627 "]}" +
628 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000629 ct = new CosmasTree(query);
630 map = ct.getRequestMap().get("query").toString();
Joachim Bingel87480d02014-01-17 14:07:46 +0000631 assertEquals(end1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000632 }
Joachim Bingeld5161a12014-01-08 11:15:49 +0000633
634
635 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000636 public void testELEM() throws QueryException {
Joachim Bingeld5161a12014-01-08 11:15:49 +0000637 // http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/syntax/elem.html
Joachim Bingeleecc7652014-01-11 17:21:07 +0000638 query="#ELEM(S)";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000639 String elem1 = "{@type=korap:span, key=s}";
640 ct = new CosmasTree(query);
641 map = ct.getRequestMap().get("query").toString();
Joachim Bingeleecc7652014-01-11 17:21:07 +0000642 assertEquals(elem1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel402c6e12014-05-08 17:09:06 +0000643
644 query="#ELEM(W ANA=N)";
645 String elem2 =
646 "{@type=korap:span, key=w, attr=" +
647 "{@type=korap:termGroup, relation=relation:and, operands=[" +
648 "{@type=korap:term, layer=pos, key=N, match=match:eq}" +
649 "]}" +
650 "}";
651 ct = new CosmasTree(query);
652 map = ct.getRequestMap().get("query").toString();
653 assertEquals(elem2.replaceAll(" ", ""), map.replaceAll(" ", ""));
654
655 query="#ELEM(W ANA != 'N V')";
656 String elem3 =
657 "{@type=korap:span, key=w, attr=" +
658 "{@type=korap:termGroup, relation=relation:and, operands=[" +
Joachim Bingelb674cca2014-05-09 14:00:58 +0000659 "{@type=korap:term, layer=pos, key=N, match=match:ne}," +
660 "{@type=korap:term, layer=pos, key=V, match=match:ne}" +
Joachim Bingel402c6e12014-05-08 17:09:06 +0000661 "]}" +
662 "}";
663 ct = new CosmasTree(query);
664 map = ct.getRequestMap().get("query").toString();
665 assertEquals(elem3.replaceAll(" ", ""), map.replaceAll(" ", ""));
666
Joachim Bingelb674cca2014-05-09 14:00:58 +0000667 query="#ELEM(W ANA != 'N A V' Genre = Sport)";
Joachim Bingel402c6e12014-05-08 17:09:06 +0000668 String elem4 =
669 "{@type=korap:span, key=w, attr=" +
670 "{@type=korap:termGroup, relation=relation:and, operands=[" +
671 "{@type=korap:termGroup, relation=relation:and, operands=[" +
Joachim Bingelb674cca2014-05-09 14:00:58 +0000672 "{@type=korap:term, layer=pos, key=N, match=match:ne}," +
673 "{@type=korap:term, layer=pos, key=A, match=match:ne}," +
674 "{@type=korap:term, layer=pos, key=V, match=match:ne}" +
675 "]}," +
Joachim Bingel402c6e12014-05-08 17:09:06 +0000676 "{@type=korap:term, layer=Genre, key=Sport, match=match:eq}" +
677 "]}" +
678 "}";
679 ct = new CosmasTree(query);
680 map = ct.getRequestMap().get("query").toString();
681 assertEquals(elem4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb674cca2014-05-09 14:00:58 +0000682
683 query="#ELEM(W ANA != 'N V' Genre != 'Sport Politik')";
684 String elem5 =
685 "{@type=korap:span, key=w, attr=" +
686 "{@type=korap:termGroup, relation=relation:and, operands=[" +
687 "{@type=korap:termGroup, relation=relation:and, operands=[" +
688 "{@type=korap:term, layer=pos, key=N, match=match:ne}," +
689 "{@type=korap:term, layer=pos, key=V, match=match:ne}" +
690 "]}," +
691 "{@type=korap:termGroup, relation=relation:and, operands=[" +
692 "{@type=korap:term, layer=Genre, key=Sport, match=match:ne}," +
693 "{@type=korap:term, layer=Genre, key=Politik, match=match:ne}" +
694 "]}" +
695 "]}" +
696 "}";
697 ct = new CosmasTree(query);
698 map = ct.getRequestMap().get("query").toString();
699 assertEquals(elem5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeld5161a12014-01-08 11:15:49 +0000700 }
701
702 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000703 public void testOPALL() throws QueryException {
Joachim Bingel89cceac2014-01-08 15:51:08 +0000704 query="#ALL(gehen /w1:10 voran)";
Joachim Bingele98d0882014-01-21 12:58:54 +0000705 String all1 =
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000706 "{@type=korap:group, operation=operation:sequence, " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000707 "operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000708 "{@type=korap:token, wrap={@type=korap:term, key=gehen, layer=orth, match=match:eq}}," +
709 "{@type=korap:token, wrap={@type=korap:term, key=voran, layer=orth, match=match:eq}}" +
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000710 "], inOrder=false, " +
711 "distances=[" +
712 "{@type=korap:distance, key=w, min=1, max=10}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000713 "]" +
714 "}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000715 ct = new CosmasTree(query);
716 map = ct.getRequestMap().get("query").toString();
Joachim Bingel89cceac2014-01-08 15:51:08 +0000717 assertEquals(all1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeld5161a12014-01-08 11:15:49 +0000718 }
719
Joachim Bingel36233b52014-02-13 10:48:24 +0000720 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000721 public void testOPNHIT() throws QueryException {
Joachim Bingel89cceac2014-01-08 15:51:08 +0000722 query="#NHIT(gehen /w1:10 voran)";
723 String nhit1 =
Joachim Bingel0de1b412014-07-02 14:51:48 +0000724 "{@type=korap:reference, operation=operation:focus, classRef=[1,2], classRefOp=classRefOp:intersection, operands=[" +
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000725 "{@type=korap:group, operation=operation:sequence, " +
Joachim Bingel36233b52014-02-13 10:48:24 +0000726 "operands=[" +
727 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
728 "{@type=korap:token, wrap={@type=korap:term, key=gehen, layer=orth, match=match:eq}}" +
729 "]}," +
730 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
731 "{@type=korap:token, wrap={@type=korap:term, key=voran, layer=orth, match=match:eq}}" +
732 "]}" +
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000733 "], inOrder=false, " +
734 "distances=[" +
735 "{@type=korap:distance, key=w, min=1, max=10}" +
Joachim Bingel36233b52014-02-13 10:48:24 +0000736 "]" +
737 "}" +
738 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000739 ct = new CosmasTree(query);
740 map = ct.getRequestMap().get("query").toString();
Joachim Bingel89cceac2014-01-08 15:51:08 +0000741 assertEquals(nhit1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeld5161a12014-01-08 11:15:49 +0000742 }
743
744 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000745 public void testOPBED() throws QueryException {
Joachim Bingeleecc7652014-01-11 17:21:07 +0000746 query = "#BED(der , sa)";
747 String bed1 =
Joachim Bingel0de1b412014-07-02 14:51:48 +0000748 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands= [" +
Joachim Bingelcd7b7252014-02-13 08:49:14 +0000749 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
750 "{@type=korap:span, key=s}," +
751 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
752 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}" +
753 "]}" +
754 "]}" +
Joachim Bingeleecc7652014-01-11 17:21:07 +0000755 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000756 ct = new CosmasTree(query);
757 map = ct.getRequestMap().get("query").toString();
Joachim Bingeleecc7652014-01-11 17:21:07 +0000758 assertEquals(bed1.replaceAll(" ", ""), map.replaceAll(" ", ""));
759
760 query = "#BED(der Mann , +pe)";
761 String bed2 =
Joachim Bingel0de1b412014-07-02 14:51:48 +0000762 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands= [" +
Joachim Bingel36233b52014-02-13 10:48:24 +0000763 "{@type=korap:group, operation=operation:position, frame=frame:endswith, operands=[" +
764 "{@type=korap:span, key=p}," +
765 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
766 "{@type=korap:group, operation=operation:sequence, operands=[" +
767 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
768 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
769 "]}" +
770 "]}" +
771 "]}" +
772 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000773 ct = new CosmasTree(query);
774 map = ct.getRequestMap().get("query").toString();
Joachim Bingel36233b52014-02-13 10:48:24 +0000775 assertEquals(bed2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000776
777 query = "#BED(der Mann , sa,-pa)";
778 String bed3 =
Joachim Bingel0de1b412014-07-02 14:51:48 +0000779 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingel36233b52014-02-13 10:48:24 +0000780 "{@type=korap:group, operation=operation:sequence, distances=[" +
781 "{@type=korap:distance, key=w, min=0, max=0}" +
782 "], operands=[" +
783 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
784 "{@type=korap:span, key=s}," +
785 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
786 "{@type=korap:group, operation=operation:sequence, operands=[" +
787 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
788 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
789 "]}" +
790 "]}" +
791 "]}," +
792 "{@type=korap:group, operation=operation:position, frame=frame:startswith, exclude=true, operands=[" +
793 "{@type=korap:span, key=p}," +
Joachim Bingel402c6e12014-05-08 17:09:06 +0000794 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
Joachim Bingel36233b52014-02-13 10:48:24 +0000795 "{@type=korap:group, operation=operation:sequence, operands=[" +
796 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
797 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
798 "]}" +
799 "]}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000800 "]}" +
801 "]}" +
802 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000803 ct = new CosmasTree(query);
804 map = ct.getRequestMap().get("query").toString();
Joachim Bingel36233b52014-02-13 10:48:24 +0000805 assertEquals(bed3.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeld5161a12014-01-08 11:15:49 +0000806 }
807
Joachim Bingel81812632014-02-18 08:55:22 +0000808 @Test
809 public void testColonSeparatedConditions() throws QueryException {
810
811 query = "Der:sa";
812 String col1 =
Joachim Bingel0de1b412014-07-02 14:51:48 +0000813 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingel81812632014-02-18 08:55:22 +0000814 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
815 "{@type=korap:span, key=s}," +
816 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
817 "{@type=korap:token, wrap={@type=korap:term, key=Der, layer=orth, match=match:eq}}" +
818 "]}" +
819 "]}" +
820 "]}";
821 ct = new CosmasTree(query);
822 map = ct.getRequestMap().get("query").toString();
823 assertEquals(col1.replaceAll(" ", ""), map.replaceAll(" ", ""));
824
825 query = "Mann:sa,-pa,+te)";
826 String col2 =
Joachim Bingel0de1b412014-07-02 14:51:48 +0000827 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingel81812632014-02-18 08:55:22 +0000828 "{@type=korap:group, operation=operation:sequence, distances=[" +
829 "{@type=korap:distance, key=w, min=0, max=0}" +
830 "], operands=[" +
831 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
832 "{@type=korap:span, key=s}," +
833 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
834 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
835 "]}" +
836 "]}," +
837 "{@type=korap:group, operation=operation:position, frame=frame:startswith, exclude=true, operands=[" +
838 "{@type=korap:span, key=p}," +
Joachim Bingel402c6e12014-05-08 17:09:06 +0000839 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
Joachim Bingel81812632014-02-18 08:55:22 +0000840 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
841 "]}" +
842 "]}," +
843 "{@type=korap:group, operation=operation:position, frame=frame:endswith, operands=[" +
844 "{@type=korap:span, key=t}," +
Joachim Bingel402c6e12014-05-08 17:09:06 +0000845 "{@type=korap:group, operation=operation:class, class=3, operands=[" +
Joachim Bingel81812632014-02-18 08:55:22 +0000846 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
847 "]}" +
848 "]}" +
849 "]}" +
850 "]}";
851 ct = new CosmasTree(query);
852 map = ct.getRequestMap().get("query").toString();
853 assertEquals(col2.replaceAll(" ", ""), map.replaceAll(" ", ""));
854 }
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000855}
856