blob: 9c84febc8ae0e8d37d4fe11b45dc9095105a9e9a [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 Bingel6cb4b642014-12-01 10:52:05 +0000530 @Test
531 public void testPositions() throws QueryException, JsonProcessingException, IOException {
532 query = "contains(<s>, der)";
533 qs.setQuery(query, "poliqarpplus");
534 res = mapper.readTree(qs.toJSON());
535 assertEquals("korap:group", res.at("/query/@type").asText());
536 assertEquals("operation:position", res.at("/query/operation").asText());
537 assertEquals("frame:contains", res.at("/query/frame").asText());
538 assertEquals("korap:span", res.at("/query/operands/0/@type").asText());
539 assertEquals("s", res.at("/query/operands/0/key").asText());
540 assertEquals("korap:token", res.at("/query/operands/1/@type").asText());
541
542 query = "overlaps(<s>, der)";
543 qs.setQuery(query, "poliqarpplus");
544 res = mapper.readTree(qs.toJSON());
545 assertEquals("korap:group", res.at("/query/@type").asText());
546 assertEquals("operation:position", res.at("/query/operation").asText());
547 assertEquals("frame:overlaps", res.at("/query/frame").asText());
548 assertEquals("korap:span", res.at("/query/operands/0/@type").asText());
549 assertEquals("s", res.at("/query/operands/0/key").asText());
550 assertEquals("korap:token", res.at("/query/operands/1/@type").asText());
551 };
552
Joachim Bingel1eef4032014-11-07 13:11:01 +0000553
Joachim Bingel4eacdd32014-10-22 15:49:47 +0000554// }
555//
556// @Test
557// public void testCoordinatedFields() throws QueryException {
558// // [base=Mann&(cas=N|cas=A)]
559// String cof1 =
560// "{@type=korap:token, wrap=" +
561// "{@type=korap:termGroup, relation=relation:and, operands=[" +
562// "{@type=korap:term, layer=lemma, key=Mann, match=match:eq}," +
563// "{@type=korap:termGroup, relation=relation:or, operands=[" +
564// "{@type=korap:term, layer=cas, key=N, match=match:eq}," +
565// "{@type=korap:term, layer=cas, key=A, match=match:eq}" +
566// "]}" +
567// "]}" +
568// "}";
569// ppt = new PoliqarpPlusTree("[base=Mann&(cas=N|cas=A)]");
570// map = ppt.getRequestMap().get("query").toString();
571// assertEquals(cof1.replaceAll(" ", ""), map.replaceAll(" ", ""));
572//
573//
574// assertEquals(
575// new PoliqarpPlusTree(" [ base=Mann & ( cas=N | cas=A)] ").getRequestMap().get("query").toString(),
576// new PoliqarpPlusTree("[base=Mann &(cas=N|cas=A)]").getRequestMap().get("query").toString()
577// );
578//
579// // [base=Mann&cas=N&gen=m]
580// String cof2 =
581// "{@type=korap:token, wrap=" +
582// "{@type=korap:termGroup, relation=relation:and, operands=[" +
583// "{@type=korap:term, layer=lemma, key=Mann, match=match:eq}," +
584// "{@type=korap:termGroup, relation=relation:and, operands=[" +
585// "{@type=korap:term, layer=cas, key=N, match=match:eq}," +
586// "{@type=korap:term, layer=gen, key=m, match=match:eq}" +
587// "]}" +
588// "]}" +
589// "}";
590// ppt = new PoliqarpPlusTree("[base=Mann&cas=N&gen=m]");
591// map = ppt.getRequestMap().get("query").toString();
592// assertEquals(cof2.replaceAll(" ", ""), map.replaceAll(" ", ""));
593// }
594//
595// @Test
596// public void testOccurrence() throws QueryException {
597// // [base=foo]*
598// String occ1 = "{@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// ppt = new PoliqarpPlusTree("[base=foo]*");
602// map = ppt.getRequestMap().get("query").toString();
603// assertEquals(occ1.replaceAll(" ", ""), map.replaceAll(" ", ""));
604//
605// // [base=foo]*[base=bar]
606// String occ2 =
607// "{@type=korap:group, operation=operation:sequence, operands=[" +
608// "{@type=korap:group, operation=operation:repetition, operands=[" +
609// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
610// "], boundary={@type=korap:boundary, min=0}, min=0 }," +
611// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}" +
612// "]}";
613// ppt = new PoliqarpPlusTree("[base=foo]*[base=bar]");
614// map = ppt.getRequestMap().get("query").toString();
615// assertEquals(occ2.replaceAll(" ", ""), map.replaceAll(" ", ""));
616//
617// // [base=bar][base=foo]*
618// String occ3 =
619// "{@type=korap:group, operation=operation:sequence, operands=[" +
620// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," +
621// "{@type=korap:group, operation=operation:repetition, operands=[" +
622// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
623// "], boundary={@type=korap:boundary, min=0}, min=0 }" +
624// "]}";
625// ppt = new PoliqarpPlusTree("[base=bar][base=foo]*");
626// map = ppt.getRequestMap().get("query").toString();
627// assertEquals(occ3.replaceAll(" ", ""), map.replaceAll(" ", ""));
628//
629// // ([base=bar][base=foo])*
630// String occ4 =
631// "{@type=korap:group, operation=operation:repetition, operands=[" +
632// "{@type=korap:group, operation=operation:sequence, operands=[" +
633// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," +
634// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
635// "]}" +
636// "], boundary={@type=korap:boundary, min=0}, min=0}" ;
637// ppt = new PoliqarpPlusTree("([base=bar][base=foo])*");
638// map = ppt.getRequestMap().get("query").toString();
639// assertEquals(occ4.replaceAll(" ", ""), map.replaceAll(" ", ""));
640//
641// // <s>([base=bar][base=foo])*
642// String occ5 =
643// "{@type=korap:group, operation=operation:sequence, operands=[" +
644// "{@type=korap:span, key=s}," +
645// "{@type=korap:group, operation=operation:repetition, operands=[" +
646// "{@type=korap:group, operation=operation:sequence, operands=[" +
647// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," +
648// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
649// "]}" +
650// "], boundary={@type=korap:boundary, min=0}, min=0 }" +
651// "]}" ;
652// ppt = new PoliqarpPlusTree("<s>([base=bar][base=foo])*");
653// map = ppt.getRequestMap().get("query").toString();
654// assertEquals(occ5.replaceAll(" ", ""), map.replaceAll(" ", ""));
655//
656// // <s><np>([base=bar][base=foo])*
657// String occ6 =
658// "{@type=korap:group, operation=operation:sequence, operands=[" +
659// "{@type=korap:span, key=s}," +
660// "{@type=korap:span, key=np}," +
661// "{@type=korap:group, operation=operation:repetition, operands=[" +
662// "{@type=korap:group, operation=operation:sequence, operands=[" +
663// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," +
664// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
665// "]}" +
666// "], boundary={@type=korap:boundary, min=0}, min=0 }" +
667// "]}" ;
668// ppt = new PoliqarpPlusTree("<s><np>([base=bar][base=foo])*");
669// map = ppt.getRequestMap().get("query").toString();
670// assertEquals(occ6.replaceAll(" ", ""), map.replaceAll(" ", ""));
671//
672// // <s><np>([base=bar][base=foo])*[p=NN]
673// // comment: embedded sequence shouldn't really be here, but does not really hurt, either. (?)
674// // really hard to get this behaviour out of the PQPlus grammar...
675// String occ7 =
676// "{@type=korap:group, operation=operation:sequence, operands=[" +
677// "{@type=korap:span, key=s}," +
678// "{@type=korap:span, key=np}," +
679// "{@type=korap:group, operation=operation:repetition, operands=[" +
680// "{@type=korap:group, operation=operation:sequence, operands=[" +
681// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," +
682// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
683// "]}" +
684// "], boundary={@type=korap:boundary, min=0}, min=0 }," +
685// "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}" +
686// "]}" ;
687// ppt = new PoliqarpPlusTree("<s><np>([base=bar][base=foo])*[p=NN]");
688// map = ppt.getRequestMap().get("query").toString();
689// assertEquals(occ7.replaceAll(" ", ""), map.replaceAll(" ", ""));
690//
691// // ([base=bar][base=foo])*[p=NN]
692// String occ8 =
693// "{@type=korap:group, operation=operation:sequence, operands=[" +
694// "{@type=korap:group, operation=operation:repetition, operands=[" +
695// "{@type=korap:group, operation=operation:sequence, operands=[" +
696// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," +
697// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
698// "]}" +
699// "], boundary={@type=korap:boundary, min=0}, min=0 }," +
700// "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}" +
701// "]}" ;
702// ppt = new PoliqarpPlusTree("([base=bar][base=foo])*[p=NN]");
703// map = ppt.getRequestMap().get("query").toString();
704// assertEquals(occ8.replaceAll(" ", ""), map.replaceAll(" ", ""));
705//
706// // [base=foo]+
707// String occ9 = "{@type=korap:group, operation=operation:repetition, operands=[" +
708// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
709// "], boundary={@type=korap:boundary, min=1}, min=1}";
710// ppt = new PoliqarpPlusTree("[base=foo]+");
711// map = ppt.getRequestMap().get("query").toString();
712// assertEquals(occ9.replaceAll(" ", ""), map.replaceAll(" ", ""));
713//
714// // [base=foo]?
715// String occ10 = "{@type=korap:group, operation=operation:repetition, operands=[" +
716// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
717// "], boundary={@type=korap:boundary, min=0, max=1}, min=0, max=1}";
718// ppt = new PoliqarpPlusTree("[base=foo]?");
719// map = ppt.getRequestMap().get("query").toString();
720// assertEquals(occ10.replaceAll(" ", ""), map.replaceAll(" ", ""));
721//
722// // [base=foo]{2,5}
723// String occ11 = "{@type=korap:group, operation=operation:repetition, operands=[" +
724// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
725// "], boundary={@type=korap:boundary, min=2, max=5}, min=2, max=5}";
726// ppt = new PoliqarpPlusTree("[base=foo]{2,5}");
727// map = ppt.getRequestMap().get("query").toString();
728// assertEquals(occ11.replaceAll(" ", ""), map.replaceAll(" ", ""));
729//
730// // [base=foo]{2}
731// String occ12 = "{@type=korap:group, operation=operation:repetition, operands=[" +
732// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
733// "], boundary={@type=korap:boundary, min=2, max=2}, min=2, max=2}";
734// ppt = new PoliqarpPlusTree("[base=foo]{2}");
735// map = ppt.getRequestMap().get("query").toString();
736// assertEquals(occ12.replaceAll(" ", ""), map.replaceAll(" ", ""));
737//
738// // [base=foo]{2}
739// String occ13 = "{@type=korap:group, operation=operation:repetition, operands=[" +
740// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
741// "], boundary={@type=korap:boundary, min=2}, min=2}";
742// ppt = new PoliqarpPlusTree("[base=foo]{2,}");
743// map = ppt.getRequestMap().get("query").toString();
744// assertEquals(occ13.replaceAll(" ", ""), map.replaceAll(" ", ""));
745//
746// // [base=foo]{2}
747// String occ14 = "{@type=korap:group, operation=operation:repetition, operands=[" +
748// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
749// "], boundary={@type=korap:boundary, min=0, max=2}, min=0, max=2}";
750// ppt = new PoliqarpPlusTree("[base=foo]{,2}");
751// map = ppt.getRequestMap().get("query").toString();
752// assertEquals(occ14.replaceAll(" ", ""), map.replaceAll(" ", ""));
753// }
754//
755// @Test
756// public void testTokenSequence() throws QueryException {
757// // [base=Mann][orth=Frau]
758// String seq1 = "{@type=korap:group, operation=operation:sequence, operands=[" +
759// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}, " +
760// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}" +
761// "]}";
762// assertTrue(equalsQueryContent(seq1, "[base=Mann][orth=Frau]"));
763//
764// // [base=Mann][orth=Frau][p=NN]
765// String seq2 = "{@type=korap:group, operation=operation:sequence, operands=[" +
766// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}, " +
767// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}, " +
768// "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}" +
769// "]}";
770// assertTrue(equalsQueryContent(seq2, "[base=Mann][orth=Frau][p=NN]"));
771// }
772//
773// @Test
774// public void testDisjSegments() throws QueryException {
775// // ([base=der]|[base=das])[base=Schild]
776// String disj1 =
777// "{@type=korap:group, operation=operation:sequence, operands=[" +
778// "{@type=korap:group, operation=operation:or, operands=[" +
779// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
780// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=das, match=match:eq}}" +
781// "]}," +
782// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Schild, match=match:eq}}" +
783// "]}";
784// ppt = new PoliqarpPlusTree("([base=der]|[base=das])[base=Schild]");
785// map = ppt.getRequestMap().get("query").toString();
786// assertEquals(disj1.replaceAll(" ", ""), map.replaceAll(" ", ""));
787//
788// // [base=Schild]([base=der]|[base=das])
789// String disj2 =
790// "{@type=korap:group, operation=operation:sequence, operands=[" +
791// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Schild, match=match:eq}}," +
792// "{@type=korap:group, operation=operation:or, operands=[" +
793// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
794// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=das, match=match:eq}}" +
795// "]}" +
796// "]}";
797// ppt = new PoliqarpPlusTree("[base=Schild]([base=der]|[base=das])");
798// map = ppt.getRequestMap().get("query").toString();
799// assertEquals(disj2.replaceAll(" ", ""), map.replaceAll(" ", ""));
800//
801// // "([orth=der][base=katze])|([orth=eine][base=baum])"
802// String disj3 =
803// "{@type=korap:group, operation=operation:or, operands=[" +
804// "{@type=korap:group, operation=operation:sequence, operands=[" +
805// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
806// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=katze, match=match:eq}}" +
807// "]}," +
808// "{@type=korap:group, operation=operation:sequence, operands=[" +
809// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=eine, match=match:eq}}," +
810// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=baum, match=match:eq}}" +
811// "]}" +
812// "]}";
813// ppt = new PoliqarpPlusTree("([orth=der][base=katze])|([orth=eine][base=baum])");
814// map = ppt.getRequestMap().get("query").toString();
815// assertEquals(disj3.replaceAll(" ", ""), map.replaceAll(" ", ""));
816//
817// // "[orth=der][base=katze]|[orth=eine][base=baum]"
818// String disj4 =
819// "{@type=korap:group, operation=operation:or, operands=[" +
820// "{@type=korap:group, operation=operation:sequence, operands=[" +
821// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
822// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=katze, match=match:eq}}" +
823// "]}," +
824// "{@type=korap:group, operation=operation:sequence, operands=[" +
825// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=eine, match=match:eq}}," +
826// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=baum, match=match:eq}}" +
827// "]}" +
828// "]}";
829// ppt = new PoliqarpPlusTree("[orth=der][base=katze]|[orth=eine][base=baum]");
830// map = ppt.getRequestMap().get("query").toString();
831// assertEquals(disj4.replaceAll(" ", ""), map.replaceAll(" ", ""));
832//
833// PoliqarpPlusTree ppt1 = new PoliqarpPlusTree("[orth=der][base=katze]|[orth=eine][base=baum]");
834// PoliqarpPlusTree ppt2 = new PoliqarpPlusTree("([orth=der][base=katze])|([orth=eine][base=baum])");
835// assertEquals(ppt1.getRequestMap().toString(), ppt2.getRequestMap().toString());
836//
837// // "[orth=der][base=katze]|[orth=der][base=hund]|[orth=der][base=baum]"
838// String disj5 =
839// "{@type=korap:group, operation=operation:or, operands=[" +
840// "{@type=korap:group, operation=operation:sequence, operands=[" +
841// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
842// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=katze, match=match:eq}}" +
843// "]}," +
844// "{@type=korap:group, operation=operation:sequence, operands=[" +
845// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
846// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=hund, match=match:eq}}" +
847// "]}," +
848// "{@type=korap:group, operation=operation:sequence, operands=[" +
849// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
850// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=baum, match=match:eq}}" +
851// "]}" +
852// "]}";
853// ppt = new PoliqarpPlusTree("[orth=der][base=katze]|[orth=der][base=hund]|[orth=der][base=baum]");
854// map = ppt.getRequestMap().get("query").toString();
855// assertEquals(disj5.replaceAll(" ", ""), map.replaceAll(" ", ""));
856//
857// // [orth=der]([base=katze]|[base=hund]|[base=baum])
858// String disj6 =
859// "{@type=korap:group, operation=operation:sequence, operands=[" +
860// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
861// "{@type=korap:group, operation=operation:or, operands=[" +
862// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=katze, match=match:eq}}," +
863// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=hund, match=match:eq}}," +
864// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=baum, match=match:eq}}" +
865// "]}" +
866// "]}";
867// ppt = new PoliqarpPlusTree("[orth=der]([base=katze]|[base=hund]|[base=baum])");
868// map = ppt.getRequestMap().get("query").toString();
869// assertEquals(disj6.replaceAll(" ", ""), map.replaceAll(" ", ""));
870// }
871//
872// @Test
873// public void testTokenElemSequence() throws QueryException {
874// // [base=Mann]<vp>
875// String seq1 = "{@type=korap:group, operation=operation:sequence, operands=[" +
876// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}, " +
877// "{@type=korap:span, key=vp}" +
878// "]}";
879// assertTrue(equalsQueryContent(seq1, "[base=Mann]<vp>"));
880//
881// // <vp>[base=Mann]
882// String seq2 = "{@type=korap:group, operation=operation:sequence, operands=[" +
883// "{@type=korap:span, key=vp}, "+
884// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}} " +
885// "]}";
886// assertTrue(equalsQueryContent(seq2, "<vp>[base=Mann]"));
887//
888// // <vp>[base=Mann]<pp>
889// String seq3 = "{@type=korap:group, operation=operation:sequence, operands=[" +
890// "{@type=korap:span, key=vp}, "+
891// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}, " +
892// "{@type=korap:span, key=pp} "+
893// "]}";
894// assertTrue(equalsQueryContent(seq3, "<vp>[base=Mann]<pp>"));
895// }
896//
897// @Test
898// public void testElemSequence() throws QueryException {
899// // <np><vp>
900// String seq1 = "{@type=korap:group, operation=operation:sequence, operands=[" +
901// "{@type=korap:span, key=np}," +
902// "{@type=korap:span, key=vp}" +
903// "]}";
904// assertTrue(equalsQueryContent(seq1, "<np><vp>"));
905//
906// // <np><vp><pp>
907// String seq2 = "{@type=korap:group, operation=operation:sequence, operands=[" +
908// "{@type=korap:span, key=np}," +
909// "{@type=korap:span, key=vp}," +
910// "{@type=korap:span, key=pp}" +
911// "]}";
912// assertTrue(equalsQueryContent(seq2, "<np><vp><pp>"));
913// }
914//
915// @Test
916// public void testClasses() throws QueryException {
917// String query;
918// // {[base=Mann]}
919// String cls1 = "{@type=korap:group, operation=operation:class, class=0, classOut=0, operands=[" +
920// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
921// "]}";
922// ppt = new PoliqarpPlusTree("{[base=Mann]}");
923// map = ppt.getRequestMap().get("query").toString();
924// assertEquals(cls1.replaceAll(" ", ""), map.replaceAll(" ", ""));
925//
926// // {[base=Mann][orth=Frau]}
927// query = "{[base=Mann][orth=Frau]}";
928// String cls2 = "{@type=korap:group, operation=operation:class, class=0, classOut=0, operands=[" +
929// "{@type=korap:group, operation=operation:sequence, operands=[" +
930// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}," +
931// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}" +
932// "]}" +
933// "]}";
934// ppt = new PoliqarpPlusTree(query);
935// map = ppt.getRequestMap().get("query").toString();
936// assertEquals(cls2.replaceAll(" ", ""), map.replaceAll(" ", ""));
937//
938// // [p=NN]{[base=Mann][orth=Frau]}
939// String cls3 = "{@type=korap:group, operation=operation:sequence, operands=[" +
940// "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}," +
941// "{@type=korap:group, operation=operation:class, class=0, classOut=0, operands=[" +
942// "{@type=korap:group, operation=operation:sequence, operands=[" +
943// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}," +
944// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}" +
945// "]}" +
946// "]}" +
947// "]}";
948// ppt = new PoliqarpPlusTree("[p=NN]{[base=Mann][orth=Frau]}");
949// map = ppt.getRequestMap().get("query").toString();
950// assertEquals(cls3.replaceAll(" ", ""), map.replaceAll(" ", ""));
951//
952// // {[base=Mann][orth=Frau]}[p=NN]
953// String cls4 = "{@type=korap:group, operation=operation:sequence, operands=[" +
954// "{@type=korap:group, operation=operation:class, class=0, classOut=0, operands=[" +
955// "{@type=korap:group, operation=operation:sequence, operands=[" +
956// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}," +
957// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}" +
958// "]}" +
959// "]}," +
960// "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}" +
961// "]}";
962// ppt = new PoliqarpPlusTree("{[base=Mann][orth=Frau]}[p=NN]");
963// map = ppt.getRequestMap().get("query").toString();
964// assertEquals(cls4.replaceAll(" ", ""), map.replaceAll(" ", ""));
965//
966// // {2:{1:[tt/p=ADJA]}[mate/p=NN]}"
967// String cls5 = "{@type=korap:group, operation=operation:class, class=2, classOut=2, operands=[" +
968// "{@type=korap:group, operation=operation:sequence, operands=[" +
969// "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" +
970// "{@type=korap:token, wrap={@type=korap:term, foundry=tt, layer=p, key=ADJA, match=match:eq}}" +
971// "]}," +
972// "{@type=korap:token, wrap={@type=korap:term, foundry=mate, layer=p, key=NN, match=match:eq}}" +
973// "]}" +
974// "]}";
975// ppt = new PoliqarpPlusTree("{2: {1:[tt/p=ADJA]}[mate/p=NN]}");
976// map = ppt.getRequestMap().get("query").toString();
977// assertEquals(cls5.replaceAll(" ", ""), map.replaceAll(" ", ""));
978// }
979//
980// @Test
981// public void testPositions() throws QueryException {
982// // contains(<s>,<np>)
983// String pos1 = "{@type=korap:group, operation=operation:position, frames=[frames:contains], operands=[" +
984// "{@type=korap:span, key=s}," +
985// "{@type=korap:span, key=np}" +
986// "], frame=frame:contains}";
987// assertTrue(equalsQueryContent(pos1, "contains(<s>,<np>)"));
988//
989// // contains(<s>,[base=Mann])
990// String pos2 = "{@type=korap:group, operation=operation:position, frames=[frames:contains], operands=[" +
991// "{@type=korap:span, key=s}," +
992// "{@type=korap:token, wrap= {@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
993// "], frame=frame:contains}";
994// assertTrue(equalsQueryContent(pos2, "contains(<s>,[base=Mann])"));
995//
996// // contains(<s>,[orth=der][orth=Mann])
997// String pos3 = "{@type=korap:group, operation=operation:position, frames=[frames:contains], operands=[" +
998// "{@type=korap:span, key=s}," +
999// "{@type=korap:group, operation=operation:sequence, operands=[" +
1000// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
1001// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" +
1002// "]}" +
1003// "], frame=frame:contains}";
1004// ppt = new PoliqarpPlusTree("contains(<s>,[orth=der][orth=Mann])");
1005// map = ppt.getRequestMap().get("query").toString();
1006// assertEquals(pos3.replaceAll(" ", ""), map.replaceAll(" ", ""));
1007//
1008// // [base=Auto]contains(<s>,[base=Mann])
1009// String pos4 =
1010// "{@type=korap:group, operation=operation:sequence, operands=[" +
1011// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Auto, match=match:eq}}," +
1012// "{@type=korap:group, operation=operation:position, frames=[frames:contains], operands=[" +
1013// "{@type=korap:span, key=s}," +
1014// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
1015// "], frame=frame:contains}" +
1016// "]}";
1017// ppt = new PoliqarpPlusTree("[base=Auto]contains(<s>,[base=Mann])");
1018// map = ppt.getRequestMap().get("query").toString();
1019// assertEquals(pos4.replaceAll(" ", ""), map.replaceAll(" ", ""));
1020//
1021// // contains(<s>,[pos=N]*)
1022// String pos5 =
1023// "{@type=korap:group, operation=operation:position, frames=[frames:contains], operands=[" +
1024// "{@type=korap:span, key=s}," +
1025// "{@type=korap:group, operation=operation:repetition, " +
1026// "operands=[{@type=korap:token, wrap={@type=korap:term, layer=pos, key=N, match=match:eq}}" +
1027// "], boundary={@type=korap:boundary, min=0}, min=0" +
1028// "}" +
1029// "], frame=frame:contains}";
1030// ppt = new PoliqarpPlusTree("contains(<s>,[pos=N]*)");
1031// map = ppt.getRequestMap().get("query").toString();
1032// assertEquals(pos5.replaceAll(" ", ""), map.replaceAll(" ", ""));
1033//
1034// // [base=Auto]contains(<s>,[pos=N]*)
1035// String pos6 =
1036// "{@type=korap:group, operation=operation:sequence, operands=[" +
1037// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Auto, match=match:eq}}," +
1038// "{@type=korap:group, operation=operation:position, frames=[frames:contains], operands=[" +
1039// "{@type=korap:span, key=s}," +
1040// "{@type=korap:group, operation=operation:repetition, " +
1041// "operands=[{@type=korap:token, wrap={@type=korap:term, layer=pos, key=N, match=match:eq}}" +
1042// "], boundary={@type=korap:boundary, min=0}, min=0" +
1043// "}" +
1044// "], frame=frame:contains}" +
1045// "]}";
1046// ppt = new PoliqarpPlusTree("[base=Auto]contains(<s>,[pos=N]*)");
1047// map = ppt.getRequestMap().get("query").toString();
1048// assertEquals(pos6.replaceAll(" ", ""), map.replaceAll(" ", ""));
1049// }
1050//
1051// @Test
1052// public void testNestedPositions() throws QueryException {
1053// // contains(<s>,startswith(<np>,[orth=Der]))
1054// String npos1 =
1055// "{@type=korap:group, operation=operation:position, frames=[frames:contains], operands=[" +
1056// "{@type=korap:span, key=s}," +
1057// "{@type=korap:group, operation=operation:position, frames=[frames:startswith], operands=[" +
1058// "{@type=korap:span, key=np}," +
1059// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}" +
1060// "], frame=frame:startswith}" +
1061// "], frame=frame:contains}";
1062// ppt = new PoliqarpPlusTree("contains(<s>, startswith(<np>,[orth=Der]))");
1063// map = ppt.getRequestMap().get("query").toString();
1064// assertEquals(npos1.replaceAll(" ", ""), map.replaceAll(" ", ""));
1065// }
1066//
1067// @Test
1068// public void testFocusSplit() throws QueryException {
1069// // focus([orth=Der]{[orth=Mann]})
1070// String shr1 =
1071// "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
1072// "{@type=korap:group, operation=operation:sequence, operands=[" +
1073// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}," +
1074// "{@type=korap:group, operation=operation:class, class=0, classOut=0, operands=[" +
1075// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" +
1076// "]}" +
1077// "]}" +
1078// "]}";
1079// ppt = new PoliqarpPlusTree("focus([orth=Der]{[orth=Mann]})");
1080// map = ppt.getRequestMap().get("query").toString();
1081// assertEquals(shr1.replaceAll(" ", ""), map.replaceAll(" ", ""));
1082//
1083// // focus([orth=Der]{[orth=Mann][orth=geht]})
1084// String shr2 =
1085// "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
1086// "{@type=korap:group, operation=operation:sequence, operands=[" +
1087// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}," +
1088// "{@type=korap:group, operation=operation:class, class=0, classOut=0, operands=[" +
1089// "{@type=korap:group, operation=operation:sequence, operands=[" +
1090// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}," +
1091// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=geht, match=match:eq}}" +
1092// "]}" +
1093// "]}" +
1094// "]}" +
1095// "]}";
1096// ppt = new PoliqarpPlusTree("focus([orth=Der]{[orth=Mann][orth=geht]})");
1097// map = ppt.getRequestMap().get("query").toString();
1098// assertEquals(shr2.replaceAll(" ", ""), map.replaceAll(" ", ""));
1099//
1100// // focus(1:[orth=Der]{1:[orth=Mann][orth=geht]})
1101// String shr3 =
1102// "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
1103// "{@type=korap:group, operation=operation:sequence, operands=[" +
1104// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}," +
1105// "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" +
1106// "{@type=korap:group, operation=operation:sequence, operands=[" +
1107// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}," +
1108// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=geht, match=match:eq}}" +
1109// "]}" +
1110// "]}" +
1111// "]}" +
1112// "]}";
1113// ppt = new PoliqarpPlusTree("focus(1:[orth=Der]{1:[orth=Mann][orth=geht]})");
1114// map = ppt.getRequestMap().get("query").toString();
1115// assertEquals(shr3.replaceAll(" ", ""), map.replaceAll(" ", ""));
1116//
1117// // focus(1:startswith(<s>,{1:<np>}))
1118// String shr4 =
1119// "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
1120// "{@type=korap:group, operation=operation:position, frames=[frames:startswith], operands=[" +
1121// "{@type=korap:span, key=s}," +
1122// "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" +
1123// "{@type=korap:span, key=np}" +
1124// "]}" +
1125// "], frame=frame:startswith}" +
1126// "]}";
1127// ppt = new PoliqarpPlusTree("focus(1:startswith(<s>,{1:<np>}))");
1128// map = ppt.getRequestMap().get("query").toString();
1129// assertEquals(shr4.replaceAll(" ", ""), map.replaceAll(" ", ""));
1130//
1131// // focus(3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))
1132// String shr5 =
1133// "{@type=korap:reference, operation=operation:focus, classRef=[3], operands=[" +
1134// "{@type=korap:group, operation=operation:position, frames=[frames:startswith], operands=[" +
1135// "{@type=korap:span, key=s}," +
1136// "{@type=korap:group, operation=operation:class, class=3, classOut=3, operands=[" +
1137// "{@type=korap:group, operation=operation:sequence, operands=[" +
1138// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
1139// "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" +
1140// "{@type=korap:group, operation=operation:sequence, operands=[" +
1141// "{@type=korap:token, wrap={@type=korap:term, foundry=mate, layer=p, key=ADJA, match=match:eq}}," +
1142// "{@type=korap:group, operation=operation:class, class=2, classOut=2, operands=[" +
1143// "{@type=korap:token, wrap={@type=korap:term, foundry=tt, layer=p, key=NN, match=match:eq}}" +
1144// "]}" +
1145// "]}" +
1146// "]}" +
1147// "]}" +
1148// "]}" +
1149// "], frame=frame:startswith}" +
1150// "]}";
1151// ppt = new PoliqarpPlusTree("focus(3:startswith(<s>,{3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) ");
1152// map = ppt.getRequestMap().get("query").toString();
1153// assertEquals(shr5.replaceAll(" ", ""), map.replaceAll(" ", ""));
1154//
1155// // split(3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))
1156// String shr6 =
1157// "{@type=korap:reference, operation=operation:split, classRef=[3], operands=[" +
1158// "{@type=korap:group, operation=operation:position, frames=[frames:startswith], operands=[" +
1159// "{@type=korap:span, key=s}," +
1160// "{@type=korap:group, operation=operation:class, class=3, classOut=3, operands=[" +
1161// "{@type=korap:group, operation=operation:sequence, operands=[" +
1162// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
1163// "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" +
1164// "{@type=korap:group, operation=operation:sequence, operands=[" +
1165// "{@type=korap:token, wrap={@type=korap:term, foundry=mate, layer=p, key=ADJA, match=match:eq}}," +
1166// "{@type=korap:group, operation=operation:class, class=2, classOut=2, operands=[" +
1167// "{@type=korap:token, wrap={@type=korap:term, foundry=tt, layer=p, key=NN, match=match:eq}}" +
1168// "]}" +
1169// "]}" +
1170// "]}" +
1171// "]}" +
1172// "]}" +
1173// "], frame=frame:startswith}" +
1174// "]}";
1175// ppt = new PoliqarpPlusTree("split(3:startswith(<s>,{3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) ");
1176// map = ppt.getRequestMap().get("query").toString();
1177// assertEquals(shr6.replaceAll(" ", ""), map.replaceAll(" ", ""));
1178//
1179// // split(2|3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))
1180// String shr7 =
1181// "{@type=korap:reference, operation=operation:split, classRef=[2, 3], classRefOp=classRefOp:intersection, operands=[" +
1182// "{@type=korap:group, operation=operation:position, frames=[frames:startswith], operands=[" +
1183// "{@type=korap:span, key=s}," +
1184// "{@type=korap:group, operation=operation:class, class=3, classOut=3, operands=[" +
1185// "{@type=korap:group, operation=operation:sequence, operands=[" +
1186// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
1187// "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" +
1188// "{@type=korap:group, operation=operation:sequence, operands=[" +
1189// "{@type=korap:token, wrap={@type=korap:term, foundry=mate, layer=p, key=ADJA, match=match:eq}}," +
1190// "{@type=korap:group, operation=operation:class, class=2, classOut=2, operands=[" +
1191// "{@type=korap:token, wrap={@type=korap:term, foundry=tt, layer=p, key=NN, match=match:eq}}" +
1192// "]}" +
1193// "]}" +
1194// "]}" +
1195// "]}" +
1196// "]}" +
1197// "], frame=frame:startswith}" +
1198// "]}";
1199// ppt = new PoliqarpPlusTree("split(2|3:startswith(<s>,{3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) ");
1200// map = ppt.getRequestMap().get("query").toString();
1201// assertEquals(shr7.replaceAll(" ", ""), map.replaceAll(" ", ""));
1202//
1203//
1204// String shr8 =
1205// "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
1206// "{@type=korap:group, operation=operation:sequence, operands=[" +
1207// "{@type=korap:group, operation=operation:class, class=0, classOut=0, operands=[" +
1208// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}" +
1209// "]}," +
1210// "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" +
1211// "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=ADJA, match=match:eq}}" +
1212// "]}" +
1213// "]}" +
1214// "]}";
1215// ppt = new PoliqarpPlusTree("focus(1:{[base=der]}{1:[pos=ADJA]})");
1216// map = ppt.getRequestMap().get("query").toString();
1217// assertEquals(shr8.replaceAll(" ", ""), map.replaceAll(" ", ""));
1218//
1219// }
1220//
1221// @Test
1222// public void testSubspan() throws QueryException {
1223// query = "submatch(1,:<s>)";
1224// expected =
1225// "{@type=korap:reference, operation=operation:focus, operands=[" +
1226// "{@type=korap:span, key=s}" +
1227// "], spanRef=[1]" +
1228// "}";
1229// ppt = new PoliqarpPlusTree(query);
1230// map = ppt.getRequestMap().get("query").toString();
1231// assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1232//
1233// query = "submatch(1,4:<s>)";
1234// expected =
1235// "{@type=korap:reference, operation=operation:focus, operands=[" +
1236// "{@type=korap:span, key=s}" +
1237// "], spanRef=[1,4]" +
1238// "}";
1239// ppt = new PoliqarpPlusTree(query);
1240// map = ppt.getRequestMap().get("query").toString();
1241// assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1242//
1243// query = "submatch(1,4:contains(<s>,[base=Haus]))";
1244// expected =
1245// "{@type=korap:reference, operation=operation:focus, operands=[" +
1246// "{@type=korap:group, operation=operation:position, frames=[frames:contains], operands=[" +
1247// "{@type=korap:span, key=s}," +
1248// "{@type=korap:token, wrap= {@type=korap:term, layer=lemma, key=Haus, match=match:eq}}" +
1249// "], frame=frame:contains}" +
1250// "], spanRef=[1,4]" +
1251// "}";
1252// ppt = new PoliqarpPlusTree(query);
1253// map = ppt.getRequestMap().get("query").toString();
1254// assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1255// }
1256//
1257// @Test
1258// public void testRelations() throws QueryException {
1259// query = "relatesTo(<s>,<np>)";
1260// expected =
1261// "{@type=korap:group, operation=operation:relation, operands=[" +
1262// "{@type=korap:span, key=s}," +
1263// "{@type=korap:span, key=np}" +
1264// "], relation={@type=korap:relation}" +
1265// "}";
1266// ppt = new PoliqarpPlusTree(query);
1267// map = ppt.getRequestMap().get("query").toString();
1268// assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1269//
1270// query = "relatesTo([base=Baum],<np>)";
1271// expected =
1272// "{@type=korap:group, operation=operation:relation, operands=[" +
1273// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Baum, match=match:eq}}," +
1274// "{@type=korap:span, key=np}" +
1275// "], relation={@type=korap:relation}" +
1276// "}";
1277// ppt = new PoliqarpPlusTree(query);
1278// map = ppt.getRequestMap().get("query").toString();
1279// assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1280//
1281// query = "dominates(<np>,[base=Baum])";
1282// expected =
1283// "{@type=korap:group, operation=operation:relation, operands=[" +
1284// "{@type=korap:span, key=np}," +
1285// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Baum, match=match:eq}}" +
1286// "], relation={@type=korap:relation, layer=c}" +
1287// "}";
1288// ppt = new PoliqarpPlusTree(query);
1289// map = ppt.getRequestMap().get("query").toString();
1290// assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1291//
1292// query = "dominates(cnx/c:<np>,[base=Baum])";
1293// expected =
1294// "{@type=korap:group, operation=operation:relation, operands=[" +
1295// "{@type=korap:span, key=np}," +
1296// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Baum, match=match:eq}}" +
1297// "], relation={@type=korap:relation, layer=c, foundry=cnx}" +
1298// "}";
1299// ppt = new PoliqarpPlusTree(query);
1300// map = ppt.getRequestMap().get("query").toString();
1301// assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1302//
1303// query = "dominates(cnx/c*:<np>,[base=Baum])";
1304// expected =
1305// "{@type=korap:group, operation=operation:relation, operands=[" +
1306// "{@type=korap:span, key=np}," +
1307// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Baum, match=match:eq}}" +
1308// "], relation={@type=korap:relation, layer=c, foundry=cnx, boundary={@type=korap:boundary, min=0}}" +
1309// "}";
1310// ppt = new PoliqarpPlusTree(query);
1311// map = ppt.getRequestMap().get("query").toString();
1312// assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1313//
1314// query = "dominates(cnx/c{1,5}:<np>,[base=Baum])";
1315// expected =
1316// "{@type=korap:group, operation=operation:relation, operands=[" +
1317// "{@type=korap:span, key=np}," +
1318// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Baum, match=match:eq}}" +
1319// "], relation={@type=korap:relation, layer=c, foundry=cnx, boundary={@type=korap:boundary, min=1, max=5}}" +
1320// "}";
1321// ppt = new PoliqarpPlusTree(query);
1322// map = ppt.getRequestMap().get("query").toString();
1323// assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1324//
1325// query = "relatesTo(mate/d=HEAD:<np>,[base=Baum])";
1326// expected =
1327// "{@type=korap:group, operation=operation:relation, operands=[" +
1328// "{@type=korap:span, key=np}," +
1329// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Baum, match=match:eq}}" +
1330// "], relation={@type=korap:relation, foundry=mate, layer=d, key=HEAD}" +
1331// "}";
1332// ppt = new PoliqarpPlusTree(query);
1333// map = ppt.getRequestMap().get("query").toString();
1334// assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1335//
1336// }
1337//
1338//
1339//
1340// @Test
1341// public void testFoundries() throws QueryException {
1342// // [tt/base=Mann]
1343// String layer1 = "{@type=korap:token, wrap={@type=korap:term, foundry=tt, layer=lemma, key=Mann, match=match:eq}}";
1344// ppt = new PoliqarpPlusTree("[tt/base=Mann]");
1345// map = ppt.getRequestMap().get("query").toString();
1346// assertEquals(layer1.replaceAll(" ", ""), map.replaceAll(" ", ""));
1347//
1348// }
1349//
1350// @Test
1351// public void testAlign() throws QueryException {
1352// // [orth=der]^[orth=Mann]
1353// query = "[orth=der]^[orth=Mann]";
1354// expected =
1355// "{@type=korap:group, operation=operation:sequence, operands=[" +
1356// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
1357// "{@type=korap:group, operation=operation:class, class=1025, classOut=1025, operands=[" +
1358// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" +
1359// "]}" +
1360// "]}";
1361// metaExpected =
1362// "{alignment=1025}";
1363// ppt = new PoliqarpPlusTree(query);
1364// map = ppt.getRequestMap().get("query").toString();
1365// metaMap = ppt.getRequestMap().get("meta").toString();
1366// assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1367// assertEquals(metaExpected.replaceAll(" ", ""), metaMap.replaceAll(" ", ""));
1368//
1369// // [orth=der]^[orth=große][orth=Mann]
1370// query = "[orth=der]^[orth=große][orth=Mann]";
1371// String expected =
1372// "{@type=korap:group, operation=operation:sequence, operands=[" +
1373// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
1374// "{@type=korap:group, operation=operation:class, class=1025, classOut=1025, operands=[" +
1375// "{@type=korap:group, operation=operation:sequence, operands=[" +
1376// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=große, match=match:eq}}," +
1377// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" +
1378// "]}" +
1379// "]}" +
1380// "]}";
1381// metaExpected =
1382// "{alignment=1025}";
1383// ppt = new PoliqarpPlusTree(query);
1384// map = ppt.getRequestMap().get("query").toString();
1385// metaMap = ppt.getRequestMap().get("meta").toString();
1386// assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1387// assertEquals(metaExpected.replaceAll(" ", ""), metaMap.replaceAll(" ", ""));
1388//
1389// query = "([base=a]^[base=b])|[base=c]";
1390// expected =
1391// "{@type=korap:group, operation=operation:or, operands=[" +
1392// "{@type=korap:group, operation=operation:sequence, operands=[" +
1393// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=a, match=match:eq}}," +
1394// "{@type=korap:group, operation=operation:class, class=1025, classOut=1025, operands=[" +
1395// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=b, match=match:eq}}" +
1396// "]}" +
1397// "]}," +
1398// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=c, match=match:eq}}" +
1399// "]}";
1400// metaExpected =
1401// "{alignment=1025}";
1402// ppt = new PoliqarpPlusTree(query);
1403// map = ppt.getRequestMap().get("query").toString();
1404// metaMap = ppt.getRequestMap().get("meta").toString();
1405// assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1406// assertEquals(metaExpected.replaceAll(" ", ""), metaMap.replaceAll(" ", ""));
1407//
1408// query = "([base=a]^[base=b][base=c])|[base=d]";
1409// expected =
1410// "{@type=korap:group, operation=operation:or, operands=[" +
1411// "{@type=korap:group, operation=operation:sequence, operands=[" +
1412// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=a, match=match:eq}}," +
1413// "{@type=korap:group, operation=operation:class, class=1025, classOut=1025, operands=[" +
1414// "{@type=korap:group, operation=operation:sequence, operands=[" +
1415// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=b, match=match:eq}}," +
1416// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=c, match=match:eq}}" +
1417// "]}" +
1418// "]}" +
1419// "]}," +
1420// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=d, match=match:eq}}" +
1421// "]}";
1422// metaExpected =
1423// "{alignment=1025}";
1424// ppt = new PoliqarpPlusTree(query);
1425// map = ppt.getRequestMap().get("query").toString();
1426// metaMap = ppt.getRequestMap().get("meta").toString();
1427// assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1428// assertEquals(metaExpected.replaceAll(" ", ""), metaMap.replaceAll(" ", ""));
1429//
1430// query = "([base=a]^[base=b]^[base=c])|[base=d]";
1431// expected =
1432// "{@type=korap:group, operation=operation:or, operands=[" +
1433// "{@type=korap:group, operation=operation:sequence, operands=[" +
1434// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=a, match=match:eq}}," +
1435// "{@type=korap:group, operation=operation:class, class=1025, classOut=1025, operands=[" +
1436// "{@type=korap:group, operation=operation:sequence, operands=[" +
1437// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=b, match=match:eq}}," +
1438// "{@type=korap:group, operation=operation:class, class=1026, classOut=1026, operands=[" +
1439// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=c, match=match:eq}}" +
1440// "]}" +
1441// "]}" +
1442// "]}" +
1443// "]}," +
1444// "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=d, match=match:eq}}" +
1445// "]}";
1446// metaExpected =
1447// "{alignment=[1025,1026]}";
1448// ppt = new PoliqarpPlusTree(query);
1449// map = ppt.getRequestMap().get("query").toString();
1450// metaMap = ppt.getRequestMap().get("meta").toString();
1451// assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1452// assertEquals(metaExpected.replaceAll(" ", ""), metaMap.replaceAll(" ", ""));
1453//
1454//
1455// }
1456//
1457// @Test
1458// public void testSimpleQueries() throws QueryException {
1459// // Baum
1460// String simple1 =
1461// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq}}";
1462// ppt = new PoliqarpPlusTree("Baum");
1463// map = ppt.getRequestMap().get("query").toString();
1464// assertEquals(simple1.replaceAll(" ", ""), map.replaceAll(" ", ""));
1465//
1466// // Baum/i
1467// String simple1b =
1468// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq, caseInsensitive=true}}";
1469// ppt = new PoliqarpPlusTree("Baum/i");
1470// map = ppt.getRequestMap().get("query").toString();
1471// assertEquals(simple1b.replaceAll(" ", ""), map.replaceAll(" ", ""));
1472//
1473// // Der Baum
1474// String simple2 =
1475// "{@type=korap:group, operation=operation:sequence, operands=[" +
1476// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}, " +
1477// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq}}" +
1478// "]}";
1479// ppt = new PoliqarpPlusTree("Der Baum");
1480// map = ppt.getRequestMap().get("query").toString();
1481// assertEquals(simple2.replaceAll(" ", ""), map.replaceAll(" ", ""));
1482//
1483// // Der Baum/i
1484// String simple2b =
1485// "{@type=korap:group, operation=operation:sequence, operands=[" +
1486// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}, " +
1487// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq, caseInsensitive=true}}" +
1488// "]}";
1489// ppt = new PoliqarpPlusTree("Der Baum/i");
1490// map = ppt.getRequestMap().get("query").toString();
1491// assertEquals(simple2b.replaceAll(" ", ""), map.replaceAll(" ", ""));
1492//
1493// // Der große Baum
1494// String simple3 =
1495// "{@type=korap:group, operation=operation:sequence, operands=[" +
1496// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}, " +
1497// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=große, match=match:eq}}, " +
1498// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq}}" +
1499// "]}";
1500// ppt = new PoliqarpPlusTree("Der große Baum");
1501// map = ppt.getRequestMap().get("query").toString();
1502// assertEquals(simple3.replaceAll(" ", ""), map.replaceAll(" ", ""));
1503//
1504// // Baum | Stein
1505// String simple4 =
1506// "{@type=korap:group, operation=operation:or, operands=[" +
1507// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq}}, " +
1508// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Stein, match=match:eq}}" +
1509// "]}";
1510// ppt = new PoliqarpPlusTree("Baum | Stein");
1511// map = ppt.getRequestMap().get("query").toString();
1512// assertEquals(simple4.replaceAll(" ", ""), map.replaceAll(" ", ""));
1513//
1514// // Baum | Stein Haus
1515// String query = "(Baum | Stein) Haus";
1516// String simple5 =
1517// "{@type=korap:group, operation=operation:sequence, operands=[" +
1518// "{@type=korap:group, operation=operation:or, operands=[" +
1519// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq}}, " +
1520// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Stein, match=match:eq}}" +
1521// "]}," +
1522// "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Haus, match=match:eq}} " +
1523// "]}";
1524// ppt = new PoliqarpPlusTree(query);
1525// map = ppt.getRequestMap().get("query").toString();
1526// assertEquals(simple5.replaceAll(" ", ""), map.replaceAll(" ", ""));
1527// }
Nils Diewald5adc3c62014-11-12 21:55:34 +00001528}