blob: 1933e20d802d427eb5f92cf17c90e5bb01d23123 [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 Bingel8c640e42014-02-07 16:20:47 +000060 public void testCaseSensitivityFlag() throws QueryException {
61 //TODO ignorieroperator $ http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/syntax/ignorierung.html
62 }
63
64 @Test
Joachim Bingelffd65e32014-01-22 14:22:57 +000065 public void testMORPH() throws QueryException {
66 query="#MORPH(V)";
67 String morph1 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +000068 "{@type=korap:token, @value={@type=korap:term, @value=V, @relation==}}";
Joachim Bingelffd65e32014-01-22 14:22:57 +000069 ppt = new CosmasTree(query);
70 map = ppt.getRequestMap().get("query").toString();
71 assertEquals(morph1.replaceAll(" ", ""), map.replaceAll(" ", ""));
72 }
73
Joachim Bingelb5f7bf02014-01-07 16:36:54 +000074 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +000075 public void testSequence() throws QueryException {
Joachim Bingelb5f7bf02014-01-07 16:36:54 +000076 query="der Mann";
77 String seq1 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +000078 "{@type=korap:sequence, @operands=[" +
79 "{@type=korap:token, @value={@type=korap:term, @value=der, @attr=orth, @relation==}}," +
80 "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=orth, @relation==}}" +
Joachim Bingelb5f7bf02014-01-07 16:36:54 +000081 "]}";
82 ppt = new CosmasTree(query);
83 map = ppt.getRequestMap().get("query").toString();
84 assertEquals(seq1.replaceAll(" ", ""), map.replaceAll(" ", ""));
85
Joachim Bingeld5161a12014-01-08 11:15:49 +000086 query="der Mann schläft";
87 String seq2 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +000088 "{@type=korap:sequence, @operands=[" +
89 "{@type=korap:token, @value={@type=korap:term, @value=der, @attr=orth, @relation==}}," +
90 "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=orth, @relation==}}," +
91 "{@type=korap:token, @value={@type=korap:term, @value=schläft, @attr=orth, @relation==}}" +
Joachim Bingeld5161a12014-01-08 11:15:49 +000092 "]}";
93 ppt = new CosmasTree(query);
94 map = ppt.getRequestMap().get("query").toString();
95 assertEquals(seq2.replaceAll(" ", ""), map.replaceAll(" ", ""));
96
97 query="der Mann schläft lang";
98 String seq3 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +000099 "{@type=korap:sequence, @operands=[" +
100 "{@type=korap:token, @value={@type=korap:term, @value=der, @attr=orth, @relation==}}," +
101 "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=orth, @relation==}}," +
102 "{@type=korap:token, @value={@type=korap:term, @value=schläft, @attr=orth, @relation==}}," +
103 "{@type=korap:token, @value={@type=korap:term, @value=lang, @attr=orth, @relation==}}" +
Joachim Bingeld5161a12014-01-08 11:15:49 +0000104 "]}";
105 ppt = new CosmasTree(query);
106 map = ppt.getRequestMap().get("query").toString();
107 assertEquals(seq3.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000108 }
109
110 @Test
111 public void testOPOR() throws QueryException {
112 query="Sonne oder Mond";
113 String disj1 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000114 "{@type=korap:group, @relation=or, @operands=[" +
115 "{@type=korap:token, @value={@type=korap:term, @value=Sonne, @attr=orth, @relation==}}," +
116 "{@type=korap:token, @value={@type=korap:term, @value=Mond, @attr=orth, @relation==}}" +
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000117 "]}";
118 ppt = new CosmasTree(query);
119 map = ppt.getRequestMap().get("query").toString();
120 assertEquals(disj1.replaceAll(" ", ""), map.replaceAll(" ", ""));
121
Joachim Bingeld5161a12014-01-08 11:15:49 +0000122 query="(Sonne scheint) oder Mond";
123 String disj2 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000124 "{@type=korap:group, @relation=or, @operands=[" +
125 "{@type=korap:sequence, @operands=[" +
126 "{@type=korap:token, @value={@type=korap:term, @value=Sonne, @attr=orth, @relation==}}," +
127 "{@type=korap:token, @value={@type=korap:term, @value=scheint, @attr=orth, @relation==}}" +
Joachim Bingeld5161a12014-01-08 11:15:49 +0000128 "]}," +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000129 "{@type=korap:token, @value={@type=korap:term, @value=Mond, @attr=orth, @relation==}}" +
Joachim Bingeld5161a12014-01-08 11:15:49 +0000130 "]}";
131 ppt = new CosmasTree(query);
132 map = ppt.getRequestMap().get("query").toString();
133 assertEquals(disj2.replaceAll(" ", ""), map.replaceAll(" ", ""));
134
135 query="(Sonne scheint) oder (Mond scheint)";
136 String disj3 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000137 "{@type=korap:group, @relation=or, @operands=[" +
138 "{@type=korap:sequence, @operands=[" +
139 "{@type=korap:token, @value={@type=korap:term, @value=Sonne, @attr=orth, @relation==}}," +
140 "{@type=korap:token, @value={@type=korap:term, @value=scheint, @attr=orth, @relation==}}" +
Joachim Bingeld5161a12014-01-08 11:15:49 +0000141 "]}," +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000142 "{@type=korap:sequence, @operands=[" +
143 "{@type=korap:token, @value={@type=korap:term, @value=Mond, @attr=orth, @relation==}}," +
144 "{@type=korap:token, @value={@type=korap:term, @value=scheint, @attr=orth, @relation==}}" +
Joachim Bingeld5161a12014-01-08 11:15:49 +0000145 "]}" +
146 "]}";
147 ppt = new CosmasTree(query);
148 map = ppt.getRequestMap().get("query").toString();
149 assertEquals(disj3.replaceAll(" ", ""), map.replaceAll(" ", ""));
150
151 }
152
153 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000154 public void testOPORAND() throws QueryException {
Joachim Bingeld5161a12014-01-08 11:15:49 +0000155 query="(Sonne oder Mond) und scheint";
156 String orand1 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000157 "{@type=korap:group, @relation=and, @operands=[" +
158 "{@type=korap:group, @relation=or, @operands=[" +
159 "{@type=korap:token, @value={@type=korap:term, @value=Sonne, @attr=orth, @relation==}}," +
160 "{@type=korap:token, @value={@type=korap:term, @value=Mond, @attr=orth, @relation==}}" +
Joachim Bingeld5161a12014-01-08 11:15:49 +0000161 "]}," +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000162 "{@type=korap:token, @value={@type=korap:term, @value=scheint, @attr=orth, @relation==}}" +
Joachim Bingeld5161a12014-01-08 11:15:49 +0000163 "]}";
164 ppt = new CosmasTree(query);
165 map = ppt.getRequestMap().get("query").toString();
166 assertEquals(orand1.replaceAll(" ", ""), map.replaceAll(" ", ""));
167
168 query="scheint und (Sonne oder Mond)";
169 String orand2 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000170 "{@type=korap:group, @relation=and, @operands=[" +
171 "{@type=korap:token, @value={@type=korap:term, @value=scheint, @attr=orth, @relation==}}," +
172 "{@type=korap:group, @relation=or, @operands=[" +
173 "{@type=korap:token, @value={@type=korap:term, @value=Sonne, @attr=orth, @relation==}}," +
174 "{@type=korap:token, @value={@type=korap:term, @value=Mond, @attr=orth, @relation==}}" +
Joachim Bingeld5161a12014-01-08 11:15:49 +0000175 "]}" +
176 "]}";
177 ppt = new CosmasTree(query);
178 map = ppt.getRequestMap().get("query").toString();
179 assertEquals(orand2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000180 }
181
182 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000183 public void testOPPROX() throws QueryException {
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000184 query="Sonne /+w1:4 Mond";
185 String prox1 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000186 "{@type=korap:sequence, @inOrder=true, " +
187 "@constraints=[" +
188 "{@type=korap:distance, @measure=w, @min=1, @max=4}" +
Joachim Bingel89cceac2014-01-08 15:51:08 +0000189 "], " +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000190 "@operands=[" +
191 "{@type=korap:token, @value={@type=korap:term, @value=Sonne, @attr=orth, @relation==}}," +
192 "{@type=korap:token, @value={@type=korap:term, @value=Mond, @attr=orth, @relation==}}" +
Joachim Bingel89cceac2014-01-08 15:51:08 +0000193 "]" +
194 "}";
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000195 ppt = new CosmasTree(query);
196 map = ppt.getRequestMap().get("query").toString();
197 assertEquals(prox1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel89cceac2014-01-08 15:51:08 +0000198
199 query="Sonne /+w1:4,s0,p1:3 Mond";
200 String prox2 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000201 "{@type=korap:sequence, @inOrder=true, " +
202 "@constraints=[" +
203 "{@type=korap:group, @relation=and, @operands=[" +
204 "{@type=korap:distance, @measure=w, @min=1, @max=4}," +
205 "{@type=korap:distance, @measure=s, @min=0, @max=0}," +
206 "{@type=korap:distance, @measure=p, @min=1, @max=3}" +
Joachim Bingel89cceac2014-01-08 15:51:08 +0000207 "]}" +
208 "], " +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000209 "@operands=[" +
210 "{@type=korap:token, @value={@type=korap:term, @value=Sonne, @attr=orth, @relation==}}," +
211 "{@type=korap:token, @value={@type=korap:term, @value=Mond, @attr=orth, @relation==}}" +
Joachim Bingel89cceac2014-01-08 15:51:08 +0000212 "]" +
213 "}";
214 ppt = new CosmasTree(query);
215 map = ppt.getRequestMap().get("query").toString();
216 assertEquals(prox2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel87480d02014-01-17 14:07:46 +0000217
218 query="Sonne %+w1:4,s0,p1:3 Mond";
219 String prox3 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000220 "{@type=korap:sequence, @inOrder=true, " +
221 "@constraints=[" +
222 "{@type=korap:group, @relation=and, @operands=[" +
223 "{@type=korap:distance, @measure=w, @min=1, @max=4, @exclude=true}," +
224 "{@type=korap:distance, @measure=s, @min=0, @max=0, @exclude=true}," +
225 "{@type=korap:distance, @measure=p, @min=1, @max=3, @exclude=true}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000226 "]}" +
227 "], " +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000228 "@operands=[" +
229 "{@type=korap:token, @value={@type=korap:term, @value=Sonne, @attr=orth, @relation==}}," +
230 "{@type=korap:token, @value={@type=korap:term, @value=Mond, @attr=orth, @relation==}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000231 "]" +
232 "}";
233 ppt = new CosmasTree(query);
234 map = ppt.getRequestMap().get("query").toString();
235 assertEquals(prox3.replaceAll(" ", ""), map.replaceAll(" ", ""));
236
237 query="Sonne /+w4 Mond";
238 String prox4 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000239 "{@type=korap:sequence, @inOrder=true, " +
240 "@constraints=[" +
241 "{@type=korap:distance, @measure=w, @min=0, @max=4}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000242 "], " +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000243 "@operands=[" +
244 "{@type=korap:token, @value={@type=korap:term, @value=Sonne, @attr=orth, @relation==}}," +
245 "{@type=korap:token, @value={@type=korap:term, @value=Mond, @attr=orth, @relation==}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000246 "]" +
247 "}";
248 ppt = new CosmasTree(query);
249 map = ppt.getRequestMap().get("query").toString();
250 assertEquals(prox4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000251
252 query="Sonne /-w4 Mond";
253 String prox5 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000254 "{@type=korap:sequence, @inOrder=true, " +
255 "@constraints=[" +
256 "{@type=korap:distance, @measure=w, @min=0, @max=4}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000257 "], " +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000258 "@operands=[" +
259 "{@type=korap:token, @value={@type=korap:term, @value=Mond, @attr=orth, @relation==}}," +
260 "{@type=korap:token, @value={@type=korap:term, @value=Sonne, @attr=orth, @relation==}}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000261 "]" +
262 "}";
263 ppt = new CosmasTree(query);
264 map = ppt.getRequestMap().get("query").toString();
265 assertEquals(prox5.replaceAll(" ", ""), map.replaceAll(" ", ""));
266 }
267
268 @Test
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000269 public void testOPPROXNested() throws QueryException {
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000270 query="Sonne /-w4 Mond /+w2 Sterne";
271 String prox6 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000272 "{@type=korap:sequence, @inOrder=true, " +
273 "@constraints=[" +
274 "{@type=korap:distance, @measure=w, @min=0, @max=4}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000275 "], " +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000276 "@operands=[" +
277 "{@type=korap:sequence, @inOrder=true, " +
278 "@constraints=[" +
279 "{@type=korap:distance, @measure=w, @min=0, @max=2}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000280 "], " +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000281 "@operands=[" +
282 "{@type=korap:token, @value={@type=korap:term, @value=Mond, @attr=orth, @relation==}}," +
283 "{@type=korap:token, @value={@type=korap:term, @value=Sterne, @attr=orth, @relation==}}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000284 "]}," +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000285 "{@type=korap:token, @value={@type=korap:term, @value=Sonne, @attr=orth, @relation==}}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000286 "]" +
287 "}";
288 ppt = new CosmasTree(query);
289 map = ppt.getRequestMap().get("query").toString();
290 assertEquals(prox6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000291 }
292
293 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000294 public void testOPIN() throws QueryException {
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000295 query="wegen #IN <s>";
Joachim Bingel3a9f7932014-01-07 17:11:31 +0000296 String opin1 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000297 "{@type=korap:group, @relation=submatch, @classRef=1, @operands=[" +
298 "{@type=korap:group, @relation=position, @position=contains, @operands=[" +
299 "{@type=korap:span, @value=s}," +
300 "{@type=korap:group, class=1, @operands=[" +
301 "{@type=korap:token, @value={@type=korap:term, @value=wegen, @attr=orth, @relation==}}" +
Joachim Bingeleecc7652014-01-11 17:21:07 +0000302 "]}" +
303 "]}" +
Joachim Bingeld5161a12014-01-08 11:15:49 +0000304 "]}";
305 ppt = new CosmasTree(query);
306 map = ppt.getRequestMap().get("query").toString();
307 assertEquals(opin1.replaceAll(" ", ""), map.replaceAll(" ", ""));
308
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000309 query="wegen #IN(L) <s>";
310 String opin2 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000311 "{@type=korap:group, @relation=submatch, @classRef=1, @operands=[" +
312 "{@type=korap:group, @relation=position, @position=startswith, @operands=[" +
313 "{@type=korap:span, @value=s}," +
314 "{@type=korap:group, class=1, @operands=[" +
315 "{@type=korap:token, @value={@type=korap:term, @value=wegen, @attr=orth, @relation==}}" +
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000316 "]}" +
317 "]}" +
318 "]}";
319 ppt = new CosmasTree(query);
320 map = ppt.getRequestMap().get("query").toString();
321 assertEquals(opin2.replaceAll(" ", ""), map.replaceAll(" ", ""));
322
Joachim Bingel87480d02014-01-17 14:07:46 +0000323 query="wegen #IN(%, L) <s>";
324 String opin3 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000325 "{@type=korap:group, @relation=submatch, @classRef=1, @operands=[" +
326 "{@type=korap:group, @relation=position, @position=startswith, @exclude=true, @operands=[" +
327 "{@type=korap:span, @value=s}," +
328 "{@type=korap:group, class=1, @operands=[" +
329 "{@type=korap:token, @value={@type=korap:term, @value=wegen, @attr=orth, @relation==}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000330 "]}" +
331 "]}" +
332 "]}";
333 ppt = new CosmasTree(query);
334 map = ppt.getRequestMap().get("query").toString();
335 assertEquals(opin3.replaceAll(" ", ""), map.replaceAll(" ", ""));
336
337 query="wegen #IN('FE,ALL,%,MIN') <s>";
338 String opin4 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000339 "{@type=korap:group, @relation=submatch, @classRef=1, @operands=[" +
Joachim Bingel84e33df2014-01-31 14:02:46 +0000340 "{@type=korap:group, @relation=position, @position=matches, range=all, @exclude=true, grouping=false, @operands=[" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000341 "{@type=korap:span, @value=s}," +
342 "{@type=korap:group, class=1, @operands=[" +
343 "{@type=korap:token, @value={@type=korap:term, @value=wegen, @attr=orth, @relation==}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000344 "]}" +
345 "]}" +
346 "]}";
347 ppt = new CosmasTree(query);
348 map = ppt.getRequestMap().get("query").toString();
349 assertEquals(opin4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeld5161a12014-01-08 11:15:49 +0000350 }
351
352 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000353 public void testOPOV() throws QueryException {
Joachim Bingeld5161a12014-01-08 11:15:49 +0000354 query="wegen #OV <s>";
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000355 String opov1 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000356 "{@type=korap:group, @relation=submatch, @classRef=1, @operands=[" +
Joachim Bingel84e33df2014-01-31 14:02:46 +0000357 "{@type=korap:group, @relation=position, @position=overlaps, @operands=[" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000358 "{@type=korap:span, @value=s}," +
359 "{@type=korap:group, class=1, @operands=[" +
360 "{@type=korap:token, @value={@type=korap:term, @value=wegen, @attr=orth, @relation==}}" +
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000361 "]}" +
362 "]}" +
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000363 "]}";
364 ppt = new CosmasTree(query);
365 map = ppt.getRequestMap().get("query").toString();
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000366 assertEquals(opov1.replaceAll(" ", ""), map.replaceAll(" ", ""));
367
368 query="wegen #OV(L) <s>";
369 String opov2 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000370 "{@type=korap:group, @relation=submatch, @classRef=1, @operands=[" +
Joachim Bingel84e33df2014-01-31 14:02:46 +0000371 "{@type=korap:group, @relation=position, @position=overlaps-left, @operands=[" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000372 "{@type=korap:span, @value=s}," +
373 "{@type=korap:group, class=1, @operands=[" +
374 "{@type=korap:token, @value={@type=korap:term, @value=wegen, @attr=orth, @relation==}}" +
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000375 "]}" +
376 "]}" +
377 "]}";
378 ppt = new CosmasTree(query);
379 map = ppt.getRequestMap().get("query").toString();
380 assertEquals(opov2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000381 }
382
383 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000384 public void testOPNOT() throws QueryException {
Joachim Bingel3a9f7932014-01-07 17:11:31 +0000385 query="Sonne nicht Mond";
386 String opnot1 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000387 "{@type=korap:group, @relation=not, @operands=[" +
388 "{@type=korap:token, @value={@type=korap:term, @value=Sonne, @attr=orth, @relation==}}," +
389 "{@type=korap:token, @value={@type=korap:term, @value=Mond, @attr=orth, @relation==}}" +
Joachim Bingel3a9f7932014-01-07 17:11:31 +0000390 "]}";
391 ppt = new CosmasTree(query);
392 map = ppt.getRequestMap().get("query").toString();
393 assertEquals(opnot1.replaceAll(" ", ""), map.replaceAll(" ", ""));
394 }
395
396 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000397 public void testBEG_END() throws QueryException {
Joachim Bingel3a9f7932014-01-07 17:11:31 +0000398 // BEG and END operators
399 // http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/syntax/links.html
400 // http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/syntax/rechts.html
401 // http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/thematische-bsp/bsp-satzlaenge.html
Joachim Bingel87480d02014-01-17 14:07:46 +0000402 query="#BEG(der /w3:5 Mann)";
403 String beg1 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000404 "{@type=korap:group, @relation=submatch, @spanRef=[0,1], @operands=[" +
405 "{@type=korap:sequence, @inOrder=false, @constraints=[" +
406 "{@type=korap:distance, @measure=w, @min=3, @max=5}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000407 "]," +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000408 "@operands = [" +
409 "{@type=korap:token, @value={@type=korap:term, @value=der, @attr=orth, @relation==}}," +
410 "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=orth, @relation==}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000411 "]}" +
412 "]}";
413 ppt = new CosmasTree(query);
414 map = ppt.getRequestMap().get("query").toString();
415 assertEquals(beg1.replaceAll(" ", ""), map.replaceAll(" ", ""));
416
417 query="#BEG(der /w3:5 Mann) /+w10 kommt"; // nesting #BEG() in a distance group
418 String beg2 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000419 "{@type=korap:sequence, @inOrder=true, @constraints=[" +
420 "{@type=korap:distance, @measure=w, @min=0, @max=10}" +
421 "], @operands=[" +
422 "{@type=korap:group, @relation=submatch, @spanRef=[0,1], @operands=[" +
423 "{@type=korap:sequence, @inOrder=false, @constraints=[" +
424 "{@type=korap:distance, @measure=w, @min=3, @max=5}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000425 "]," +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000426 "@operands = [" +
427 "{@type=korap:token, @value={@type=korap:term, @value=der, @attr=orth, @relation==}}," +
428 "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=orth, @relation==}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000429 "]}" +
430 "]}," +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000431 "{@type=korap:token, @value={@type=korap:term, @value=kommt, @attr=orth, @relation==}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000432 "]}";
433 ppt = new CosmasTree(query);
434 map = ppt.getRequestMap().get("query").toString();
435 assertEquals(beg2.replaceAll(" ", ""), map.replaceAll(" ", ""));
436
437 query="#END(der /w3:5 Mann)";
438 String end1 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000439 "{@type=korap:group, @relation=submatch, @spanRef=[-1,1], @operands=[" +
440 "{@type=korap:sequence, @inOrder=false, @constraints=[" +
441 "{@type=korap:distance, @measure=w, @min=3, @max=5}" +
442 "], " +
443 "@operands = [" +
444 "{@type=korap:token, @value={@type=korap:term, @value=der, @attr=orth, @relation==}}," +
445 "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=orth, @relation==}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000446 "]}" +
447 "]}";
448 ppt = new CosmasTree(query);
449 map = ppt.getRequestMap().get("query").toString();
450 assertEquals(end1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000451 }
Joachim Bingeld5161a12014-01-08 11:15:49 +0000452
453
454 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000455 public void testELEM() throws QueryException {
Joachim Bingeld5161a12014-01-08 11:15:49 +0000456 // http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/syntax/elem.html
Joachim Bingeleecc7652014-01-11 17:21:07 +0000457 query="#ELEM(S)";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000458 String elem1 = "{@type=korap:span, @value=s}";
Joachim Bingeleecc7652014-01-11 17:21:07 +0000459 ppt = new CosmasTree(query);
460 map = ppt.getRequestMap().get("query").toString();
461 assertEquals(elem1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeld5161a12014-01-08 11:15:49 +0000462 }
463
464 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000465 public void testOPALL() throws QueryException {
Joachim Bingel89cceac2014-01-08 15:51:08 +0000466 query="#ALL(gehen /w1:10 voran)";
Joachim Bingele98d0882014-01-21 12:58:54 +0000467 String all1 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000468 "{@type=korap:sequence, @inOrder=false, " +
469 "@constraints=[" +
470 "{@type=korap:distance, @measure=w, @min=1, @max=10}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000471 "], " +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000472 "@operands=[" +
473 "{@type=korap:token, @value={@type=korap:term, @value=gehen, @attr=orth, @relation==}}," +
474 "{@type=korap:token, @value={@type=korap:term, @value=voran, @attr=orth, @relation==}}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000475 "]" +
476 "}";
Joachim Bingel89cceac2014-01-08 15:51:08 +0000477 ppt = new CosmasTree(query);
478 map = ppt.getRequestMap().get("query").toString();
479 assertEquals(all1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeld5161a12014-01-08 11:15:49 +0000480 }
481
Joachim Bingel8c640e42014-02-07 16:20:47 +0000482// @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000483 public void testOPNHIT() throws QueryException {
Joachim Bingel89cceac2014-01-08 15:51:08 +0000484 query="#NHIT(gehen /w1:10 voran)";
485 String nhit1 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000486 "{@type=korap:sequence, @inOrder=false, " +
487 "@constraints=[" +
488 "{@type=korap:distance, @measure=w, @min=1, @max=10}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000489 "], " +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000490 "@operands=[" +
491 "{@type=korap:token, @value={@type=korap:term, @value=gehen, @attr=orth, @relation==}}," +
492 "{@type=korap:token, @value={@type=korap:term, @value=voran, @attr=orth, @relation==}}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000493 "]" +
494 "}";
Joachim Bingel89cceac2014-01-08 15:51:08 +0000495 ppt = new CosmasTree(query);
496 map = ppt.getRequestMap().get("query").toString();
497 assertEquals(nhit1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeld5161a12014-01-08 11:15:49 +0000498 }
499
500 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000501 public void testOPBED() throws QueryException {
Joachim Bingeleecc7652014-01-11 17:21:07 +0000502 query = "#BED(der , sa)";
503 String bed1 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000504 "{@type=korap:group, @relation=position, @position=startswith, @operands=[" +
505 "{@type=korap:span, @value=s}," +
506 "{@type=korap:token, @value={@type=korap:term, @value=der, @attr=orth, @relation==}}" +
Joachim Bingeleecc7652014-01-11 17:21:07 +0000507 "]}";
508 ppt = new CosmasTree(query);
509 map = ppt.getRequestMap().get("query").toString();
510 assertEquals(bed1.replaceAll(" ", ""), map.replaceAll(" ", ""));
511
512 query = "#BED(der Mann , +pe)";
513 String bed2 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000514 "{@type=korap:group, @relation=position, @position=endswith, @operands=[" +
515 "{@type=korap:span, @value=p}," +
516 "{@type=korap:sequence, @operands=[" +
517 "{@type=korap:token, @value={@type=korap:term, @value=der, @attr=orth, @relation==}}," +
518 "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=orth, @relation==}}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000519 "]}" +
Joachim Bingeleecc7652014-01-11 17:21:07 +0000520 "]}";
521 ppt = new CosmasTree(query);
522 map = ppt.getRequestMap().get("query").toString();
523 assertEquals(bed2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000524
525 query = "#BED(der Mann , sa,-pa)";
526 String bed3 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000527 "{@type=korap:group, @relation=and, @operands=[" +
528 "{@type=korap:group, @relation=position, @position=startswith, @operands=[" +
529 "{@type=korap:span, @value=s}," +
530 "{@type=korap:sequence, @operands=[" +
531 "{@type=korap:token, @value={@type=korap:term, @value=der, @attr=orth, @relation==}}," +
532 "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=orth, @relation==}}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000533 "]}" +
534 "]}," +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000535 "{@type=korap:group, @relation=position, @position=startswith, @exclude=true, @operands=[" +
536 "{@type=korap:span, @value=p}," +
537 "{@type=korap:sequence, @operands=[" +
538 "{@type=korap:token, @value={@type=korap:term, @value=der, @attr=orth, @relation==}}," +
539 "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=orth, @relation==}}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000540 "]}" +
541 "]}" +
542 "]}";
543 ppt = new CosmasTree(query);
544 map = ppt.getRequestMap().get("query").toString();
545 assertEquals(bed3.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeld5161a12014-01-08 11:15:49 +0000546 }
547
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000548}
549