blob: efe86f6cc570450ad47c98acc4f95c7b24e25917 [file] [log] [blame]
Joachim Bingelb5f7bf02014-01-07 16:36:54 +00001import static org.junit.Assert.*;
2
3import org.junit.Test;
4
5import de.ids_mannheim.korap.query.serialize.CosmasTree;
Joachim Bingelb5f7bf02014-01-07 16:36:54 +00006import de.ids_mannheim.korap.util.QueryException;
7
8public class CosmasTreeTest {
9
10 CosmasTree ppt;
11 String map;
12 String query;
13
14 private boolean equalsContent(String str, Object map) {
15 str = str.replaceAll(" ", "");
16 String mapStr = map.toString().replaceAll(" ", "");
17 return str.equals(mapStr);
18 }
19
20 private boolean equalsQueryContent(String res, String query) throws QueryException {
21 res = res.replaceAll(" ", "");
22 ppt = new CosmasTree(query);
23 String queryMap = ppt.getRequestMap().get("query").toString().replaceAll(" ", "");
24 return res.equals(queryMap);
25 }
26
27 @Test
28 public void testContext() throws QueryException {
Joachim Bingelba9a0ab2014-01-29 10:12:25 +000029 String contextString = "{korap=http://korap.ids-mannheim.de/ns/query, @language=de, @operands={@id=korap:operands, @container=@list}, @relation={@id=korap:relation, @type=korap:relation#types}, class={@id=korap:class, @type=xsd:integer}, query=korap:query, filter=korap:filter, meta=korap:meta}";
Joachim Bingelb5f7bf02014-01-07 16:36:54 +000030 ppt = new CosmasTree("Test");
31 assertTrue(equalsContent(contextString, ppt.getRequestMap().get("@context")));
32 }
33
34
35 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +000036 public void testSingleToken() throws QueryException {
Joachim Bingelb5f7bf02014-01-07 16:36:54 +000037 query="der";
38 String single1 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +000039 "{@type=korap:token, @value={@type=korap:term, @value=der, @attr=orth, @relation==}}";
Joachim Bingelb5f7bf02014-01-07 16:36:54 +000040 ppt = new CosmasTree(query);
41 map = ppt.getRequestMap().get("query").toString();
42 assertEquals(single1.replaceAll(" ", ""), map.replaceAll(" ", ""));
43
44 query="Mann";
45 String single2 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +000046 "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=orth, @relation==}}";
Joachim Bingelb5f7bf02014-01-07 16:36:54 +000047 ppt = new CosmasTree(query);
48 map = ppt.getRequestMap().get("query").toString();
49 assertEquals(single2.replaceAll(" ", ""), map.replaceAll(" ", ""));
50
51 query="&Mann";
52 String single3 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +000053 "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=lemma, @relation==}}";
Joachim Bingelb5f7bf02014-01-07 16:36:54 +000054 ppt = new CosmasTree(query);
55 map = ppt.getRequestMap().get("query").toString();
56 assertEquals(single3.replaceAll(" ", ""), map.replaceAll(" ", ""));
57 }
58
Joachim Bingelba9a0ab2014-01-29 10:12:25 +000059 @Test
Joachim Bingelffd65e32014-01-22 14:22:57 +000060 public void testMORPH() throws QueryException {
61 query="#MORPH(V)";
62 String morph1 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +000063 "{@type=korap:token, @value={@type=korap:term, @value=V, @relation==}}";
Joachim Bingelffd65e32014-01-22 14:22:57 +000064 ppt = new CosmasTree(query);
65 map = ppt.getRequestMap().get("query").toString();
66 assertEquals(morph1.replaceAll(" ", ""), map.replaceAll(" ", ""));
67 }
68
Joachim Bingelb5f7bf02014-01-07 16:36:54 +000069 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +000070 public void testSequence() throws QueryException {
Joachim Bingelb5f7bf02014-01-07 16:36:54 +000071 query="der Mann";
72 String seq1 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +000073 "{@type=korap:sequence, @operands=[" +
74 "{@type=korap:token, @value={@type=korap:term, @value=der, @attr=orth, @relation==}}," +
75 "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=orth, @relation==}}" +
Joachim Bingelb5f7bf02014-01-07 16:36:54 +000076 "]}";
77 ppt = new CosmasTree(query);
78 map = ppt.getRequestMap().get("query").toString();
79 assertEquals(seq1.replaceAll(" ", ""), map.replaceAll(" ", ""));
80
Joachim Bingeld5161a12014-01-08 11:15:49 +000081 query="der Mann schläft";
82 String seq2 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +000083 "{@type=korap:sequence, @operands=[" +
84 "{@type=korap:token, @value={@type=korap:term, @value=der, @attr=orth, @relation==}}," +
85 "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=orth, @relation==}}," +
86 "{@type=korap:token, @value={@type=korap:term, @value=schläft, @attr=orth, @relation==}}" +
Joachim Bingeld5161a12014-01-08 11:15:49 +000087 "]}";
88 ppt = new CosmasTree(query);
89 map = ppt.getRequestMap().get("query").toString();
90 assertEquals(seq2.replaceAll(" ", ""), map.replaceAll(" ", ""));
91
92 query="der Mann schläft lang";
93 String seq3 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +000094 "{@type=korap:sequence, @operands=[" +
95 "{@type=korap:token, @value={@type=korap:term, @value=der, @attr=orth, @relation==}}," +
96 "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=orth, @relation==}}," +
97 "{@type=korap:token, @value={@type=korap:term, @value=schläft, @attr=orth, @relation==}}," +
98 "{@type=korap:token, @value={@type=korap:term, @value=lang, @attr=orth, @relation==}}" +
Joachim Bingeld5161a12014-01-08 11:15:49 +000099 "]}";
100 ppt = new CosmasTree(query);
101 map = ppt.getRequestMap().get("query").toString();
102 assertEquals(seq3.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000103 }
104
105 @Test
106 public void testOPOR() throws QueryException {
107 query="Sonne oder Mond";
108 String disj1 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000109 "{@type=korap:group, @relation=or, @operands=[" +
110 "{@type=korap:token, @value={@type=korap:term, @value=Sonne, @attr=orth, @relation==}}," +
111 "{@type=korap:token, @value={@type=korap:term, @value=Mond, @attr=orth, @relation==}}" +
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000112 "]}";
113 ppt = new CosmasTree(query);
114 map = ppt.getRequestMap().get("query").toString();
115 assertEquals(disj1.replaceAll(" ", ""), map.replaceAll(" ", ""));
116
Joachim Bingeld5161a12014-01-08 11:15:49 +0000117 query="(Sonne scheint) oder Mond";
118 String disj2 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000119 "{@type=korap:group, @relation=or, @operands=[" +
120 "{@type=korap:sequence, @operands=[" +
121 "{@type=korap:token, @value={@type=korap:term, @value=Sonne, @attr=orth, @relation==}}," +
122 "{@type=korap:token, @value={@type=korap:term, @value=scheint, @attr=orth, @relation==}}" +
Joachim Bingeld5161a12014-01-08 11:15:49 +0000123 "]}," +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000124 "{@type=korap:token, @value={@type=korap:term, @value=Mond, @attr=orth, @relation==}}" +
Joachim Bingeld5161a12014-01-08 11:15:49 +0000125 "]}";
126 ppt = new CosmasTree(query);
127 map = ppt.getRequestMap().get("query").toString();
128 assertEquals(disj2.replaceAll(" ", ""), map.replaceAll(" ", ""));
129
130 query="(Sonne scheint) oder (Mond scheint)";
131 String disj3 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000132 "{@type=korap:group, @relation=or, @operands=[" +
133 "{@type=korap:sequence, @operands=[" +
134 "{@type=korap:token, @value={@type=korap:term, @value=Sonne, @attr=orth, @relation==}}," +
135 "{@type=korap:token, @value={@type=korap:term, @value=scheint, @attr=orth, @relation==}}" +
Joachim Bingeld5161a12014-01-08 11:15:49 +0000136 "]}," +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000137 "{@type=korap:sequence, @operands=[" +
138 "{@type=korap:token, @value={@type=korap:term, @value=Mond, @attr=orth, @relation==}}," +
139 "{@type=korap:token, @value={@type=korap:term, @value=scheint, @attr=orth, @relation==}}" +
Joachim Bingeld5161a12014-01-08 11:15:49 +0000140 "]}" +
141 "]}";
142 ppt = new CosmasTree(query);
143 map = ppt.getRequestMap().get("query").toString();
144 assertEquals(disj3.replaceAll(" ", ""), map.replaceAll(" ", ""));
145
146 }
147
148 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000149 public void testOPORAND() throws QueryException {
Joachim Bingeld5161a12014-01-08 11:15:49 +0000150 query="(Sonne oder Mond) und scheint";
151 String orand1 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000152 "{@type=korap:group, @relation=and, @operands=[" +
153 "{@type=korap:group, @relation=or, @operands=[" +
154 "{@type=korap:token, @value={@type=korap:term, @value=Sonne, @attr=orth, @relation==}}," +
155 "{@type=korap:token, @value={@type=korap:term, @value=Mond, @attr=orth, @relation==}}" +
Joachim Bingeld5161a12014-01-08 11:15:49 +0000156 "]}," +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000157 "{@type=korap:token, @value={@type=korap:term, @value=scheint, @attr=orth, @relation==}}" +
Joachim Bingeld5161a12014-01-08 11:15:49 +0000158 "]}";
159 ppt = new CosmasTree(query);
160 map = ppt.getRequestMap().get("query").toString();
161 assertEquals(orand1.replaceAll(" ", ""), map.replaceAll(" ", ""));
162
163 query="scheint und (Sonne oder Mond)";
164 String orand2 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000165 "{@type=korap:group, @relation=and, @operands=[" +
166 "{@type=korap:token, @value={@type=korap:term, @value=scheint, @attr=orth, @relation==}}," +
167 "{@type=korap:group, @relation=or, @operands=[" +
168 "{@type=korap:token, @value={@type=korap:term, @value=Sonne, @attr=orth, @relation==}}," +
169 "{@type=korap:token, @value={@type=korap:term, @value=Mond, @attr=orth, @relation==}}" +
Joachim Bingeld5161a12014-01-08 11:15:49 +0000170 "]}" +
171 "]}";
172 ppt = new CosmasTree(query);
173 map = ppt.getRequestMap().get("query").toString();
174 assertEquals(orand2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000175 }
176
177 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000178 public void testOPPROX() throws QueryException {
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000179 query="Sonne /+w1:4 Mond";
180 String prox1 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000181 "{@type=korap:sequence, @inOrder=true, " +
182 "@constraints=[" +
183 "{@type=korap:distance, @measure=w, @min=1, @max=4}" +
Joachim Bingel89cceac2014-01-08 15:51:08 +0000184 "], " +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000185 "@operands=[" +
186 "{@type=korap:token, @value={@type=korap:term, @value=Sonne, @attr=orth, @relation==}}," +
187 "{@type=korap:token, @value={@type=korap:term, @value=Mond, @attr=orth, @relation==}}" +
Joachim Bingel89cceac2014-01-08 15:51:08 +0000188 "]" +
189 "}";
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000190 ppt = new CosmasTree(query);
191 map = ppt.getRequestMap().get("query").toString();
192 assertEquals(prox1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel89cceac2014-01-08 15:51:08 +0000193
194 query="Sonne /+w1:4,s0,p1:3 Mond";
195 String prox2 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000196 "{@type=korap:sequence, @inOrder=true, " +
197 "@constraints=[" +
198 "{@type=korap:group, @relation=and, @operands=[" +
199 "{@type=korap:distance, @measure=w, @min=1, @max=4}," +
200 "{@type=korap:distance, @measure=s, @min=0, @max=0}," +
201 "{@type=korap:distance, @measure=p, @min=1, @max=3}" +
Joachim Bingel89cceac2014-01-08 15:51:08 +0000202 "]}" +
203 "], " +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000204 "@operands=[" +
205 "{@type=korap:token, @value={@type=korap:term, @value=Sonne, @attr=orth, @relation==}}," +
206 "{@type=korap:token, @value={@type=korap:term, @value=Mond, @attr=orth, @relation==}}" +
Joachim Bingel89cceac2014-01-08 15:51:08 +0000207 "]" +
208 "}";
209 ppt = new CosmasTree(query);
210 map = ppt.getRequestMap().get("query").toString();
211 assertEquals(prox2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel87480d02014-01-17 14:07:46 +0000212
213 query="Sonne %+w1:4,s0,p1:3 Mond";
214 String prox3 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000215 "{@type=korap:sequence, @inOrder=true, " +
216 "@constraints=[" +
217 "{@type=korap:group, @relation=and, @operands=[" +
218 "{@type=korap:distance, @measure=w, @min=1, @max=4, @exclude=true}," +
219 "{@type=korap:distance, @measure=s, @min=0, @max=0, @exclude=true}," +
220 "{@type=korap:distance, @measure=p, @min=1, @max=3, @exclude=true}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000221 "]}" +
222 "], " +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000223 "@operands=[" +
224 "{@type=korap:token, @value={@type=korap:term, @value=Sonne, @attr=orth, @relation==}}," +
225 "{@type=korap:token, @value={@type=korap:term, @value=Mond, @attr=orth, @relation==}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000226 "]" +
227 "}";
228 ppt = new CosmasTree(query);
229 map = ppt.getRequestMap().get("query").toString();
230 assertEquals(prox3.replaceAll(" ", ""), map.replaceAll(" ", ""));
231
232 query="Sonne /+w4 Mond";
233 String prox4 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000234 "{@type=korap:sequence, @inOrder=true, " +
235 "@constraints=[" +
236 "{@type=korap:distance, @measure=w, @min=0, @max=4}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000237 "], " +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000238 "@operands=[" +
239 "{@type=korap:token, @value={@type=korap:term, @value=Sonne, @attr=orth, @relation==}}," +
240 "{@type=korap:token, @value={@type=korap:term, @value=Mond, @attr=orth, @relation==}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000241 "]" +
242 "}";
243 ppt = new CosmasTree(query);
244 map = ppt.getRequestMap().get("query").toString();
245 assertEquals(prox4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000246
247 query="Sonne /-w4 Mond";
248 String prox5 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000249 "{@type=korap:sequence, @inOrder=true, " +
250 "@constraints=[" +
251 "{@type=korap:distance, @measure=w, @min=0, @max=4}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000252 "], " +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000253 "@operands=[" +
254 "{@type=korap:token, @value={@type=korap:term, @value=Mond, @attr=orth, @relation==}}," +
255 "{@type=korap:token, @value={@type=korap:term, @value=Sonne, @attr=orth, @relation==}}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000256 "]" +
257 "}";
258 ppt = new CosmasTree(query);
259 map = ppt.getRequestMap().get("query").toString();
260 assertEquals(prox5.replaceAll(" ", ""), map.replaceAll(" ", ""));
261 }
262
263 @Test
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000264 public void testOPPROXNested() throws QueryException {
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000265 query="Sonne /-w4 Mond /+w2 Sterne";
266 String prox6 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000267 "{@type=korap:sequence, @inOrder=true, " +
268 "@constraints=[" +
269 "{@type=korap:distance, @measure=w, @min=0, @max=4}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000270 "], " +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000271 "@operands=[" +
272 "{@type=korap:sequence, @inOrder=true, " +
273 "@constraints=[" +
274 "{@type=korap:distance, @measure=w, @min=0, @max=2}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000275 "], " +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000276 "@operands=[" +
277 "{@type=korap:token, @value={@type=korap:term, @value=Mond, @attr=orth, @relation==}}," +
278 "{@type=korap:token, @value={@type=korap:term, @value=Sterne, @attr=orth, @relation==}}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000279 "]}," +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000280 "{@type=korap:token, @value={@type=korap:term, @value=Sonne, @attr=orth, @relation==}}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000281 "]" +
282 "}";
283 ppt = new CosmasTree(query);
284 map = ppt.getRequestMap().get("query").toString();
285 assertEquals(prox6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000286 }
287
288 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000289 public void testOPIN() throws QueryException {
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000290 query="wegen #IN <s>";
Joachim Bingel3a9f7932014-01-07 17:11:31 +0000291 String opin1 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000292 "{@type=korap:group, @relation=submatch, @classRef=1, @operands=[" +
293 "{@type=korap:group, @relation=position, @position=contains, @operands=[" +
294 "{@type=korap:span, @value=s}," +
295 "{@type=korap:group, class=1, @operands=[" +
296 "{@type=korap:token, @value={@type=korap:term, @value=wegen, @attr=orth, @relation==}}" +
Joachim Bingeleecc7652014-01-11 17:21:07 +0000297 "]}" +
298 "]}" +
Joachim Bingeld5161a12014-01-08 11:15:49 +0000299 "]}";
300 ppt = new CosmasTree(query);
301 map = ppt.getRequestMap().get("query").toString();
302 assertEquals(opin1.replaceAll(" ", ""), map.replaceAll(" ", ""));
303
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000304 query="wegen #IN(L) <s>";
305 String opin2 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000306 "{@type=korap:group, @relation=submatch, @classRef=1, @operands=[" +
307 "{@type=korap:group, @relation=position, @position=startswith, @operands=[" +
308 "{@type=korap:span, @value=s}," +
309 "{@type=korap:group, class=1, @operands=[" +
310 "{@type=korap:token, @value={@type=korap:term, @value=wegen, @attr=orth, @relation==}}" +
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000311 "]}" +
312 "]}" +
313 "]}";
314 ppt = new CosmasTree(query);
315 map = ppt.getRequestMap().get("query").toString();
316 assertEquals(opin2.replaceAll(" ", ""), map.replaceAll(" ", ""));
317
Joachim Bingel87480d02014-01-17 14:07:46 +0000318 query="wegen #IN(%, L) <s>";
319 String opin3 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000320 "{@type=korap:group, @relation=submatch, @classRef=1, @operands=[" +
321 "{@type=korap:group, @relation=position, @position=startswith, @exclude=true, @operands=[" +
322 "{@type=korap:span, @value=s}," +
323 "{@type=korap:group, class=1, @operands=[" +
324 "{@type=korap:token, @value={@type=korap:term, @value=wegen, @attr=orth, @relation==}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000325 "]}" +
326 "]}" +
327 "]}";
328 ppt = new CosmasTree(query);
329 map = ppt.getRequestMap().get("query").toString();
330 assertEquals(opin3.replaceAll(" ", ""), map.replaceAll(" ", ""));
331
332 query="wegen #IN('FE,ALL,%,MIN') <s>";
333 String opin4 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000334 "{@type=korap:group, @relation=submatch, @classRef=1, @operands=[" +
335 "{@type=korap:group, @relation=position, @position=ident, range=all, @exclude=true, grouping=false, @operands=[" +
336 "{@type=korap:span, @value=s}," +
337 "{@type=korap:group, class=1, @operands=[" +
338 "{@type=korap:token, @value={@type=korap:term, @value=wegen, @attr=orth, @relation==}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000339 "]}" +
340 "]}" +
341 "]}";
342 ppt = new CosmasTree(query);
343 map = ppt.getRequestMap().get("query").toString();
344 assertEquals(opin4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeld5161a12014-01-08 11:15:49 +0000345 }
346
347 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000348 public void testOPOV() throws QueryException {
Joachim Bingeld5161a12014-01-08 11:15:49 +0000349 query="wegen #OV <s>";
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000350 String opov1 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000351 "{@type=korap:group, @relation=submatch, @classRef=1, @operands=[" +
352 "{@type=korap:group, @relation=overlaps, @position=any, @operands=[" +
353 "{@type=korap:span, @value=s}," +
354 "{@type=korap:group, class=1, @operands=[" +
355 "{@type=korap:token, @value={@type=korap:term, @value=wegen, @attr=orth, @relation==}}" +
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000356 "]}" +
357 "]}" +
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000358 "]}";
359 ppt = new CosmasTree(query);
360 map = ppt.getRequestMap().get("query").toString();
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000361 assertEquals(opov1.replaceAll(" ", ""), map.replaceAll(" ", ""));
362
363 query="wegen #OV(L) <s>";
364 String opov2 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000365 "{@type=korap:group, @relation=submatch, @classRef=1, @operands=[" +
366 "{@type=korap:group, @relation=overlaps, @position=startswith, @operands=[" +
367 "{@type=korap:span, @value=s}," +
368 "{@type=korap:group, class=1, @operands=[" +
369 "{@type=korap:token, @value={@type=korap:term, @value=wegen, @attr=orth, @relation==}}" +
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000370 "]}" +
371 "]}" +
372 "]}";
373 ppt = new CosmasTree(query);
374 map = ppt.getRequestMap().get("query").toString();
375 assertEquals(opov2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000376 }
377
378 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000379 public void testOPNOT() throws QueryException {
Joachim Bingel3a9f7932014-01-07 17:11:31 +0000380 query="Sonne nicht Mond";
381 String opnot1 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000382 "{@type=korap:group, @relation=not, @operands=[" +
383 "{@type=korap:token, @value={@type=korap:term, @value=Sonne, @attr=orth, @relation==}}," +
384 "{@type=korap:token, @value={@type=korap:term, @value=Mond, @attr=orth, @relation==}}" +
Joachim Bingel3a9f7932014-01-07 17:11:31 +0000385 "]}";
386 ppt = new CosmasTree(query);
387 map = ppt.getRequestMap().get("query").toString();
388 assertEquals(opnot1.replaceAll(" ", ""), map.replaceAll(" ", ""));
389 }
390
391 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000392 public void testBEG_END() throws QueryException {
Joachim Bingel3a9f7932014-01-07 17:11:31 +0000393 // BEG and END operators
394 // http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/syntax/links.html
395 // http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/syntax/rechts.html
396 // http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/thematische-bsp/bsp-satzlaenge.html
Joachim Bingel87480d02014-01-17 14:07:46 +0000397 query="#BEG(der /w3:5 Mann)";
398 String beg1 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000399 "{@type=korap:group, @relation=submatch, @spanRef=[0,1], @operands=[" +
400 "{@type=korap:sequence, @inOrder=false, @constraints=[" +
401 "{@type=korap:distance, @measure=w, @min=3, @max=5}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000402 "]," +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000403 "@operands = [" +
404 "{@type=korap:token, @value={@type=korap:term, @value=der, @attr=orth, @relation==}}," +
405 "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=orth, @relation==}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000406 "]}" +
407 "]}";
408 ppt = new CosmasTree(query);
409 map = ppt.getRequestMap().get("query").toString();
410 assertEquals(beg1.replaceAll(" ", ""), map.replaceAll(" ", ""));
411
412 query="#BEG(der /w3:5 Mann) /+w10 kommt"; // nesting #BEG() in a distance group
413 String beg2 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000414 "{@type=korap:sequence, @inOrder=true, @constraints=[" +
415 "{@type=korap:distance, @measure=w, @min=0, @max=10}" +
416 "], @operands=[" +
417 "{@type=korap:group, @relation=submatch, @spanRef=[0,1], @operands=[" +
418 "{@type=korap:sequence, @inOrder=false, @constraints=[" +
419 "{@type=korap:distance, @measure=w, @min=3, @max=5}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000420 "]," +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000421 "@operands = [" +
422 "{@type=korap:token, @value={@type=korap:term, @value=der, @attr=orth, @relation==}}," +
423 "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=orth, @relation==}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000424 "]}" +
425 "]}," +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000426 "{@type=korap:token, @value={@type=korap:term, @value=kommt, @attr=orth, @relation==}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000427 "]}";
428 ppt = new CosmasTree(query);
429 map = ppt.getRequestMap().get("query").toString();
430 assertEquals(beg2.replaceAll(" ", ""), map.replaceAll(" ", ""));
431
432 query="#END(der /w3:5 Mann)";
433 String end1 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000434 "{@type=korap:group, @relation=submatch, @spanRef=[-1,1], @operands=[" +
435 "{@type=korap:sequence, @inOrder=false, @constraints=[" +
436 "{@type=korap:distance, @measure=w, @min=3, @max=5}" +
437 "], " +
438 "@operands = [" +
439 "{@type=korap:token, @value={@type=korap:term, @value=der, @attr=orth, @relation==}}," +
440 "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=orth, @relation==}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000441 "]}" +
442 "]}";
443 ppt = new CosmasTree(query);
444 map = ppt.getRequestMap().get("query").toString();
445 assertEquals(end1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000446 }
Joachim Bingeld5161a12014-01-08 11:15:49 +0000447
448
449 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000450 public void testELEM() throws QueryException {
Joachim Bingeld5161a12014-01-08 11:15:49 +0000451 // http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/syntax/elem.html
Joachim Bingeleecc7652014-01-11 17:21:07 +0000452 query="#ELEM(S)";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000453 String elem1 = "{@type=korap:span, @value=s}";
Joachim Bingeleecc7652014-01-11 17:21:07 +0000454 ppt = new CosmasTree(query);
455 map = ppt.getRequestMap().get("query").toString();
456 assertEquals(elem1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeld5161a12014-01-08 11:15:49 +0000457 }
458
459 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000460 public void testOPALL() throws QueryException {
Joachim Bingel89cceac2014-01-08 15:51:08 +0000461 query="#ALL(gehen /w1:10 voran)";
Joachim Bingele98d0882014-01-21 12:58:54 +0000462 String all1 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000463 "{@type=korap:sequence, @inOrder=false, " +
464 "@constraints=[" +
465 "{@type=korap:distance, @measure=w, @min=1, @max=10}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000466 "], " +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000467 "@operands=[" +
468 "{@type=korap:token, @value={@type=korap:term, @value=gehen, @attr=orth, @relation==}}," +
469 "{@type=korap:token, @value={@type=korap:term, @value=voran, @attr=orth, @relation==}}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000470 "]" +
471 "}";
Joachim Bingel89cceac2014-01-08 15:51:08 +0000472 ppt = new CosmasTree(query);
473 map = ppt.getRequestMap().get("query").toString();
474 assertEquals(all1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeld5161a12014-01-08 11:15:49 +0000475 }
476
477 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000478 public void testOPNHIT() throws QueryException {
Joachim Bingel89cceac2014-01-08 15:51:08 +0000479 query="#NHIT(gehen /w1:10 voran)";
480 String nhit1 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000481 "{@type=korap:sequence, @inOrder=false, " +
482 "@constraints=[" +
483 "{@type=korap:distance, @measure=w, @min=1, @max=10}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000484 "], " +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000485 "@operands=[" +
486 "{@type=korap:token, @value={@type=korap:term, @value=gehen, @attr=orth, @relation==}}," +
487 "{@type=korap:token, @value={@type=korap:term, @value=voran, @attr=orth, @relation==}}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000488 "]" +
489 "}";
Joachim Bingel89cceac2014-01-08 15:51:08 +0000490 ppt = new CosmasTree(query);
491 map = ppt.getRequestMap().get("query").toString();
492 assertEquals(nhit1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeld5161a12014-01-08 11:15:49 +0000493 }
494
495 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000496 public void testOPBED() throws QueryException {
Joachim Bingeleecc7652014-01-11 17:21:07 +0000497 query = "#BED(der , sa)";
498 String bed1 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000499 "{@type=korap:group, @relation=position, @position=startswith, @operands=[" +
500 "{@type=korap:span, @value=s}," +
501 "{@type=korap:token, @value={@type=korap:term, @value=der, @attr=orth, @relation==}}" +
Joachim Bingeleecc7652014-01-11 17:21:07 +0000502 "]}";
503 ppt = new CosmasTree(query);
504 map = ppt.getRequestMap().get("query").toString();
505 assertEquals(bed1.replaceAll(" ", ""), map.replaceAll(" ", ""));
506
507 query = "#BED(der Mann , +pe)";
508 String bed2 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000509 "{@type=korap:group, @relation=position, @position=endswith, @operands=[" +
510 "{@type=korap:span, @value=p}," +
511 "{@type=korap:sequence, @operands=[" +
512 "{@type=korap:token, @value={@type=korap:term, @value=der, @attr=orth, @relation==}}," +
513 "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=orth, @relation==}}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000514 "]}" +
Joachim Bingeleecc7652014-01-11 17:21:07 +0000515 "]}";
516 ppt = new CosmasTree(query);
517 map = ppt.getRequestMap().get("query").toString();
518 assertEquals(bed2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000519
520 query = "#BED(der Mann , sa,-pa)";
521 String bed3 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000522 "{@type=korap:group, @relation=and, @operands=[" +
523 "{@type=korap:group, @relation=position, @position=startswith, @operands=[" +
524 "{@type=korap:span, @value=s}," +
525 "{@type=korap:sequence, @operands=[" +
526 "{@type=korap:token, @value={@type=korap:term, @value=der, @attr=orth, @relation==}}," +
527 "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=orth, @relation==}}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000528 "]}" +
529 "]}," +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000530 "{@type=korap:group, @relation=position, @position=startswith, @exclude=true, @operands=[" +
531 "{@type=korap:span, @value=p}," +
532 "{@type=korap:sequence, @operands=[" +
533 "{@type=korap:token, @value={@type=korap:term, @value=der, @attr=orth, @relation==}}," +
534 "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=orth, @relation==}}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000535 "]}" +
536 "]}" +
537 "]}";
538 ppt = new CosmasTree(query);
539 map = ppt.getRequestMap().get("query").toString();
540 assertEquals(bed3.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeld5161a12014-01-08 11:15:49 +0000541 }
542
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000543}
544