blob: fe9a7dcca74200db5c9121d845e0f0ef0ce37a4d [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;
Joachim Bingel37a803f2014-07-28 14:21:44 +000013 String expected;
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 Bingelfbc88792014-09-17 11:11:52 +0000213 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
214 "{@type=korap:group, operation=operation:sequence, " +
215 "operands=[" +
216 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
217 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
218 "]}," +
219 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
220 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
221 "]}" +
222 "], inOrder=true, " +
223 "distances=[" +
224 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1, max=4}, min=1, max=4}" +
225 "]" +
226 "}" +
227 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000228 ct = new CosmasTree(query);
229 map = ct.getRequestMap().get("query").toString();
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000230 assertEquals(prox1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel89cceac2014-01-08 15:51:08 +0000231
232 query="Sonne /+w1:4,s0,p1:3 Mond";
233 String prox2 =
Joachim Bingelfbc88792014-09-17 11:11:52 +0000234 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000235 "{@type=korap:group, operation=operation:sequence, " +
236 "operands=[" +
Joachim Bingelfbc88792014-09-17 11:11:52 +0000237 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
238 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
239 "]}," +
240 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
241 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
242 "]}" +
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000243 "], inOrder=true, " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000244 "distances=[" +
Joachim Bingel03dfd952014-07-30 08:08:53 +0000245 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1, max=4}, min=1, max=4}," +
246 "{@type=korap:distance, key=s, boundary={@type=korap:boundary, min=0, max=0}, min=0, max=0}," +
247 "{@type=korap:distance, key=p, boundary={@type=korap:boundary, min=1, max=3}, min=1, max=3}" +
Joachim Bingel89cceac2014-01-08 15:51:08 +0000248 "]" +
Joachim Bingelfbc88792014-09-17 11:11:52 +0000249 "}" +
250 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000251 ct = new CosmasTree(query);
252 map = ct.getRequestMap().get("query").toString();
Joachim Bingel89cceac2014-01-08 15:51:08 +0000253 assertEquals(prox2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel87480d02014-01-17 14:07:46 +0000254
255 query="Sonne %+w1:4,s0,p1:3 Mond";
256 String prox3 =
Joachim Bingelfbc88792014-09-17 11:11:52 +0000257 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
258 "{@type=korap:group, operation=operation:sequence, " +
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000259 "operands=[" +
Joachim Bingelfbc88792014-09-17 11:11:52 +0000260 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
261 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
262 "]}," +
263 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
264 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
265 "]}" +
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000266 "], inOrder=true, " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000267 "distances=[" +
Joachim Bingel03dfd952014-07-30 08:08:53 +0000268 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1, max=4}, min=1, max=4, exclude=true}," +
269 "{@type=korap:distance, key=s, boundary={@type=korap:boundary, min=0, max=0}, min=0, max=0, exclude=true}," +
270 "{@type=korap:distance, key=p, boundary={@type=korap:boundary, min=1, max=3}, min=1, max=3, exclude=true}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000271 "]" +
Joachim Bingelfbc88792014-09-17 11:11:52 +0000272 "}" +
273 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000274 ct = new CosmasTree(query);
275 map = ct.getRequestMap().get("query").toString();
Joachim Bingel03dfd952014-07-30 08:08:53 +0000276// assertEquals(prox3.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel87480d02014-01-17 14:07:46 +0000277
278 query="Sonne /+w4 Mond";
279 String prox4 =
Joachim Bingel37a803f2014-07-28 14:21:44 +0000280 "{@type=korap:group, operation=operation:or, operands=[" +
281 "{@type=korap:group, operation=operation:position, frame=frame:overlaps, operands=[" +
Joachim Bingelfbc88792014-09-17 11:11:52 +0000282 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
283 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
284 "]}," +
285 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
Joachim Bingel37a803f2014-07-28 14:21:44 +0000286 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
Joachim Bingelfbc88792014-09-17 11:11:52 +0000287 "]}" +
288 "]}," +
289 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
290 "{@type=korap:group, operation=operation:sequence, " +
291 "operands=[" +
292 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
293 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
294 "]}," +
295 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
296 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
297 "]}" +
298 "], inOrder=true, " +
299 "distances=[" +
300 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1, max=4}, min=1, max=4}" +
301 "]" +
302 "}" +
303 "]}" +
Joachim Bingel37a803f2014-07-28 14:21:44 +0000304 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000305 ct = new CosmasTree(query);
306 map = ct.getRequestMap().get("query").toString();
Joachim Bingel87480d02014-01-17 14:07:46 +0000307 assertEquals(prox4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000308
309 query="Sonne /-w4 Mond";
310 String prox5 =
Joachim Bingel37a803f2014-07-28 14:21:44 +0000311 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingelfbc88792014-09-17 11:11:52 +0000312 "{@type=korap:group, operation=operation:position, frame=frame:overlaps, operands=[" +
313 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
314 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
Joachim Bingel37a803f2014-07-28 14:21:44 +0000315 "]}," +
Joachim Bingelfbc88792014-09-17 11:11:52 +0000316 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
317 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
318 "]}" +
319 "]}," +
320 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
Joachim Bingel37a803f2014-07-28 14:21:44 +0000321 "{@type=korap:group, operation=operation:sequence, " +
322 "operands=[" +
Joachim Bingelfbc88792014-09-17 11:11:52 +0000323 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
324 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
325 "]}," +
326 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
327 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
328 "]}" +
Joachim Bingel37a803f2014-07-28 14:21:44 +0000329 "], inOrder=true, " +
330 "distances=[" +
Joachim Bingel03dfd952014-07-30 08:08:53 +0000331 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1, max=4}, min=1, max=4}" +
Joachim Bingel37a803f2014-07-28 14:21:44 +0000332 "]" +
333 "}" +
Joachim Bingelfbc88792014-09-17 11:11:52 +0000334 "]}" +
335 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000336 ct = new CosmasTree(query);
337 map = ct.getRequestMap().get("query").toString();
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000338 assertEquals(prox5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000339
340 query="Sonne /w4 Mond";
341 String prox6 =
Joachim Bingel37a803f2014-07-28 14:21:44 +0000342 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingelfbc88792014-09-17 11:11:52 +0000343 "{@type=korap:group, operation=operation:position, frame=frame:overlaps, operands=[" +
344 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
345 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
Joachim Bingel37a803f2014-07-28 14:21:44 +0000346 "]}," +
Joachim Bingelfbc88792014-09-17 11:11:52 +0000347 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
348 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
349 "]}" +
350 "]}," +
351 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000352 "{@type=korap:group, operation=operation:sequence, " +
353 "operands=[" +
Joachim Bingelfbc88792014-09-17 11:11:52 +0000354 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
355 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
356 "]}," +
357 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
358 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
359 "]}" +
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000360 "], inOrder=false, " +
361 "distances=[" +
Joachim Bingel03dfd952014-07-30 08:08:53 +0000362 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1, max=4}, min=1, max=4}" +
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000363 "]" +
Joachim Bingel37a803f2014-07-28 14:21:44 +0000364 "}" +
Joachim Bingelfbc88792014-09-17 11:11:52 +0000365 "]}" +
366 "]}";
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000367 ct = new CosmasTree(query);
368 map = ct.getRequestMap().get("query").toString();
369 assertEquals(prox6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000370 }
371
372 @Test
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000373 public void testOPPROXNested() throws QueryException {
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000374 query="Sonne /-w4 Mond /+w2 Sterne";
Joachim Bingel37a803f2014-07-28 14:21:44 +0000375
376 String mondsterne =
377 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}," +
378 "{@type=korap:token, wrap={@type=korap:term, key=Sterne, layer=orth, match=match:eq}}" ;
Joachim Bingelfbc88792014-09-17 11:11:52 +0000379
380 String mondsterneClasses =
381 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
382 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
383 "]}," +
384 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
385 "{@type=korap:token, wrap={@type=korap:term, key=Sterne, layer=orth, match=match:eq}}" +
386 "]}";
Joachim Bingel37a803f2014-07-28 14:21:44 +0000387 String mondsterneSeq =
388 "{@type=korap:group, operation=operation:sequence, operands=[" +
389 mondsterne +
390 "], inOrder=true, distances=[" +
Joachim Bingel03dfd952014-07-30 08:08:53 +0000391 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1, max=2}, min=1, max=2}" +
Joachim Bingel37a803f2014-07-28 14:21:44 +0000392 "]}" ;
Joachim Bingelfbc88792014-09-17 11:11:52 +0000393 String mondsterneClassesSeq =
394 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
395 "{@type=korap:group, operation=operation:sequence, operands=[" +
396 mondsterneClasses +
397 "], inOrder=true, distances=[" +
398 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1, max=2}, min=1, max=2}" +
399 "]}" +
400 "]}" ;
Joachim Bingel37a803f2014-07-28 14:21:44 +0000401 String mondsterneOv =
402 "{@type=korap:group, operation=operation:position, frame=frame:overlaps, operands=[" +
403 mondsterne +
404 "]}";
Joachim Bingelfbc88792014-09-17 11:11:52 +0000405 String mondsterneClassesOv =
406 "{@type=korap:group, operation=operation:position, frame=frame:overlaps, operands=[" +
407 mondsterneClasses +
408 "]}";
Joachim Bingel37a803f2014-07-28 14:21:44 +0000409 String mondsterneAll =
410 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingelfbc88792014-09-17 11:11:52 +0000411 mondsterneOv + "," + mondsterneClassesSeq +
Joachim Bingel37a803f2014-07-28 14:21:44 +0000412 "]}";
Joachim Bingelfbc88792014-09-17 11:11:52 +0000413 String mondsterneAllClasses =
414 "{@type=korap:group, operation=operation:or, operands=[" +
415 mondsterneClassesOv + "," + mondsterneClassesSeq +
416 "]}";
417
418
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000419 String prox6 =
Joachim Bingel37a803f2014-07-28 14:21:44 +0000420 "{@type=korap:group, operation=operation:or, operands=[" +
421 "{@type=korap:group, operation=operation:position, frame=frame:overlaps, operands=[" +
Joachim Bingelfbc88792014-09-17 11:11:52 +0000422 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
423 mondsterneAllClasses +
424 "]}," +
425 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
Joachim Bingel37a803f2014-07-28 14:21:44 +0000426 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
Joachim Bingelfbc88792014-09-17 11:11:52 +0000427 "]}" +
428 "]}," +
429 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
430 "{@type=korap:group, operation=operation:sequence, " +
431 "operands=[" +
432 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
433 mondsterneAllClasses +
434 "]}," +
435 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
436 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
437 "]}" +
438 "], inOrder=true, " +
439 "distances=[" +
440 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1, max=4}, min=1, max=4}" +
441 "]" +
442 "}" +
443 "]}" +
Joachim Bingel37a803f2014-07-28 14:21:44 +0000444 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000445 ct = new CosmasTree(query);
446 map = ct.getRequestMap().get("query").toString();
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000447 assertEquals(prox6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000448 }
449
450 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000451 public void testOPIN() throws QueryException {
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000452 query="wegen #IN <s>";
Joachim Bingel3a9f7932014-01-07 17:11:31 +0000453 String opin1 =
Joachim Bingel0de1b412014-07-02 14:51:48 +0000454 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000455 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
456 "{@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 Bingeleecc7652014-01-11 17:21:07 +0000459 "]}" +
460 "]}" +
Joachim Bingeld5161a12014-01-08 11:15:49 +0000461 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000462 ct = new CosmasTree(query);
463 map = ct.getRequestMap().get("query").toString();
Joachim Bingeld5161a12014-01-08 11:15:49 +0000464 assertEquals(opin1.replaceAll(" ", ""), map.replaceAll(" ", ""));
465
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000466 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 +0000467 String opin2 =
Joachim Bingel0de1b412014-07-02 14:51:48 +0000468 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000469 "{@type=korap:group, operation=operation:position, frame=frame:matches, operands=[" +
470 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
471 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
472 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
473 "{@type=korap:span, key=s}" +
474 "]}," +
475 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
476 "{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
477 "]}" +
478 "]}" +
479 "]}," +
480 "{@type=korap:reference, operation=operation:focus, classRef=[2]}" +
481 "], exclude=true}" +
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000482 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000483 ct = new CosmasTree(query);
484 map = ct.getRequestMap().get("query").toString();
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000485 assertEquals(opin2.replaceAll(" ", ""), map.replaceAll(" ", ""));
486
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000487
488 query="wegen #IN(F) <s>";
489 String opin3=
490 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
491 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
492 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
493 "{@type=korap:group, operation=operation:position, frame=frame:endswith, operands=[" +
494 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
495 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
496 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
497 "{@type=korap:span, key=s}" +
498 "]}," +
499 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
500 "{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
501 "]}" +
502 "]}" +
503 "]}," +
504 "{@type=korap:reference, operation=operation:focus, classRef=[2]}" +
505 "]}" +
506 "]}," +
507 "{@type=korap:reference, operation=operation:focus, classRef=[2]}" +
508 "]}" +
509 "]}" +
510 "";
511 ct = new CosmasTree(query);
512 map = ct.getRequestMap().get("query").toString();
513 assertEquals(opin3.replaceAll(" ", ""), map.replaceAll(" ", ""));
514
515 query="wegen #IN(FI) <s>";
516 String opin4=
517 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
518 "{@type=korap:group, operation=operation:position, frame=frame:matches, operands=[" +
519 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
520 "{@type=korap:group, operation=operation:position, frame=frame:endswith, operands=[" +
521 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
522 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
523 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
524 "{@type=korap:span, key=s}" +
525 "]}," +
526 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
527 "{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
528 "]}" +
529 "]}" +
530 "]}," +
531 "{@type=korap:reference, operation=operation:focus, classRef=[2]}" +
532 "]}" +
533 "]}," +
534 "{@type=korap:reference, operation=operation:focus, classRef=[2]}" +
535 "], exclude=true}" +
536 "]}" +
537 "";
538 ct = new CosmasTree(query);
539 map = ct.getRequestMap().get("query").toString();
540 assertEquals(opin4.replaceAll(" ", ""), map.replaceAll(" ", ""));
541
542 query="wegen #IN(FE) <s>";
543 String opin5=
544 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
545 "{@type=korap:group, operation=operation:position, frame=frame:matches, operands=[" +
546 "{@type=korap:span, key=s}," +
547 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
548 "{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
549 "]}" +
550 "]}" +
551 "]}" +
552 "";
553 ct = new CosmasTree(query);
554 map = ct.getRequestMap().get("query").toString();
555 assertEquals(opin5.replaceAll(" ", ""), map.replaceAll(" ", ""));
556
Joachim Bingel87480d02014-01-17 14:07:46 +0000557 query="wegen #IN(%, L) <s>";
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000558 String opin6 =
Joachim Bingel0de1b412014-07-02 14:51:48 +0000559 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
560 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000561 "{@type=korap:span, key=s}," +
562 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000563 "{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000564 "]}" +
Joachim Bingel0de1b412014-07-02 14:51:48 +0000565 "], exclude=true}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000566 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000567 ct = new CosmasTree(query);
568 map = ct.getRequestMap().get("query").toString();
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000569 assertEquals(opin6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel87480d02014-01-17 14:07:46 +0000570
571 query="wegen #IN('FE,ALL,%,MIN') <s>";
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000572 String opin7 =
Joachim Bingel0de1b412014-07-02 14:51:48 +0000573 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
574 "{@type=korap:group, operation=operation:position, frame=frame:matches, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000575 "{@type=korap:span, key=s}," +
576 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000577 "{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000578 "]}" +
Joachim Bingel0de1b412014-07-02 14:51:48 +0000579 "], range=all, exclude=true, grouping=false}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000580 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000581 ct = new CosmasTree(query);
582 map = ct.getRequestMap().get("query").toString();
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000583 assertEquals(opin7.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeld5161a12014-01-08 11:15:49 +0000584 }
585
586 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000587 public void testOPOV() throws QueryException {
Joachim Bingeld5161a12014-01-08 11:15:49 +0000588 query="wegen #OV <s>";
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000589 String opov1 =
Joachim Bingel0de1b412014-07-02 14:51:48 +0000590 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000591 "{@type=korap:group, operation=operation:position, frame=frame:overlaps, operands=[" +
592 "{@type=korap:span, key=s}," +
593 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000594 "{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000595 "]}" +
596 "]}" +
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000597 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000598 ct = new CosmasTree(query);
599 map = ct.getRequestMap().get("query").toString();
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000600 assertEquals(opov1.replaceAll(" ", ""), map.replaceAll(" ", ""));
601
602 query="wegen #OV(L) <s>";
603 String opov2 =
Joachim Bingel0de1b412014-07-02 14:51:48 +0000604 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000605 "{@type=korap:group, operation=operation:position, frame=frame:overlapsLeft, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000606 "{@type=korap:span, key=s}," +
607 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000608 "{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000609 "]}" +
610 "]}" +
611 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000612 ct = new CosmasTree(query);
613 map = ct.getRequestMap().get("query").toString();
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000614 assertEquals(opov2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000615
616 query="wegen #OV(F) <s>";
617 String opov3=
618 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
619 "{@type=korap:group, operation=operation:position, frame=frame:endswith, operands=[" +
620 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
621 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
622 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
623 "{@type=korap:span, key=s}" +
624 "]}," +
625 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
626 "{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
627 "]}" +
628 "]}" +
629 "]}," +
630 "{@type=korap:reference, operation=operation:focus, classRef=[2]}" +
631 "]}" +
632 "]}" +
633 "";
634 ct = new CosmasTree(query);
635 map = ct.getRequestMap().get("query").toString();
636 assertEquals(opov3.replaceAll(" ", ""), map.replaceAll(" ", ""));
637
638 query="wegen #OV(FI) <s>";
639 String opov4=
640 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
641 "{@type=korap:group, operation=operation:position, frame=frame:matches, operands=[" +
642 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
643 "{@type=korap:group, operation=operation:position, frame=frame:endswith, operands=[" +
644 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
645 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
646 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
647 "{@type=korap:span, key=s}" +
648 "]}," +
649 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
650 "{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
651 "]}" +
652 "]}" +
653 "]}," +
654 "{@type=korap:reference, operation=operation:focus, classRef=[2]}" +
655 "]}" +
656 "]}," +
657 "{@type=korap:reference, operation=operation:focus, classRef=[2]}" +
658 "], exclude=true}" +
659 "]}" +
660 "";
661 ct = new CosmasTree(query);
662 map = ct.getRequestMap().get("query").toString();
663 assertEquals(opov4.replaceAll(" ", ""), map.replaceAll(" ", ""));
664
665 query="wegen #OV(FE) <s>";
666 String opov5=
667 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
668 "{@type=korap:group, operation=operation:position, frame=frame:matches, operands=[" +
669 "{@type=korap:span, key=s}," +
670 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
671 "{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
672 "]}" +
673 "]}" +
674 "]}" +
675 "";
676 ct = new CosmasTree(query);
677 map = ct.getRequestMap().get("query").toString();
678 assertEquals(opov5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000679 }
680
681 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000682 public void testOPNOT() throws QueryException {
Joachim Bingel3a9f7932014-01-07 17:11:31 +0000683 query="Sonne nicht Mond";
684 String opnot1 =
Joachim Bingelb7a59792014-02-14 13:52:29 +0000685 "{@type=korap:group, operation=operation:sequence, distances=[" +
686 "{@type=korap:distance, key=t, min=0, max=0, exclude=true}" +
687 "], operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000688 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}," +
689 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
Joachim Bingel3a9f7932014-01-07 17:11:31 +0000690 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000691 ct = new CosmasTree(query);
692 map = ct.getRequestMap().get("query").toString();
Joachim Bingel3a9f7932014-01-07 17:11:31 +0000693 assertEquals(opnot1.replaceAll(" ", ""), map.replaceAll(" ", ""));
694 }
695
696 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000697 public void testBEG_END() throws QueryException {
Joachim Bingel3a9f7932014-01-07 17:11:31 +0000698 // BEG and END operators
699 // http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/syntax/links.html
700 // http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/syntax/rechts.html
701 // http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/thematische-bsp/bsp-satzlaenge.html
Joachim Bingel87480d02014-01-17 14:07:46 +0000702 query="#BEG(der /w3:5 Mann)";
703 String beg1 =
Joachim Bingel0de1b412014-07-02 14:51:48 +0000704 "{@type=korap:reference, operation=operation:focus, spanRef=[0,1], operands=[" +
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000705 "{@type=korap:group, operation=operation:sequence," +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000706 "operands = [" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000707 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
708 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000709 "], inOrder=false, distances=[" +
Joachim Bingel03dfd952014-07-30 08:08:53 +0000710 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=3, max=5}, min=3, max=5}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000711 "]}" +
712 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000713 ct = new CosmasTree(query);
714 map = ct.getRequestMap().get("query").toString();
Joachim Bingel87480d02014-01-17 14:07:46 +0000715 assertEquals(beg1.replaceAll(" ", ""), map.replaceAll(" ", ""));
716
Joachim Bingel37a803f2014-07-28 14:21:44 +0000717
Joachim Bingelfbc88792014-09-17 11:11:52 +0000718// String dermannSeq = "{@type=korap:group, operation=operation:sequence," +
719// "operands = [" +
720// "{@type=korap:group, operation=operation:class, class=0, operands=[" +
721// "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}" +
722// "]}," +
723// "{@type=korap:group, operation=operation:class, class=0, operands=[" +
724// "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
725// "]}" +
726//
727// "], inOrder=false, distances=[" +
728// "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=3, max=5}, min=3, max=5}" +
729// "]}";
730//
731// String begDermannSeq =
732//// "{@type=korap:group, operation=operation:class, class=0, operands=[" +
733// "{@type=korap:reference, operation=operation:focus, spanRef=[0,1], operands=[" +
734// dermannSeq +
735// "]}" +
736//// "]}" +
737// "";
738
Joachim Bingel37a803f2014-07-28 14:21:44 +0000739 String kommt = "{@type=korap:token, wrap={@type=korap:term, key=kommt, layer=orth, match=match:eq}}";
740
Joachim Bingel87480d02014-01-17 14:07:46 +0000741 query="#BEG(der /w3:5 Mann) /+w10 kommt"; // nesting #BEG() in a distance group
742 String beg2 =
Joachim Bingelfbc88792014-09-17 11:11:52 +0000743 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingel37a803f2014-07-28 14:21:44 +0000744 "{@type=korap:group, operation=operation:position, frame=frame:overlaps, operands=[" +
Joachim Bingelfbc88792014-09-17 11:11:52 +0000745 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
746 beg1 +
747 "]}" + "," +
748 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
749 kommt +
750 "]}" +
Joachim Bingel37a803f2014-07-28 14:21:44 +0000751 "]}," +
Joachim Bingelfbc88792014-09-17 11:11:52 +0000752 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
753 "{@type=korap:group, operation=operation:sequence, operands=[" +
754 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
755 beg1 +
756 "]}," +
757 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
758 kommt +
759 "]}" +
760 "], inOrder=true, distances=[" +
761 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1, max=10}, min=1, max=10}" +
762 "]}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000763 "]}" +
Joachim Bingelfbc88792014-09-17 11:11:52 +0000764 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000765 ct = new CosmasTree(query);
766 map = ct.getRequestMap().get("query").toString();
Joachim Bingel87480d02014-01-17 14:07:46 +0000767 assertEquals(beg2.replaceAll(" ", ""), map.replaceAll(" ", ""));
768
Joachim Bingel37a803f2014-07-28 14:21:44 +0000769 query="kommt /+w10 #BEG(der /w3:5 Mann)";
770 String beg3 =
771 "{@type=korap:group, operation=operation:or, operands=[" +
772 "{@type=korap:group, operation=operation:position, frame=frame:overlaps, operands=[" +
Joachim Bingelfbc88792014-09-17 11:11:52 +0000773 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
774 kommt +
775// "," +
776 "]}," +
777 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
778 beg1+
779 "]}" +
Joachim Bingel37a803f2014-07-28 14:21:44 +0000780 "]}," +
Joachim Bingelfbc88792014-09-17 11:11:52 +0000781 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
782 "{@type=korap:group, operation=operation:sequence, operands=[" +
783 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
784 kommt +
785 "]}," +
786 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
787 beg1+
788 "]}" +
789 "], inOrder=true, distances=[" +
790 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1, max=10}, min=1, max=10}" +
791 "]}" +
Joachim Bingel37a803f2014-07-28 14:21:44 +0000792 "]}" +
Joachim Bingelfbc88792014-09-17 11:11:52 +0000793 "]}";
Joachim Bingel37a803f2014-07-28 14:21:44 +0000794 ct = new CosmasTree(query);
795 map = ct.getRequestMap().get("query").toString();
796 assertEquals(beg3.replaceAll(" ", ""), map.replaceAll(" ", ""));
797
Joachim Bingel87480d02014-01-17 14:07:46 +0000798 query="#END(der /w3:5 Mann)";
799 String end1 =
Joachim Bingel0de1b412014-07-02 14:51:48 +0000800 "{@type=korap:reference, operation=operation:focus, spanRef=[-1,1], operands=[" +
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000801 "{@type=korap:group, operation=operation:sequence, " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000802 "operands = [" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000803 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
804 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000805 "], inOrder=false, distances=[" +
Joachim Bingel03dfd952014-07-30 08:08:53 +0000806 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=3, max=5}, min=3, max=5}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000807 "]}" +
808 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000809 ct = new CosmasTree(query);
810 map = ct.getRequestMap().get("query").toString();
Joachim Bingel87480d02014-01-17 14:07:46 +0000811 assertEquals(end1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000812 }
Joachim Bingeld5161a12014-01-08 11:15:49 +0000813
Joachim Bingel03dfd952014-07-30 08:08:53 +0000814 /*
815 * YET UNCLEAR HOW TO SERIALIZE SPAN DISTANCES. BEING DISCUSSED.
816 *
Joachim Bingel37a803f2014-07-28 14:21:44 +0000817 @Test
818 public void testSentenceDistance() throws QueryException {
Joachim Bingel03dfd952014-07-30 08:08:53 +0000819 query="Sonne /s0 Mond"; // contains(focus(1:contains({1:<s>},Sonne)),Mond)
Joachim Bingel37a803f2014-07-28 14:21:44 +0000820 expected =
821 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
Joachim Bingel03dfd952014-07-30 08:08:53 +0000822 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingel37a803f2014-07-28 14:21:44 +0000823 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
Joachim Bingel03dfd952014-07-30 08:08:53 +0000824 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
Joachim Bingel37a803f2014-07-28 14:21:44 +0000825 "{@type=korap:span, key=s}" +
826 "]}," +
827 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
828 "]}" +
829 "]}," +
830 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
831 "]}";
832 ct = new CosmasTree(query);
833 map = ct.getRequestMap().get("query").toString();
834 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
835
Joachim Bingel03dfd952014-07-30 08:08:53 +0000836 query="Sonne /s0,w5 Mond";
837 expected =
838 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
839 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
840 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
841 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
842 "{@type=korap:span, key=s}" +
843 "]}," +
844 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
845 "]}" +
846 "]}," +
847 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
848 "]}";
849// ct = new CosmasTree(query);
850// map = ct.getRequestMap().get("query").toString();
851// assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
852
Joachim Bingel37a803f2014-07-28 14:21:44 +0000853 query="Sonne /s2:2 Mond"; // contains(<s>,Sonne)<s>contains(<s>,Mond)
854 expected =
855 "{@type=korap:group, operation=operation:sequence, operands=[" +
856 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
857 "{@type=korap:span, key=s}," +
858 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
859 "]}," +
860 "{@type=korap:span, key=s}," +
861 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
862 "{@type=korap:span, key=s}," +
863 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
Joachim Bingel03dfd952014-07-30 08:08:53 +0000864 "]}" +
Joachim Bingel37a803f2014-07-28 14:21:44 +0000865 "]}";
866 ct = new CosmasTree(query);
867 map = ct.getRequestMap().get("query").toString();
Joachim Bingel03dfd952014-07-30 08:08:53 +0000868// assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel37a803f2014-07-28 14:21:44 +0000869
Joachim Bingel03dfd952014-07-30 08:08:53 +0000870 query="Sonne /s2:3 Mond"; // contains(<s>,Sonne)<s>contains(<s>,Mond)
871 expected =
872 "{@type=korap:group, operation=operation:sequence, operands=[" +
873 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
874 "{@type=korap:span, key=s}," +
875 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
876 "]}," +
877 "{@type=korap:group, operation=operation:repetition, operands=[" +
878 "{@type=korap:span, key=s}" +
879 "], boundary={@type=korap:boundary, min=1, max=2}, min=1, max=2}," +
880 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
881 "{@type=korap:span, key=s}," +
882 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
883 "]}" +
884 "]}";
885 ct = new CosmasTree(query);
886 map = ct.getRequestMap().get("query").toString();
887// assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
888
889 query="Sonne /s2 Mond"; // contains(focus(1:contains({1:<s>},Sonne)),Mond) | contains(<s>,Sonne)<s>?contains(<s>,Mond)
Joachim Bingel37a803f2014-07-28 14:21:44 +0000890 expected =
891 "{@type=korap:group, operation=operation:or, operands=[" +
892 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
Joachim Bingel03dfd952014-07-30 08:08:53 +0000893 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingel37a803f2014-07-28 14:21:44 +0000894 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
Joachim Bingel03dfd952014-07-30 08:08:53 +0000895 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
Joachim Bingel37a803f2014-07-28 14:21:44 +0000896 "{@type=korap:span, key=s}" +
897 "]}," +
898 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
899 "]}" +
900 "]}," +
901 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
902 "]}," +
903 "{@type=korap:group, operation=operation:sequence, operands=[" +
904 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
905 "{@type=korap:span, key=s}," +
906 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
907 "]}," +
Joachim Bingel03dfd952014-07-30 08:08:53 +0000908 "{@type=korap:group, operation=operation:repetition, operands=[" +
909 "{@type=korap:span, key=s}" +
910 "], boundary={@type=korap:boundary, min=0, max=1}, min=0, max=1}," +
Joachim Bingel37a803f2014-07-28 14:21:44 +0000911 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
912 "{@type=korap:span, key=s}," +
913 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
Joachim Bingel03dfd952014-07-30 08:08:53 +0000914 "]}" +
Joachim Bingel37a803f2014-07-28 14:21:44 +0000915 "]}" +
916 "]}";
917 ct = new CosmasTree(query);
918 map = ct.getRequestMap().get("query").toString();
Joachim Bingel03dfd952014-07-30 08:08:53 +0000919// assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel37a803f2014-07-28 14:21:44 +0000920 }
Joachim Bingel03dfd952014-07-30 08:08:53 +0000921 */
Joachim Bingel37a803f2014-07-28 14:21:44 +0000922
Joachim Bingeld5161a12014-01-08 11:15:49 +0000923
924 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000925 public void testELEM() throws QueryException {
Joachim Bingeld5161a12014-01-08 11:15:49 +0000926 // http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/syntax/elem.html
Joachim Bingeleecc7652014-01-11 17:21:07 +0000927 query="#ELEM(S)";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000928 String elem1 = "{@type=korap:span, key=s}";
929 ct = new CosmasTree(query);
930 map = ct.getRequestMap().get("query").toString();
Joachim Bingeleecc7652014-01-11 17:21:07 +0000931 assertEquals(elem1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel402c6e12014-05-08 17:09:06 +0000932
933 query="#ELEM(W ANA=N)";
934 String elem2 =
935 "{@type=korap:span, key=w, attr=" +
936 "{@type=korap:termGroup, relation=relation:and, operands=[" +
937 "{@type=korap:term, layer=pos, key=N, match=match:eq}" +
938 "]}" +
939 "}";
940 ct = new CosmasTree(query);
941 map = ct.getRequestMap().get("query").toString();
942 assertEquals(elem2.replaceAll(" ", ""), map.replaceAll(" ", ""));
943
944 query="#ELEM(W ANA != 'N V')";
945 String elem3 =
946 "{@type=korap:span, key=w, attr=" +
947 "{@type=korap:termGroup, relation=relation:and, operands=[" +
Joachim Bingelb674cca2014-05-09 14:00:58 +0000948 "{@type=korap:term, layer=pos, key=N, match=match:ne}," +
949 "{@type=korap:term, layer=pos, key=V, match=match:ne}" +
Joachim Bingel402c6e12014-05-08 17:09:06 +0000950 "]}" +
951 "}";
952 ct = new CosmasTree(query);
953 map = ct.getRequestMap().get("query").toString();
954 assertEquals(elem3.replaceAll(" ", ""), map.replaceAll(" ", ""));
955
Joachim Bingelb674cca2014-05-09 14:00:58 +0000956 query="#ELEM(W ANA != 'N A V' Genre = Sport)";
Joachim Bingel402c6e12014-05-08 17:09:06 +0000957 String elem4 =
958 "{@type=korap:span, key=w, attr=" +
959 "{@type=korap:termGroup, relation=relation:and, operands=[" +
960 "{@type=korap:termGroup, relation=relation:and, operands=[" +
Joachim Bingelb674cca2014-05-09 14:00:58 +0000961 "{@type=korap:term, layer=pos, key=N, match=match:ne}," +
962 "{@type=korap:term, layer=pos, key=A, match=match:ne}," +
963 "{@type=korap:term, layer=pos, key=V, match=match:ne}" +
964 "]}," +
Joachim Bingel402c6e12014-05-08 17:09:06 +0000965 "{@type=korap:term, layer=Genre, key=Sport, match=match:eq}" +
966 "]}" +
967 "}";
968 ct = new CosmasTree(query);
969 map = ct.getRequestMap().get("query").toString();
970 assertEquals(elem4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb674cca2014-05-09 14:00:58 +0000971
972 query="#ELEM(W ANA != 'N V' Genre != 'Sport Politik')";
973 String elem5 =
974 "{@type=korap:span, key=w, attr=" +
975 "{@type=korap:termGroup, relation=relation:and, operands=[" +
976 "{@type=korap:termGroup, relation=relation:and, operands=[" +
977 "{@type=korap:term, layer=pos, key=N, match=match:ne}," +
978 "{@type=korap:term, layer=pos, key=V, match=match:ne}" +
979 "]}," +
980 "{@type=korap:termGroup, relation=relation:and, operands=[" +
981 "{@type=korap:term, layer=Genre, key=Sport, match=match:ne}," +
982 "{@type=korap:term, layer=Genre, key=Politik, match=match:ne}" +
983 "]}" +
984 "]}" +
985 "}";
986 ct = new CosmasTree(query);
987 map = ct.getRequestMap().get("query").toString();
988 assertEquals(elem5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeld5161a12014-01-08 11:15:49 +0000989 }
990
991 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000992 public void testOPALL() throws QueryException {
Joachim Bingel89cceac2014-01-08 15:51:08 +0000993 query="#ALL(gehen /w1:10 voran)";
Joachim Bingele98d0882014-01-21 12:58:54 +0000994 String all1 =
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000995 "{@type=korap:group, operation=operation:sequence, " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000996 "operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000997 "{@type=korap:token, wrap={@type=korap:term, key=gehen, layer=orth, match=match:eq}}," +
998 "{@type=korap:token, wrap={@type=korap:term, key=voran, layer=orth, match=match:eq}}" +
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000999 "], inOrder=false, " +
1000 "distances=[" +
Joachim Bingel03dfd952014-07-30 08:08:53 +00001001 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1, max=10}, min=1, max=10}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +00001002 "]" +
1003 "}";
Joachim Bingel2daf9862014-02-12 10:18:54 +00001004 ct = new CosmasTree(query);
1005 map = ct.getRequestMap().get("query").toString();
Joachim Bingel89cceac2014-01-08 15:51:08 +00001006 assertEquals(all1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeld5161a12014-01-08 11:15:49 +00001007 }
1008
Joachim Bingel36233b52014-02-13 10:48:24 +00001009 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +00001010 public void testOPNHIT() throws QueryException {
Joachim Bingel89cceac2014-01-08 15:51:08 +00001011 query="#NHIT(gehen /w1:10 voran)";
1012 String nhit1 =
Joachim Bingel0de1b412014-07-02 14:51:48 +00001013 "{@type=korap:reference, operation=operation:focus, classRef=[1,2], classRefOp=classRefOp:intersection, operands=[" +
Joachim Bingel097c1eb2014-07-11 14:57:25 +00001014 "{@type=korap:group, operation=operation:sequence, " +
Joachim Bingel36233b52014-02-13 10:48:24 +00001015 "operands=[" +
1016 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
1017 "{@type=korap:token, wrap={@type=korap:term, key=gehen, layer=orth, match=match:eq}}" +
1018 "]}," +
1019 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
1020 "{@type=korap:token, wrap={@type=korap:term, key=voran, layer=orth, match=match:eq}}" +
1021 "]}" +
Joachim Bingel097c1eb2014-07-11 14:57:25 +00001022 "], inOrder=false, " +
1023 "distances=[" +
Joachim Bingel03dfd952014-07-30 08:08:53 +00001024 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1, max=10}, min=1, max=10}" +
Joachim Bingel36233b52014-02-13 10:48:24 +00001025 "]" +
1026 "}" +
1027 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +00001028 ct = new CosmasTree(query);
1029 map = ct.getRequestMap().get("query").toString();
Joachim Bingel89cceac2014-01-08 15:51:08 +00001030 assertEquals(nhit1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeld5161a12014-01-08 11:15:49 +00001031 }
1032
1033 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +00001034 public void testOPBED() throws QueryException {
Joachim Bingeleecc7652014-01-11 17:21:07 +00001035 query = "#BED(der , sa)";
1036 String bed1 =
Joachim Bingel0de1b412014-07-02 14:51:48 +00001037 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands= [" +
Joachim Bingelcd7b7252014-02-13 08:49:14 +00001038 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
1039 "{@type=korap:span, key=s}," +
1040 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
1041 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}" +
1042 "]}" +
1043 "]}" +
Joachim Bingeleecc7652014-01-11 17:21:07 +00001044 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +00001045 ct = new CosmasTree(query);
1046 map = ct.getRequestMap().get("query").toString();
Joachim Bingeleecc7652014-01-11 17:21:07 +00001047 assertEquals(bed1.replaceAll(" ", ""), map.replaceAll(" ", ""));
1048
1049 query = "#BED(der Mann , +pe)";
1050 String bed2 =
Joachim Bingel0de1b412014-07-02 14:51:48 +00001051 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands= [" +
Joachim Bingel36233b52014-02-13 10:48:24 +00001052 "{@type=korap:group, operation=operation:position, frame=frame:endswith, operands=[" +
1053 "{@type=korap:span, key=p}," +
1054 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
1055 "{@type=korap:group, operation=operation:sequence, operands=[" +
1056 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
1057 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
1058 "]}" +
1059 "]}" +
1060 "]}" +
1061 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +00001062 ct = new CosmasTree(query);
1063 map = ct.getRequestMap().get("query").toString();
Joachim Bingel36233b52014-02-13 10:48:24 +00001064 assertEquals(bed2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel3f0850c2014-01-17 16:50:10 +00001065
1066 query = "#BED(der Mann , sa,-pa)";
1067 String bed3 =
Joachim Bingel0de1b412014-07-02 14:51:48 +00001068 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingel37a803f2014-07-28 14:21:44 +00001069 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel36233b52014-02-13 10:48:24 +00001070 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
1071 "{@type=korap:span, key=s}," +
1072 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
1073 "{@type=korap:group, operation=operation:sequence, operands=[" +
1074 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
1075 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
1076 "]}" +
1077 "]}" +
1078 "]}," +
Joachim Bingel37a803f2014-07-28 14:21:44 +00001079 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
Joachim Bingel36233b52014-02-13 10:48:24 +00001080 "{@type=korap:span, key=p}," +
Joachim Bingel402c6e12014-05-08 17:09:06 +00001081 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
Joachim Bingel36233b52014-02-13 10:48:24 +00001082 "{@type=korap:group, operation=operation:sequence, operands=[" +
1083 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
1084 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
1085 "]}" +
1086 "]}" +
Joachim Bingel37a803f2014-07-28 14:21:44 +00001087 "], exclude=true}" +
1088 "], distances=[" +
1089 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0, max=0}, min=0, max=0}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +00001090 "]}" +
1091 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +00001092 ct = new CosmasTree(query);
1093 map = ct.getRequestMap().get("query").toString();
Joachim Bingel36233b52014-02-13 10:48:24 +00001094 assertEquals(bed3.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeld5161a12014-01-08 11:15:49 +00001095 }
1096
Joachim Bingel81812632014-02-18 08:55:22 +00001097 @Test
1098 public void testColonSeparatedConditions() throws QueryException {
1099
1100 query = "Der:sa";
1101 String col1 =
Joachim Bingel0de1b412014-07-02 14:51:48 +00001102 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingel81812632014-02-18 08:55:22 +00001103 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
1104 "{@type=korap:span, key=s}," +
1105 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
1106 "{@type=korap:token, wrap={@type=korap:term, key=Der, layer=orth, match=match:eq}}" +
1107 "]}" +
1108 "]}" +
1109 "]}";
1110 ct = new CosmasTree(query);
1111 map = ct.getRequestMap().get("query").toString();
1112 assertEquals(col1.replaceAll(" ", ""), map.replaceAll(" ", ""));
1113
1114 query = "Mann:sa,-pa,+te)";
1115 String col2 =
Joachim Bingel0de1b412014-07-02 14:51:48 +00001116 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingel37a803f2014-07-28 14:21:44 +00001117 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel81812632014-02-18 08:55:22 +00001118 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
1119 "{@type=korap:span, key=s}," +
1120 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
1121 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
1122 "]}" +
1123 "]}," +
Joachim Bingel37a803f2014-07-28 14:21:44 +00001124 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
Joachim Bingel81812632014-02-18 08:55:22 +00001125 "{@type=korap:span, key=p}," +
Joachim Bingel402c6e12014-05-08 17:09:06 +00001126 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
Joachim Bingel81812632014-02-18 08:55:22 +00001127 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
1128 "]}" +
Joachim Bingel37a803f2014-07-28 14:21:44 +00001129 "], exclude=true}," +
Joachim Bingel81812632014-02-18 08:55:22 +00001130 "{@type=korap:group, operation=operation:position, frame=frame:endswith, operands=[" +
1131 "{@type=korap:span, key=t}," +
Joachim Bingel402c6e12014-05-08 17:09:06 +00001132 "{@type=korap:group, operation=operation:class, class=3, operands=[" +
Joachim Bingel81812632014-02-18 08:55:22 +00001133 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
1134 "]}" +
1135 "]}" +
Joachim Bingel37a803f2014-07-28 14:21:44 +00001136 "], distances=[" +
1137 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0, max=0}, min=0, max=0}" +
Joachim Bingel81812632014-02-18 08:55:22 +00001138 "]}" +
1139 "]}";
1140 ct = new CosmasTree(query);
1141 map = ct.getRequestMap().get("query").toString();
1142 assertEquals(col2.replaceAll(" ", ""), map.replaceAll(" ", ""));
1143 }
Joachim Bingelb5f7bf02014-01-07 16:36:54 +00001144}
1145