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