blob: 85546a8c60361af634f9bece8b214821a87758be [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 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 Bingel37a803f2014-07-28 14:21:44 +0000262 "{@type=korap:group, operation=operation:or, operands=[" +
263 "{@type=korap:group, operation=operation:position, frame=frame:overlaps, 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 Bingel37a803f2014-07-28 14:21:44 +0000266 "]}," +
267 "{@type=korap:group, operation=operation:sequence, " +
268 "operands=[" +
269 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}," +
270 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
271 "], inOrder=true, " +
272 "distances=[" +
273 "{@type=korap:distance, key=w, min=1, max=4}" +
274 "]" +
275 "}" +
276 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000277 ct = new CosmasTree(query);
278 map = ct.getRequestMap().get("query").toString();
Joachim Bingel87480d02014-01-17 14:07:46 +0000279 assertEquals(prox4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000280
281 query="Sonne /-w4 Mond";
282 String prox5 =
Joachim Bingel37a803f2014-07-28 14:21:44 +0000283 "{@type=korap:group, operation=operation:or, operands=[" +
284 "{@type=korap:group, operation=operation:position, frame=frame:overlaps, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000285 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}," +
286 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
Joachim Bingel37a803f2014-07-28 14:21:44 +0000287 "]}," +
288 "{@type=korap:group, operation=operation:sequence, " +
289 "operands=[" +
290 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}," +
291 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
292 "], inOrder=true, " +
293 "distances=[" +
294 "{@type=korap:distance, key=w, min=1, max=4}" +
295 "]" +
296 "}" +
297 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000298 ct = new CosmasTree(query);
299 map = ct.getRequestMap().get("query").toString();
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000300 assertEquals(prox5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000301
302 query="Sonne /w4 Mond";
303 String prox6 =
Joachim Bingel37a803f2014-07-28 14:21:44 +0000304 "{@type=korap:group, operation=operation:or, operands=[" +
305 "{@type=korap:group, operation=operation:position, frame=frame:overlaps, operands=[" +
306 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}," +
307 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
308 "]}," +
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000309 "{@type=korap:group, operation=operation:sequence, " +
310 "operands=[" +
311 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}," +
312 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
313 "], inOrder=false, " +
314 "distances=[" +
Joachim Bingel37a803f2014-07-28 14:21:44 +0000315 "{@type=korap:distance, key=w, min=1, max=4}" +
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000316 "]" +
Joachim Bingel37a803f2014-07-28 14:21:44 +0000317 "}" +
318 "]}";
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000319 ct = new CosmasTree(query);
320 map = ct.getRequestMap().get("query").toString();
321 assertEquals(prox6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000322 }
323
324 @Test
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000325 public void testOPPROXNested() throws QueryException {
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000326 query="Sonne /-w4 Mond /+w2 Sterne";
Joachim Bingel37a803f2014-07-28 14:21:44 +0000327
328 String mondsterne =
329 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}," +
330 "{@type=korap:token, wrap={@type=korap:term, key=Sterne, layer=orth, match=match:eq}}" ;
331 String mondsterneSeq =
332 "{@type=korap:group, operation=operation:sequence, operands=[" +
333 mondsterne +
334 "], inOrder=true, distances=[" +
335 "{@type=korap:distance, key=w, min=1, max=2}" +
336 "]}" ;
337 String mondsterneOv =
338 "{@type=korap:group, operation=operation:position, frame=frame:overlaps, operands=[" +
339 mondsterne +
340 "]}";
341 String mondsterneAll =
342 "{@type=korap:group, operation=operation:or, operands=[" +
343 mondsterneOv + "," + mondsterneSeq +
344 "]}";
345
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000346 String prox6 =
Joachim Bingel37a803f2014-07-28 14:21:44 +0000347 "{@type=korap:group, operation=operation:or, operands=[" +
348 "{@type=korap:group, operation=operation:position, frame=frame:overlaps, operands=[" +
349 mondsterneAll + "," +
350 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
351 "]}," +
352 "{@type=korap:group, operation=operation:sequence, " +
353 "operands=[" +
354 mondsterneAll + "," +
355 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
356 "], inOrder=true, " +
357 "distances=[" +
358 "{@type=korap:distance, key=w, min=1, max=4}" +
359 "]" +
360 "}" +
361 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000362 ct = new CosmasTree(query);
363 map = ct.getRequestMap().get("query").toString();
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000364 assertEquals(prox6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000365 }
366
367 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000368 public void testOPIN() throws QueryException {
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000369 query="wegen #IN <s>";
Joachim Bingel3a9f7932014-01-07 17:11:31 +0000370 String opin1 =
Joachim Bingel0de1b412014-07-02 14:51:48 +0000371 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000372 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
373 "{@type=korap:span, key=s}," +
374 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000375 "{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
Joachim Bingeleecc7652014-01-11 17:21:07 +0000376 "]}" +
377 "]}" +
Joachim Bingeld5161a12014-01-08 11:15:49 +0000378 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000379 ct = new CosmasTree(query);
380 map = ct.getRequestMap().get("query").toString();
Joachim Bingeld5161a12014-01-08 11:15:49 +0000381 assertEquals(opin1.replaceAll(" ", ""), map.replaceAll(" ", ""));
382
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000383 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 +0000384 String opin2 =
Joachim Bingel0de1b412014-07-02 14:51:48 +0000385 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000386 "{@type=korap:group, operation=operation:position, frame=frame:matches, operands=[" +
387 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
388 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
389 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
390 "{@type=korap:span, key=s}" +
391 "]}," +
392 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
393 "{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
394 "]}" +
395 "]}" +
396 "]}," +
397 "{@type=korap:reference, operation=operation:focus, classRef=[2]}" +
398 "], exclude=true}" +
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000399 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000400 ct = new CosmasTree(query);
401 map = ct.getRequestMap().get("query").toString();
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000402 assertEquals(opin2.replaceAll(" ", ""), map.replaceAll(" ", ""));
403
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000404
405 query="wegen #IN(F) <s>";
406 String opin3=
407 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
408 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
409 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
410 "{@type=korap:group, operation=operation:position, frame=frame:endswith, operands=[" +
411 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
412 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
413 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
414 "{@type=korap:span, key=s}" +
415 "]}," +
416 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
417 "{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
418 "]}" +
419 "]}" +
420 "]}," +
421 "{@type=korap:reference, operation=operation:focus, classRef=[2]}" +
422 "]}" +
423 "]}," +
424 "{@type=korap:reference, operation=operation:focus, classRef=[2]}" +
425 "]}" +
426 "]}" +
427 "";
428 ct = new CosmasTree(query);
429 map = ct.getRequestMap().get("query").toString();
430 assertEquals(opin3.replaceAll(" ", ""), map.replaceAll(" ", ""));
431
432 query="wegen #IN(FI) <s>";
433 String opin4=
434 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
435 "{@type=korap:group, operation=operation:position, frame=frame:matches, operands=[" +
436 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
437 "{@type=korap:group, operation=operation:position, frame=frame:endswith, operands=[" +
438 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
439 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
440 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
441 "{@type=korap:span, key=s}" +
442 "]}," +
443 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
444 "{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
445 "]}" +
446 "]}" +
447 "]}," +
448 "{@type=korap:reference, operation=operation:focus, classRef=[2]}" +
449 "]}" +
450 "]}," +
451 "{@type=korap:reference, operation=operation:focus, classRef=[2]}" +
452 "], exclude=true}" +
453 "]}" +
454 "";
455 ct = new CosmasTree(query);
456 map = ct.getRequestMap().get("query").toString();
457 assertEquals(opin4.replaceAll(" ", ""), map.replaceAll(" ", ""));
458
459 query="wegen #IN(FE) <s>";
460 String opin5=
461 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
462 "{@type=korap:group, operation=operation:position, frame=frame:matches, operands=[" +
463 "{@type=korap:span, key=s}," +
464 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
465 "{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
466 "]}" +
467 "]}" +
468 "]}" +
469 "";
470 ct = new CosmasTree(query);
471 map = ct.getRequestMap().get("query").toString();
472 assertEquals(opin5.replaceAll(" ", ""), map.replaceAll(" ", ""));
473
Joachim Bingel87480d02014-01-17 14:07:46 +0000474 query="wegen #IN(%, L) <s>";
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000475 String opin6 =
Joachim Bingel0de1b412014-07-02 14:51:48 +0000476 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
477 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000478 "{@type=korap:span, key=s}," +
479 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000480 "{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000481 "]}" +
Joachim Bingel0de1b412014-07-02 14:51:48 +0000482 "], exclude=true}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000483 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000484 ct = new CosmasTree(query);
485 map = ct.getRequestMap().get("query").toString();
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000486 assertEquals(opin6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel87480d02014-01-17 14:07:46 +0000487
488 query="wegen #IN('FE,ALL,%,MIN') <s>";
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000489 String opin7 =
Joachim Bingel0de1b412014-07-02 14:51:48 +0000490 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
491 "{@type=korap:group, operation=operation:position, frame=frame:matches, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000492 "{@type=korap:span, key=s}," +
493 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000494 "{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000495 "]}" +
Joachim Bingel0de1b412014-07-02 14:51:48 +0000496 "], range=all, exclude=true, grouping=false}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000497 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000498 ct = new CosmasTree(query);
499 map = ct.getRequestMap().get("query").toString();
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000500 assertEquals(opin7.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeld5161a12014-01-08 11:15:49 +0000501 }
502
503 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000504 public void testOPOV() throws QueryException {
Joachim Bingeld5161a12014-01-08 11:15:49 +0000505 query="wegen #OV <s>";
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000506 String opov1 =
Joachim Bingel0de1b412014-07-02 14:51:48 +0000507 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000508 "{@type=korap:group, operation=operation:position, frame=frame:overlaps, operands=[" +
509 "{@type=korap:span, key=s}," +
510 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000511 "{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000512 "]}" +
513 "]}" +
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000514 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000515 ct = new CosmasTree(query);
516 map = ct.getRequestMap().get("query").toString();
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000517 assertEquals(opov1.replaceAll(" ", ""), map.replaceAll(" ", ""));
518
519 query="wegen #OV(L) <s>";
520 String opov2 =
Joachim Bingel0de1b412014-07-02 14:51:48 +0000521 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000522 "{@type=korap:group, operation=operation:position, frame=frame:overlapsLeft, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000523 "{@type=korap:span, key=s}," +
524 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000525 "{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000526 "]}" +
527 "]}" +
528 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000529 ct = new CosmasTree(query);
530 map = ct.getRequestMap().get("query").toString();
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000531 assertEquals(opov2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000532
533 query="wegen #OV(F) <s>";
534 String opov3=
535 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
536 "{@type=korap:group, operation=operation:position, frame=frame:endswith, operands=[" +
537 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
538 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
539 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
540 "{@type=korap:span, key=s}" +
541 "]}," +
542 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
543 "{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
544 "]}" +
545 "]}" +
546 "]}," +
547 "{@type=korap:reference, operation=operation:focus, classRef=[2]}" +
548 "]}" +
549 "]}" +
550 "";
551 ct = new CosmasTree(query);
552 map = ct.getRequestMap().get("query").toString();
553 assertEquals(opov3.replaceAll(" ", ""), map.replaceAll(" ", ""));
554
555 query="wegen #OV(FI) <s>";
556 String opov4=
557 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
558 "{@type=korap:group, operation=operation:position, frame=frame:matches, operands=[" +
559 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
560 "{@type=korap:group, operation=operation:position, frame=frame:endswith, operands=[" +
561 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
562 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
563 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
564 "{@type=korap:span, key=s}" +
565 "]}," +
566 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
567 "{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
568 "]}" +
569 "]}" +
570 "]}," +
571 "{@type=korap:reference, operation=operation:focus, classRef=[2]}" +
572 "]}" +
573 "]}," +
574 "{@type=korap:reference, operation=operation:focus, classRef=[2]}" +
575 "], exclude=true}" +
576 "]}" +
577 "";
578 ct = new CosmasTree(query);
579 map = ct.getRequestMap().get("query").toString();
580 assertEquals(opov4.replaceAll(" ", ""), map.replaceAll(" ", ""));
581
582 query="wegen #OV(FE) <s>";
583 String opov5=
584 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
585 "{@type=korap:group, operation=operation:position, frame=frame:matches, operands=[" +
586 "{@type=korap:span, key=s}," +
587 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
588 "{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
589 "]}" +
590 "]}" +
591 "]}" +
592 "";
593 ct = new CosmasTree(query);
594 map = ct.getRequestMap().get("query").toString();
595 assertEquals(opov5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000596 }
597
598 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000599 public void testOPNOT() throws QueryException {
Joachim Bingel3a9f7932014-01-07 17:11:31 +0000600 query="Sonne nicht Mond";
601 String opnot1 =
Joachim Bingelb7a59792014-02-14 13:52:29 +0000602 "{@type=korap:group, operation=operation:sequence, distances=[" +
603 "{@type=korap:distance, key=t, min=0, max=0, exclude=true}" +
604 "], operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000605 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}," +
606 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
Joachim Bingel3a9f7932014-01-07 17:11:31 +0000607 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000608 ct = new CosmasTree(query);
609 map = ct.getRequestMap().get("query").toString();
Joachim Bingel3a9f7932014-01-07 17:11:31 +0000610 assertEquals(opnot1.replaceAll(" ", ""), map.replaceAll(" ", ""));
611 }
612
613 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000614 public void testBEG_END() throws QueryException {
Joachim Bingel3a9f7932014-01-07 17:11:31 +0000615 // BEG and END operators
616 // http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/syntax/links.html
617 // http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/syntax/rechts.html
618 // http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/thematische-bsp/bsp-satzlaenge.html
Joachim Bingel87480d02014-01-17 14:07:46 +0000619 query="#BEG(der /w3:5 Mann)";
620 String beg1 =
Joachim Bingel0de1b412014-07-02 14:51:48 +0000621 "{@type=korap:reference, operation=operation:focus, spanRef=[0,1], operands=[" +
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000622 "{@type=korap:group, operation=operation:sequence," +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000623 "operands = [" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000624 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
625 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000626 "], inOrder=false, distances=[" +
627 "{@type=korap:distance, key=w, min=3, max=5}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000628 "]}" +
629 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000630 ct = new CosmasTree(query);
631 map = ct.getRequestMap().get("query").toString();
Joachim Bingel87480d02014-01-17 14:07:46 +0000632 assertEquals(beg1.replaceAll(" ", ""), map.replaceAll(" ", ""));
633
Joachim Bingel37a803f2014-07-28 14:21:44 +0000634
635 String dermannSeq = "{@type=korap:group, operation=operation:sequence," +
636 "operands = [" +
637 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
638 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
639 "], inOrder=false, distances=[" +
640 "{@type=korap:distance, key=w, min=3, max=5}" +
641 "]}";
642 String begDermannSeq = "{@type=korap:reference, operation=operation:focus, spanRef=[0,1], operands=[" +
643 dermannSeq +
644 "]}";
645 String kommt = "{@type=korap:token, wrap={@type=korap:term, key=kommt, layer=orth, match=match:eq}}";
646
Joachim Bingel87480d02014-01-17 14:07:46 +0000647 query="#BEG(der /w3:5 Mann) /+w10 kommt"; // nesting #BEG() in a distance group
648 String beg2 =
Joachim Bingel37a803f2014-07-28 14:21:44 +0000649 "{@type=korap:group, operation=operation:or, operands=[" +
650 "{@type=korap:group, operation=operation:position, frame=frame:overlaps, operands=[" +
651 begDermannSeq + "," +
652 kommt +
653 "]}," +
654 "{@type=korap:group, operation=operation:sequence, operands=[" +
655 begDermannSeq + "," +
656 kommt +
657 "], inOrder=true, distances=[" +
658 "{@type=korap:distance, key=w, min=1, max=10}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000659 "]}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000660 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000661 ct = new CosmasTree(query);
662 map = ct.getRequestMap().get("query").toString();
Joachim Bingel87480d02014-01-17 14:07:46 +0000663 assertEquals(beg2.replaceAll(" ", ""), map.replaceAll(" ", ""));
664
Joachim Bingel37a803f2014-07-28 14:21:44 +0000665 query="kommt /+w10 #BEG(der /w3:5 Mann)";
666 String beg3 =
667 "{@type=korap:group, operation=operation:or, operands=[" +
668 "{@type=korap:group, operation=operation:position, frame=frame:overlaps, operands=[" +
669 kommt + "," +
670 begDermannSeq +
671 "]}," +
672 "{@type=korap:group, operation=operation:sequence, operands=[" +
673 kommt + "," +
674 begDermannSeq +
675 "], inOrder=true, distances=[" +
676 "{@type=korap:distance, key=w, min=1, max=10}" +
677 "]}" +
678 "]}";
679 ct = new CosmasTree(query);
680 map = ct.getRequestMap().get("query").toString();
681 assertEquals(beg3.replaceAll(" ", ""), map.replaceAll(" ", ""));
682
Joachim Bingel87480d02014-01-17 14:07:46 +0000683 query="#END(der /w3:5 Mann)";
684 String end1 =
Joachim Bingel0de1b412014-07-02 14:51:48 +0000685 "{@type=korap:reference, operation=operation:focus, spanRef=[-1,1], operands=[" +
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000686 "{@type=korap:group, operation=operation:sequence, " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000687 "operands = [" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000688 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
689 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000690 "], inOrder=false, distances=[" +
691 "{@type=korap:distance, key=w, min=3, max=5}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000692 "]}" +
693 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000694 ct = new CosmasTree(query);
695 map = ct.getRequestMap().get("query").toString();
Joachim Bingel87480d02014-01-17 14:07:46 +0000696 assertEquals(end1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000697 }
Joachim Bingeld5161a12014-01-08 11:15:49 +0000698
Joachim Bingel37a803f2014-07-28 14:21:44 +0000699 @Test
700 public void testSentenceDistance() throws QueryException {
701 query="Sonne /s0 Mond"; // contains(focus(contains({<s>},Sonne)),Mond)
702 expected =
703 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
704 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
705 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
706 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
707 "{@type=korap:span, key=s}" +
708 "]}," +
709 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
710 "]}" +
711 "]}," +
712 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
713 "]}";
714 ct = new CosmasTree(query);
715 map = ct.getRequestMap().get("query").toString();
716 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
717
718 query="Sonne /s2:2 Mond"; // contains(<s>,Sonne)<s>contains(<s>,Mond)
719 expected =
720 "{@type=korap:group, operation=operation:sequence, operands=[" +
721 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
722 "{@type=korap:span, key=s}," +
723 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
724 "]}," +
725 "{@type=korap:span, key=s}," +
726 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
727 "{@type=korap:span, key=s}," +
728 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
729 "]}," +
730 "]}";
731 ct = new CosmasTree(query);
732 map = ct.getRequestMap().get("query").toString();
733 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
734
735 query="Sonne /s2 Mond"; // contains(focus(contains({<s>},Sonne)),Mond) | contains(<s>,Sonne)<s>?contains(<s>,Mond)
736 expected =
737 "{@type=korap:group, operation=operation:or, operands=[" +
738 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
739 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
740 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
741 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
742 "{@type=korap:span, key=s}" +
743 "]}," +
744 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
745 "]}" +
746 "]}," +
747 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
748 "]}," +
749 "{@type=korap:group, operation=operation:sequence, operands=[" +
750 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
751 "{@type=korap:span, key=s}," +
752 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
753 "]}," +
754 "{@type=korap:group, operation=operation:repetition, repetition={@type=korap:boundary, min=0, max=1}, min=0, max=1, operands=[" +
755 "{@type=korap:span, key=s}," +
756 "]}," +
757 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
758 "{@type=korap:span, key=s}," +
759 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
760 "]}," +
761 "]}" +
762 "]}";
763 ct = new CosmasTree(query);
764 map = ct.getRequestMap().get("query").toString();
765 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
766 }
767
Joachim Bingeld5161a12014-01-08 11:15:49 +0000768
769 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000770 public void testELEM() throws QueryException {
Joachim Bingeld5161a12014-01-08 11:15:49 +0000771 // http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/syntax/elem.html
Joachim Bingeleecc7652014-01-11 17:21:07 +0000772 query="#ELEM(S)";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000773 String elem1 = "{@type=korap:span, key=s}";
774 ct = new CosmasTree(query);
775 map = ct.getRequestMap().get("query").toString();
Joachim Bingeleecc7652014-01-11 17:21:07 +0000776 assertEquals(elem1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel402c6e12014-05-08 17:09:06 +0000777
778 query="#ELEM(W ANA=N)";
779 String elem2 =
780 "{@type=korap:span, key=w, attr=" +
781 "{@type=korap:termGroup, relation=relation:and, operands=[" +
782 "{@type=korap:term, layer=pos, key=N, match=match:eq}" +
783 "]}" +
784 "}";
785 ct = new CosmasTree(query);
786 map = ct.getRequestMap().get("query").toString();
787 assertEquals(elem2.replaceAll(" ", ""), map.replaceAll(" ", ""));
788
789 query="#ELEM(W ANA != 'N V')";
790 String elem3 =
791 "{@type=korap:span, key=w, attr=" +
792 "{@type=korap:termGroup, relation=relation:and, operands=[" +
Joachim Bingelb674cca2014-05-09 14:00:58 +0000793 "{@type=korap:term, layer=pos, key=N, match=match:ne}," +
794 "{@type=korap:term, layer=pos, key=V, match=match:ne}" +
Joachim Bingel402c6e12014-05-08 17:09:06 +0000795 "]}" +
796 "}";
797 ct = new CosmasTree(query);
798 map = ct.getRequestMap().get("query").toString();
799 assertEquals(elem3.replaceAll(" ", ""), map.replaceAll(" ", ""));
800
Joachim Bingelb674cca2014-05-09 14:00:58 +0000801 query="#ELEM(W ANA != 'N A V' Genre = Sport)";
Joachim Bingel402c6e12014-05-08 17:09:06 +0000802 String elem4 =
803 "{@type=korap:span, key=w, attr=" +
804 "{@type=korap:termGroup, relation=relation:and, operands=[" +
805 "{@type=korap:termGroup, relation=relation:and, operands=[" +
Joachim Bingelb674cca2014-05-09 14:00:58 +0000806 "{@type=korap:term, layer=pos, key=N, match=match:ne}," +
807 "{@type=korap:term, layer=pos, key=A, match=match:ne}," +
808 "{@type=korap:term, layer=pos, key=V, match=match:ne}" +
809 "]}," +
Joachim Bingel402c6e12014-05-08 17:09:06 +0000810 "{@type=korap:term, layer=Genre, key=Sport, match=match:eq}" +
811 "]}" +
812 "}";
813 ct = new CosmasTree(query);
814 map = ct.getRequestMap().get("query").toString();
815 assertEquals(elem4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb674cca2014-05-09 14:00:58 +0000816
817 query="#ELEM(W ANA != 'N V' Genre != 'Sport Politik')";
818 String elem5 =
819 "{@type=korap:span, key=w, attr=" +
820 "{@type=korap:termGroup, relation=relation:and, operands=[" +
821 "{@type=korap:termGroup, relation=relation:and, operands=[" +
822 "{@type=korap:term, layer=pos, key=N, match=match:ne}," +
823 "{@type=korap:term, layer=pos, key=V, match=match:ne}" +
824 "]}," +
825 "{@type=korap:termGroup, relation=relation:and, operands=[" +
826 "{@type=korap:term, layer=Genre, key=Sport, match=match:ne}," +
827 "{@type=korap:term, layer=Genre, key=Politik, match=match:ne}" +
828 "]}" +
829 "]}" +
830 "}";
831 ct = new CosmasTree(query);
832 map = ct.getRequestMap().get("query").toString();
833 assertEquals(elem5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeld5161a12014-01-08 11:15:49 +0000834 }
835
836 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000837 public void testOPALL() throws QueryException {
Joachim Bingel89cceac2014-01-08 15:51:08 +0000838 query="#ALL(gehen /w1:10 voran)";
Joachim Bingele98d0882014-01-21 12:58:54 +0000839 String all1 =
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000840 "{@type=korap:group, operation=operation:sequence, " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000841 "operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000842 "{@type=korap:token, wrap={@type=korap:term, key=gehen, layer=orth, match=match:eq}}," +
843 "{@type=korap:token, wrap={@type=korap:term, key=voran, layer=orth, match=match:eq}}" +
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000844 "], inOrder=false, " +
845 "distances=[" +
846 "{@type=korap:distance, key=w, min=1, max=10}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000847 "]" +
848 "}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000849 ct = new CosmasTree(query);
850 map = ct.getRequestMap().get("query").toString();
Joachim Bingel89cceac2014-01-08 15:51:08 +0000851 assertEquals(all1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeld5161a12014-01-08 11:15:49 +0000852 }
853
Joachim Bingel36233b52014-02-13 10:48:24 +0000854 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000855 public void testOPNHIT() throws QueryException {
Joachim Bingel89cceac2014-01-08 15:51:08 +0000856 query="#NHIT(gehen /w1:10 voran)";
857 String nhit1 =
Joachim Bingel0de1b412014-07-02 14:51:48 +0000858 "{@type=korap:reference, operation=operation:focus, classRef=[1,2], classRefOp=classRefOp:intersection, operands=[" +
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000859 "{@type=korap:group, operation=operation:sequence, " +
Joachim Bingel36233b52014-02-13 10:48:24 +0000860 "operands=[" +
861 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
862 "{@type=korap:token, wrap={@type=korap:term, key=gehen, layer=orth, match=match:eq}}" +
863 "]}," +
864 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
865 "{@type=korap:token, wrap={@type=korap:term, key=voran, layer=orth, match=match:eq}}" +
866 "]}" +
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000867 "], inOrder=false, " +
868 "distances=[" +
869 "{@type=korap:distance, key=w, min=1, max=10}" +
Joachim Bingel36233b52014-02-13 10:48:24 +0000870 "]" +
871 "}" +
872 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000873 ct = new CosmasTree(query);
874 map = ct.getRequestMap().get("query").toString();
Joachim Bingel89cceac2014-01-08 15:51:08 +0000875 assertEquals(nhit1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeld5161a12014-01-08 11:15:49 +0000876 }
877
878 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000879 public void testOPBED() throws QueryException {
Joachim Bingeleecc7652014-01-11 17:21:07 +0000880 query = "#BED(der , sa)";
881 String bed1 =
Joachim Bingel0de1b412014-07-02 14:51:48 +0000882 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands= [" +
Joachim Bingelcd7b7252014-02-13 08:49:14 +0000883 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
884 "{@type=korap:span, key=s}," +
885 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
886 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}" +
887 "]}" +
888 "]}" +
Joachim Bingeleecc7652014-01-11 17:21:07 +0000889 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000890 ct = new CosmasTree(query);
891 map = ct.getRequestMap().get("query").toString();
Joachim Bingeleecc7652014-01-11 17:21:07 +0000892 assertEquals(bed1.replaceAll(" ", ""), map.replaceAll(" ", ""));
893
894 query = "#BED(der Mann , +pe)";
895 String bed2 =
Joachim Bingel0de1b412014-07-02 14:51:48 +0000896 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands= [" +
Joachim Bingel36233b52014-02-13 10:48:24 +0000897 "{@type=korap:group, operation=operation:position, frame=frame:endswith, operands=[" +
898 "{@type=korap:span, key=p}," +
899 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
900 "{@type=korap:group, operation=operation:sequence, operands=[" +
901 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
902 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
903 "]}" +
904 "]}" +
905 "]}" +
906 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000907 ct = new CosmasTree(query);
908 map = ct.getRequestMap().get("query").toString();
Joachim Bingel36233b52014-02-13 10:48:24 +0000909 assertEquals(bed2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000910
911 query = "#BED(der Mann , sa,-pa)";
912 String bed3 =
Joachim Bingel0de1b412014-07-02 14:51:48 +0000913 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingel37a803f2014-07-28 14:21:44 +0000914 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel36233b52014-02-13 10:48:24 +0000915 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
916 "{@type=korap:span, key=s}," +
917 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
918 "{@type=korap:group, operation=operation:sequence, operands=[" +
919 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
920 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
921 "]}" +
922 "]}" +
923 "]}," +
Joachim Bingel37a803f2014-07-28 14:21:44 +0000924 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
Joachim Bingel36233b52014-02-13 10:48:24 +0000925 "{@type=korap:span, key=p}," +
Joachim Bingel402c6e12014-05-08 17:09:06 +0000926 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
Joachim Bingel36233b52014-02-13 10:48:24 +0000927 "{@type=korap:group, operation=operation:sequence, operands=[" +
928 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
929 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
930 "]}" +
931 "]}" +
Joachim Bingel37a803f2014-07-28 14:21:44 +0000932 "], exclude=true}" +
933 "], distances=[" +
934 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0, max=0}, min=0, max=0}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000935 "]}" +
936 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000937 ct = new CosmasTree(query);
938 map = ct.getRequestMap().get("query").toString();
Joachim Bingel36233b52014-02-13 10:48:24 +0000939 assertEquals(bed3.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeld5161a12014-01-08 11:15:49 +0000940 }
941
Joachim Bingel81812632014-02-18 08:55:22 +0000942 @Test
943 public void testColonSeparatedConditions() throws QueryException {
944
945 query = "Der:sa";
946 String col1 =
Joachim Bingel0de1b412014-07-02 14:51:48 +0000947 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingel81812632014-02-18 08:55:22 +0000948 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
949 "{@type=korap:span, key=s}," +
950 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
951 "{@type=korap:token, wrap={@type=korap:term, key=Der, layer=orth, match=match:eq}}" +
952 "]}" +
953 "]}" +
954 "]}";
955 ct = new CosmasTree(query);
956 map = ct.getRequestMap().get("query").toString();
957 assertEquals(col1.replaceAll(" ", ""), map.replaceAll(" ", ""));
958
959 query = "Mann:sa,-pa,+te)";
960 String col2 =
Joachim Bingel0de1b412014-07-02 14:51:48 +0000961 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingel37a803f2014-07-28 14:21:44 +0000962 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel81812632014-02-18 08:55:22 +0000963 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
964 "{@type=korap:span, key=s}," +
965 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
966 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
967 "]}" +
968 "]}," +
Joachim Bingel37a803f2014-07-28 14:21:44 +0000969 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
Joachim Bingel81812632014-02-18 08:55:22 +0000970 "{@type=korap:span, key=p}," +
Joachim Bingel402c6e12014-05-08 17:09:06 +0000971 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
Joachim Bingel81812632014-02-18 08:55:22 +0000972 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
973 "]}" +
Joachim Bingel37a803f2014-07-28 14:21:44 +0000974 "], exclude=true}," +
Joachim Bingel81812632014-02-18 08:55:22 +0000975 "{@type=korap:group, operation=operation:position, frame=frame:endswith, operands=[" +
976 "{@type=korap:span, key=t}," +
Joachim Bingel402c6e12014-05-08 17:09:06 +0000977 "{@type=korap:group, operation=operation:class, class=3, operands=[" +
Joachim Bingel81812632014-02-18 08:55:22 +0000978 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
979 "]}" +
980 "]}" +
Joachim Bingel37a803f2014-07-28 14:21:44 +0000981 "], distances=[" +
982 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0, max=0}, min=0, max=0}" +
Joachim Bingel81812632014-02-18 08:55:22 +0000983 "]}" +
984 "]}";
985 ct = new CosmasTree(query);
986 map = ct.getRequestMap().get("query").toString();
987 assertEquals(col2.replaceAll(" ", ""), map.replaceAll(" ", ""));
988 }
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000989}
990