blob: 49bac86e6f1e103f0d0ae76d5cf0168914993a89 [file] [log] [blame]
Joachim Bingel4eacdd32014-10-22 15:49:47 +00001import static org.junit.Assert.*;
2
3import java.io.IOException;
4import java.util.ArrayList;
Joachim Bingel4eacdd32014-10-22 15:49:47 +00005
6import org.junit.Test;
7
Joachim Bingel4eacdd32014-10-22 15:49:47 +00008import com.fasterxml.jackson.core.JsonProcessingException;
9import com.fasterxml.jackson.databind.JsonNode;
10import com.fasterxml.jackson.databind.ObjectMapper;
11import com.google.common.collect.Lists;
12
13
14import de.ids_mannheim.korap.query.serialize.QuerySerializer;
15import de.ids_mannheim.korap.util.QueryException;
16
17public class PoliqarpPlusTreeJSONTest {
18
19 String map;
20 String expected;
21 String metaExpected;
22 String metaMap;
23 String query;
24 ArrayList<JsonNode> operands;
25
26 QuerySerializer qs = new QuerySerializer();
27 ObjectMapper mapper = new ObjectMapper();
28 JsonNode res;
29
30 @Test
31 public void testContext() throws QueryException, JsonProcessingException, IOException {
32 query = "foo";
33 String contextString = "http://ids-mannheim.de/ns/KorAP/json-ld/v0.2/context.jsonld";
34 qs.setQuery(query, "poliqarpplus");
35 res = mapper.readTree(qs.toJSON());
36 assertEquals(contextString, res.get("@context").asText());
37 }
38
39
40
41 @Test
42 public void testSingleTokens() throws QueryException, JsonProcessingException, IOException {
43 query = "[base=Mann]";
44 qs.setQuery(query, "poliqarpplus");
45 res = mapper.readTree(qs.toJSON());
46 assertEquals("korap:token", res.at("/query/@type").asText());
47 assertEquals("Mann", res.at("/query/wrap/key").asText());
48 assertEquals("lemma", res.at("/query/wrap/layer").asText());
49 assertEquals("match:eq", res.at("/query/wrap/match").asText());
50
51 query = "[orth!=Frau]";
52 qs.setQuery(query, "poliqarpplus");
53 res = mapper.readTree(qs.toJSON());
54 assertEquals("korap:token", res.at("/query/@type").asText());
55 assertEquals("Frau", res.at("/query/wrap/key").asText());
56 assertEquals("orth", res.at("/query/wrap/layer").asText());
57 assertEquals("match:ne", res.at("/query/wrap/match").asText());
58
59 query = "[p!=NN]";
60 qs.setQuery(query, "poliqarpplus");
61 res = mapper.readTree(qs.toJSON());
62 assertEquals("korap:token", res.at("/query/@type").asText());
63 assertEquals("NN", res.at("/query/wrap/key").asText());
64 assertEquals("p", res.at("/query/wrap/layer").asText());
65 assertEquals("match:ne", res.at("/query/wrap/match").asText());
66
67 query = "[!p!=NN]";
68 qs.setQuery(query, "poliqarpplus");
69 res = mapper.readTree(qs.toJSON());
70 assertEquals("korap:token", res.at("/query/@type").asText());
71 assertEquals("NN", res.at("/query/wrap/key").asText());
72 assertEquals("p", res.at("/query/wrap/layer").asText());
73 assertEquals("match:eq", res.at("/query/wrap/match").asText());
74
75 query = "[base=schland/x]";
76 qs.setQuery(query, "poliqarpplus");
77 res = mapper.readTree(qs.toJSON());
78 assertEquals("korap:token", res.at("/query/@type").asText());
79 assertEquals(".*?schland.*?", res.at("/query/wrap/key").asText());
80 assertEquals("lemma", res.at("/query/wrap/layer").asText());
81 assertEquals("type:regex", res.at("/query/wrap/type").asText());
82 assertEquals("match:eq", res.at("/query/wrap/match").asText());
83 }
84
85 @Test
86 public void testValue() throws QueryException, JsonProcessingException, IOException {
87 query = "[mate/m=temp:pres]";
88 qs.setQuery(query, "poliqarpplus");
89 res = mapper.readTree(qs.toJSON());
90 assertEquals("korap:token", res.at("/query/@type").asText());
91 assertEquals("korap:term", res.at("/query/wrap/@type").asText());
92 assertEquals("temp", res.at("/query/wrap/key").asText());
93 assertEquals("pres", res.at("/query/wrap/value").asText());
94 assertEquals("m", res.at("/query/wrap/layer").asText());
95 assertEquals("mate", res.at("/query/wrap/foundry").asText());
96 assertEquals("match:eq", res.at("/query/wrap/match").asText());
97 }
98
99 @Test
100 public void testRegex() throws QueryException, JsonProcessingException, IOException {
101 query = "[orth=\"M(a|ä)nn(er)?\"]";
102 qs.setQuery(query, "poliqarpplus");
103 res = mapper.readTree(qs.toJSON());
104 assertEquals("korap:token", res.at("/query/@type").asText());
105 assertEquals("korap:term", res.at("/query/wrap/@type").asText());
106 assertEquals("M(a|ä)nn(er)?", res.at("/query/wrap/key").asText());
107 assertEquals("type:regex", res.at("/query/wrap/type").asText());
108 assertEquals("orth", res.at("/query/wrap/layer").asText());
109 assertEquals("match:eq", res.at("/query/wrap/match").asText());
110
111 query = "[orth=\"M(a|ä)nn(er)?\"/x]";
112 qs.setQuery(query, "poliqarpplus");
113 res = mapper.readTree(qs.toJSON());
114 assertEquals("korap:token", res.at("/query/@type").asText());
115 assertEquals("korap:term", res.at("/query/wrap/@type").asText());
116 assertEquals(".*?M(a|ä)nn(er)?.*?", res.at("/query/wrap/key").asText());
117 assertEquals("type:regex", res.at("/query/wrap/type").asText());
118 assertEquals("orth", res.at("/query/wrap/layer").asText());
119 assertEquals("match:eq", res.at("/query/wrap/match").asText());
120
121 query = "\".*?Mann.*?\"";
122 qs.setQuery(query, "poliqarpplus");
123 res = mapper.readTree(qs.toJSON());
124 assertEquals("korap:token", res.at("/query/@type").asText());
125 assertEquals("korap:term", res.at("/query/wrap/@type").asText());
126 assertEquals(".*?Mann.*?", res.at("/query/wrap/key").asText());
127 assertEquals("type:regex", res.at("/query/wrap/type").asText());
128 assertEquals("orth", res.at("/query/wrap/layer").asText());
129 assertEquals("match:eq", res.at("/query/wrap/match").asText());
130
131 query = "z.B./x";
132 qs.setQuery(query, "poliqarpplus");
133 res = mapper.readTree(qs.toJSON());
134 assertEquals("korap:token", res.at("/query/@type").asText());
135 assertEquals("korap:term", res.at("/query/wrap/@type").asText());
136 assertEquals(".*?z\\.B\\..*?", res.at("/query/wrap/key").asText());
137 assertEquals("type:regex", res.at("/query/wrap/type").asText());
138 assertEquals("orth", res.at("/query/wrap/layer").asText());
139 assertEquals("match:eq", res.at("/query/wrap/match").asText());
140
141 }
142
143 @Test
144 public void testCaseSensitivityFlag() throws QueryException, JsonProcessingException, IOException {
145 query = "[orth=deutscher/i]";
146 qs.setQuery(query, "poliqarpplus");
147 res = mapper.readTree(qs.toJSON());
148 assertEquals("korap:token", res.at("/query/@type").asText());
149 assertEquals("korap:term", res.at("/query/wrap/@type").asText());
150 assertEquals("deutscher", res.at("/query/wrap/key").asText());
151 assertEquals("true", res.at("/query/wrap/caseInsensitive").asText());
152 assertEquals("orth", res.at("/query/wrap/layer").asText());
153 assertEquals("match:eq", res.at("/query/wrap/match").asText());
154
155 query = "deutscher/i";
156 qs.setQuery(query, "poliqarpplus");
157 res = mapper.readTree(qs.toJSON());
158 assertEquals("korap:token", res.at("/query/@type").asText());
159 assertEquals("korap:term", res.at("/query/wrap/@type").asText());
160 assertEquals("deutscher", res.at("/query/wrap/key").asText());
161 assertEquals("true", res.at("/query/wrap/caseInsensitive").asText());
162 assertEquals("orth", res.at("/query/wrap/layer").asText());
163 assertEquals("match:eq", res.at("/query/wrap/match").asText());
164
165 query = "deutscher/I";
166 qs.setQuery(query, "poliqarpplus");
167 res = mapper.readTree(qs.toJSON());
168 assertEquals("korap:token", res.at("/query/@type").asText());
169 assertEquals("korap:term", res.at("/query/wrap/@type").asText());
170 assertEquals("deutscher", res.at("/query/wrap/key").asText());
171 assertEquals("false", res.at("/query/wrap/caseInsensitive").asText());
172 assertEquals("orth", res.at("/query/wrap/layer").asText());
173 assertEquals("match:eq", res.at("/query/wrap/match").asText());
174
175 query = "[orth=deutscher/i][orth=Bundestag]";
176 qs.setQuery(query, "poliqarpplus");
177 res = mapper.readTree(qs.toJSON());
178 assertEquals("korap:group", res.at("/query/@type").asText());
179 assertEquals("operation:sequence", res.at("/query/operation").asText());
180 operands = Lists.newArrayList(res.at("/query/operands").elements());
181 assertEquals("korap:token", operands.get(0).at("/@type").asText());
182 assertEquals("deutscher", operands.get(0).at("/wrap/key").asText());
183 assertEquals("orth", operands.get(0).at("/wrap/layer").asText());
184 assertEquals("match:eq", operands.get(0).at("/wrap/match").asText());
Joachim Bingel33763632014-10-23 13:31:05 +0000185 assertEquals(true, operands.get(0).at("/wrap/caseInsensitive").asBoolean());
Joachim Bingel4eacdd32014-10-22 15:49:47 +0000186 assertEquals("korap:token", operands.get(1).at("/@type").asText());
187 assertEquals("Bundestag", operands.get(1).at("/wrap/key").asText());
188 assertEquals("orth", operands.get(1).at("/wrap/layer").asText());
189 assertEquals("match:eq", operands.get(1).at("/wrap/match").asText());
190 assertEquals(true, operands.get(1).at("/wrap/caseInsensitive").isMissingNode());
191
192 query = "deutscher/i Bundestag";
193 qs.setQuery(query, "poliqarpplus");
194 res = mapper.readTree(qs.toJSON());
195 assertEquals("korap:group", res.at("/query/@type").asText());
196 assertEquals("operation:sequence", res.at("/query/operation").asText());
197 operands = Lists.newArrayList(res.at("/query/operands").elements());
198 assertEquals("korap:token", operands.get(0).at("/@type").asText());
199 assertEquals("deutscher", operands.get(0).at("/wrap/key").asText());
200 assertEquals("orth", operands.get(0).at("/wrap/layer").asText());
201 assertEquals("match:eq", operands.get(0).at("/wrap/match").asText());
Joachim Bingel33763632014-10-23 13:31:05 +0000202 assertEquals(true, operands.get(0).at("/wrap/caseInsensitive").asBoolean());
Joachim Bingel4eacdd32014-10-22 15:49:47 +0000203 assertEquals("korap:token", operands.get(1).at("/@type").asText());
204 assertEquals("Bundestag", operands.get(1).at("/wrap/key").asText());
205 assertEquals("orth", operands.get(1).at("/wrap/layer").asText());
206 assertEquals("match:eq", operands.get(1).at("/wrap/match").asText());
207 assertEquals(true, operands.get(1).at("/wrap/caseInsensitive").isMissingNode());
208 }
209
210 @Test
211 public void testSpans() throws QueryException, JsonProcessingException, IOException {
212 query = "<s>";
213 qs.setQuery(query, "poliqarpplus");
214 res = mapper.readTree(qs.toJSON());
215 assertEquals("korap:span", res.at("/query/@type").asText());
216 assertEquals("s", res.at("/query/key").asText());
217
218 query = "<vp>";
219 qs.setQuery(query, "poliqarpplus");
220 res = mapper.readTree(qs.toJSON());
221 assertEquals("korap:span", res.at("/query/@type").asText());
222 assertEquals("vp", res.at("/query/key").asText());
223
224 query = "<cnx/c=vp>";
225 qs.setQuery(query, "poliqarpplus");
226 res = mapper.readTree(qs.toJSON());
227 assertEquals("korap:span", res.at("/query/@type").asText());
228 assertEquals("vp", res.at("/query/key").asText());
229 assertEquals("cnx", res.at("/query/foundry").asText());
230 assertEquals("c", res.at("/query/layer").asText());
231
232 query = "<cnx/c!=vp>";
233 qs.setQuery(query, "poliqarpplus");
234 res = mapper.readTree(qs.toJSON());
235 assertEquals("korap:span", res.at("/query/@type").asText());
236 assertEquals("vp", res.at("/query/key").asText());
237 assertEquals("cnx", res.at("/query/foundry").asText());
238 assertEquals("c", res.at("/query/layer").asText());
239 assertEquals("match:ne", res.at("/query/match").asText());
240
241 query = "<cnx/c!=vp class!=header>";
242 qs.setQuery(query, "poliqarpplus");
243 res = mapper.readTree(qs.toJSON());
244 assertEquals("korap:span", res.at("/query/@type").asText());
245 assertEquals("vp", res.at("/query/key").asText());
246 assertEquals("cnx", res.at("/query/foundry").asText());
247 assertEquals("c", res.at("/query/layer").asText());
248 assertEquals("match:ne", res.at("/query/match").asText());
249 assertEquals("class", res.at("/query/attr/key").asText());
250 assertEquals("header", res.at("/query/attr/value").asText());
251 assertEquals("match:ne", res.at("/query/attr/match").asText());
252
253 query = "<cnx/c!=vp !(class!=header)>";
254 qs.setQuery(query, "poliqarpplus");
255 res = mapper.readTree(qs.toJSON());
256 assertEquals("korap:span", res.at("/query/@type").asText());
257 assertEquals("vp", res.at("/query/key").asText());
258 assertEquals("cnx", res.at("/query/foundry").asText());
259 assertEquals("c", res.at("/query/layer").asText());
260 assertEquals("match:ne", res.at("/query/match").asText());
261 assertEquals("class", res.at("/query/attr/key").asText());
262 assertEquals("header", res.at("/query/attr/value").asText());
263 assertEquals("match:eq", res.at("/query/attr/match").asText());
264
265 query = "<cnx/c!=vp !(class=header & id=7)>";
266 qs.setQuery(query, "poliqarpplus");
267 res = mapper.readTree(qs.toJSON());
268 assertEquals("korap:span", res.at("/query/@type").asText());
269 assertEquals("vp", res.at("/query/key").asText());
270 assertEquals("cnx", res.at("/query/foundry").asText());
271 assertEquals("c", res.at("/query/layer").asText());
272 assertEquals("match:ne", res.at("/query/match").asText());
273 assertEquals("korap:termGroup", res.at("/query/attr/@type").asText());
274 assertEquals("relation:and", res.at("/query/attr/relation").asText());
275 operands = Lists.newArrayList( res.at("/query/attr/operands").elements());
276 assertEquals("korap:term", operands.get(0).at("/@type").asText());
277 assertEquals("class", operands.get(0).at("/key").asText());
278 assertEquals("header", operands.get(0).at("/value").asText());
279 assertEquals("match:ne", operands.get(0).at("/match").asText());
280 assertEquals("korap:term", operands.get(1).at("/@type").asText());
281 assertEquals("id", operands.get(1).at("/key").asText());
Joachim Bingel33763632014-10-23 13:31:05 +0000282 assertEquals(7, operands.get(1).at("/value").asInt());
Joachim Bingel4eacdd32014-10-22 15:49:47 +0000283 assertEquals("match:ne", operands.get(1).at("/match").asText());
284 }
285
286 @Test
287 public void testDistances() throws QueryException, JsonProcessingException, IOException {
288 query = "[base=der][][base=Mann]";
289 qs.setQuery(query, "poliqarpplus");
290 res = mapper.readTree(qs.toJSON());
Joachim Bingel4eacdd32014-10-22 15:49:47 +0000291 assertEquals("korap:group", res.at("/query/@type").asText());
292 assertEquals("operation:sequence", res.at("/query/operation").asText());
293 assertEquals("true", res.at("/query/inOrder").asText());
294 assertEquals("korap:distance", res.at("/query/distances").elements().next().at("/@type").asText());
295 assertEquals("w", res.at("/query/distances").elements().next().at("/key").asText());
296 assertEquals("korap:boundary", res.at("/query/distances").elements().next().at("/boundary/@type").asText());
Joachim Bingel33763632014-10-23 13:31:05 +0000297 assertEquals(2, res.at("/query/distances").elements().next().at("/boundary/min").asInt());
298 assertEquals(2, res.at("/query/distances").elements().next().at("/boundary/max").asInt());
Joachim Bingel4eacdd32014-10-22 15:49:47 +0000299 operands = Lists.newArrayList(res.at("/query/operands").elements());
300 assertEquals("korap:token", operands.get(0).at("/@type").asText());
301 assertEquals("der", operands.get(0).at("/wrap/key").asText());
302 assertEquals("lemma", operands.get(0).at("/wrap/layer").asText());
303 assertEquals("match:eq", operands.get(0).at("/wrap/match").asText());
304 assertEquals("korap:token", operands.get(1).at("/@type").asText());
305 assertEquals("Mann", operands.get(1).at("/wrap/key").asText());
306 assertEquals("lemma", operands.get(1).at("/wrap/layer").asText());
307 assertEquals("match:eq", operands.get(1).at("/wrap/match").asText());
308
309 query = "[base=der][][][base=Mann]";
310 qs.setQuery(query, "poliqarpplus");
311 res = mapper.readTree(qs.toJSON());
Joachim Bingel4eacdd32014-10-22 15:49:47 +0000312 assertEquals("korap:group", res.at("/query/@type").asText());
313 assertEquals("operation:sequence", res.at("/query/operation").asText());
314 assertEquals("true", res.at("/query/inOrder").asText());
315 assertEquals("korap:distance", res.at("/query/distances").elements().next().at("/@type").asText());
316 assertEquals("w", res.at("/query/distances").elements().next().at("/key").asText());
317 assertEquals("korap:boundary", res.at("/query/distances").elements().next().at("/boundary/@type").asText());
Joachim Bingel33763632014-10-23 13:31:05 +0000318 assertEquals(3, res.at("/query/distances").elements().next().at("/boundary/min").asInt());
319 assertEquals(3, res.at("/query/distances").elements().next().at("/boundary/max").asInt());
Joachim Bingel4eacdd32014-10-22 15:49:47 +0000320 operands = Lists.newArrayList(res.at("/query/operands").elements());
321 assertEquals("korap:token", operands.get(0).at("/@type").asText());
322 assertEquals("der", operands.get(0).at("/wrap/key").asText());
323 assertEquals("lemma", operands.get(0).at("/wrap/layer").asText());
324 assertEquals("match:eq", operands.get(0).at("/wrap/match").asText());
325 assertEquals("korap:token", operands.get(1).at("/@type").asText());
326 assertEquals("Mann", operands.get(1).at("/wrap/key").asText());
327 assertEquals("lemma", operands.get(1).at("/wrap/layer").asText());
328 assertEquals("match:eq", operands.get(1).at("/wrap/match").asText());
329
330 query = "[base=der][][]?[base=Mann]";
331 qs.setQuery(query, "poliqarpplus");
332 res = mapper.readTree(qs.toJSON());
Joachim Bingel4eacdd32014-10-22 15:49:47 +0000333 assertEquals("korap:group", res.at("/query/@type").asText());
334 assertEquals("operation:sequence", res.at("/query/operation").asText());
335 assertEquals("true", res.at("/query/inOrder").asText());
336 assertEquals("korap:distance", res.at("/query/distances").elements().next().at("/@type").asText());
337 assertEquals("w", res.at("/query/distances").elements().next().at("/key").asText());
338 assertEquals("korap:boundary", res.at("/query/distances").elements().next().at("/boundary/@type").asText());
Joachim Bingel33763632014-10-23 13:31:05 +0000339 assertEquals(2, res.at("/query/distances").elements().next().at("/boundary/min").asInt());
340 assertEquals(3, res.at("/query/distances").elements().next().at("/boundary/max").asInt());
Joachim Bingel4eacdd32014-10-22 15:49:47 +0000341 operands = Lists.newArrayList(res.at("/query/operands").elements());
342 assertEquals("korap:token", operands.get(0).at("/@type").asText());
343 assertEquals("der", operands.get(0).at("/wrap/key").asText());
344 assertEquals("lemma", operands.get(0).at("/wrap/layer").asText());
345 assertEquals("match:eq", operands.get(0).at("/wrap/match").asText());
346 assertEquals("korap:token", operands.get(1).at("/@type").asText());
347 assertEquals("Mann", operands.get(1).at("/wrap/key").asText());
348 assertEquals("lemma", operands.get(1).at("/wrap/layer").asText());
349 assertEquals("match:eq", operands.get(1).at("/wrap/match").asText());
Joachim Bingel33763632014-10-23 13:31:05 +0000350
351 query = "[base=der][]+[base=Mann]";
352 qs.setQuery(query, "poliqarpplus");
353 res = mapper.readTree(qs.toJSON());
354 assertEquals("korap:group", res.at("/query/@type").asText());
355 assertEquals("operation:sequence", res.at("/query/operation").asText());
356 assertEquals("true", res.at("/query/inOrder").asText());
357 assertEquals("korap:distance", res.at("/query/distances").elements().next().at("/@type").asText());
358 assertEquals("w", res.at("/query/distances").elements().next().at("/key").asText());
359 assertEquals("korap:boundary", res.at("/query/distances").elements().next().at("/boundary/@type").asText());
360 assertEquals(2, res.at("/query/distances").elements().next().at("/boundary/min").asInt());
361 assertEquals(true, res.at("/query/distances").elements().next().at("/boundary/max").isMissingNode());
362 operands = Lists.newArrayList(res.at("/query/operands").elements());
363 assertEquals("korap:token", operands.get(0).at("/@type").asText());
364 assertEquals("der", operands.get(0).at("/wrap/key").asText());
365 assertEquals("lemma", operands.get(0).at("/wrap/layer").asText());
366 assertEquals("match:eq", operands.get(0).at("/wrap/match").asText());
367 assertEquals("korap:token", operands.get(1).at("/@type").asText());
368 assertEquals("Mann", operands.get(1).at("/wrap/key").asText());
369 assertEquals("lemma", operands.get(1).at("/wrap/layer").asText());
370 assertEquals("match:eq", operands.get(1).at("/wrap/match").asText());
371
372 query = "[base=der][]*[base=Mann]";
373 qs.setQuery(query, "poliqarpplus");
374 res = mapper.readTree(qs.toJSON());
375 assertEquals("korap:group", res.at("/query/@type").asText());
376 assertEquals("operation:sequence", res.at("/query/operation").asText());
377 assertEquals("true", res.at("/query/inOrder").asText());
378 assertEquals("korap:distance", res.at("/query/distances").elements().next().at("/@type").asText());
379 assertEquals("w", res.at("/query/distances").elements().next().at("/key").asText());
380 assertEquals("korap:boundary", res.at("/query/distances").elements().next().at("/boundary/@type").asText());
381 assertEquals(1, res.at("/query/distances").elements().next().at("/boundary/min").asInt());
382 assertEquals(true, res.at("/query/distances").elements().next().at("/boundary/max").isMissingNode());
383
384 query = "[base=der][]{2,5}[base=Mann][]?[][base=Frau]";
385 qs.setQuery(query, "poliqarpplus");
386 res = mapper.readTree(qs.toJSON());
387 assertEquals("korap:group", res.at("/query/@type").asText());
388 assertEquals("operation:sequence", res.at("/query/operation").asText());
389 assertEquals("true", res.at("/query/inOrder").asText());
390 assertEquals("korap:distance", res.at("/query/distances").elements().next().at("/@type").asText());
391 assertEquals("w", res.at("/query/distances").elements().next().at("/key").asText());
392 assertEquals("korap:boundary", res.at("/query/distances").elements().next().at("/boundary/@type").asText());
393 assertEquals(3, res.at("/query/distances").elements().next().at("/boundary/min").asInt());
394 assertEquals(6, res.at("/query/distances").elements().next().at("/boundary/max").asInt());
395 operands = Lists.newArrayList(res.at("/query/operands").elements());
396 assertEquals("korap:token", operands.get(0).at("/@type").asText());
397 assertEquals("der", operands.get(0).at("/wrap/key").asText());
398 assertEquals("lemma", operands.get(0).at("/wrap/layer").asText());
399 assertEquals("match:eq", operands.get(0).at("/wrap/match").asText());
400 assertEquals("korap:group", operands.get(1).at("/@type").asText());
401 assertEquals("operation:sequence", operands.get(1).at("/operation").asText());
402 assertEquals("korap:distance", operands.get(1).get("distances").elements().next().at("/@type").asText());
403 assertEquals("w", operands.get(1).get("distances").elements().next().at("/key").asText());
404 assertEquals("korap:boundary", operands.get(1).get("distances").elements().next().at("/boundary/@type").asText());
405 assertEquals(2, operands.get(1).get("distances").elements().next().at("/boundary/min").asInt());
406 assertEquals(3, operands.get(1).get("distances").elements().next().at("/boundary/max").asInt());
407 operands = Lists.newArrayList(operands.get(1).get("operands").elements());
408 assertEquals("Mann", operands.get(0).at("/wrap/key").asText());
409 assertEquals("lemma", operands.get(0).at("/wrap/layer").asText());
410 assertEquals("match:eq", operands.get(0).at("/wrap/match").asText());
411 assertEquals("Frau", operands.get(1).at("/wrap/key").asText());
412 assertEquals("lemma", operands.get(1).at("/wrap/layer").asText());
413 assertEquals("match:eq", operands.get(1).at("/wrap/match").asText());
414
415 query = "[base=geht][base=der][]*contains(<s>,<np>)";
416 qs.setQuery(query, "poliqarpplus");
417 res = mapper.readTree(qs.toJSON());
418 assertEquals("korap:group", res.at("/query/@type").asText());
419 assertEquals("operation:sequence", res.at("/query/operation").asText());
420 assertEquals(true, res.at("/query/inOrder").isMissingNode());
421 assertEquals(true, res.at("/query/distances").isMissingNode());
422 operands = Lists.newArrayList(res.at("/query/operands").elements());
423 assertEquals("korap:token", operands.get(0).at("/@type").asText());
424 assertEquals("geht", operands.get(0).at("/wrap/key").asText());
425 assertEquals("lemma", operands.get(0).at("/wrap/layer").asText());
426 assertEquals("match:eq", operands.get(0).at("/wrap/match").asText());
427 assertEquals("korap:group", operands.get(1).at("/@type").asText());
428 assertEquals("operation:sequence", operands.get(1).at("/operation").asText());
429 assertEquals("korap:distance", operands.get(1).get("distances").elements().next().at("/@type").asText());
430 assertEquals("w", operands.get(1).get("distances").elements().next().at("/key").asText());
431 assertEquals("korap:boundary", operands.get(1).get("distances").elements().next().at("/boundary/@type").asText());
432 assertEquals(1, operands.get(1).get("distances").elements().next().at("/boundary/min").asInt());
433 assertEquals(true, operands.get(1).get("distances").elements().next().at("/boundary/max").isMissingNode());
434 operands = Lists.newArrayList(operands.get(1).get("operands").elements());
435 assertEquals("der", operands.get(0).at("/wrap/key").asText());
436 assertEquals("lemma", operands.get(0).at("/wrap/layer").asText());
437 assertEquals("match:eq", operands.get(0).at("/wrap/match").asText());
438 assertEquals("korap:group", operands.get(1).at("/@type").asText());
439 assertEquals("operation:position", operands.get(1).at("/operation").asText());
Joachim Bingel4eacdd32014-10-22 15:49:47 +0000440 }
Joachim Bingel33763632014-10-23 13:31:05 +0000441
442 @Test
443 public void testDistancesWithClass() throws QueryException, JsonProcessingException, IOException {
444 query = "[base=der]{[]}[base=Mann]";
445 qs.setQuery(query, "poliqarpplus");
446 res = mapper.readTree(qs.toJSON());
447 assertEquals("korap:group", res.at("/query/@type").asText());
448 assertEquals("operation:sequence", res.at("/query/operation").asText());
449 assertEquals(true, res.at("/query/inOrder").isMissingNode());
450 assertEquals(true, res.at("/query/distances").isMissingNode());
451 operands = Lists.newArrayList(res.at("/query/operands").elements());
452 assertEquals("der", operands.get(0).at("/wrap/key").asText());
453 assertEquals("Mann", operands.get(2).at("/wrap/key").asText());
454 assertEquals("korap:group", operands.get(1).at("/@type").asText());
455 assertEquals("operation:class", operands.get(1).at("/operation").asText());
456 assertEquals(1, operands.get(1).at("/classOut").asInt());
457 operands = Lists.newArrayList(operands.get(1).at("/operands").elements());
458 assertEquals("korap:token", operands.get(0).at("/@type").asText());
459 assertEquals(true, operands.get(0).at("/wrap").isMissingNode());
460
461 query = "[base=der]{2:[]}[base=Mann]";
462 qs.setQuery(query, "poliqarpplus");
463 res = mapper.readTree(qs.toJSON());
464 operands = Lists.newArrayList(res.at("/query/operands").elements());
465 assertEquals("operation:class", operands.get(1).at("/operation").asText());
466 assertEquals(2, operands.get(1).at("/classOut").asInt());
467
468 query = "{1:[]}[base=der][base=Mann]";
469 qs.setQuery(query, "poliqarpplus");
470 res = mapper.readTree(qs.toJSON());
471 operands = Lists.newArrayList(res.at("/query/operands").elements());
472 assertEquals("operation:class", operands.get(0).at("/operation").asText());
473 assertEquals(1, operands.get(0).at("/classOut").asInt());
Joachim Bingel1eef4032014-11-07 13:11:01 +0000474
475 query = "{1:{2:der} {3:[]} Mann}";
476 qs.setQuery(query, "poliqarpplus");
477 res = mapper.readTree(qs.toJSON());
478 operands = Lists.newArrayList(res.at("/query/operands").elements());
479 assertEquals(1, operands.size()); // class operation may only have one operand (the sequence)
480 operands = Lists.newArrayList(operands.get(0).at("/operands").elements());
481 assertEquals(3, operands.size()); // the sequence has three operands ("der", "[]" and "Mann")
482
Joachim Bingel33763632014-10-23 13:31:05 +0000483 }
484
485 @Test
486 public void testLeadingTrailingEmptyTokens() throws QueryException, JsonProcessingException, IOException {
487 query = "[][base=Mann]";
488 qs.setQuery(query, "poliqarpplus");
489 res = mapper.readTree(qs.toJSON());
490 operands = Lists.newArrayList(res.at("/query/operands").elements());
491 assertEquals("korap:token", operands.get(0).at("/@type").asText());
492 assertEquals(true, operands.get(0).at("/key").isMissingNode());
493
494 query = "[][][base=Mann]";
495 qs.setQuery(query, "poliqarpplus");
496 res = mapper.readTree(qs.toJSON());
497 operands = Lists.newArrayList(res.at("/query/operands").elements());
498 assertEquals("korap:group", operands.get(0).at("/@type").asText());
499 assertEquals("operation:repetition",operands.get(0).at("/operation").asText());
500 assertEquals(2, operands.get(0).at("/boundary/min").asInt());
501 assertEquals(2, operands.get(0).at("/boundary/max").asInt());
502 operands = Lists.newArrayList(operands.get(0).at("/operands").elements());
503 assertEquals("korap:token", operands.get(0).at("/@type").asText());
504 assertEquals(true, operands.get(0).at("/key").isMissingNode());
505
506 query = "startswith(<s>, [][base=Mann])";
507 qs.setQuery(query, "poliqarpplus");
508 res = mapper.readTree(qs.toJSON());
509 operands = Lists.newArrayList(res.at("/query/operands"));
510 operands = Lists.newArrayList(operands.get(1).at("/operands"));
511 assertEquals("korap:token", operands.get(0).at("/@type").asText());
512 assertEquals(true, operands.get(0).at("/key").isMissingNode());
513 }
Joachim Bingel1eef4032014-11-07 13:11:01 +0000514
515
Nils Diewald5adc3c62014-11-12 21:55:34 +0000516 @Test
517 public void testGroupRepetition() throws QueryException, JsonProcessingException, IOException {
518 query = "contains(<s>, (der){3})";
519 qs.setQuery(query, "poliqarpplus");
520 res = mapper.readTree(qs.toJSON());
521 assertEquals("korap:group", res.at("/query/@type").asText());
522 assertEquals("operation:position", res.at("/query/operation").asText());
523 assertEquals("korap:span", res.at("/query/operands/0/@type").asText());
524 assertEquals("s", res.at("/query/operands/0/key").asText());
525 assertEquals("korap:group", res.at("/query/operands/1/@type").asText());
526 assertEquals("operation:repetition", res.at("/query/operands/1/operation").asText());
527 };
528
529
Joachim Bingel1eef4032014-11-07 13:11:01 +0000530
Joachim Bingel4eacdd32014-10-22 15:49:47 +0000531// }
532//
533// @Test
534// public void testCoordinatedFields() throws QueryException {
535// // [base=Mann&(cas=N|cas=A)]
536// String cof1 =
537// "{@type=korap:token, wrap=" +
538// "{@type=korap:termGroup, relation=relation:and, operands=[" +
539// "{@type=korap:term, layer=lemma, key=Mann, match=match:eq}," +
540// "{@type=korap:termGroup, relation=relation:or, operands=[" +
541// "{@type=korap:term, layer=cas, key=N, match=match:eq}," +
542// "{@type=korap:term, layer=cas, key=A, match=match:eq}" +
543// "]}" +
544// "]}" +
545// "}";
546// ppt = new PoliqarpPlusTree("[base=Mann&(cas=N|cas=A)]");
547// map = ppt.getRequestMap().get("query").toString();
548// assertEquals(cof1.replaceAll(" ", ""), map.replaceAll(" ", ""));
549//
550//
551// assertEquals(
552// new PoliqarpPlusTree(" [ base=Mann & ( cas=N | cas=A)] ").getRequestMap().get("query").toString(),
553// new PoliqarpPlusTree("[base=Mann &(cas=N|cas=A)]").getRequestMap().get("query").toString()
554// );
555//
556// // [base=Mann&cas=N&gen=m]
557// String cof2 =
558// "{@type=korap:token, wrap=" +
559// "{@type=korap:termGroup, relation=relation:and, operands=[" +
560// "{@type=korap:term, layer=lemma, key=Mann, match=match:eq}," +
561// "{@type=korap:termGroup, relation=relation:and, operands=[" +
562// "{@type=korap:term, layer=cas, key=N, match=match:eq}," +
563// "{@type=korap:term, layer=gen, key=m, match=match:eq}" +
564// "]}" +
565// "]}" +
566// "}";
567// ppt = new PoliqarpPlusTree("[base=Mann&cas=N&gen=m]");
568// map = ppt.getRequestMap().get("query").toString();
569// assertEquals(cof2.replaceAll(" ", ""), map.replaceAll(" ", ""));
570// }
571//
572// @Test
573// public void testOccurrence() throws QueryException {
574// // [base=foo]*
575// String occ1 = "{@type=korap:group, operation=operation:repetition, operands=[" +
576// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
577// "], boundary={@type=korap:boundary, min=0}, min=0}";
578// ppt = new PoliqarpPlusTree("[base=foo]*");
579// map = ppt.getRequestMap().get("query").toString();
580// assertEquals(occ1.replaceAll(" ", ""), map.replaceAll(" ", ""));
581//
582// // [base=foo]*[base=bar]
583// String occ2 =
584// "{@type=korap:group, operation=operation:sequence, operands=[" +
585// "{@type=korap:group, operation=operation:repetition, operands=[" +
586// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
587// "], boundary={@type=korap:boundary, min=0}, min=0 }," +
588// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}" +
589// "]}";
590// ppt = new PoliqarpPlusTree("[base=foo]*[base=bar]");
591// map = ppt.getRequestMap().get("query").toString();
592// assertEquals(occ2.replaceAll(" ", ""), map.replaceAll(" ", ""));
593//
594// // [base=bar][base=foo]*
595// String occ3 =
596// "{@type=korap:group, operation=operation:sequence, operands=[" +
597// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," +
598// "{@type=korap:group, operation=operation:repetition, operands=[" +
599// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
600// "], boundary={@type=korap:boundary, min=0}, min=0 }" +
601// "]}";
602// ppt = new PoliqarpPlusTree("[base=bar][base=foo]*");
603// map = ppt.getRequestMap().get("query").toString();
604// assertEquals(occ3.replaceAll(" ", ""), map.replaceAll(" ", ""));
605//
606// // ([base=bar][base=foo])*
607// String occ4 =
608// "{@type=korap:group, operation=operation:repetition, operands=[" +
609// "{@type=korap:group, operation=operation:sequence, operands=[" +
610// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," +
611// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
612// "]}" +
613// "], boundary={@type=korap:boundary, min=0}, min=0}" ;
614// ppt = new PoliqarpPlusTree("([base=bar][base=foo])*");
615// map = ppt.getRequestMap().get("query").toString();
616// assertEquals(occ4.replaceAll(" ", ""), map.replaceAll(" ", ""));
617//
618// // <s>([base=bar][base=foo])*
619// String occ5 =
620// "{@type=korap:group, operation=operation:sequence, operands=[" +
621// "{@type=korap:span, key=s}," +
622// "{@type=korap:group, operation=operation:repetition, operands=[" +
623// "{@type=korap:group, operation=operation:sequence, operands=[" +
624// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," +
625// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
626// "]}" +
627// "], boundary={@type=korap:boundary, min=0}, min=0 }" +
628// "]}" ;
629// ppt = new PoliqarpPlusTree("<s>([base=bar][base=foo])*");
630// map = ppt.getRequestMap().get("query").toString();
631// assertEquals(occ5.replaceAll(" ", ""), map.replaceAll(" ", ""));
632//
633// // <s><np>([base=bar][base=foo])*
634// String occ6 =
635// "{@type=korap:group, operation=operation:sequence, operands=[" +
636// "{@type=korap:span, key=s}," +
637// "{@type=korap:span, key=np}," +
638// "{@type=korap:group, operation=operation:repetition, operands=[" +
639// "{@type=korap:group, operation=operation:sequence, operands=[" +
640// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," +
641// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
642// "]}" +
643// "], boundary={@type=korap:boundary, min=0}, min=0 }" +
644// "]}" ;
645// ppt = new PoliqarpPlusTree("<s><np>([base=bar][base=foo])*");
646// map = ppt.getRequestMap().get("query").toString();
647// assertEquals(occ6.replaceAll(" ", ""), map.replaceAll(" ", ""));
648//
649// // <s><np>([base=bar][base=foo])*[p=NN]
650// // comment: embedded sequence shouldn't really be here, but does not really hurt, either. (?)
651// // really hard to get this behaviour out of the PQPlus grammar...
652// String occ7 =
653// "{@type=korap:group, operation=operation:sequence, operands=[" +
654// "{@type=korap:span, key=s}," +
655// "{@type=korap:span, key=np}," +
656// "{@type=korap:group, operation=operation:repetition, operands=[" +
657// "{@type=korap:group, operation=operation:sequence, operands=[" +
658// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," +
659// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
660// "]}" +
661// "], boundary={@type=korap:boundary, min=0}, min=0 }," +
662// "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}" +
663// "]}" ;
664// ppt = new PoliqarpPlusTree("<s><np>([base=bar][base=foo])*[p=NN]");
665// map = ppt.getRequestMap().get("query").toString();
666// assertEquals(occ7.replaceAll(" ", ""), map.replaceAll(" ", ""));
667//
668// // ([base=bar][base=foo])*[p=NN]
669// String occ8 =
670// "{@type=korap:group, operation=operation:sequence, operands=[" +
671// "{@type=korap:group, operation=operation:repetition, operands=[" +
672// "{@type=korap:group, operation=operation:sequence, operands=[" +
673// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," +
674// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
675// "]}" +
676// "], boundary={@type=korap:boundary, min=0}, min=0 }," +
677// "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}" +
678// "]}" ;
679// ppt = new PoliqarpPlusTree("([base=bar][base=foo])*[p=NN]");
680// map = ppt.getRequestMap().get("query").toString();
681// assertEquals(occ8.replaceAll(" ", ""), map.replaceAll(" ", ""));
682//
683// // [base=foo]+
684// String occ9 = "{@type=korap:group, operation=operation:repetition, operands=[" +
685// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
686// "], boundary={@type=korap:boundary, min=1}, min=1}";
687// ppt = new PoliqarpPlusTree("[base=foo]+");
688// map = ppt.getRequestMap().get("query").toString();
689// assertEquals(occ9.replaceAll(" ", ""), map.replaceAll(" ", ""));
690//
691// // [base=foo]?
692// String occ10 = "{@type=korap:group, operation=operation:repetition, operands=[" +
693// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
694// "], boundary={@type=korap:boundary, min=0, max=1}, min=0, max=1}";
695// ppt = new PoliqarpPlusTree("[base=foo]?");
696// map = ppt.getRequestMap().get("query").toString();
697// assertEquals(occ10.replaceAll(" ", ""), map.replaceAll(" ", ""));
698//
699// // [base=foo]{2,5}
700// String occ11 = "{@type=korap:group, operation=operation:repetition, operands=[" +
701// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
702// "], boundary={@type=korap:boundary, min=2, max=5}, min=2, max=5}";
703// ppt = new PoliqarpPlusTree("[base=foo]{2,5}");
704// map = ppt.getRequestMap().get("query").toString();
705// assertEquals(occ11.replaceAll(" ", ""), map.replaceAll(" ", ""));
706//
707// // [base=foo]{2}
708// String occ12 = "{@type=korap:group, operation=operation:repetition, operands=[" +
709// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
710// "], boundary={@type=korap:boundary, min=2, max=2}, min=2, max=2}";
711// ppt = new PoliqarpPlusTree("[base=foo]{2}");
712// map = ppt.getRequestMap().get("query").toString();
713// assertEquals(occ12.replaceAll(" ", ""), map.replaceAll(" ", ""));
714//
715// // [base=foo]{2}
716// String occ13 = "{@type=korap:group, operation=operation:repetition, operands=[" +
717// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
718// "], boundary={@type=korap:boundary, min=2}, min=2}";
719// ppt = new PoliqarpPlusTree("[base=foo]{2,}");
720// map = ppt.getRequestMap().get("query").toString();
721// assertEquals(occ13.replaceAll(" ", ""), map.replaceAll(" ", ""));
722//
723// // [base=foo]{2}
724// String occ14 = "{@type=korap:group, operation=operation:repetition, operands=[" +
725// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
726// "], boundary={@type=korap:boundary, min=0, max=2}, min=0, max=2}";
727// ppt = new PoliqarpPlusTree("[base=foo]{,2}");
728// map = ppt.getRequestMap().get("query").toString();
729// assertEquals(occ14.replaceAll(" ", ""), map.replaceAll(" ", ""));
730// }
731//
732// @Test
733// public void testTokenSequence() throws QueryException {
734// // [base=Mann][orth=Frau]
735// String seq1 = "{@type=korap:group, operation=operation:sequence, operands=[" +
736// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}, " +
737// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}" +
738// "]}";
739// assertTrue(equalsQueryContent(seq1, "[base=Mann][orth=Frau]"));
740//
741// // [base=Mann][orth=Frau][p=NN]
742// String seq2 = "{@type=korap:group, operation=operation:sequence, operands=[" +
743// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}, " +
744// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}, " +
745// "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}" +
746// "]}";
747// assertTrue(equalsQueryContent(seq2, "[base=Mann][orth=Frau][p=NN]"));
748// }
749//
750// @Test
751// public void testDisjSegments() throws QueryException {
752// // ([base=der]|[base=das])[base=Schild]
753// String disj1 =
754// "{@type=korap:group, operation=operation:sequence, operands=[" +
755// "{@type=korap:group, operation=operation:or, operands=[" +
756// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
757// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=das, match=match:eq}}" +
758// "]}," +
759// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Schild, match=match:eq}}" +
760// "]}";
761// ppt = new PoliqarpPlusTree("([base=der]|[base=das])[base=Schild]");
762// map = ppt.getRequestMap().get("query").toString();
763// assertEquals(disj1.replaceAll(" ", ""), map.replaceAll(" ", ""));
764//
765// // [base=Schild]([base=der]|[base=das])
766// String disj2 =
767// "{@type=korap:group, operation=operation:sequence, operands=[" +
768// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Schild, match=match:eq}}," +
769// "{@type=korap:group, operation=operation:or, operands=[" +
770// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
771// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=das, match=match:eq}}" +
772// "]}" +
773// "]}";
774// ppt = new PoliqarpPlusTree("[base=Schild]([base=der]|[base=das])");
775// map = ppt.getRequestMap().get("query").toString();
776// assertEquals(disj2.replaceAll(" ", ""), map.replaceAll(" ", ""));
777//
778// // "([orth=der][base=katze])|([orth=eine][base=baum])"
779// String disj3 =
780// "{@type=korap:group, operation=operation:or, operands=[" +
781// "{@type=korap:group, operation=operation:sequence, operands=[" +
782// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
783// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=katze, match=match:eq}}" +
784// "]}," +
785// "{@type=korap:group, operation=operation:sequence, operands=[" +
786// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=eine, match=match:eq}}," +
787// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=baum, match=match:eq}}" +
788// "]}" +
789// "]}";
790// ppt = new PoliqarpPlusTree("([orth=der][base=katze])|([orth=eine][base=baum])");
791// map = ppt.getRequestMap().get("query").toString();
792// assertEquals(disj3.replaceAll(" ", ""), map.replaceAll(" ", ""));
793//
794// // "[orth=der][base=katze]|[orth=eine][base=baum]"
795// String disj4 =
796// "{@type=korap:group, operation=operation:or, operands=[" +
797// "{@type=korap:group, operation=operation:sequence, operands=[" +
798// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
799// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=katze, match=match:eq}}" +
800// "]}," +
801// "{@type=korap:group, operation=operation:sequence, operands=[" +
802// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=eine, match=match:eq}}," +
803// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=baum, match=match:eq}}" +
804// "]}" +
805// "]}";
806// ppt = new PoliqarpPlusTree("[orth=der][base=katze]|[orth=eine][base=baum]");
807// map = ppt.getRequestMap().get("query").toString();
808// assertEquals(disj4.replaceAll(" ", ""), map.replaceAll(" ", ""));
809//
810// PoliqarpPlusTree ppt1 = new PoliqarpPlusTree("[orth=der][base=katze]|[orth=eine][base=baum]");
811// PoliqarpPlusTree ppt2 = new PoliqarpPlusTree("([orth=der][base=katze])|([orth=eine][base=baum])");
812// assertEquals(ppt1.getRequestMap().toString(), ppt2.getRequestMap().toString());
813//
814// // "[orth=der][base=katze]|[orth=der][base=hund]|[orth=der][base=baum]"
815// String disj5 =
816// "{@type=korap:group, operation=operation:or, operands=[" +
817// "{@type=korap:group, operation=operation:sequence, operands=[" +
818// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
819// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=katze, match=match:eq}}" +
820// "]}," +
821// "{@type=korap:group, operation=operation:sequence, operands=[" +
822// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
823// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=hund, match=match:eq}}" +
824// "]}," +
825// "{@type=korap:group, operation=operation:sequence, operands=[" +
826// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
827// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=baum, match=match:eq}}" +
828// "]}" +
829// "]}";
830// ppt = new PoliqarpPlusTree("[orth=der][base=katze]|[orth=der][base=hund]|[orth=der][base=baum]");
831// map = ppt.getRequestMap().get("query").toString();
832// assertEquals(disj5.replaceAll(" ", ""), map.replaceAll(" ", ""));
833//
834// // [orth=der]([base=katze]|[base=hund]|[base=baum])
835// String disj6 =
836// "{@type=korap:group, operation=operation:sequence, operands=[" +
837// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
838// "{@type=korap:group, operation=operation:or, operands=[" +
839// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=katze, match=match:eq}}," +
840// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=hund, match=match:eq}}," +
841// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=baum, match=match:eq}}" +
842// "]}" +
843// "]}";
844// ppt = new PoliqarpPlusTree("[orth=der]([base=katze]|[base=hund]|[base=baum])");
845// map = ppt.getRequestMap().get("query").toString();
846// assertEquals(disj6.replaceAll(" ", ""), map.replaceAll(" ", ""));
847// }
848//
849// @Test
850// public void testTokenElemSequence() throws QueryException {
851// // [base=Mann]<vp>
852// String seq1 = "{@type=korap:group, operation=operation:sequence, operands=[" +
853// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}, " +
854// "{@type=korap:span, key=vp}" +
855// "]}";
856// assertTrue(equalsQueryContent(seq1, "[base=Mann]<vp>"));
857//
858// // <vp>[base=Mann]
859// String seq2 = "{@type=korap:group, operation=operation:sequence, operands=[" +
860// "{@type=korap:span, key=vp}, "+
861// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}} " +
862// "]}";
863// assertTrue(equalsQueryContent(seq2, "<vp>[base=Mann]"));
864//
865// // <vp>[base=Mann]<pp>
866// String seq3 = "{@type=korap:group, operation=operation:sequence, operands=[" +
867// "{@type=korap:span, key=vp}, "+
868// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}, " +
869// "{@type=korap:span, key=pp} "+
870// "]}";
871// assertTrue(equalsQueryContent(seq3, "<vp>[base=Mann]<pp>"));
872// }
873//
874// @Test
875// public void testElemSequence() throws QueryException {
876// // <np><vp>
877// String seq1 = "{@type=korap:group, operation=operation:sequence, operands=[" +
878// "{@type=korap:span, key=np}," +
879// "{@type=korap:span, key=vp}" +
880// "]}";
881// assertTrue(equalsQueryContent(seq1, "<np><vp>"));
882//
883// // <np><vp><pp>
884// String seq2 = "{@type=korap:group, operation=operation:sequence, operands=[" +
885// "{@type=korap:span, key=np}," +
886// "{@type=korap:span, key=vp}," +
887// "{@type=korap:span, key=pp}" +
888// "]}";
889// assertTrue(equalsQueryContent(seq2, "<np><vp><pp>"));
890// }
891//
892// @Test
893// public void testClasses() throws QueryException {
894// String query;
895// // {[base=Mann]}
896// String cls1 = "{@type=korap:group, operation=operation:class, class=0, classOut=0, operands=[" +
897// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
898// "]}";
899// ppt = new PoliqarpPlusTree("{[base=Mann]}");
900// map = ppt.getRequestMap().get("query").toString();
901// assertEquals(cls1.replaceAll(" ", ""), map.replaceAll(" ", ""));
902//
903// // {[base=Mann][orth=Frau]}
904// query = "{[base=Mann][orth=Frau]}";
905// String cls2 = "{@type=korap:group, operation=operation:class, class=0, classOut=0, operands=[" +
906// "{@type=korap:group, operation=operation:sequence, operands=[" +
907// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}," +
908// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}" +
909// "]}" +
910// "]}";
911// ppt = new PoliqarpPlusTree(query);
912// map = ppt.getRequestMap().get("query").toString();
913// assertEquals(cls2.replaceAll(" ", ""), map.replaceAll(" ", ""));
914//
915// // [p=NN]{[base=Mann][orth=Frau]}
916// String cls3 = "{@type=korap:group, operation=operation:sequence, operands=[" +
917// "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}," +
918// "{@type=korap:group, operation=operation:class, class=0, classOut=0, operands=[" +
919// "{@type=korap:group, operation=operation:sequence, operands=[" +
920// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}," +
921// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}" +
922// "]}" +
923// "]}" +
924// "]}";
925// ppt = new PoliqarpPlusTree("[p=NN]{[base=Mann][orth=Frau]}");
926// map = ppt.getRequestMap().get("query").toString();
927// assertEquals(cls3.replaceAll(" ", ""), map.replaceAll(" ", ""));
928//
929// // {[base=Mann][orth=Frau]}[p=NN]
930// String cls4 = "{@type=korap:group, operation=operation:sequence, operands=[" +
931// "{@type=korap:group, operation=operation:class, class=0, classOut=0, operands=[" +
932// "{@type=korap:group, operation=operation:sequence, operands=[" +
933// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}," +
934// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}" +
935// "]}" +
936// "]}," +
937// "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}" +
938// "]}";
939// ppt = new PoliqarpPlusTree("{[base=Mann][orth=Frau]}[p=NN]");
940// map = ppt.getRequestMap().get("query").toString();
941// assertEquals(cls4.replaceAll(" ", ""), map.replaceAll(" ", ""));
942//
943// // {2:{1:[tt/p=ADJA]}[mate/p=NN]}"
944// String cls5 = "{@type=korap:group, operation=operation:class, class=2, classOut=2, operands=[" +
945// "{@type=korap:group, operation=operation:sequence, operands=[" +
946// "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" +
947// "{@type=korap:token, wrap={@type=korap:term, foundry=tt, layer=p, key=ADJA, match=match:eq}}" +
948// "]}," +
949// "{@type=korap:token, wrap={@type=korap:term, foundry=mate, layer=p, key=NN, match=match:eq}}" +
950// "]}" +
951// "]}";
952// ppt = new PoliqarpPlusTree("{2: {1:[tt/p=ADJA]}[mate/p=NN]}");
953// map = ppt.getRequestMap().get("query").toString();
954// assertEquals(cls5.replaceAll(" ", ""), map.replaceAll(" ", ""));
955// }
956//
957// @Test
958// public void testPositions() throws QueryException {
959// // contains(<s>,<np>)
960// String pos1 = "{@type=korap:group, operation=operation:position, frames=[frames:contains], operands=[" +
961// "{@type=korap:span, key=s}," +
962// "{@type=korap:span, key=np}" +
963// "], frame=frame:contains}";
964// assertTrue(equalsQueryContent(pos1, "contains(<s>,<np>)"));
965//
966// // contains(<s>,[base=Mann])
967// String pos2 = "{@type=korap:group, operation=operation:position, frames=[frames:contains], operands=[" +
968// "{@type=korap:span, key=s}," +
969// "{@type=korap:token, wrap= {@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
970// "], frame=frame:contains}";
971// assertTrue(equalsQueryContent(pos2, "contains(<s>,[base=Mann])"));
972//
973// // contains(<s>,[orth=der][orth=Mann])
974// String pos3 = "{@type=korap:group, operation=operation:position, frames=[frames:contains], operands=[" +
975// "{@type=korap:span, key=s}," +
976// "{@type=korap:group, operation=operation:sequence, operands=[" +
977// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
978// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" +
979// "]}" +
980// "], frame=frame:contains}";
981// ppt = new PoliqarpPlusTree("contains(<s>,[orth=der][orth=Mann])");
982// map = ppt.getRequestMap().get("query").toString();
983// assertEquals(pos3.replaceAll(" ", ""), map.replaceAll(" ", ""));
984//
985// // [base=Auto]contains(<s>,[base=Mann])
986// String pos4 =
987// "{@type=korap:group, operation=operation:sequence, operands=[" +
988// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Auto, match=match:eq}}," +
989// "{@type=korap:group, operation=operation:position, frames=[frames:contains], operands=[" +
990// "{@type=korap:span, key=s}," +
991// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
992// "], frame=frame:contains}" +
993// "]}";
994// ppt = new PoliqarpPlusTree("[base=Auto]contains(<s>,[base=Mann])");
995// map = ppt.getRequestMap().get("query").toString();
996// assertEquals(pos4.replaceAll(" ", ""), map.replaceAll(" ", ""));
997//
998// // contains(<s>,[pos=N]*)
999// String pos5 =
1000// "{@type=korap:group, operation=operation:position, frames=[frames:contains], operands=[" +
1001// "{@type=korap:span, key=s}," +
1002// "{@type=korap:group, operation=operation:repetition, " +
1003// "operands=[{@type=korap:token, wrap={@type=korap:term, layer=pos, key=N, match=match:eq}}" +
1004// "], boundary={@type=korap:boundary, min=0}, min=0" +
1005// "}" +
1006// "], frame=frame:contains}";
1007// ppt = new PoliqarpPlusTree("contains(<s>,[pos=N]*)");
1008// map = ppt.getRequestMap().get("query").toString();
1009// assertEquals(pos5.replaceAll(" ", ""), map.replaceAll(" ", ""));
1010//
1011// // [base=Auto]contains(<s>,[pos=N]*)
1012// String pos6 =
1013// "{@type=korap:group, operation=operation:sequence, operands=[" +
1014// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Auto, match=match:eq}}," +
1015// "{@type=korap:group, operation=operation:position, frames=[frames:contains], operands=[" +
1016// "{@type=korap:span, key=s}," +
1017// "{@type=korap:group, operation=operation:repetition, " +
1018// "operands=[{@type=korap:token, wrap={@type=korap:term, layer=pos, key=N, match=match:eq}}" +
1019// "], boundary={@type=korap:boundary, min=0}, min=0" +
1020// "}" +
1021// "], frame=frame:contains}" +
1022// "]}";
1023// ppt = new PoliqarpPlusTree("[base=Auto]contains(<s>,[pos=N]*)");
1024// map = ppt.getRequestMap().get("query").toString();
1025// assertEquals(pos6.replaceAll(" ", ""), map.replaceAll(" ", ""));
1026// }
1027//
1028// @Test
1029// public void testNestedPositions() throws QueryException {
1030// // contains(<s>,startswith(<np>,[orth=Der]))
1031// String npos1 =
1032// "{@type=korap:group, operation=operation:position, frames=[frames:contains], operands=[" +
1033// "{@type=korap:span, key=s}," +
1034// "{@type=korap:group, operation=operation:position, frames=[frames:startswith], operands=[" +
1035// "{@type=korap:span, key=np}," +
1036// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}" +
1037// "], frame=frame:startswith}" +
1038// "], frame=frame:contains}";
1039// ppt = new PoliqarpPlusTree("contains(<s>, startswith(<np>,[orth=Der]))");
1040// map = ppt.getRequestMap().get("query").toString();
1041// assertEquals(npos1.replaceAll(" ", ""), map.replaceAll(" ", ""));
1042// }
1043//
1044// @Test
1045// public void testFocusSplit() throws QueryException {
1046// // focus([orth=Der]{[orth=Mann]})
1047// String shr1 =
1048// "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
1049// "{@type=korap:group, operation=operation:sequence, operands=[" +
1050// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}," +
1051// "{@type=korap:group, operation=operation:class, class=0, classOut=0, operands=[" +
1052// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" +
1053// "]}" +
1054// "]}" +
1055// "]}";
1056// ppt = new PoliqarpPlusTree("focus([orth=Der]{[orth=Mann]})");
1057// map = ppt.getRequestMap().get("query").toString();
1058// assertEquals(shr1.replaceAll(" ", ""), map.replaceAll(" ", ""));
1059//
1060// // focus([orth=Der]{[orth=Mann][orth=geht]})
1061// String shr2 =
1062// "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
1063// "{@type=korap:group, operation=operation:sequence, operands=[" +
1064// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}," +
1065// "{@type=korap:group, operation=operation:class, class=0, classOut=0, operands=[" +
1066// "{@type=korap:group, operation=operation:sequence, operands=[" +
1067// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}," +
1068// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=geht, match=match:eq}}" +
1069// "]}" +
1070// "]}" +
1071// "]}" +
1072// "]}";
1073// ppt = new PoliqarpPlusTree("focus([orth=Der]{[orth=Mann][orth=geht]})");
1074// map = ppt.getRequestMap().get("query").toString();
1075// assertEquals(shr2.replaceAll(" ", ""), map.replaceAll(" ", ""));
1076//
1077// // focus(1:[orth=Der]{1:[orth=Mann][orth=geht]})
1078// String shr3 =
1079// "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
1080// "{@type=korap:group, operation=operation:sequence, operands=[" +
1081// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}," +
1082// "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" +
1083// "{@type=korap:group, operation=operation:sequence, operands=[" +
1084// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}," +
1085// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=geht, match=match:eq}}" +
1086// "]}" +
1087// "]}" +
1088// "]}" +
1089// "]}";
1090// ppt = new PoliqarpPlusTree("focus(1:[orth=Der]{1:[orth=Mann][orth=geht]})");
1091// map = ppt.getRequestMap().get("query").toString();
1092// assertEquals(shr3.replaceAll(" ", ""), map.replaceAll(" ", ""));
1093//
1094// // focus(1:startswith(<s>,{1:<np>}))
1095// String shr4 =
1096// "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
1097// "{@type=korap:group, operation=operation:position, frames=[frames:startswith], operands=[" +
1098// "{@type=korap:span, key=s}," +
1099// "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" +
1100// "{@type=korap:span, key=np}" +
1101// "]}" +
1102// "], frame=frame:startswith}" +
1103// "]}";
1104// ppt = new PoliqarpPlusTree("focus(1:startswith(<s>,{1:<np>}))");
1105// map = ppt.getRequestMap().get("query").toString();
1106// assertEquals(shr4.replaceAll(" ", ""), map.replaceAll(" ", ""));
1107//
1108// // focus(3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))
1109// String shr5 =
1110// "{@type=korap:reference, operation=operation:focus, classRef=[3], operands=[" +
1111// "{@type=korap:group, operation=operation:position, frames=[frames:startswith], operands=[" +
1112// "{@type=korap:span, key=s}," +
1113// "{@type=korap:group, operation=operation:class, class=3, classOut=3, operands=[" +
1114// "{@type=korap:group, operation=operation:sequence, operands=[" +
1115// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
1116// "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" +
1117// "{@type=korap:group, operation=operation:sequence, operands=[" +
1118// "{@type=korap:token, wrap={@type=korap:term, foundry=mate, layer=p, key=ADJA, match=match:eq}}," +
1119// "{@type=korap:group, operation=operation:class, class=2, classOut=2, operands=[" +
1120// "{@type=korap:token, wrap={@type=korap:term, foundry=tt, layer=p, key=NN, match=match:eq}}" +
1121// "]}" +
1122// "]}" +
1123// "]}" +
1124// "]}" +
1125// "]}" +
1126// "], frame=frame:startswith}" +
1127// "]}";
1128// ppt = new PoliqarpPlusTree("focus(3:startswith(<s>,{3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) ");
1129// map = ppt.getRequestMap().get("query").toString();
1130// assertEquals(shr5.replaceAll(" ", ""), map.replaceAll(" ", ""));
1131//
1132// // split(3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))
1133// String shr6 =
1134// "{@type=korap:reference, operation=operation:split, classRef=[3], operands=[" +
1135// "{@type=korap:group, operation=operation:position, frames=[frames:startswith], operands=[" +
1136// "{@type=korap:span, key=s}," +
1137// "{@type=korap:group, operation=operation:class, class=3, classOut=3, operands=[" +
1138// "{@type=korap:group, operation=operation:sequence, operands=[" +
1139// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
1140// "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" +
1141// "{@type=korap:group, operation=operation:sequence, operands=[" +
1142// "{@type=korap:token, wrap={@type=korap:term, foundry=mate, layer=p, key=ADJA, match=match:eq}}," +
1143// "{@type=korap:group, operation=operation:class, class=2, classOut=2, operands=[" +
1144// "{@type=korap:token, wrap={@type=korap:term, foundry=tt, layer=p, key=NN, match=match:eq}}" +
1145// "]}" +
1146// "]}" +
1147// "]}" +
1148// "]}" +
1149// "]}" +
1150// "], frame=frame:startswith}" +
1151// "]}";
1152// ppt = new PoliqarpPlusTree("split(3:startswith(<s>,{3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) ");
1153// map = ppt.getRequestMap().get("query").toString();
1154// assertEquals(shr6.replaceAll(" ", ""), map.replaceAll(" ", ""));
1155//
1156// // split(2|3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))
1157// String shr7 =
1158// "{@type=korap:reference, operation=operation:split, classRef=[2, 3], classRefOp=classRefOp:intersection, operands=[" +
1159// "{@type=korap:group, operation=operation:position, frames=[frames:startswith], operands=[" +
1160// "{@type=korap:span, key=s}," +
1161// "{@type=korap:group, operation=operation:class, class=3, classOut=3, operands=[" +
1162// "{@type=korap:group, operation=operation:sequence, operands=[" +
1163// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
1164// "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" +
1165// "{@type=korap:group, operation=operation:sequence, operands=[" +
1166// "{@type=korap:token, wrap={@type=korap:term, foundry=mate, layer=p, key=ADJA, match=match:eq}}," +
1167// "{@type=korap:group, operation=operation:class, class=2, classOut=2, operands=[" +
1168// "{@type=korap:token, wrap={@type=korap:term, foundry=tt, layer=p, key=NN, match=match:eq}}" +
1169// "]}" +
1170// "]}" +
1171// "]}" +
1172// "]}" +
1173// "]}" +
1174// "], frame=frame:startswith}" +
1175// "]}";
1176// ppt = new PoliqarpPlusTree("split(2|3:startswith(<s>,{3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) ");
1177// map = ppt.getRequestMap().get("query").toString();
1178// assertEquals(shr7.replaceAll(" ", ""), map.replaceAll(" ", ""));
1179//
1180//
1181// String shr8 =
1182// "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
1183// "{@type=korap:group, operation=operation:sequence, operands=[" +
1184// "{@type=korap:group, operation=operation:class, class=0, classOut=0, operands=[" +
1185// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}" +
1186// "]}," +
1187// "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" +
1188// "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=ADJA, match=match:eq}}" +
1189// "]}" +
1190// "]}" +
1191// "]}";
1192// ppt = new PoliqarpPlusTree("focus(1:{[base=der]}{1:[pos=ADJA]})");
1193// map = ppt.getRequestMap().get("query").toString();
1194// assertEquals(shr8.replaceAll(" ", ""), map.replaceAll(" ", ""));
1195//
1196// }
1197//
1198// @Test
1199// public void testSubspan() throws QueryException {
1200// query = "submatch(1,:<s>)";
1201// expected =
1202// "{@type=korap:reference, operation=operation:focus, operands=[" +
1203// "{@type=korap:span, key=s}" +
1204// "], spanRef=[1]" +
1205// "}";
1206// ppt = new PoliqarpPlusTree(query);
1207// map = ppt.getRequestMap().get("query").toString();
1208// assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1209//
1210// query = "submatch(1,4:<s>)";
1211// expected =
1212// "{@type=korap:reference, operation=operation:focus, operands=[" +
1213// "{@type=korap:span, key=s}" +
1214// "], spanRef=[1,4]" +
1215// "}";
1216// ppt = new PoliqarpPlusTree(query);
1217// map = ppt.getRequestMap().get("query").toString();
1218// assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1219//
1220// query = "submatch(1,4:contains(<s>,[base=Haus]))";
1221// expected =
1222// "{@type=korap:reference, operation=operation:focus, operands=[" +
1223// "{@type=korap:group, operation=operation:position, frames=[frames:contains], operands=[" +
1224// "{@type=korap:span, key=s}," +
1225// "{@type=korap:token, wrap= {@type=korap:term, layer=lemma, key=Haus, match=match:eq}}" +
1226// "], frame=frame:contains}" +
1227// "], spanRef=[1,4]" +
1228// "}";
1229// ppt = new PoliqarpPlusTree(query);
1230// map = ppt.getRequestMap().get("query").toString();
1231// assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1232// }
1233//
1234// @Test
1235// public void testRelations() throws QueryException {
1236// query = "relatesTo(<s>,<np>)";
1237// expected =
1238// "{@type=korap:group, operation=operation:relation, operands=[" +
1239// "{@type=korap:span, key=s}," +
1240// "{@type=korap:span, key=np}" +
1241// "], relation={@type=korap:relation}" +
1242// "}";
1243// ppt = new PoliqarpPlusTree(query);
1244// map = ppt.getRequestMap().get("query").toString();
1245// assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1246//
1247// query = "relatesTo([base=Baum],<np>)";
1248// expected =
1249// "{@type=korap:group, operation=operation:relation, operands=[" +
1250// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Baum, match=match:eq}}," +
1251// "{@type=korap:span, key=np}" +
1252// "], relation={@type=korap:relation}" +
1253// "}";
1254// ppt = new PoliqarpPlusTree(query);
1255// map = ppt.getRequestMap().get("query").toString();
1256// assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1257//
1258// query = "dominates(<np>,[base=Baum])";
1259// expected =
1260// "{@type=korap:group, operation=operation:relation, operands=[" +
1261// "{@type=korap:span, key=np}," +
1262// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Baum, match=match:eq}}" +
1263// "], relation={@type=korap:relation, layer=c}" +
1264// "}";
1265// ppt = new PoliqarpPlusTree(query);
1266// map = ppt.getRequestMap().get("query").toString();
1267// assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1268//
1269// query = "dominates(cnx/c:<np>,[base=Baum])";
1270// expected =
1271// "{@type=korap:group, operation=operation:relation, operands=[" +
1272// "{@type=korap:span, key=np}," +
1273// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Baum, match=match:eq}}" +
1274// "], relation={@type=korap:relation, layer=c, foundry=cnx}" +
1275// "}";
1276// ppt = new PoliqarpPlusTree(query);
1277// map = ppt.getRequestMap().get("query").toString();
1278// assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1279//
1280// query = "dominates(cnx/c*:<np>,[base=Baum])";
1281// expected =
1282// "{@type=korap:group, operation=operation:relation, operands=[" +
1283// "{@type=korap:span, key=np}," +
1284// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Baum, match=match:eq}}" +
1285// "], relation={@type=korap:relation, layer=c, foundry=cnx, boundary={@type=korap:boundary, min=0}}" +
1286// "}";
1287// ppt = new PoliqarpPlusTree(query);
1288// map = ppt.getRequestMap().get("query").toString();
1289// assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1290//
1291// query = "dominates(cnx/c{1,5}:<np>,[base=Baum])";
1292// expected =
1293// "{@type=korap:group, operation=operation:relation, operands=[" +
1294// "{@type=korap:span, key=np}," +
1295// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Baum, match=match:eq}}" +
1296// "], relation={@type=korap:relation, layer=c, foundry=cnx, boundary={@type=korap:boundary, min=1, max=5}}" +
1297// "}";
1298// ppt = new PoliqarpPlusTree(query);
1299// map = ppt.getRequestMap().get("query").toString();
1300// assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1301//
1302// query = "relatesTo(mate/d=HEAD:<np>,[base=Baum])";
1303// expected =
1304// "{@type=korap:group, operation=operation:relation, operands=[" +
1305// "{@type=korap:span, key=np}," +
1306// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Baum, match=match:eq}}" +
1307// "], relation={@type=korap:relation, foundry=mate, layer=d, key=HEAD}" +
1308// "}";
1309// ppt = new PoliqarpPlusTree(query);
1310// map = ppt.getRequestMap().get("query").toString();
1311// assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1312//
1313// }
1314//
1315//
1316//
1317// @Test
1318// public void testFoundries() throws QueryException {
1319// // [tt/base=Mann]
1320// String layer1 = "{@type=korap:token, wrap={@type=korap:term, foundry=tt, layer=lemma, key=Mann, match=match:eq}}";
1321// ppt = new PoliqarpPlusTree("[tt/base=Mann]");
1322// map = ppt.getRequestMap().get("query").toString();
1323// assertEquals(layer1.replaceAll(" ", ""), map.replaceAll(" ", ""));
1324//
1325// }
1326//
1327// @Test
1328// public void testAlign() throws QueryException {
1329// // [orth=der]^[orth=Mann]
1330// query = "[orth=der]^[orth=Mann]";
1331// expected =
1332// "{@type=korap:group, operation=operation:sequence, operands=[" +
1333// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
1334// "{@type=korap:group, operation=operation:class, class=1025, classOut=1025, operands=[" +
1335// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" +
1336// "]}" +
1337// "]}";
1338// metaExpected =
1339// "{alignment=1025}";
1340// ppt = new PoliqarpPlusTree(query);
1341// map = ppt.getRequestMap().get("query").toString();
1342// metaMap = ppt.getRequestMap().get("meta").toString();
1343// assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1344// assertEquals(metaExpected.replaceAll(" ", ""), metaMap.replaceAll(" ", ""));
1345//
1346// // [orth=der]^[orth=große][orth=Mann]
1347// query = "[orth=der]^[orth=große][orth=Mann]";
1348// String expected =
1349// "{@type=korap:group, operation=operation:sequence, operands=[" +
1350// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
1351// "{@type=korap:group, operation=operation:class, class=1025, classOut=1025, operands=[" +
1352// "{@type=korap:group, operation=operation:sequence, operands=[" +
1353// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=große, match=match:eq}}," +
1354// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" +
1355// "]}" +
1356// "]}" +
1357// "]}";
1358// metaExpected =
1359// "{alignment=1025}";
1360// ppt = new PoliqarpPlusTree(query);
1361// map = ppt.getRequestMap().get("query").toString();
1362// metaMap = ppt.getRequestMap().get("meta").toString();
1363// assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1364// assertEquals(metaExpected.replaceAll(" ", ""), metaMap.replaceAll(" ", ""));
1365//
1366// query = "([base=a]^[base=b])|[base=c]";
1367// expected =
1368// "{@type=korap:group, operation=operation:or, operands=[" +
1369// "{@type=korap:group, operation=operation:sequence, operands=[" +
1370// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=a, match=match:eq}}," +
1371// "{@type=korap:group, operation=operation:class, class=1025, classOut=1025, operands=[" +
1372// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=b, match=match:eq}}" +
1373// "]}" +
1374// "]}," +
1375// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=c, match=match:eq}}" +
1376// "]}";
1377// metaExpected =
1378// "{alignment=1025}";
1379// ppt = new PoliqarpPlusTree(query);
1380// map = ppt.getRequestMap().get("query").toString();
1381// metaMap = ppt.getRequestMap().get("meta").toString();
1382// assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1383// assertEquals(metaExpected.replaceAll(" ", ""), metaMap.replaceAll(" ", ""));
1384//
1385// query = "([base=a]^[base=b][base=c])|[base=d]";
1386// expected =
1387// "{@type=korap:group, operation=operation:or, operands=[" +
1388// "{@type=korap:group, operation=operation:sequence, operands=[" +
1389// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=a, match=match:eq}}," +
1390// "{@type=korap:group, operation=operation:class, class=1025, classOut=1025, operands=[" +
1391// "{@type=korap:group, operation=operation:sequence, operands=[" +
1392// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=b, match=match:eq}}," +
1393// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=c, match=match:eq}}" +
1394// "]}" +
1395// "]}" +
1396// "]}," +
1397// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=d, match=match:eq}}" +
1398// "]}";
1399// metaExpected =
1400// "{alignment=1025}";
1401// ppt = new PoliqarpPlusTree(query);
1402// map = ppt.getRequestMap().get("query").toString();
1403// metaMap = ppt.getRequestMap().get("meta").toString();
1404// assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1405// assertEquals(metaExpected.replaceAll(" ", ""), metaMap.replaceAll(" ", ""));
1406//
1407// query = "([base=a]^[base=b]^[base=c])|[base=d]";
1408// expected =
1409// "{@type=korap:group, operation=operation:or, operands=[" +
1410// "{@type=korap:group, operation=operation:sequence, operands=[" +
1411// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=a, match=match:eq}}," +
1412// "{@type=korap:group, operation=operation:class, class=1025, classOut=1025, operands=[" +
1413// "{@type=korap:group, operation=operation:sequence, operands=[" +
1414// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=b, match=match:eq}}," +
1415// "{@type=korap:group, operation=operation:class, class=1026, classOut=1026, operands=[" +
1416// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=c, match=match:eq}}" +
1417// "]}" +
1418// "]}" +
1419// "]}" +
1420// "]}," +
1421// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=d, match=match:eq}}" +
1422// "]}";
1423// metaExpected =
1424// "{alignment=[1025,1026]}";
1425// ppt = new PoliqarpPlusTree(query);
1426// map = ppt.getRequestMap().get("query").toString();
1427// metaMap = ppt.getRequestMap().get("meta").toString();
1428// assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1429// assertEquals(metaExpected.replaceAll(" ", ""), metaMap.replaceAll(" ", ""));
1430//
1431//
1432// }
1433//
1434// @Test
1435// public void testSimpleQueries() throws QueryException {
1436// // Baum
1437// String simple1 =
1438// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq}}";
1439// ppt = new PoliqarpPlusTree("Baum");
1440// map = ppt.getRequestMap().get("query").toString();
1441// assertEquals(simple1.replaceAll(" ", ""), map.replaceAll(" ", ""));
1442//
1443// // Baum/i
1444// String simple1b =
1445// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq, caseInsensitive=true}}";
1446// ppt = new PoliqarpPlusTree("Baum/i");
1447// map = ppt.getRequestMap().get("query").toString();
1448// assertEquals(simple1b.replaceAll(" ", ""), map.replaceAll(" ", ""));
1449//
1450// // Der Baum
1451// String simple2 =
1452// "{@type=korap:group, operation=operation:sequence, operands=[" +
1453// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}, " +
1454// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq}}" +
1455// "]}";
1456// ppt = new PoliqarpPlusTree("Der Baum");
1457// map = ppt.getRequestMap().get("query").toString();
1458// assertEquals(simple2.replaceAll(" ", ""), map.replaceAll(" ", ""));
1459//
1460// // Der Baum/i
1461// String simple2b =
1462// "{@type=korap:group, operation=operation:sequence, operands=[" +
1463// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}, " +
1464// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq, caseInsensitive=true}}" +
1465// "]}";
1466// ppt = new PoliqarpPlusTree("Der Baum/i");
1467// map = ppt.getRequestMap().get("query").toString();
1468// assertEquals(simple2b.replaceAll(" ", ""), map.replaceAll(" ", ""));
1469//
1470// // Der große Baum
1471// String simple3 =
1472// "{@type=korap:group, operation=operation:sequence, operands=[" +
1473// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}, " +
1474// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=große, match=match:eq}}, " +
1475// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq}}" +
1476// "]}";
1477// ppt = new PoliqarpPlusTree("Der große Baum");
1478// map = ppt.getRequestMap().get("query").toString();
1479// assertEquals(simple3.replaceAll(" ", ""), map.replaceAll(" ", ""));
1480//
1481// // Baum | Stein
1482// String simple4 =
1483// "{@type=korap:group, operation=operation:or, operands=[" +
1484// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq}}, " +
1485// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Stein, match=match:eq}}" +
1486// "]}";
1487// ppt = new PoliqarpPlusTree("Baum | Stein");
1488// map = ppt.getRequestMap().get("query").toString();
1489// assertEquals(simple4.replaceAll(" ", ""), map.replaceAll(" ", ""));
1490//
1491// // Baum | Stein Haus
1492// String query = "(Baum | Stein) Haus";
1493// String simple5 =
1494// "{@type=korap:group, operation=operation:sequence, operands=[" +
1495// "{@type=korap:group, operation=operation:or, operands=[" +
1496// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq}}, " +
1497// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Stein, match=match:eq}}" +
1498// "]}," +
1499// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Haus, match=match:eq}} " +
1500// "]}";
1501// ppt = new PoliqarpPlusTree(query);
1502// map = ppt.getRequestMap().get("query").toString();
1503// assertEquals(simple5.replaceAll(" ", ""), map.replaceAll(" ", ""));
1504// }
Nils Diewald5adc3c62014-11-12 21:55:34 +00001505}