blob: e7eec8746b4ca6c82c337e67073453b788d8db3c [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 Bingelfbc88792014-09-17 11:11:52 +0000280 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
281 "{@type=korap:group, operation=operation:sequence, " +
282 "operands=[" +
283 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
284 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
285 "]}," +
286 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
287 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
288 "]}" +
289 "], inOrder=true, " +
290 "distances=[" +
Joachim Bingelacb2ab32014-09-24 15:36:14 +0000291 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0, max=4}, min=0, max=4}" +
Joachim Bingelfbc88792014-09-17 11:11:52 +0000292 "]" +
293 "}" +
Joachim Bingelacb2ab32014-09-24 15:36:14 +0000294 "]}";
295// "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingel93e6c702014-09-30 15:19:23 +0000296// "{@type=korap:group, operation=operation:position, frames=[frame:], sharedClasses=[sharedClasses:intersects], operands=[" +
Joachim Bingelacb2ab32014-09-24 15:36:14 +0000297// "{@type=korap:group, operation=operation:class, class=0, operands=[" +
298// "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
299// "]}," +
300// "{@type=korap:group, operation=operation:class, class=0, operands=[" +
301// "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
302// "]}" +
Joachim Bingel93e6c702014-09-30 15:19:23 +0000303// "], frame=frame:overlaps}," +
Joachim Bingelacb2ab32014-09-24 15:36:14 +0000304// "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
305// "{@type=korap:group, operation=operation:sequence, " +
306// "operands=[" +
307// "{@type=korap:group, operation=operation:class, class=0, operands=[" +
308// "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
309// "]}," +
310// "{@type=korap:group, operation=operation:class, class=0, operands=[" +
311// "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
312// "]}" +
313// "], inOrder=true, " +
314// "distances=[" +
315// "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1, max=4}, min=1, max=4}" +
316// "]" +
317// "}" +
318// "]}" +
319// "]}";
320
321
Joachim Bingel2daf9862014-02-12 10:18:54 +0000322 ct = new CosmasTree(query);
323 map = ct.getRequestMap().get("query").toString();
Joachim Bingel87480d02014-01-17 14:07:46 +0000324 assertEquals(prox4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000325
326 query="Sonne /-w4 Mond";
327 String prox5 =
Joachim Bingelfbc88792014-09-17 11:11:52 +0000328 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
Joachim Bingel37a803f2014-07-28 14:21:44 +0000329 "{@type=korap:group, operation=operation:sequence, " +
330 "operands=[" +
Joachim Bingelfbc88792014-09-17 11:11:52 +0000331 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
332 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
333 "]}," +
334 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
335 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
336 "]}" +
Joachim Bingel37a803f2014-07-28 14:21:44 +0000337 "], inOrder=true, " +
338 "distances=[" +
Joachim Bingelacb2ab32014-09-24 15:36:14 +0000339 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0, max=4}, min=0, max=4}" +
Joachim Bingel37a803f2014-07-28 14:21:44 +0000340 "]" +
341 "}" +
Joachim Bingelacb2ab32014-09-24 15:36:14 +0000342 "]}";
343// "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingel93e6c702014-09-30 15:19:23 +0000344// "{@type=korap:group, operation=operation:position, frames=[frame:], sharedClasses=[sharedClasses:intersects], operands=[" +
Joachim Bingelacb2ab32014-09-24 15:36:14 +0000345// "{@type=korap:group, operation=operation:class, class=0, operands=[" +
346// "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
347// "]}," +
348// "{@type=korap:group, operation=operation:class, class=0, operands=[" +
349// "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
350// "]}" +
Joachim Bingel93e6c702014-09-30 15:19:23 +0000351// "], frame=frame:overlaps}," +
Joachim Bingelacb2ab32014-09-24 15:36:14 +0000352// "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
353// "{@type=korap:group, operation=operation:sequence, " +
354// "operands=[" +
355// "{@type=korap:group, operation=operation:class, class=0, operands=[" +
356// "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
357// "]}," +
358// "{@type=korap:group, operation=operation:class, class=0, operands=[" +
359// "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
360// "]}" +
361// "], inOrder=true, " +
362// "distances=[" +
363// "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1, max=4}, min=1, max=4}" +
364// "]" +
365// "}" +
366// "]}" +
367// "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000368 ct = new CosmasTree(query);
369 map = ct.getRequestMap().get("query").toString();
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000370 assertEquals(prox5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000371
372 query="Sonne /w4 Mond";
373 String prox6 =
Joachim Bingelfbc88792014-09-17 11:11:52 +0000374 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000375 "{@type=korap:group, operation=operation:sequence, " +
376 "operands=[" +
Joachim Bingelfbc88792014-09-17 11:11:52 +0000377 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
378 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
379 "]}," +
380 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
381 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
382 "]}" +
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000383 "], inOrder=false, " +
384 "distances=[" +
Joachim Bingelacb2ab32014-09-24 15:36:14 +0000385 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0, max=4}, min=0, max=4}" +
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000386 "]" +
Joachim Bingel37a803f2014-07-28 14:21:44 +0000387 "}" +
Joachim Bingelacb2ab32014-09-24 15:36:14 +0000388 "]}";
389// "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingel93e6c702014-09-30 15:19:23 +0000390// "{@type=korap:group, operation=operation:position, frames=[frame:], sharedClasses=[sharedClasses:intersects], operands=[" +
Joachim Bingelacb2ab32014-09-24 15:36:14 +0000391// "{@type=korap:group, operation=operation:class, class=0, operands=[" +
392// "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
393// "]}," +
394// "{@type=korap:group, operation=operation:class, class=0, operands=[" +
395// "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
396// "]}" +
Joachim Bingel93e6c702014-09-30 15:19:23 +0000397// "], frame=frame:overlaps}," +
Joachim Bingelacb2ab32014-09-24 15:36:14 +0000398// "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
399// "{@type=korap:group, operation=operation:sequence, " +
400// "operands=[" +
401// "{@type=korap:group, operation=operation:class, class=0, operands=[" +
402// "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
403// "]}," +
404// "{@type=korap:group, operation=operation:class, class=0, operands=[" +
405// "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
406// "]}" +
407// "], inOrder=false, " +
408// "distances=[" +
409// "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1, max=4}, min=1, max=4}" +
410// "]" +
411// "}" +
412// "]}" +
413// "]}";
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000414 ct = new CosmasTree(query);
415 map = ct.getRequestMap().get("query").toString();
416 assertEquals(prox6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000417 }
418
419 @Test
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000420 public void testOPPROXNested() throws QueryException {
Joachim Bingel09737972014-09-22 09:43:06 +0000421 query="Sonne /+w1:4 Mond /-w1:7 Sterne";
422 expected =
423 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
424 "{@type=korap:group, operation=operation:sequence, " +
425 "operands=[" +
426 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
427 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
428 "]}," +
429 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
430 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
431 "{@type=korap:group, operation=operation:sequence, " +
432 "operands=[" +
433 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
Joachim Bingelacb2ab32014-09-24 15:36:14 +0000434 "{@type=korap:token, wrap={@type=korap:term, key=Sterne, layer=orth, match=match:eq}}" +
Joachim Bingel09737972014-09-22 09:43:06 +0000435 "]}," +
436 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
Joachim Bingelacb2ab32014-09-24 15:36:14 +0000437 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
Joachim Bingel09737972014-09-22 09:43:06 +0000438 "]}" +
439 "], inOrder=true, " +
440 "distances=[" +
441 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1, max=7}, min=1, max=7}" +
442 "]" +
443 "}" +
444 "]}" +
445 "]}" +
446 "], inOrder=true, " +
447 "distances=[" +
448 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1, max=4}, min=1, max=4}" +
449 "]" +
450 "}" +
451 "]}" +
452 "" ;
453 ct = new CosmasTree(query);
454 map = ct.getRequestMap().get("query").toString();
455 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
456
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000457 query="Sonne /-w4 Mond /+w2 Sterne";
Joachim Bingel37a803f2014-07-28 14:21:44 +0000458
Joachim Bingelceb79062014-09-22 11:50:37 +0000459// String mondsterne =
460// "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}," +
461// "{@type=korap:token, wrap={@type=korap:term, key=Sterne, layer=orth, match=match:eq}}" ;
Joachim Bingelfbc88792014-09-17 11:11:52 +0000462
463 String mondsterneClasses =
464 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
465 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
466 "]}," +
467 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
468 "{@type=korap:token, wrap={@type=korap:term, key=Sterne, layer=orth, match=match:eq}}" +
469 "]}";
Joachim Bingelceb79062014-09-22 11:50:37 +0000470// String mondsterneSeq =
471// "{@type=korap:group, operation=operation:sequence, operands=[" +
472// mondsterne +
473// "], inOrder=true, distances=[" +
474// "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1, max=2}, min=1, max=2}" +
475// "]}" ;
Joachim Bingelfbc88792014-09-17 11:11:52 +0000476 String mondsterneClassesSeq =
477 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
478 "{@type=korap:group, operation=operation:sequence, operands=[" +
479 mondsterneClasses +
480 "], inOrder=true, distances=[" +
481 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1, max=2}, min=1, max=2}" +
482 "]}" +
483 "]}" ;
Joachim Bingelceb79062014-09-22 11:50:37 +0000484// String mondsterneOv =
Joachim Bingel93e6c702014-09-30 15:19:23 +0000485// "{@type=korap:group, operation=operation:position, frames=[frame:], sharedClasses=[sharedClasses:intersects], operands=[" +
Joachim Bingelceb79062014-09-22 11:50:37 +0000486// mondsterne +
487// "]}";
Joachim Bingelfbc88792014-09-17 11:11:52 +0000488 String mondsterneClassesOv =
Joachim Bingel93e6c702014-09-30 15:19:23 +0000489 "{@type=korap:group, operation=operation:position, frames=[frame:], sharedClasses=[sharedClasses:intersects], operands=[" +
Joachim Bingelfbc88792014-09-17 11:11:52 +0000490 mondsterneClasses +
Joachim Bingel93e6c702014-09-30 15:19:23 +0000491 "], frame=frame:overlaps}";
Joachim Bingelceb79062014-09-22 11:50:37 +0000492// String mondsterneAll =
493// "{@type=korap:group, operation=operation:or, operands=[" +
494// mondsterneOv + "," + mondsterneClassesSeq +
495// "]}";
Joachim Bingelfbc88792014-09-17 11:11:52 +0000496 String mondsterneAllClasses =
497 "{@type=korap:group, operation=operation:or, operands=[" +
498 mondsterneClassesOv + "," + mondsterneClassesSeq +
499 "]}";
500
501
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000502 String prox6 =
Joachim Bingelfbc88792014-09-17 11:11:52 +0000503 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
Joachim Bingelacb2ab32014-09-24 15:36:14 +0000504 "{@type=korap:group, operation=operation:sequence, " +
505 "operands=[" +
Joachim Bingelacb2ab32014-09-24 15:36:14 +0000506 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
507 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
508 "{@type=korap:group, operation=operation:sequence, " +
509 "operands=[" +
510 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
511 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
512 "]}," +
513 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
514 "{@type=korap:token, wrap={@type=korap:term, key=Sterne, layer=orth, match=match:eq}}" +
515 "]}" +
516 "], inOrder=true, " +
517 "distances=[" +
518 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0, max=2}, min=0, max=2}" +
519 "]" +
520 "}" +
521 "]}" +
522 "]}," +
523 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
524 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
525 "]}" +
526 "], inOrder=true, " +
527 "distances=[" +
528 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0, max=4}, min=0, max=4}" +
529 "]" +
530 "}" +
531 "]}" +
532 "" ;
533// "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingel93e6c702014-09-30 15:19:23 +0000534// "{@type=korap:group, operation=operation:position, frames=[frame:], sharedClasses=[sharedClasses:intersects], operands=[" +
Joachim Bingelacb2ab32014-09-24 15:36:14 +0000535// "{@type=korap:group, operation=operation:class, class=0, operands=[" +
536// mondsterneAllClasses +
537// "]}," +
538// "{@type=korap:group, operation=operation:class, class=0, operands=[" +
539// "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
540// "]}" +
Joachim Bingel93e6c702014-09-30 15:19:23 +0000541// "], frame=frame:overlaps}," +
Joachim Bingelacb2ab32014-09-24 15:36:14 +0000542// "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
543// "{@type=korap:group, operation=operation:sequence, " +
544// "operands=[" +
545// "{@type=korap:group, operation=operation:class, class=0, operands=[" +
546// mondsterneAllClasses +
547// "]}," +
548// "{@type=korap:group, operation=operation:class, class=0, operands=[" +
549// "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
550// "]}" +
551// "], inOrder=true, " +
552// "distances=[" +
553// "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1, max=4}, min=1, max=4}" +
554// "]" +
555// "}" +
556// "]}" +
557// "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000558 ct = new CosmasTree(query);
559 map = ct.getRequestMap().get("query").toString();
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000560 assertEquals(prox6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000561 }
562
563 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000564 public void testOPIN() throws QueryException {
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000565 query="wegen #IN <s>";
Joachim Bingel3a9f7932014-01-07 17:11:31 +0000566 String opin1 =
Joachim Bingel0de1b412014-07-02 14:51:48 +0000567 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingel09737972014-09-22 09:43:06 +0000568 "{@type=korap:group, operation=operation:position, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000569 "{@type=korap:span, key=s}," +
570 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000571 "{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
Joachim Bingeleecc7652014-01-11 17:21:07 +0000572 "]}" +
Joachim Bingel93e6c702014-09-30 15:19:23 +0000573 "], frames=[], sharedClasses=[sharedClasses:includes], frame=frame:contains}" +
Joachim Bingeld5161a12014-01-08 11:15:49 +0000574 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000575 ct = new CosmasTree(query);
576 map = ct.getRequestMap().get("query").toString();
Joachim Bingeld5161a12014-01-08 11:15:49 +0000577 assertEquals(opin1.replaceAll(" ", ""), map.replaceAll(" ", ""));
578
Joachim Bingel09737972014-09-22 09:43:06 +0000579 query="wegen #IN(L) <s>";
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000580 String opin2 =
Joachim Bingel0de1b412014-07-02 14:51:48 +0000581 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingel09737972014-09-22 09:43:06 +0000582 "{@type=korap:group, operation=operation:position, operands=[" +
583 "{@type=korap:span, key=s}," +
584 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
585 "{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
586 "]}" +
Joachim Bingel93e6c702014-09-30 15:19:23 +0000587 "], frames=[frame:startswith], sharedClasses=[sharedClasses:includes], frame=frame:startswith}" +
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000588 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000589 ct = new CosmasTree(query);
590 map = ct.getRequestMap().get("query").toString();
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000591 assertEquals(opin2.replaceAll(" ", ""), map.replaceAll(" ", ""));
592
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000593
594 query="wegen #IN(F) <s>";
595 String opin3=
596 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingel09737972014-09-22 09:43:06 +0000597 "{@type=korap:group, operation=operation:position, operands=[" +
598 "{@type=korap:span, key=s}," +
599 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
600 "{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
601 "]}" +
Joachim Bingel93e6c702014-09-30 15:19:23 +0000602 "], frames=[frame:matches], sharedClasses=[sharedClasses:includes], frame=frame:matches}" +
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000603 "]}" +
604 "";
605 ct = new CosmasTree(query);
606 map = ct.getRequestMap().get("query").toString();
607 assertEquals(opin3.replaceAll(" ", ""), map.replaceAll(" ", ""));
608
609 query="wegen #IN(FI) <s>";
610 String opin4=
611 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingel09737972014-09-22 09:43:06 +0000612 "{@type=korap:group, operation=operation:position, operands=[" +
613 "{@type=korap:span, key=s}," +
614 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
615 "{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
616 "]}" +
Joachim Bingel93e6c702014-09-30 15:19:23 +0000617 "], frames=[frame:matches], sharedClasses=[sharedClasses:unequals,sharedClasses:includes], frame=frame:matches-noident}" +
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000618 "]}" +
619 "";
620 ct = new CosmasTree(query);
621 map = ct.getRequestMap().get("query").toString();
622 assertEquals(opin4.replaceAll(" ", ""), map.replaceAll(" ", ""));
623
624 query="wegen #IN(FE) <s>";
625 String opin5=
Joachim Bingel09737972014-09-22 09:43:06 +0000626 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
627 "{@type=korap:group, operation=operation:position, operands=[" +
628 "{@type=korap:span, key=s}," +
629 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
630 "{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000631 "]}" +
Joachim Bingel93e6c702014-09-30 15:19:23 +0000632 "], frames=[frame:matches], sharedClasses=[sharedClasses:equals], frame=frame:matches}" +
Joachim Bingel09737972014-09-22 09:43:06 +0000633 "]}" +
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000634 "";
635 ct = new CosmasTree(query);
636 map = ct.getRequestMap().get("query").toString();
637 assertEquals(opin5.replaceAll(" ", ""), map.replaceAll(" ", ""));
638
Joachim Bingel87480d02014-01-17 14:07:46 +0000639 query="wegen #IN(%, L) <s>";
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000640 String opin6 =
Joachim Bingel0de1b412014-07-02 14:51:48 +0000641 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingel09737972014-09-22 09:43:06 +0000642 "{@type=korap:group, operation=operation:position, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000643 "{@type=korap:span, key=s}," +
644 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000645 "{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000646 "]}" +
Joachim Bingel93e6c702014-09-30 15:19:23 +0000647 "], frames=[frame:startswith], sharedClasses=[sharedClasses:includes], frame=frame:startswith, exclude=true}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000648 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000649 ct = new CosmasTree(query);
650 map = ct.getRequestMap().get("query").toString();
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000651 assertEquals(opin6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel87480d02014-01-17 14:07:46 +0000652
653 query="wegen #IN('FE,ALL,%,MIN') <s>";
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000654 String opin7 =
Joachim Bingel0de1b412014-07-02 14:51:48 +0000655 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingel09737972014-09-22 09:43:06 +0000656 "{@type=korap:group, operation=operation:position, operands=[" +
657 "{@type=korap:reference, operation=operation:focus, reset=true, operands=[" +
658 "{@type=korap:span, key=s}" +
659 "]}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000660 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000661 "{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000662 "]}" +
Joachim Bingel93e6c702014-09-30 15:19:23 +0000663 "], frames=[frame:matches], sharedClasses=[sharedClasses:equals], frame=frame:matches, exclude=true, grouping=false}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000664 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000665 ct = new CosmasTree(query);
666 map = ct.getRequestMap().get("query").toString();
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000667 assertEquals(opin7.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeld5161a12014-01-08 11:15:49 +0000668 }
669
670 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000671 public void testOPOV() throws QueryException {
Joachim Bingeld5161a12014-01-08 11:15:49 +0000672 query="wegen #OV <s>";
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000673 String opov1 =
Joachim Bingel0de1b412014-07-02 14:51:48 +0000674 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingel09737972014-09-22 09:43:06 +0000675 "{@type=korap:group, operation=operation:position, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000676 "{@type=korap:span, key=s}," +
677 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000678 "{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000679 "]}" +
Joachim Bingel93e6c702014-09-30 15:19:23 +0000680 "], frames=[], sharedClasses=[sharedClasses:intersects], frame=frame:overlaps}" +
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000681 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000682 ct = new CosmasTree(query);
683 map = ct.getRequestMap().get("query").toString();
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000684 assertEquals(opov1.replaceAll(" ", ""), map.replaceAll(" ", ""));
685
686 query="wegen #OV(L) <s>";
687 String opov2 =
Joachim Bingel0de1b412014-07-02 14:51:48 +0000688 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingel09737972014-09-22 09:43:06 +0000689 "{@type=korap:group, operation=operation:position, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000690 "{@type=korap:span, key=s}," +
691 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000692 "{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000693 "]}" +
Joachim Bingel93e6c702014-09-30 15:19:23 +0000694 "], frames=[frame:startswith,frame:overlapsLeft], sharedClasses=[sharedClasses:intersects], frame=frame:overlapsLeft}" +
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000695 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000696 ct = new CosmasTree(query);
697 map = ct.getRequestMap().get("query").toString();
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000698 assertEquals(opov2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000699
700 query="wegen #OV(F) <s>";
701 String opov3=
702 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingel09737972014-09-22 09:43:06 +0000703 "{@type=korap:group, operation=operation:position, operands=[" +
704 "{@type=korap:span, key=s}," +
705 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
706 "{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
707 "]}" +
Joachim Bingel93e6c702014-09-30 15:19:23 +0000708 "], frames=[frame:matches], sharedClasses=[sharedClasses:intersects], frame=frame:matches}" +
Joachim Bingel09737972014-09-22 09:43:06 +0000709 "]}";
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000710 ct = new CosmasTree(query);
711 map = ct.getRequestMap().get("query").toString();
712 assertEquals(opov3.replaceAll(" ", ""), map.replaceAll(" ", ""));
713
714 query="wegen #OV(FI) <s>";
715 String opov4=
716 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingel09737972014-09-22 09:43:06 +0000717 "{@type=korap:group, operation=operation:position, operands=[" +
718 "{@type=korap:span, key=s}," +
719 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
720 "{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
721 "]}" +
Joachim Bingel93e6c702014-09-30 15:19:23 +0000722 "], frames=[frame:matches], sharedClasses=[sharedClasses:unequals], frame=frame:matches-noident}" +
Joachim Bingel09737972014-09-22 09:43:06 +0000723 "]}";
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000724 ct = new CosmasTree(query);
725 map = ct.getRequestMap().get("query").toString();
726 assertEquals(opov4.replaceAll(" ", ""), map.replaceAll(" ", ""));
727
728 query="wegen #OV(FE) <s>";
729 String opov5=
730 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingel09737972014-09-22 09:43:06 +0000731 "{@type=korap:group, operation=operation:position, operands=[" +
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000732 "{@type=korap:span, key=s}," +
733 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
734 "{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" +
735 "]}" +
Joachim Bingel93e6c702014-09-30 15:19:23 +0000736 "], frames=[frame:matches], sharedClasses=[sharedClasses:equals], frame=frame:matches}" +
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000737 "]}" +
738 "";
739 ct = new CosmasTree(query);
740 map = ct.getRequestMap().get("query").toString();
741 assertEquals(opov5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000742 }
743
744 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000745 public void testOPNOT() throws QueryException {
Joachim Bingel3a9f7932014-01-07 17:11:31 +0000746 query="Sonne nicht Mond";
747 String opnot1 =
Joachim Bingelb7a59792014-02-14 13:52:29 +0000748 "{@type=korap:group, operation=operation:sequence, distances=[" +
749 "{@type=korap:distance, key=t, min=0, max=0, exclude=true}" +
750 "], operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000751 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}," +
752 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
Joachim Bingel3a9f7932014-01-07 17:11:31 +0000753 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000754 ct = new CosmasTree(query);
755 map = ct.getRequestMap().get("query").toString();
Joachim Bingel3a9f7932014-01-07 17:11:31 +0000756 assertEquals(opnot1.replaceAll(" ", ""), map.replaceAll(" ", ""));
757 }
758
759 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000760 public void testBEG_END() throws QueryException {
Joachim Bingel3a9f7932014-01-07 17:11:31 +0000761 // BEG and END operators
762 // http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/syntax/links.html
763 // http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/syntax/rechts.html
764 // http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/thematische-bsp/bsp-satzlaenge.html
Joachim Bingel87480d02014-01-17 14:07:46 +0000765 query="#BEG(der /w3:5 Mann)";
766 String beg1 =
Joachim Bingel0de1b412014-07-02 14:51:48 +0000767 "{@type=korap:reference, operation=operation:focus, spanRef=[0,1], operands=[" +
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000768 "{@type=korap:group, operation=operation:sequence," +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000769 "operands = [" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000770 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
771 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000772 "], inOrder=false, distances=[" +
Joachim Bingel03dfd952014-07-30 08:08:53 +0000773 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=3, max=5}, min=3, max=5}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000774 "]}" +
775 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000776 ct = new CosmasTree(query);
777 map = ct.getRequestMap().get("query").toString();
Joachim Bingel87480d02014-01-17 14:07:46 +0000778 assertEquals(beg1.replaceAll(" ", ""), map.replaceAll(" ", ""));
779
Joachim Bingel37a803f2014-07-28 14:21:44 +0000780
Joachim Bingelfbc88792014-09-17 11:11:52 +0000781// String dermannSeq = "{@type=korap:group, operation=operation:sequence," +
782// "operands = [" +
783// "{@type=korap:group, operation=operation:class, class=0, operands=[" +
784// "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}" +
785// "]}," +
786// "{@type=korap:group, operation=operation:class, class=0, operands=[" +
787// "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
788// "]}" +
789//
790// "], inOrder=false, distances=[" +
791// "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=3, max=5}, min=3, max=5}" +
792// "]}";
793//
794// String begDermannSeq =
795//// "{@type=korap:group, operation=operation:class, class=0, operands=[" +
796// "{@type=korap:reference, operation=operation:focus, spanRef=[0,1], operands=[" +
797// dermannSeq +
798// "]}" +
799//// "]}" +
800// "";
801
Joachim Bingel37a803f2014-07-28 14:21:44 +0000802 String kommt = "{@type=korap:token, wrap={@type=korap:term, key=kommt, layer=orth, match=match:eq}}";
803
Joachim Bingel87480d02014-01-17 14:07:46 +0000804 query="#BEG(der /w3:5 Mann) /+w10 kommt"; // nesting #BEG() in a distance group
805 String beg2 =
Joachim Bingelacb2ab32014-09-24 15:36:14 +0000806// "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingel93e6c702014-09-30 15:19:23 +0000807// "{@type=korap:group, operation=operation:position, frames=[frame:], sharedClasses=[sharedClasses:intersects], operands=[" +
Joachim Bingelacb2ab32014-09-24 15:36:14 +0000808// "{@type=korap:group, operation=operation:class, class=0, operands=[" +
809// beg1 +
810// "]}" + "," +
811// "{@type=korap:group, operation=operation:class, class=0, operands=[" +
812// kommt +
813// "]}" +
Joachim Bingel93e6c702014-09-30 15:19:23 +0000814// "], frame=frame:overlaps}," +
Joachim Bingelacb2ab32014-09-24 15:36:14 +0000815// "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
816// "{@type=korap:group, operation=operation:sequence, operands=[" +
817// "{@type=korap:group, operation=operation:class, class=0, operands=[" +
818// beg1 +
819// "]}," +
820// "{@type=korap:group, operation=operation:class, class=0, operands=[" +
821// kommt +
822// "]}" +
823// "], inOrder=true, distances=[" +
824// "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1, max=10}, min=1, max=10}" +
825// "]}" +
826// "]}" +
827// "]}";
828//
Joachim Bingelfbc88792014-09-17 11:11:52 +0000829 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
830 "{@type=korap:group, operation=operation:sequence, operands=[" +
831 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
832 beg1 +
833 "]}," +
834 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
835 kommt +
836 "]}" +
837 "], inOrder=true, distances=[" +
Joachim Bingelacb2ab32014-09-24 15:36:14 +0000838 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0, max=10}, min=0, max=10}" +
Joachim Bingelfbc88792014-09-17 11:11:52 +0000839 "]}" +
Joachim Bingelacb2ab32014-09-24 15:36:14 +0000840 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000841 ct = new CosmasTree(query);
842 map = ct.getRequestMap().get("query").toString();
Joachim Bingel87480d02014-01-17 14:07:46 +0000843 assertEquals(beg2.replaceAll(" ", ""), map.replaceAll(" ", ""));
844
Joachim Bingel37a803f2014-07-28 14:21:44 +0000845 query="kommt /+w10 #BEG(der /w3:5 Mann)";
846 String beg3 =
Joachim Bingelacb2ab32014-09-24 15:36:14 +0000847// "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingel93e6c702014-09-30 15:19:23 +0000848// "{@type=korap:group, operation=operation:position, frames=[frame:], sharedClasses=[sharedClasses:intersects], operands=[" +
Joachim Bingelacb2ab32014-09-24 15:36:14 +0000849// "{@type=korap:group, operation=operation:class, class=0, operands=[" +
850// kommt +
851//// "," +
852// "]}," +
853// "{@type=korap:group, operation=operation:class, class=0, operands=[" +
854// beg1+
855// "]}" +
Joachim Bingel93e6c702014-09-30 15:19:23 +0000856// "], frame=frame:overlaps}," +
Joachim Bingelacb2ab32014-09-24 15:36:14 +0000857// "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
858// "{@type=korap:group, operation=operation:sequence, operands=[" +
859// "{@type=korap:group, operation=operation:class, class=0, operands=[" +
860// kommt +
861// "]}," +
862// "{@type=korap:group, operation=operation:class, class=0, operands=[" +
863// beg1+
864// "]}" +
865// "], inOrder=true, distances=[" +
866// "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1, max=10}, min=1, max=10}" +
867// "]}" +
868// "]}" +
869// "]}";
870
Joachim Bingelfbc88792014-09-17 11:11:52 +0000871 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
872 "{@type=korap:group, operation=operation:sequence, operands=[" +
873 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
874 kommt +
875 "]}," +
876 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
877 beg1+
878 "]}" +
879 "], inOrder=true, distances=[" +
Joachim Bingelacb2ab32014-09-24 15:36:14 +0000880 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0, max=10}, min=0, max=10}" +
Joachim Bingelfbc88792014-09-17 11:11:52 +0000881 "]}" +
Joachim Bingelacb2ab32014-09-24 15:36:14 +0000882 "]}";
Joachim Bingel37a803f2014-07-28 14:21:44 +0000883 ct = new CosmasTree(query);
884 map = ct.getRequestMap().get("query").toString();
885 assertEquals(beg3.replaceAll(" ", ""), map.replaceAll(" ", ""));
886
Joachim Bingel87480d02014-01-17 14:07:46 +0000887 query="#END(der /w3:5 Mann)";
888 String end1 =
Joachim Bingel0de1b412014-07-02 14:51:48 +0000889 "{@type=korap:reference, operation=operation:focus, spanRef=[-1,1], operands=[" +
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000890 "{@type=korap:group, operation=operation:sequence, " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000891 "operands = [" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000892 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
893 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
Joachim Bingel097c1eb2014-07-11 14:57:25 +0000894 "], inOrder=false, distances=[" +
Joachim Bingel03dfd952014-07-30 08:08:53 +0000895 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=3, max=5}, min=3, max=5}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000896 "]}" +
897 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000898 ct = new CosmasTree(query);
899 map = ct.getRequestMap().get("query").toString();
Joachim Bingel87480d02014-01-17 14:07:46 +0000900 assertEquals(end1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000901 }
Joachim Bingeld5161a12014-01-08 11:15:49 +0000902
Joachim Bingel03dfd952014-07-30 08:08:53 +0000903 /*
904 * YET UNCLEAR HOW TO SERIALIZE SPAN DISTANCES. BEING DISCUSSED.
905 *
Joachim Bingel37a803f2014-07-28 14:21:44 +0000906 @Test
907 public void testSentenceDistance() throws QueryException {
Joachim Bingel03dfd952014-07-30 08:08:53 +0000908 query="Sonne /s0 Mond"; // contains(focus(1:contains({1:<s>},Sonne)),Mond)
Joachim Bingel37a803f2014-07-28 14:21:44 +0000909 expected =
Joachim Bingel93e6c702014-09-30 15:19:23 +0000910 "{@type=korap:group, operation=operation:position, frame=frame:frame:contains, operands=[" +
Joachim Bingel03dfd952014-07-30 08:08:53 +0000911 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingel93e6c702014-09-30 15:19:23 +0000912 "{@type=korap:group, operation=operation:position, frame=frame:frame:contains, operands=[" +
Joachim Bingel03dfd952014-07-30 08:08:53 +0000913 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
Joachim Bingel37a803f2014-07-28 14:21:44 +0000914 "{@type=korap:span, key=s}" +
915 "]}," +
916 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
917 "]}" +
918 "]}," +
919 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
920 "]}";
921 ct = new CosmasTree(query);
922 map = ct.getRequestMap().get("query").toString();
923 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
924
Joachim Bingel03dfd952014-07-30 08:08:53 +0000925 query="Sonne /s0,w5 Mond";
926 expected =
Joachim Bingel93e6c702014-09-30 15:19:23 +0000927 "{@type=korap:group, operation=operation:position, frame=frame:frame:contains, operands=[" +
Joachim Bingel03dfd952014-07-30 08:08:53 +0000928 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingel93e6c702014-09-30 15:19:23 +0000929 "{@type=korap:group, operation=operation:position, frame=frame:frame:contains, operands=[" +
Joachim Bingel03dfd952014-07-30 08:08:53 +0000930 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
931 "{@type=korap:span, key=s}" +
932 "]}," +
933 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
934 "]}" +
935 "]}," +
936 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
937 "]}";
938// ct = new CosmasTree(query);
939// map = ct.getRequestMap().get("query").toString();
940// assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
941
Joachim Bingel37a803f2014-07-28 14:21:44 +0000942 query="Sonne /s2:2 Mond"; // contains(<s>,Sonne)<s>contains(<s>,Mond)
943 expected =
944 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel93e6c702014-09-30 15:19:23 +0000945 "{@type=korap:group, operation=operation:position, frame=frame:frame:contains, operands=[" +
Joachim Bingel37a803f2014-07-28 14:21:44 +0000946 "{@type=korap:span, key=s}," +
947 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
948 "]}," +
949 "{@type=korap:span, key=s}," +
Joachim Bingel93e6c702014-09-30 15:19:23 +0000950 "{@type=korap:group, operation=operation:position, frame=frame:frame:contains, operands=[" +
Joachim Bingel37a803f2014-07-28 14:21:44 +0000951 "{@type=korap:span, key=s}," +
952 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
Joachim Bingel03dfd952014-07-30 08:08:53 +0000953 "]}" +
Joachim Bingel37a803f2014-07-28 14:21:44 +0000954 "]}";
955 ct = new CosmasTree(query);
956 map = ct.getRequestMap().get("query").toString();
Joachim Bingel03dfd952014-07-30 08:08:53 +0000957// assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel37a803f2014-07-28 14:21:44 +0000958
Joachim Bingel03dfd952014-07-30 08:08:53 +0000959 query="Sonne /s2:3 Mond"; // contains(<s>,Sonne)<s>contains(<s>,Mond)
960 expected =
961 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel93e6c702014-09-30 15:19:23 +0000962 "{@type=korap:group, operation=operation:position, frame=frame:frame:contains, operands=[" +
Joachim Bingel03dfd952014-07-30 08:08:53 +0000963 "{@type=korap:span, key=s}," +
964 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
965 "]}," +
966 "{@type=korap:group, operation=operation:repetition, operands=[" +
967 "{@type=korap:span, key=s}" +
968 "], boundary={@type=korap:boundary, min=1, max=2}, min=1, max=2}," +
Joachim Bingel93e6c702014-09-30 15:19:23 +0000969 "{@type=korap:group, operation=operation:position, frame=frame:frame:contains, operands=[" +
Joachim Bingel03dfd952014-07-30 08:08:53 +0000970 "{@type=korap:span, key=s}," +
971 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
972 "]}" +
973 "]}";
974 ct = new CosmasTree(query);
975 map = ct.getRequestMap().get("query").toString();
976// assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
977
978 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 +0000979 expected =
980 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingel93e6c702014-09-30 15:19:23 +0000981 "{@type=korap:group, operation=operation:position, frame=frame:frame:contains, operands=[" +
Joachim Bingel03dfd952014-07-30 08:08:53 +0000982 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingel93e6c702014-09-30 15:19:23 +0000983 "{@type=korap:group, operation=operation:position, frame=frame:frame:contains, operands=[" +
Joachim Bingel03dfd952014-07-30 08:08:53 +0000984 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
Joachim Bingel37a803f2014-07-28 14:21:44 +0000985 "{@type=korap:span, key=s}" +
986 "]}," +
987 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
988 "]}" +
989 "]}," +
990 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
991 "]}," +
992 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel93e6c702014-09-30 15:19:23 +0000993 "{@type=korap:group, operation=operation:position, frame=frame:frame:contains, operands=[" +
Joachim Bingel37a803f2014-07-28 14:21:44 +0000994 "{@type=korap:span, key=s}," +
995 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" +
996 "]}," +
Joachim Bingel03dfd952014-07-30 08:08:53 +0000997 "{@type=korap:group, operation=operation:repetition, operands=[" +
998 "{@type=korap:span, key=s}" +
999 "], boundary={@type=korap:boundary, min=0, max=1}, min=0, max=1}," +
Joachim Bingel93e6c702014-09-30 15:19:23 +00001000 "{@type=korap:group, operation=operation:position, frame=frame:frame:contains, operands=[" +
Joachim Bingel37a803f2014-07-28 14:21:44 +00001001 "{@type=korap:span, key=s}," +
1002 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" +
Joachim Bingel03dfd952014-07-30 08:08:53 +00001003 "]}" +
Joachim Bingel37a803f2014-07-28 14:21:44 +00001004 "]}" +
1005 "]}";
1006 ct = new CosmasTree(query);
1007 map = ct.getRequestMap().get("query").toString();
Joachim Bingel03dfd952014-07-30 08:08:53 +00001008// assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel37a803f2014-07-28 14:21:44 +00001009 }
Joachim Bingel03dfd952014-07-30 08:08:53 +00001010 */
Joachim Bingel37a803f2014-07-28 14:21:44 +00001011
Joachim Bingeld5161a12014-01-08 11:15:49 +00001012
1013 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +00001014 public void testELEM() throws QueryException {
Joachim Bingeld5161a12014-01-08 11:15:49 +00001015 // http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/syntax/elem.html
Joachim Bingeleecc7652014-01-11 17:21:07 +00001016 query="#ELEM(S)";
Joachim Bingel2daf9862014-02-12 10:18:54 +00001017 String elem1 = "{@type=korap:span, key=s}";
1018 ct = new CosmasTree(query);
1019 map = ct.getRequestMap().get("query").toString();
Joachim Bingeleecc7652014-01-11 17:21:07 +00001020 assertEquals(elem1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel402c6e12014-05-08 17:09:06 +00001021
1022 query="#ELEM(W ANA=N)";
1023 String elem2 =
1024 "{@type=korap:span, key=w, attr=" +
1025 "{@type=korap:termGroup, relation=relation:and, operands=[" +
1026 "{@type=korap:term, layer=pos, key=N, match=match:eq}" +
1027 "]}" +
1028 "}";
1029 ct = new CosmasTree(query);
1030 map = ct.getRequestMap().get("query").toString();
1031 assertEquals(elem2.replaceAll(" ", ""), map.replaceAll(" ", ""));
1032
1033 query="#ELEM(W ANA != 'N V')";
1034 String elem3 =
1035 "{@type=korap:span, key=w, attr=" +
1036 "{@type=korap:termGroup, relation=relation:and, operands=[" +
Joachim Bingelb674cca2014-05-09 14:00:58 +00001037 "{@type=korap:term, layer=pos, key=N, match=match:ne}," +
1038 "{@type=korap:term, layer=pos, key=V, match=match:ne}" +
Joachim Bingel402c6e12014-05-08 17:09:06 +00001039 "]}" +
1040 "}";
1041 ct = new CosmasTree(query);
1042 map = ct.getRequestMap().get("query").toString();
1043 assertEquals(elem3.replaceAll(" ", ""), map.replaceAll(" ", ""));
1044
Joachim Bingelb674cca2014-05-09 14:00:58 +00001045 query="#ELEM(W ANA != 'N A V' Genre = Sport)";
Joachim Bingel402c6e12014-05-08 17:09:06 +00001046 String elem4 =
1047 "{@type=korap:span, key=w, attr=" +
1048 "{@type=korap:termGroup, relation=relation:and, operands=[" +
1049 "{@type=korap:termGroup, relation=relation:and, operands=[" +
Joachim Bingelb674cca2014-05-09 14:00:58 +00001050 "{@type=korap:term, layer=pos, key=N, match=match:ne}," +
1051 "{@type=korap:term, layer=pos, key=A, match=match:ne}," +
1052 "{@type=korap:term, layer=pos, key=V, match=match:ne}" +
1053 "]}," +
Joachim Bingel402c6e12014-05-08 17:09:06 +00001054 "{@type=korap:term, layer=Genre, key=Sport, match=match:eq}" +
1055 "]}" +
1056 "}";
1057 ct = new CosmasTree(query);
1058 map = ct.getRequestMap().get("query").toString();
1059 assertEquals(elem4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb674cca2014-05-09 14:00:58 +00001060
1061 query="#ELEM(W ANA != 'N V' Genre != 'Sport Politik')";
1062 String elem5 =
1063 "{@type=korap:span, key=w, attr=" +
1064 "{@type=korap:termGroup, relation=relation:and, operands=[" +
1065 "{@type=korap:termGroup, relation=relation:and, operands=[" +
1066 "{@type=korap:term, layer=pos, key=N, match=match:ne}," +
1067 "{@type=korap:term, layer=pos, key=V, match=match:ne}" +
1068 "]}," +
1069 "{@type=korap:termGroup, relation=relation:and, operands=[" +
1070 "{@type=korap:term, layer=Genre, key=Sport, match=match:ne}," +
1071 "{@type=korap:term, layer=Genre, key=Politik, match=match:ne}" +
1072 "]}" +
1073 "]}" +
1074 "}";
1075 ct = new CosmasTree(query);
1076 map = ct.getRequestMap().get("query").toString();
1077 assertEquals(elem5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeld5161a12014-01-08 11:15:49 +00001078 }
1079
1080 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +00001081 public void testOPALL() throws QueryException {
Joachim Bingel89cceac2014-01-08 15:51:08 +00001082 query="#ALL(gehen /w1:10 voran)";
Joachim Bingele98d0882014-01-21 12:58:54 +00001083 String all1 =
Joachim Bingel097c1eb2014-07-11 14:57:25 +00001084 "{@type=korap:group, operation=operation:sequence, " +
Joachim Bingel11d5b152014-02-11 21:33:47 +00001085 "operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +00001086 "{@type=korap:token, wrap={@type=korap:term, key=gehen, layer=orth, match=match:eq}}," +
1087 "{@type=korap:token, wrap={@type=korap:term, key=voran, layer=orth, match=match:eq}}" +
Joachim Bingel097c1eb2014-07-11 14:57:25 +00001088 "], inOrder=false, " +
1089 "distances=[" +
Joachim Bingel03dfd952014-07-30 08:08:53 +00001090 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1, max=10}, min=1, max=10}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +00001091 "]" +
1092 "}";
Joachim Bingel2daf9862014-02-12 10:18:54 +00001093 ct = new CosmasTree(query);
1094 map = ct.getRequestMap().get("query").toString();
Joachim Bingel89cceac2014-01-08 15:51:08 +00001095 assertEquals(all1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeld5161a12014-01-08 11:15:49 +00001096 }
1097
Joachim Bingel36233b52014-02-13 10:48:24 +00001098 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +00001099 public void testOPNHIT() throws QueryException {
Joachim Bingel89cceac2014-01-08 15:51:08 +00001100 query="#NHIT(gehen /w1:10 voran)";
1101 String nhit1 =
Joachim Bingel09737972014-09-22 09:43:06 +00001102 "{@type=korap:reference, operation=operation:focus, classRef=[1], classRefOp=classRefOp:inversion, operands=[" +
Joachim Bingel097c1eb2014-07-11 14:57:25 +00001103 "{@type=korap:group, operation=operation:sequence, " +
Joachim Bingel36233b52014-02-13 10:48:24 +00001104 "operands=[" +
1105 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
1106 "{@type=korap:token, wrap={@type=korap:term, key=gehen, layer=orth, match=match:eq}}" +
1107 "]}," +
Joachim Bingel09737972014-09-22 09:43:06 +00001108 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
Joachim Bingel36233b52014-02-13 10:48:24 +00001109 "{@type=korap:token, wrap={@type=korap:term, key=voran, layer=orth, match=match:eq}}" +
1110 "]}" +
Joachim Bingel097c1eb2014-07-11 14:57:25 +00001111 "], inOrder=false, " +
1112 "distances=[" +
Joachim Bingel03dfd952014-07-30 08:08:53 +00001113 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1, max=10}, min=1, max=10}" +
Joachim Bingel36233b52014-02-13 10:48:24 +00001114 "]" +
1115 "}" +
1116 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +00001117 ct = new CosmasTree(query);
1118 map = ct.getRequestMap().get("query").toString();
Joachim Bingel89cceac2014-01-08 15:51:08 +00001119 assertEquals(nhit1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeld5161a12014-01-08 11:15:49 +00001120 }
1121
1122 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +00001123 public void testOPBED() throws QueryException {
Joachim Bingeleecc7652014-01-11 17:21:07 +00001124 query = "#BED(der , sa)";
1125 String bed1 =
Joachim Bingel0de1b412014-07-02 14:51:48 +00001126 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands= [" +
Joachim Bingel93e6c702014-09-30 15:19:23 +00001127 "{@type=korap:group, operation=operation:position, frames=[frame:startswith], sharedClasses=[sharedClasses:includes], operands=[" +
Joachim Bingelcd7b7252014-02-13 08:49:14 +00001128 "{@type=korap:span, key=s}," +
1129 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
1130 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}" +
1131 "]}" +
Joachim Bingel93e6c702014-09-30 15:19:23 +00001132 "], frame=frame:startswith}" +
Joachim Bingeleecc7652014-01-11 17:21:07 +00001133 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +00001134 ct = new CosmasTree(query);
1135 map = ct.getRequestMap().get("query").toString();
Joachim Bingeleecc7652014-01-11 17:21:07 +00001136 assertEquals(bed1.replaceAll(" ", ""), map.replaceAll(" ", ""));
1137
1138 query = "#BED(der Mann , +pe)";
1139 String bed2 =
Joachim Bingel0de1b412014-07-02 14:51:48 +00001140 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands= [" +
Joachim Bingel93e6c702014-09-30 15:19:23 +00001141 "{@type=korap:group, operation=operation:position, frames=[frame:endswith], sharedClasses=[sharedClasses:includes], operands=[" +
Joachim Bingel36233b52014-02-13 10:48:24 +00001142 "{@type=korap:span, key=p}," +
1143 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
1144 "{@type=korap:group, operation=operation:sequence, operands=[" +
1145 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
1146 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
1147 "]}" +
1148 "]}" +
Joachim Bingel93e6c702014-09-30 15:19:23 +00001149 "], frame=frame:endswith}" +
Joachim Bingel36233b52014-02-13 10:48:24 +00001150 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +00001151 ct = new CosmasTree(query);
1152 map = ct.getRequestMap().get("query").toString();
Joachim Bingel36233b52014-02-13 10:48:24 +00001153 assertEquals(bed2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel3f0850c2014-01-17 16:50:10 +00001154
1155 query = "#BED(der Mann , sa,-pa)";
1156 String bed3 =
Joachim Bingel0de1b412014-07-02 14:51:48 +00001157 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingel37a803f2014-07-28 14:21:44 +00001158 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel93e6c702014-09-30 15:19:23 +00001159 "{@type=korap:group, operation=operation:position, frames=[frame:startswith], sharedClasses=[sharedClasses:includes], operands=[" +
Joachim Bingel36233b52014-02-13 10:48:24 +00001160 "{@type=korap:span, key=s}," +
1161 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
1162 "{@type=korap:group, operation=operation:sequence, operands=[" +
1163 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
1164 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
1165 "]}" +
1166 "]}" +
Joachim Bingel93e6c702014-09-30 15:19:23 +00001167 "], frame=frame:startswith}," +
1168 "{@type=korap:group, operation=operation:position, frames=[frame:startswith], sharedClasses=[sharedClasses:includes], operands=[" +
Joachim Bingel36233b52014-02-13 10:48:24 +00001169 "{@type=korap:span, key=p}," +
Joachim Bingel402c6e12014-05-08 17:09:06 +00001170 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
Joachim Bingel36233b52014-02-13 10:48:24 +00001171 "{@type=korap:group, operation=operation:sequence, operands=[" +
1172 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
1173 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
1174 "]}" +
1175 "]}" +
Joachim Bingel93e6c702014-09-30 15:19:23 +00001176 "], frame=frame:startswith, exclude=true}" +
Joachim Bingel37a803f2014-07-28 14:21:44 +00001177 "], distances=[" +
1178 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0, max=0}, min=0, max=0}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +00001179 "]}" +
1180 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +00001181 ct = new CosmasTree(query);
1182 map = ct.getRequestMap().get("query").toString();
Joachim Bingel36233b52014-02-13 10:48:24 +00001183 assertEquals(bed3.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeld5161a12014-01-08 11:15:49 +00001184 }
1185
Joachim Bingel81812632014-02-18 08:55:22 +00001186 @Test
1187 public void testColonSeparatedConditions() throws QueryException {
1188
1189 query = "Der:sa";
1190 String col1 =
Joachim Bingel0de1b412014-07-02 14:51:48 +00001191 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingel93e6c702014-09-30 15:19:23 +00001192 "{@type=korap:group, operation=operation:position, frames=[frame:startswith], sharedClasses=[sharedClasses:includes], operands=[" +
Joachim Bingel81812632014-02-18 08:55:22 +00001193 "{@type=korap:span, key=s}," +
1194 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
1195 "{@type=korap:token, wrap={@type=korap:term, key=Der, layer=orth, match=match:eq}}" +
1196 "]}" +
Joachim Bingel93e6c702014-09-30 15:19:23 +00001197 "], frame=frame:startswith}" +
Joachim Bingel81812632014-02-18 08:55:22 +00001198 "]}";
1199 ct = new CosmasTree(query);
1200 map = ct.getRequestMap().get("query").toString();
1201 assertEquals(col1.replaceAll(" ", ""), map.replaceAll(" ", ""));
1202
1203 query = "Mann:sa,-pa,+te)";
1204 String col2 =
Joachim Bingel0de1b412014-07-02 14:51:48 +00001205 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingel37a803f2014-07-28 14:21:44 +00001206 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel93e6c702014-09-30 15:19:23 +00001207 "{@type=korap:group, operation=operation:position, frames=[frame:startswith], sharedClasses=[sharedClasses:includes], operands=[" +
Joachim Bingel81812632014-02-18 08:55:22 +00001208 "{@type=korap:span, key=s}," +
1209 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
1210 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
1211 "]}" +
Joachim Bingel93e6c702014-09-30 15:19:23 +00001212 "], frame=frame:startswith}," +
1213 "{@type=korap:group, operation=operation:position, frames=[frame:startswith], sharedClasses=[sharedClasses:includes], operands=[" +
Joachim Bingel81812632014-02-18 08:55:22 +00001214 "{@type=korap:span, key=p}," +
Joachim Bingel402c6e12014-05-08 17:09:06 +00001215 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
Joachim Bingel81812632014-02-18 08:55:22 +00001216 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
1217 "]}" +
Joachim Bingel93e6c702014-09-30 15:19:23 +00001218 "], frame=frame:startswith, exclude=true}," +
1219 "{@type=korap:group, operation=operation:position, frames=[frame:endswith], sharedClasses=[sharedClasses:includes], operands=[" +
Joachim Bingel81812632014-02-18 08:55:22 +00001220 "{@type=korap:span, key=t}," +
Joachim Bingel402c6e12014-05-08 17:09:06 +00001221 "{@type=korap:group, operation=operation:class, class=3, operands=[" +
Joachim Bingel81812632014-02-18 08:55:22 +00001222 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
Joachim Bingelaaabb722014-09-24 14:29:10 +00001223 "]}" +
Joachim Bingel93e6c702014-09-30 15:19:23 +00001224 "], frame=frame:endswith}" +
Joachim Bingel37a803f2014-07-28 14:21:44 +00001225 "], distances=[" +
1226 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0, max=0}, min=0, max=0}" +
Joachim Bingel81812632014-02-18 08:55:22 +00001227 "]}" +
1228 "]}";
1229 ct = new CosmasTree(query);
1230 map = ct.getRequestMap().get("query").toString();
1231 assertEquals(col2.replaceAll(" ", ""), map.replaceAll(" ", ""));
1232 }
Joachim Bingelb5f7bf02014-01-07 16:36:54 +00001233}
1234