blob: 1388dcd54a3109964d870b8cdf012acdfd3c5af4 [file] [log] [blame]
Joachim Bingel53333e62013-12-09 19:25:52 +00001import static org.junit.Assert.*;
2
Joachim Bingel7cc5f352014-12-03 09:40:04 +00003import java.io.IOException;
4import java.util.ArrayList;
5
Joachim Bingel53333e62013-12-09 19:25:52 +00006import org.junit.Test;
7
Joachim Bingel7cc5f352014-12-03 09:40:04 +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;
Joachim Bingel16da4e12013-12-17 09:48:12 +000015import de.ids_mannheim.korap.util.QueryException;
Joachim Bingel53333e62013-12-09 19:25:52 +000016
Joachim Bingel7cc5f352014-12-03 09:40:04 +000017/**
18 * Tests for JSON-LD serialization of PoliqarpPlus queries.
19 * @author Joachim Bingel (bingel@ids-mannheim.de)
20 * @version 1.0
21 */
Joachim Bingel53333e62013-12-09 19:25:52 +000022public class PoliqarpPlusTreeTest {
Joachim Bingel7cc5f352014-12-03 09:40:04 +000023
Joachim Bingel53333e62013-12-09 19:25:52 +000024 String map;
Joachim Bingel14239d82014-07-22 09:55:04 +000025 String expected;
Joachim Bingel832800e2014-10-17 14:46:39 +000026 String metaExpected;
27 String metaMap;
Joachim Bingel14239d82014-07-22 09:55:04 +000028 String query;
Joachim Bingel7cc5f352014-12-03 09:40:04 +000029 ArrayList<JsonNode> operands;
30
31 QuerySerializer qs = new QuerySerializer();
32 ObjectMapper mapper = new ObjectMapper();
33 JsonNode res;
34
Joachim Bingel81812632014-02-18 08:55:22 +000035 @Test
Joachim Bingel7cc5f352014-12-03 09:40:04 +000036 public void testContext() throws QueryException, JsonProcessingException, IOException {
37 query = "foo";
Joachim Bingel832800e2014-10-17 14:46:39 +000038 String contextString = "http://ids-mannheim.de/ns/KorAP/json-ld/v0.2/context.jsonld";
Joachim Bingel7cc5f352014-12-03 09:40:04 +000039 qs.setQuery(query, "poliqarpplus");
40 res = mapper.readTree(qs.toJSON());
41 assertEquals(contextString, res.get("@context").asText());
Joachim Bingel53333e62013-12-09 19:25:52 +000042 }
Joachim Bingel7cc5f352014-12-03 09:40:04 +000043
Joachim Bingel53333e62013-12-09 19:25:52 +000044 @Test
Joachim Bingel7cc5f352014-12-03 09:40:04 +000045 public void testSingleTokens() throws QueryException, JsonProcessingException, IOException {
46 query = "[base=Mann]";
47 qs.setQuery(query, "poliqarpplus");
48 res = mapper.readTree(qs.toJSON());
49 assertEquals("korap:token", res.at("/query/@type").asText());
50 assertEquals("Mann", res.at("/query/wrap/key").asText());
51 assertEquals("lemma", res.at("/query/wrap/layer").asText());
52 assertEquals("match:eq", res.at("/query/wrap/match").asText());
53
54 query = "[orth!=Frau]";
55 qs.setQuery(query, "poliqarpplus");
56 res = mapper.readTree(qs.toJSON());
57 assertEquals("korap:token", res.at("/query/@type").asText());
58 assertEquals("Frau", res.at("/query/wrap/key").asText());
59 assertEquals("orth", res.at("/query/wrap/layer").asText());
60 assertEquals("match:ne", res.at("/query/wrap/match").asText());
61
62 query = "[p!=NN]";
63 qs.setQuery(query, "poliqarpplus");
64 res = mapper.readTree(qs.toJSON());
65 assertEquals("korap:token", res.at("/query/@type").asText());
66 assertEquals("NN", res.at("/query/wrap/key").asText());
67 assertEquals("p", res.at("/query/wrap/layer").asText());
68 assertEquals("match:ne", res.at("/query/wrap/match").asText());
69
Joachim Bingel0900a892014-06-30 16:26:21 +000070 query = "[!p!=NN]";
Joachim Bingel7cc5f352014-12-03 09:40:04 +000071 qs.setQuery(query, "poliqarpplus");
72 res = mapper.readTree(qs.toJSON());
73 assertEquals("korap:token", res.at("/query/@type").asText());
74 assertEquals("NN", res.at("/query/wrap/key").asText());
75 assertEquals("p", res.at("/query/wrap/layer").asText());
76 assertEquals("match:eq", res.at("/query/wrap/match").asText());
77
Joachim Bingeld1a3e712014-07-16 08:02:05 +000078 query = "[base=schland/x]";
Joachim Bingel7cc5f352014-12-03 09:40:04 +000079 qs.setQuery(query, "poliqarpplus");
80 res = mapper.readTree(qs.toJSON());
81 assertEquals("korap:token", res.at("/query/@type").asText());
82 assertEquals(".*?schland.*?", res.at("/query/wrap/key").asText());
83 assertEquals("lemma", res.at("/query/wrap/layer").asText());
84 assertEquals("type:regex", res.at("/query/wrap/type").asText());
85 assertEquals("match:eq", res.at("/query/wrap/match").asText());
Joachim Bingeld1a3e712014-07-16 08:02:05 +000086 }
Joachim Bingel7cc5f352014-12-03 09:40:04 +000087
Joachim Bingeld1a3e712014-07-16 08:02:05 +000088 @Test
Joachim Bingel7cc5f352014-12-03 09:40:04 +000089 public void testValue() throws QueryException, JsonProcessingException, IOException {
Joachim Bingeld1a3e712014-07-16 08:02:05 +000090 query = "[mate/m=temp:pres]";
Joachim Bingel7cc5f352014-12-03 09:40:04 +000091 qs.setQuery(query, "poliqarpplus");
92 res = mapper.readTree(qs.toJSON());
93 assertEquals("korap:token", res.at("/query/@type").asText());
94 assertEquals("korap:term", res.at("/query/wrap/@type").asText());
95 assertEquals("temp", res.at("/query/wrap/key").asText());
96 assertEquals("pres", res.at("/query/wrap/value").asText());
97 assertEquals("m", res.at("/query/wrap/layer").asText());
98 assertEquals("mate", res.at("/query/wrap/foundry").asText());
99 assertEquals("match:eq", res.at("/query/wrap/match").asText());
Joachim Bingel53333e62013-12-09 19:25:52 +0000100 }
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000101
Joachim Bingel53333e62013-12-09 19:25:52 +0000102 @Test
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000103 public void testRegex() throws QueryException, JsonProcessingException, IOException {
Joachim Bingel832800e2014-10-17 14:46:39 +0000104 query = "[orth=\"M(a|ä)nn(er)?\"]";
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000105 qs.setQuery(query, "poliqarpplus");
106 res = mapper.readTree(qs.toJSON());
107 assertEquals("korap:token", res.at("/query/@type").asText());
108 assertEquals("korap:term", res.at("/query/wrap/@type").asText());
109 assertEquals("M(a|ä)nn(er)?", res.at("/query/wrap/key").asText());
110 assertEquals("type:regex", res.at("/query/wrap/type").asText());
111 assertEquals("orth", res.at("/query/wrap/layer").asText());
112 assertEquals("match:eq", res.at("/query/wrap/match").asText());
113
Joachim Bingel0900a892014-06-30 16:26:21 +0000114 query = "[orth=\"M(a|ä)nn(er)?\"/x]";
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000115 qs.setQuery(query, "poliqarpplus");
116 res = mapper.readTree(qs.toJSON());
117 assertEquals("korap:token", res.at("/query/@type").asText());
118 assertEquals("korap:term", res.at("/query/wrap/@type").asText());
119 assertEquals(".*?M(a|ä)nn(er)?.*?", res.at("/query/wrap/key").asText());
120 assertEquals("type:regex", res.at("/query/wrap/type").asText());
121 assertEquals("orth", res.at("/query/wrap/layer").asText());
122 assertEquals("match:eq", res.at("/query/wrap/match").asText());
123
Joachim Bingeld1a3e712014-07-16 08:02:05 +0000124 query = "\".*?Mann.*?\"";
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000125 qs.setQuery(query, "poliqarpplus");
126 res = mapper.readTree(qs.toJSON());
127 assertEquals("korap:token", res.at("/query/@type").asText());
128 assertEquals("korap:term", res.at("/query/wrap/@type").asText());
129 assertEquals(".*?Mann.*?", res.at("/query/wrap/key").asText());
130 assertEquals("type:regex", res.at("/query/wrap/type").asText());
131 assertEquals("orth", res.at("/query/wrap/layer").asText());
132 assertEquals("match:eq", res.at("/query/wrap/match").asText());
133
Joachim Bingela83f8cc2014-08-05 14:12:59 +0000134 query = "z.B./x";
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000135 qs.setQuery(query, "poliqarpplus");
136 res = mapper.readTree(qs.toJSON());
137 assertEquals("korap:token", res.at("/query/@type").asText());
138 assertEquals("korap:term", res.at("/query/wrap/@type").asText());
139 assertEquals(".*?z\\.B\\..*?", res.at("/query/wrap/key").asText());
140 assertEquals("type:regex", res.at("/query/wrap/type").asText());
141 assertEquals("orth", res.at("/query/wrap/layer").asText());
142 assertEquals("match:eq", res.at("/query/wrap/match").asText());
143
Joachim Bingel41e112e2014-02-12 10:46:18 +0000144 }
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000145
Joachim Bingel41e112e2014-02-12 10:46:18 +0000146 @Test
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000147 public void testCaseSensitivityFlag() throws QueryException, JsonProcessingException, IOException {
148 query = "[orth=deutscher/i]";
149 qs.setQuery(query, "poliqarpplus");
150 res = mapper.readTree(qs.toJSON());
151 assertEquals("korap:token", res.at("/query/@type").asText());
152 assertEquals("korap:term", res.at("/query/wrap/@type").asText());
153 assertEquals("deutscher", res.at("/query/wrap/key").asText());
154 assertEquals("true", res.at("/query/wrap/caseInsensitive").asText());
155 assertEquals("orth", res.at("/query/wrap/layer").asText());
156 assertEquals("match:eq", res.at("/query/wrap/match").asText());
157
158 query = "deutscher/i";
159 qs.setQuery(query, "poliqarpplus");
160 res = mapper.readTree(qs.toJSON());
161 assertEquals("korap:token", res.at("/query/@type").asText());
162 assertEquals("korap:term", res.at("/query/wrap/@type").asText());
163 assertEquals("deutscher", res.at("/query/wrap/key").asText());
164 assertEquals("true", res.at("/query/wrap/caseInsensitive").asText());
165 assertEquals("orth", res.at("/query/wrap/layer").asText());
166 assertEquals("match:eq", res.at("/query/wrap/match").asText());
167
168 query = "deutscher/I";
169 qs.setQuery(query, "poliqarpplus");
170 res = mapper.readTree(qs.toJSON());
171 assertEquals("korap:token", res.at("/query/@type").asText());
172 assertEquals("korap:term", res.at("/query/wrap/@type").asText());
173 assertEquals("deutscher", res.at("/query/wrap/key").asText());
174 assertEquals("false", res.at("/query/wrap/caseInsensitive").asText());
175 assertEquals("orth", res.at("/query/wrap/layer").asText());
176 assertEquals("match:eq", res.at("/query/wrap/match").asText());
177
178 query = "[orth=deutscher/i][orth=Bundestag]";
179 qs.setQuery(query, "poliqarpplus");
180 res = mapper.readTree(qs.toJSON());
181 assertEquals("korap:group", res.at("/query/@type").asText());
182 assertEquals("operation:sequence", res.at("/query/operation").asText());
183 operands = Lists.newArrayList(res.at("/query/operands").elements());
184 assertEquals("korap:token", operands.get(0).at("/@type").asText());
185 assertEquals("deutscher", operands.get(0).at("/wrap/key").asText());
186 assertEquals("orth", operands.get(0).at("/wrap/layer").asText());
187 assertEquals("match:eq", operands.get(0).at("/wrap/match").asText());
188 assertEquals(true, operands.get(0).at("/wrap/caseInsensitive").asBoolean());
189 assertEquals("korap:token", operands.get(1).at("/@type").asText());
190 assertEquals("Bundestag", operands.get(1).at("/wrap/key").asText());
191 assertEquals("orth", operands.get(1).at("/wrap/layer").asText());
192 assertEquals("match:eq", operands.get(1).at("/wrap/match").asText());
193 assertEquals(true, operands.get(1).at("/wrap/caseInsensitive").isMissingNode());
194
195 query = "deutscher/i Bundestag";
196 qs.setQuery(query, "poliqarpplus");
197 res = mapper.readTree(qs.toJSON());
198 assertEquals("korap:group", res.at("/query/@type").asText());
199 assertEquals("operation:sequence", res.at("/query/operation").asText());
200 operands = Lists.newArrayList(res.at("/query/operands").elements());
201 assertEquals("korap:token", operands.get(0).at("/@type").asText());
202 assertEquals("deutscher", operands.get(0).at("/wrap/key").asText());
203 assertEquals("orth", operands.get(0).at("/wrap/layer").asText());
204 assertEquals("match:eq", operands.get(0).at("/wrap/match").asText());
205 assertEquals(true, operands.get(0).at("/wrap/caseInsensitive").asBoolean());
206 assertEquals("korap:token", operands.get(1).at("/@type").asText());
207 assertEquals("Bundestag", operands.get(1).at("/wrap/key").asText());
208 assertEquals("orth", operands.get(1).at("/wrap/layer").asText());
209 assertEquals("match:eq", operands.get(1).at("/wrap/match").asText());
210 assertEquals(true, operands.get(1).at("/wrap/caseInsensitive").isMissingNode());
Joachim Bingel0207d5e2014-02-12 14:18:41 +0000211 }
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000212
Joachim Bingel0207d5e2014-02-12 14:18:41 +0000213 @Test
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000214 public void testSpans() throws QueryException, JsonProcessingException, IOException {
215 query = "<s>";
216 qs.setQuery(query, "poliqarpplus");
217 res = mapper.readTree(qs.toJSON());
218 assertEquals("korap:span", res.at("/query/@type").asText());
219 assertEquals("s", res.at("/query/key").asText());
220
221 query = "<vp>";
222 qs.setQuery(query, "poliqarpplus");
223 res = mapper.readTree(qs.toJSON());
224 assertEquals("korap:span", res.at("/query/@type").asText());
225 assertEquals("vp", res.at("/query/key").asText());
226
Joachim Bingelfc1fb352014-02-26 14:40:27 +0000227 query = "<cnx/c=vp>";
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000228 qs.setQuery(query, "poliqarpplus");
229 res = mapper.readTree(qs.toJSON());
230 assertEquals("korap:span", res.at("/query/@type").asText());
231 assertEquals("vp", res.at("/query/key").asText());
232 assertEquals("cnx", res.at("/query/foundry").asText());
233 assertEquals("c", res.at("/query/layer").asText());
234
Joachim Bingel3a41a442014-07-22 12:16:16 +0000235 query = "<cnx/c!=vp>";
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000236 qs.setQuery(query, "poliqarpplus");
237 res = mapper.readTree(qs.toJSON());
238 assertEquals("korap:span", res.at("/query/@type").asText());
239 assertEquals("vp", res.at("/query/key").asText());
240 assertEquals("cnx", res.at("/query/foundry").asText());
241 assertEquals("c", res.at("/query/layer").asText());
242 assertEquals("match:ne", res.at("/query/match").asText());
243
244 query = "<cnx/c!=vp class!=header>";
245 qs.setQuery(query, "poliqarpplus");
246 res = mapper.readTree(qs.toJSON());
247 assertEquals("korap:span", res.at("/query/@type").asText());
248 assertEquals("vp", res.at("/query/key").asText());
249 assertEquals("cnx", res.at("/query/foundry").asText());
250 assertEquals("c", res.at("/query/layer").asText());
251 assertEquals("match:ne", res.at("/query/match").asText());
252 assertEquals("class", res.at("/query/attr/key").asText());
253 assertEquals("header", res.at("/query/attr/value").asText());
254 assertEquals("match:ne", res.at("/query/attr/match").asText());
255
256 query = "<cnx/c!=vp !(class!=header)>";
257 qs.setQuery(query, "poliqarpplus");
258 res = mapper.readTree(qs.toJSON());
259 assertEquals("korap:span", res.at("/query/@type").asText());
260 assertEquals("vp", res.at("/query/key").asText());
261 assertEquals("cnx", res.at("/query/foundry").asText());
262 assertEquals("c", res.at("/query/layer").asText());
263 assertEquals("match:ne", res.at("/query/match").asText());
264 assertEquals("class", res.at("/query/attr/key").asText());
265 assertEquals("header", res.at("/query/attr/value").asText());
266 assertEquals("match:eq", res.at("/query/attr/match").asText());
267
268 query = "<cnx/c!=vp !(class=header & id=7)>";
269 qs.setQuery(query, "poliqarpplus");
270 res = mapper.readTree(qs.toJSON());
271 assertEquals("korap:span", res.at("/query/@type").asText());
272 assertEquals("vp", res.at("/query/key").asText());
273 assertEquals("cnx", res.at("/query/foundry").asText());
274 assertEquals("c", res.at("/query/layer").asText());
275 assertEquals("match:ne", res.at("/query/match").asText());
276 assertEquals("korap:termGroup", res.at("/query/attr/@type").asText());
277 assertEquals("relation:and", res.at("/query/attr/relation").asText());
278 operands = Lists.newArrayList( res.at("/query/attr/operands").elements());
279 assertEquals("korap:term", operands.get(0).at("/@type").asText());
280 assertEquals("class", operands.get(0).at("/key").asText());
281 assertEquals("header", operands.get(0).at("/value").asText());
282 assertEquals("match:ne", operands.get(0).at("/match").asText());
283 assertEquals("korap:term", operands.get(1).at("/@type").asText());
284 assertEquals("id", operands.get(1).at("/key").asText());
285 assertEquals(7, operands.get(1).at("/value").asInt());
286 assertEquals("match:ne", operands.get(1).at("/match").asText());
Joachim Bingel53333e62013-12-09 19:25:52 +0000287 }
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000288
Joachim Bingel87480d02014-01-17 14:07:46 +0000289 @Test
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000290 public void testDistances() throws QueryException, JsonProcessingException, IOException {
291 query = "[base=der][][base=Mann]";
292 qs.setQuery(query, "poliqarpplus");
293 res = mapper.readTree(qs.toJSON());
294 assertEquals("korap:group", res.at("/query/@type").asText());
295 assertEquals("operation:sequence", res.at("/query/operation").asText());
296 assertEquals("true", res.at("/query/inOrder").asText());
297 assertEquals("korap:distance", res.at("/query/distances").elements().next().at("/@type").asText());
298 assertEquals("w", res.at("/query/distances").elements().next().at("/key").asText());
299 assertEquals("korap:boundary", res.at("/query/distances").elements().next().at("/boundary/@type").asText());
300 assertEquals(2, res.at("/query/distances").elements().next().at("/boundary/min").asInt());
301 assertEquals(2, res.at("/query/distances").elements().next().at("/boundary/max").asInt());
302 operands = Lists.newArrayList(res.at("/query/operands").elements());
303 assertEquals("korap:token", operands.get(0).at("/@type").asText());
304 assertEquals("der", operands.get(0).at("/wrap/key").asText());
305 assertEquals("lemma", operands.get(0).at("/wrap/layer").asText());
306 assertEquals("match:eq", operands.get(0).at("/wrap/match").asText());
307 assertEquals("korap:token", operands.get(1).at("/@type").asText());
308 assertEquals("Mann", operands.get(1).at("/wrap/key").asText());
309 assertEquals("lemma", operands.get(1).at("/wrap/layer").asText());
310 assertEquals("match:eq", operands.get(1).at("/wrap/match").asText());
311
312 query = "[base=der][][][base=Mann]";
313 qs.setQuery(query, "poliqarpplus");
314 res = mapper.readTree(qs.toJSON());
315 assertEquals("korap:group", res.at("/query/@type").asText());
316 assertEquals("operation:sequence", res.at("/query/operation").asText());
317 assertEquals("true", res.at("/query/inOrder").asText());
318 assertEquals("korap:distance", res.at("/query/distances").elements().next().at("/@type").asText());
319 assertEquals("w", res.at("/query/distances").elements().next().at("/key").asText());
320 assertEquals("korap:boundary", res.at("/query/distances").elements().next().at("/boundary/@type").asText());
321 assertEquals(3, res.at("/query/distances").elements().next().at("/boundary/min").asInt());
322 assertEquals(3, res.at("/query/distances").elements().next().at("/boundary/max").asInt());
323 operands = Lists.newArrayList(res.at("/query/operands").elements());
324 assertEquals("korap:token", operands.get(0).at("/@type").asText());
325 assertEquals("der", operands.get(0).at("/wrap/key").asText());
326 assertEquals("lemma", operands.get(0).at("/wrap/layer").asText());
327 assertEquals("match:eq", operands.get(0).at("/wrap/match").asText());
328 assertEquals("korap:token", operands.get(1).at("/@type").asText());
329 assertEquals("Mann", operands.get(1).at("/wrap/key").asText());
330 assertEquals("lemma", operands.get(1).at("/wrap/layer").asText());
331 assertEquals("match:eq", operands.get(1).at("/wrap/match").asText());
332
333 query = "[base=der][][]?[base=Mann]";
334 qs.setQuery(query, "poliqarpplus");
335 res = mapper.readTree(qs.toJSON());
336 assertEquals("korap:group", res.at("/query/@type").asText());
337 assertEquals("operation:sequence", res.at("/query/operation").asText());
338 assertEquals("true", res.at("/query/inOrder").asText());
339 assertEquals("korap:distance", res.at("/query/distances").elements().next().at("/@type").asText());
340 assertEquals("w", res.at("/query/distances").elements().next().at("/key").asText());
341 assertEquals("korap:boundary", res.at("/query/distances").elements().next().at("/boundary/@type").asText());
342 assertEquals(2, res.at("/query/distances").elements().next().at("/boundary/min").asInt());
343 assertEquals(3, res.at("/query/distances").elements().next().at("/boundary/max").asInt());
344 operands = Lists.newArrayList(res.at("/query/operands").elements());
345 assertEquals("korap:token", operands.get(0).at("/@type").asText());
346 assertEquals("der", operands.get(0).at("/wrap/key").asText());
347 assertEquals("lemma", operands.get(0).at("/wrap/layer").asText());
348 assertEquals("match:eq", operands.get(0).at("/wrap/match").asText());
349 assertEquals("korap:token", operands.get(1).at("/@type").asText());
350 assertEquals("Mann", operands.get(1).at("/wrap/key").asText());
351 assertEquals("lemma", operands.get(1).at("/wrap/layer").asText());
352 assertEquals("match:eq", operands.get(1).at("/wrap/match").asText());
353
354 query = "[base=der][]+[base=Mann]";
355 qs.setQuery(query, "poliqarpplus");
356 res = mapper.readTree(qs.toJSON());
357 assertEquals("korap:group", res.at("/query/@type").asText());
358 assertEquals("operation:sequence", res.at("/query/operation").asText());
359 assertEquals("true", res.at("/query/inOrder").asText());
360 assertEquals("korap:distance", res.at("/query/distances").elements().next().at("/@type").asText());
361 assertEquals("w", res.at("/query/distances").elements().next().at("/key").asText());
362 assertEquals("korap:boundary", res.at("/query/distances").elements().next().at("/boundary/@type").asText());
363 assertEquals(2, res.at("/query/distances").elements().next().at("/boundary/min").asInt());
364 assertEquals(true, res.at("/query/distances").elements().next().at("/boundary/max").isMissingNode());
365 operands = Lists.newArrayList(res.at("/query/operands").elements());
366 assertEquals("korap:token", operands.get(0).at("/@type").asText());
367 assertEquals("der", operands.get(0).at("/wrap/key").asText());
368 assertEquals("lemma", operands.get(0).at("/wrap/layer").asText());
369 assertEquals("match:eq", operands.get(0).at("/wrap/match").asText());
370 assertEquals("korap:token", operands.get(1).at("/@type").asText());
371 assertEquals("Mann", operands.get(1).at("/wrap/key").asText());
372 assertEquals("lemma", operands.get(1).at("/wrap/layer").asText());
373 assertEquals("match:eq", operands.get(1).at("/wrap/match").asText());
374
375 query = "[base=der][]*[base=Mann]";
376 qs.setQuery(query, "poliqarpplus");
377 res = mapper.readTree(qs.toJSON());
378 assertEquals("korap:group", res.at("/query/@type").asText());
379 assertEquals("operation:sequence", res.at("/query/operation").asText());
380 assertEquals("true", res.at("/query/inOrder").asText());
381 assertEquals("korap:distance", res.at("/query/distances").elements().next().at("/@type").asText());
382 assertEquals("w", res.at("/query/distances").elements().next().at("/key").asText());
383 assertEquals("korap:boundary", res.at("/query/distances").elements().next().at("/boundary/@type").asText());
384 assertEquals(1, res.at("/query/distances").elements().next().at("/boundary/min").asInt());
385 assertEquals(true, res.at("/query/distances").elements().next().at("/boundary/max").isMissingNode());
386
387 query = "[base=der][]{2,5}[base=Mann][]?[][base=Frau]";
388 qs.setQuery(query, "poliqarpplus");
389 res = mapper.readTree(qs.toJSON());
390 assertEquals("korap:group", res.at("/query/@type").asText());
391 assertEquals("operation:sequence", res.at("/query/operation").asText());
392 assertEquals("true", res.at("/query/inOrder").asText());
393 assertEquals("korap:distance", res.at("/query/distances").elements().next().at("/@type").asText());
394 assertEquals("w", res.at("/query/distances").elements().next().at("/key").asText());
395 assertEquals("korap:boundary", res.at("/query/distances").elements().next().at("/boundary/@type").asText());
396 assertEquals(3, res.at("/query/distances").elements().next().at("/boundary/min").asInt());
397 assertEquals(6, res.at("/query/distances").elements().next().at("/boundary/max").asInt());
398 operands = Lists.newArrayList(res.at("/query/operands").elements());
399 assertEquals("korap:token", operands.get(0).at("/@type").asText());
400 assertEquals("der", operands.get(0).at("/wrap/key").asText());
401 assertEquals("lemma", operands.get(0).at("/wrap/layer").asText());
402 assertEquals("match:eq", operands.get(0).at("/wrap/match").asText());
403 assertEquals("korap:group", operands.get(1).at("/@type").asText());
404 assertEquals("operation:sequence", operands.get(1).at("/operation").asText());
405 assertEquals("korap:distance", operands.get(1).get("distances").elements().next().at("/@type").asText());
406 assertEquals("w", operands.get(1).get("distances").elements().next().at("/key").asText());
407 assertEquals("korap:boundary", operands.get(1).get("distances").elements().next().at("/boundary/@type").asText());
408 assertEquals(2, operands.get(1).get("distances").elements().next().at("/boundary/min").asInt());
409 assertEquals(3, operands.get(1).get("distances").elements().next().at("/boundary/max").asInt());
410 operands = Lists.newArrayList(operands.get(1).get("operands").elements());
411 assertEquals("Mann", operands.get(0).at("/wrap/key").asText());
412 assertEquals("lemma", operands.get(0).at("/wrap/layer").asText());
413 assertEquals("match:eq", operands.get(0).at("/wrap/match").asText());
414 assertEquals("Frau", operands.get(1).at("/wrap/key").asText());
415 assertEquals("lemma", operands.get(1).at("/wrap/layer").asText());
416 assertEquals("match:eq", operands.get(1).at("/wrap/match").asText());
417
Joachim Bingel14239d82014-07-22 09:55:04 +0000418 query = "[base=geht][base=der][]*contains(<s>,<np>)";
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000419 qs.setQuery(query, "poliqarpplus");
420 res = mapper.readTree(qs.toJSON());
421 assertEquals("korap:group", res.at("/query/@type").asText());
422 assertEquals("operation:sequence", res.at("/query/operation").asText());
423 assertEquals(true, res.at("/query/inOrder").isMissingNode());
424 assertEquals(true, res.at("/query/distances").isMissingNode());
425 operands = Lists.newArrayList(res.at("/query/operands").elements());
426 assertEquals("korap:token", operands.get(0).at("/@type").asText());
427 assertEquals("geht", operands.get(0).at("/wrap/key").asText());
428 assertEquals("lemma", operands.get(0).at("/wrap/layer").asText());
429 assertEquals("match:eq", operands.get(0).at("/wrap/match").asText());
430 assertEquals("korap:group", operands.get(1).at("/@type").asText());
431 assertEquals("operation:sequence", operands.get(1).at("/operation").asText());
432 assertEquals("korap:distance", operands.get(1).get("distances").elements().next().at("/@type").asText());
433 assertEquals("w", operands.get(1).get("distances").elements().next().at("/key").asText());
434 assertEquals("korap:boundary", operands.get(1).get("distances").elements().next().at("/boundary/@type").asText());
435 assertEquals(1, operands.get(1).get("distances").elements().next().at("/boundary/min").asInt());
436 assertEquals(true, operands.get(1).get("distances").elements().next().at("/boundary/max").isMissingNode());
437 operands = Lists.newArrayList(operands.get(1).get("operands").elements());
438 assertEquals("der", operands.get(0).at("/wrap/key").asText());
439 assertEquals("lemma", operands.get(0).at("/wrap/layer").asText());
440 assertEquals("match:eq", operands.get(0).at("/wrap/match").asText());
441 assertEquals("korap:group", operands.get(1).at("/@type").asText());
442 assertEquals("operation:position", operands.get(1).at("/operation").asText());
Joachim Bingel87480d02014-01-17 14:07:46 +0000443 }
Joachim Bingel53333e62013-12-09 19:25:52 +0000444
445 @Test
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000446 public void testDistancesWithClass() throws QueryException, JsonProcessingException, IOException {
447 query = "[base=der]{[]}[base=Mann]";
448 qs.setQuery(query, "poliqarpplus");
449 res = mapper.readTree(qs.toJSON());
450 assertEquals("korap:group", res.at("/query/@type").asText());
451 assertEquals("operation:sequence", res.at("/query/operation").asText());
452 assertEquals(true, res.at("/query/inOrder").isMissingNode());
453 assertEquals(true, res.at("/query/distances").isMissingNode());
454 operands = Lists.newArrayList(res.at("/query/operands").elements());
455 assertEquals("der", operands.get(0).at("/wrap/key").asText());
456 assertEquals("Mann", operands.get(2).at("/wrap/key").asText());
457 assertEquals("korap:group", operands.get(1).at("/@type").asText());
458 assertEquals("operation:class", operands.get(1).at("/operation").asText());
459 assertEquals(1, operands.get(1).at("/classOut").asInt());
460 operands = Lists.newArrayList(operands.get(1).at("/operands").elements());
461 assertEquals("korap:token", operands.get(0).at("/@type").asText());
462 assertEquals(true, operands.get(0).at("/wrap").isMissingNode());
463
464 query = "[base=der]{2:[]}[base=Mann]";
465 qs.setQuery(query, "poliqarpplus");
466 res = mapper.readTree(qs.toJSON());
467 operands = Lists.newArrayList(res.at("/query/operands").elements());
468 assertEquals("operation:class", operands.get(1).at("/operation").asText());
469 assertEquals(2, operands.get(1).at("/classOut").asInt());
470
Joachim Bingelbd386362014-10-02 12:03:18 +0000471 query = "{1:[]}[base=der][base=Mann]";
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000472 qs.setQuery(query, "poliqarpplus");
473 res = mapper.readTree(qs.toJSON());
474 operands = Lists.newArrayList(res.at("/query/operands").elements());
475 assertEquals("operation:class", operands.get(0).at("/operation").asText());
476 assertEquals(1, operands.get(0).at("/classOut").asInt());
477
478 query = "{1:{2:der} {3:[]} Mann}";
479 qs.setQuery(query, "poliqarpplus");
480 res = mapper.readTree(qs.toJSON());
481 operands = Lists.newArrayList(res.at("/query/operands").elements());
482 assertEquals(1, operands.size()); // class operation may only have one operand (the sequence)
483 operands = Lists.newArrayList(operands.get(0).at("/operands").elements());
484 assertEquals(3, operands.size()); // the sequence has three operands ("der", "[]" and "Mann")
485
Joachim Bingelbd386362014-10-02 12:03:18 +0000486 }
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000487
Joachim Bingelbd386362014-10-02 12:03:18 +0000488 @Test
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000489 public void testLeadingTrailingEmptyTokens() throws QueryException, JsonProcessingException, IOException {
Joachim Bingel14239d82014-07-22 09:55:04 +0000490 query = "[][base=Mann]";
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000491 qs.setQuery(query, "poliqarpplus");
492 res = mapper.readTree(qs.toJSON());
493 operands = Lists.newArrayList(res.at("/query/operands").elements());
494 assertEquals("korap:token", operands.get(0).at("/@type").asText());
495 assertEquals(true, operands.get(0).at("/key").isMissingNode());
496
Joachim Bingel14239d82014-07-22 09:55:04 +0000497 query = "[][][base=Mann]";
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000498 qs.setQuery(query, "poliqarpplus");
499 res = mapper.readTree(qs.toJSON());
500 operands = Lists.newArrayList(res.at("/query/operands").elements());
501 assertEquals("korap:group", operands.get(0).at("/@type").asText());
502 assertEquals("operation:repetition",operands.get(0).at("/operation").asText());
503 assertEquals(2, operands.get(0).at("/boundary/min").asInt());
504 assertEquals(2, operands.get(0).at("/boundary/max").asInt());
505 operands = Lists.newArrayList(operands.get(0).at("/operands").elements());
506 assertEquals("korap:token", operands.get(0).at("/@type").asText());
507 assertEquals(true, operands.get(0).at("/key").isMissingNode());
Nils Diewald7d486c22013-12-13 16:32:18 +0000508
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000509 query = "startswith(<s>, [][base=Mann])";
510 qs.setQuery(query, "poliqarpplus");
511 res = mapper.readTree(qs.toJSON());
512 operands = Lists.newArrayList(res.at("/query/operands"));
513 operands = Lists.newArrayList(operands.get(1).at("/operands"));
514 assertEquals("korap:token", operands.get(0).at("/@type").asText());
515 assertEquals(true, operands.get(0).at("/key").isMissingNode());
516 }
Nils Diewald7d486c22013-12-13 16:32:18 +0000517
Joachim Bingel53333e62013-12-09 19:25:52 +0000518 @Test
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000519 public void testRepetition() throws QueryException, JsonProcessingException, IOException {
520 query = "der{3}";
521 qs.setQuery(query, "poliqarpplus");
522 res = mapper.readTree(qs.toJSON());
523 assertEquals("korap:group", res.at("/query/@type").asText());
524 assertEquals("operation:repetition", res.at("/query/operation").asText());
525 assertEquals("der", res.at("/query/operands/0/wrap/key").asText());
526 assertEquals(3, res.at("/query/boundary/min").asInt());
527 assertEquals(3, res.at("/query/boundary/max").asInt());
528
529 query = "der{,3}";
530 qs.setQuery(query, "poliqarpplus");
531 res = mapper.readTree(qs.toJSON());
532 assertEquals(0, res.at("/query/boundary/min").asInt());
533 assertEquals(3, res.at("/query/boundary/max").asInt());
534
535 query = "der{3,}";
536 qs.setQuery(query, "poliqarpplus");
537 res = mapper.readTree(qs.toJSON());
538 assertEquals(3, res.at("/query/boundary/min").asInt());
539 assertEquals(true, res.at("/query/boundary/max").isMissingNode());
540
541 query = "der{3,7}";
542 qs.setQuery(query, "poliqarpplus");
543 res = mapper.readTree(qs.toJSON());
544 assertEquals(3, res.at("/query/boundary/min").asInt());
545 assertEquals(7, res.at("/query/boundary/max").asInt());
546
547 query = "der*";
548 qs.setQuery(query, "poliqarpplus");
549 res = mapper.readTree(qs.toJSON());
550 assertEquals(0, res.at("/query/boundary/min").asInt());
551 assertEquals(true, res.at("/query/boundary/max").isMissingNode());
552
553 query = "der+";
554 qs.setQuery(query, "poliqarpplus");
555 res = mapper.readTree(qs.toJSON());
556 assertEquals(1, res.at("/query/boundary/min").asInt());
557 assertEquals(true, res.at("/query/boundary/max").isMissingNode());
558 };
559
Joachim Bingel53333e62013-12-09 19:25:52 +0000560 @Test
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000561 public void testGroupRepetition() throws QueryException, JsonProcessingException, IOException {
562 query = "contains(<s>, (der){3})";
563 qs.setQuery(query, "poliqarpplus");
564 res = mapper.readTree(qs.toJSON());
565 assertEquals("korap:group", res.at("/query/@type").asText());
566 assertEquals("operation:position", res.at("/query/operation").asText());
567 assertEquals("korap:span", res.at("/query/operands/0/@type").asText());
568 assertEquals("s", res.at("/query/operands/0/key").asText());
569 assertEquals("korap:group", res.at("/query/operands/1/@type").asText());
570 assertEquals("operation:repetition",res.at("/query/operands/1/operation").asText());
571
572 query = "contains(<s>, (der){3,})";
573 qs.setQuery(query, "poliqarpplus");
574 res = mapper.readTree(qs.toJSON());
575 assertEquals(3, res.at("/query/operands/1/boundary/min").asInt());
576 assertEquals(true, res.at("/query/operands/1/boundary/max").isMissingNode());
577
578 query = "contains(<s>, (der){,3})";
579 qs.setQuery(query, "poliqarpplus");
580 res = mapper.readTree(qs.toJSON());
581 assertEquals(0, res.at("/query/operands/1/boundary/min").asInt());
582 assertEquals(3, res.at("/query/operands/1/boundary/max").asInt());
583
584 query = "contains(<s>, (der){3,7})";
585 qs.setQuery(query, "poliqarpplus");
586 res = mapper.readTree(qs.toJSON());
587 assertEquals(3, res.at("/query/operands/1/boundary/min").asInt());
588 assertEquals(7, res.at("/query/operands/1/boundary/max").asInt());
589
590 query = "contains(<s>, (der)*)";
591 qs.setQuery(query, "poliqarpplus");
592 res = mapper.readTree(qs.toJSON());
593 assertEquals(0, res.at("/query/operands/1/boundary/min").asInt());
594 assertEquals(true, res.at("/query/operands/1/boundary/max").isMissingNode());
595 };
596
Joachim Bingel53333e62013-12-09 19:25:52 +0000597 @Test
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000598 public void testPositions() throws QueryException, JsonProcessingException, IOException {
599 query = "contains(<s>, der)";
600 qs.setQuery(query, "poliqarpplus");
601 res = mapper.readTree(qs.toJSON());
602 assertEquals("korap:group", res.at("/query/@type").asText());
603 assertEquals("operation:position", res.at("/query/operation").asText());
604 assertEquals("frames:contains", res.at("/query/frames/0").asText());
605 assertEquals(true, res.at("/query/frames/1").isMissingNode());
606 assertEquals("korap:span", res.at("/query/operands/0/@type").asText());
607 assertEquals("s", res.at("/query/operands/0/key").asText());
608 assertEquals("korap:token", res.at("/query/operands/1/@type").asText());
609
610 query = "contains(<s>,<np>)";
611 qs.setQuery(query, "poliqarpplus");
612 res = mapper.readTree(qs.toJSON());
613 assertEquals("s", res.at("/query/operands/0/key").asText());
614 assertEquals("np", res.at("/query/operands/1/key").asText());
615
616 query = "contains(<s>,[orth=der][orth=Mann])";
617 qs.setQuery(query, "poliqarpplus");
618 res = mapper.readTree(qs.toJSON());
619 assertEquals("korap:group", res.at("/query/@type").asText());
620 assertEquals("operation:position", res.at("/query/operation").asText());
621 assertEquals("frames:contains", res.at("/query/frames/0").asText());
622 assertEquals("s", res.at("/query/operands/0/key").asText());
623 assertEquals("korap:group", res.at("/query/operands/1/@type").asText());
624 assertEquals("operation:sequence", res.at("/query/operands/1/operation").asText());
625 assertEquals("der", res.at("/query/operands/1/operands/0/wrap/key").asText());
626 assertEquals("Mann", res.at("/query/operands/1/operands/1/wrap/key").asText());
627
628 query = "contains(<s>,[orth=der][orth=Mann]*)";
629 qs.setQuery(query, "poliqarpplus");
630 res = mapper.readTree(qs.toJSON());
631 assertEquals("korap:group", res.at("/query/@type").asText());
632 assertEquals("operation:position", res.at("/query/operation").asText());
633 assertEquals("frames:contains", res.at("/query/frames/0").asText());
634 assertEquals("s", res.at("/query/operands/0/key").asText());
635 assertEquals("korap:group", res.at("/query/operands/1/@type").asText());
636 assertEquals("operation:sequence", res.at("/query/operands/1/operation").asText());
637 assertEquals("der", res.at("/query/operands/1/operands/0/wrap/key").asText());
638 assertEquals("operation:repetition", res.at("/query/operands/1/operands/1/operation").asText());
639 assertEquals(0, res.at("/query/operands/1/operands/1/boundary/min").asInt());
640 assertEquals(true, res.at("/query/operands/1/operands/1/boundary/max").isMissingNode());
641 assertEquals("Mann", res.at("/query/operands/1/operands/1/operands/0/wrap/key").asText());
642
643 query = "contains(<s>,startswith(<np>,<pp>))";
644 qs.setQuery(query, "poliqarpplus");
645 res = mapper.readTree(qs.toJSON());
646 assertEquals("s", res.at("/query/operands/0/key").asText());
647 assertEquals("korap:group", res.at("/query/operands/1/@type").asText());
648 assertEquals("frames:startswith", res.at("/query/operands/1/frames/0").asText());
649 assertEquals("operation:position", res.at("/query/operands/1/operation").asText());
650 assertEquals("np", res.at("/query/operands/1/operands/0/key").asText());
651 assertEquals("pp", res.at("/query/operands/1/operands/1/key").asText());
652
653 query = "[base=Auto]overlaps(<s>, der)";
654 qs.setQuery(query, "poliqarpplus");
655 res = mapper.readTree(qs.toJSON());
656 assertEquals("korap:group", res.at("/query/@type").asText());
657 assertEquals("operation:sequence", res.at("/query/operation").asText());
658 assertEquals("korap:group", res.at("/query/operands/1/@type").asText());
659 assertEquals("operation:position", res.at("/query/operands/1/operation").asText());
660 assertEquals("frames:overlapsLeft", res.at("/query/operands/1/frames/0").asText());
661 assertEquals("frames:overlapsRight", res.at("/query/operands/1/frames/1").asText());
662 assertEquals("korap:span", res.at("/query/operands/1/operands/0/@type").asText());
663 assertEquals("s", res.at("/query/operands/1/operands/0/key").asText());
664 assertEquals("korap:token", res.at("/query/operands/1/operands/1/@type").asText());
665
666 query = "[base=Auto] overlaps(<s>, der)";
667 qs.setQuery(query, "poliqarpplus");
668 res = mapper.readTree(qs.toJSON());
669 assertEquals("korap:group", res.at("/query/@type").asText());
670 assertEquals("operation:sequence", res.at("/query/operation").asText());
671 assertEquals("korap:group", res.at("/query/operands/1/@type").asText());
672 assertEquals("operation:position", res.at("/query/operands/1/operation").asText());
673 assertEquals("frames:overlapsLeft", res.at("/query/operands/1/frames/0").asText());
674 assertEquals("frames:overlapsRight", res.at("/query/operands/1/frames/1").asText());
675 assertEquals("korap:span", res.at("/query/operands/1/operands/0/@type").asText());
676 assertEquals("s", res.at("/query/operands/1/operands/0/key").asText());
677 assertEquals("korap:token", res.at("/query/operands/1/operands/1/@type").asText());
678 };
679
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000680 @Test
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000681 public void testCoordinatedFields() throws QueryException, JsonProcessingException, IOException {
682 query = "[base=Mann&(cas=N|cas=A)]";
683 qs.setQuery(query, "poliqarpplus");
684 res = mapper.readTree(qs.toJSON());
685 assertEquals("korap:token", res.at("/query/@type").asText());
686 assertEquals("relation:and", res.at("/query/wrap/relation").asText());
687 assertEquals("Mann", res.at("/query/wrap/operands/0/key").asText());
688 assertEquals("lemma", res.at("/query/wrap/operands/0/layer").asText());
689 assertEquals("korap:termGroup", res.at("/query/wrap/operands/1/@type").asText());
690 assertEquals("relation:or", res.at("/query/wrap/operands/1/relation").asText());
691 assertEquals("N", res.at("/query/wrap/operands/1/operands/0/key").asText());
692 assertEquals("cas", res.at("/query/wrap/operands/1/operands/0/layer").asText());
693 assertEquals("A", res.at("/query/wrap/operands/1/operands/1/key").asText());
694 assertEquals("cas", res.at("/query/wrap/operands/1/operands/1/layer").asText());
695
696 query = "[base=Mann&cas=N&gen=m]";
697 qs.setQuery(query, "poliqarpplus");
698 res = mapper.readTree(qs.toJSON());
699 assertEquals("korap:token", res.at("/query/@type").asText());
700 assertEquals("relation:and", res.at("/query/wrap/relation").asText());
701 assertEquals("Mann", res.at("/query/wrap/operands/0/key").asText());
702 assertEquals("lemma", res.at("/query/wrap/operands/0/layer").asText());
703 assertEquals("korap:termGroup", res.at("/query/wrap/operands/1/@type").asText());
704 assertEquals("relation:and", res.at("/query/wrap/operands/1/relation").asText());
705 assertEquals("N", res.at("/query/wrap/operands/1/operands/0/key").asText());
706 assertEquals("cas", res.at("/query/wrap/operands/1/operands/0/layer").asText());
707 assertEquals("m", res.at("/query/wrap/operands/1/operands/1/key").asText());
708 assertEquals("gen", res.at("/query/wrap/operands/1/operands/1/layer").asText());
Joachim Bingel53333e62013-12-09 19:25:52 +0000709 }
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000710
Joachim Bingel53333e62013-12-09 19:25:52 +0000711 @Test
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000712 public void testTokenSequence() throws QueryException, JsonProcessingException, IOException {
713 query = "[base=Mann][orth=Frau]";
714 qs.setQuery(query, "poliqarpplus");
715 res = mapper.readTree(qs.toJSON());
716 assertEquals("korap:group", res.at("/query/@type").asText());
717 assertEquals("operation:sequence", res.at("/query/operation").asText());
718 assertEquals("Mann", res.at("/query/operands/0/wrap/key").asText());
719 assertEquals("lemma", res.at("/query/operands/0/wrap/layer").asText());
720 assertEquals("Frau", res.at("/query/operands/1/wrap/key").asText());
721 assertEquals("orth", res.at("/query/operands/1/wrap/layer").asText());
722
723 query = "[base=Mann][orth=Frau][p=NN]";
724 qs.setQuery(query, "poliqarpplus");
725 res = mapper.readTree(qs.toJSON());
726 assertEquals("NN", res.at("/query/operands/2/wrap/key").asText());
727 assertEquals("p", res.at("/query/operands/2/wrap/layer").asText());
728
729 query = "[base=Mann][orth=Frau][p=NN][foo=bar]";
730 qs.setQuery(query, "poliqarpplus");
731 res = mapper.readTree(qs.toJSON());
732 assertEquals("bar", res.at("/query/operands/3/wrap/key").asText());
733 assertEquals("foo", res.at("/query/operands/3/wrap/layer").asText());
Joachim Bingel53333e62013-12-09 19:25:52 +0000734 }
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000735
736 @Test
737 public void testDisjSegments() throws QueryException, JsonProcessingException, IOException {
738 query = "[base=der]|[base=das]";
739 qs.setQuery(query, "poliqarpplus");
740 res = mapper.readTree(qs.toJSON());
741 assertEquals("korap:group", res.at("/query/@type").asText());
742 assertEquals("operation:or", res.at("/query/operation").asText());
743 assertEquals("korap:token", res.at("/query/operands/0/@type").asText());
744 assertEquals("korap:token", res.at("/query/operands/1/@type").asText());
745 assertEquals("der", res.at("/query/operands/0/wrap/key").asText());
746 assertEquals("lemma", res.at("/query/operands/0/wrap/layer").asText());
747 assertEquals("das", res.at("/query/operands/1/wrap/key").asText());
748 assertEquals("lemma", res.at("/query/operands/1/wrap/layer").asText());
749
750 query = "([base=der]|[base=das])[base=Schild]";
751 qs.setQuery(query, "poliqarpplus");
752 res = mapper.readTree(qs.toJSON());
753 assertEquals("korap:group", res.at("/query/@type").asText());
754 assertEquals("operation:sequence", res.at("/query/operation").asText());
755 assertEquals("Schild", res.at("/query/operands/1/wrap/key").asText());
756 assertEquals("korap:group", res.at("/query/operands/0/@type").asText());
757 assertEquals("operation:or", res.at("/query/operands/0/operation").asText());
758
759 query = "[base=Schild]([base=der]|[base=das])";
760 qs.setQuery(query, "poliqarpplus");
761 res = mapper.readTree(qs.toJSON());
762 assertEquals("Schild", res.at("/query/operands/0/wrap/key").asText());
763 assertEquals("korap:group", res.at("/query/operands/1/@type").asText());
764 assertEquals("operation:or", res.at("/query/operands/1/operation").asText());
765
766 query = "([orth=der][base=katze])|([orth=eine][base=baum])";
767 qs.setQuery(query, "poliqarpplus");
768 res = mapper.readTree(qs.toJSON());
769 assertEquals("korap:group", res.at("/query/@type").asText());
770 assertEquals("operation:or", res.at("/query/operation").asText());
771 assertEquals("korap:group", res.at("/query/operands/0/@type").asText());
772 assertEquals("operation:sequence", res.at("/query/operands/0/operation").asText());
773 assertEquals("korap:token", res.at("/query/operands/0/operands/0/@type").asText());
774 assertEquals("der", res.at("/query/operands/0/operands/0/wrap/key").asText());
775 assertEquals("katze", res.at("/query/operands/0/operands/1/wrap/key").asText());
776 assertEquals("eine", res.at("/query/operands/1/operands/0/wrap/key").asText());
777 assertEquals("baum", res.at("/query/operands/1/operands/1/wrap/key").asText());
778
779 query = "[orth=der][base=katze]|[orth=eine][base=baum]";
780 qs.setQuery(query, "poliqarpplus");
781 res = mapper.readTree(qs.toJSON());
782 assertEquals("korap:group", res.at("/query/@type").asText());
783 assertEquals("operation:or", res.at("/query/operation").asText());
784 assertEquals("korap:group", res.at("/query/operands/0/@type").asText());
785 assertEquals("operation:sequence", res.at("/query/operands/0/operation").asText());
786 assertEquals("korap:token", res.at("/query/operands/0/operands/0/@type").asText());
787 assertEquals("der", res.at("/query/operands/0/operands/0/wrap/key").asText());
788 assertEquals("katze", res.at("/query/operands/0/operands/1/wrap/key").asText());
789 assertEquals("eine", res.at("/query/operands/1/operands/0/wrap/key").asText());
790 assertEquals("baum", res.at("/query/operands/1/operands/1/wrap/key").asText());
791
792 query = "[orth=der]([base=katze]|[orth=eine])[base=baum]";
793 qs.setQuery(query, "poliqarpplus");
794 res = mapper.readTree(qs.toJSON());
795 assertEquals("korap:group", res.at("/query/@type").asText());
796 assertEquals("operation:sequence", res.at("/query/operation").asText());
797 assertEquals("korap:group", res.at("/query/operands/1/@type").asText());
798 assertEquals("operation:or", res.at("/query/operands/1/operation").asText());
799 assertEquals("korap:token", res.at("/query/operands/0/@type").asText());
800 assertEquals("korap:token", res.at("/query/operands/2/@type").asText());
801 assertEquals("der", res.at("/query/operands/0/wrap/key").asText());
802 assertEquals("katze", res.at("/query/operands/1/operands/0/wrap/key").asText());
803 assertEquals("eine", res.at("/query/operands/1/operands/1/wrap/key").asText());
804 assertEquals("baum", res.at("/query/operands/2/wrap/key").asText());
805
806 query = "[orth=der][base=katze]|[orth=der][base=hund]|[orth=der][base=baum]";
807 qs.setQuery(query, "poliqarpplus");
808 res = mapper.readTree(qs.toJSON());
809 assertEquals("der", res.at("/query/operands/2/operands/0/wrap/key").asText());
810 assertEquals("baum", res.at("/query/operands/2/operands/1/wrap/key").asText());
811
812 query = "[orth=der]([base=katze]|[base=hund]|[base=baum])";
813 qs.setQuery(query, "poliqarpplus");
814 res = mapper.readTree(qs.toJSON());
815 assertEquals("korap:group", res.at("/query/@type").asText());
816 assertEquals("operation:sequence", res.at("/query/operation").asText());
817 assertEquals("korap:group", res.at("/query/operands/1/@type").asText());
818 assertEquals("operation:or", res.at("/query/operands/1/operation").asText());
819 assertEquals("korap:token", res.at("/query/operands/0/@type").asText());
820 assertEquals("korap:token", res.at("/query/operands/1/operands/0/@type").asText());
821 assertEquals("korap:token", res.at("/query/operands/1/operands/1/@type").asText());
822 assertEquals("korap:token", res.at("/query/operands/1/operands/2/@type").asText());
823 assertEquals("katze", res.at("/query/operands/1/operands/0/wrap/key").asText());
824 assertEquals("hund", res.at("/query/operands/1/operands/1/wrap/key").asText());
825 assertEquals("baum", res.at("/query/operands/1/operands/2/wrap/key").asText());
826 }
827
828 @Test
829 public void testTokenSpanSequence() throws QueryException, JsonProcessingException, IOException {
830 query = "[base=Mann]<vp>";
831 qs.setQuery(query, "poliqarpplus");
832 res = mapper.readTree(qs.toJSON());
833 assertEquals("korap:group", res.at("/query/@type").asText());
834 assertEquals("operation:sequence", res.at("/query/operation").asText());
835 assertEquals("korap:token", res.at("/query/operands/0/@type").asText());
836 assertEquals("Mann", res.at("/query/operands/0/wrap/key").asText());
837 assertEquals("korap:span", res.at("/query/operands/1/@type").asText());
838 assertEquals("vp", res.at("/query/operands/1/key").asText());
839
840 query = "<vp>[base=Mann]";
841 qs.setQuery(query, "poliqarpplus");
842 res = mapper.readTree(qs.toJSON());
843 assertEquals("korap:group", res.at("/query/@type").asText());
844 assertEquals("operation:sequence", res.at("/query/operation").asText());
845 assertEquals("korap:span", res.at("/query/operands/0/@type").asText());
846 assertEquals("vp", res.at("/query/operands/0/key").asText());
847 assertEquals("korap:token", res.at("/query/operands/1/@type").asText());
848 assertEquals("Mann", res.at("/query/operands/1/wrap/key").asText());
849
850 query = "<vp>[base=Mann]<pp>";
851 qs.setQuery(query, "poliqarpplus");
852 res = mapper.readTree(qs.toJSON());
853 assertEquals("korap:span", res.at("/query/operands/2/@type").asText());
854 assertEquals("pp", res.at("/query/operands/2/key").asText());
855
856 query = "<vp>[base=Mann]<pp><np>";
857 qs.setQuery(query, "poliqarpplus");
858 res = mapper.readTree(qs.toJSON());
859 assertEquals("pp", res.at("/query/operands/2/key").asText());
860 assertEquals("np", res.at("/query/operands/3/key").asText());
861 }
862
Joachim Bingel53333e62013-12-09 19:25:52 +0000863 @Test
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000864 public void testClasses() throws QueryException, JsonProcessingException, IOException {
865 query = "{[base=Mann]}";
866 qs.setQuery(query, "poliqarpplus");
867 res = mapper.readTree(qs.toJSON());
868 assertEquals("korap:group", res.at("/query/@type").asText());
869 assertEquals("operation:class", res.at("/query/operation").asText());
870 assertEquals(1, res.at("/query/classOut").asInt());
871 assertEquals(true, res.at("/query/classIn").isMissingNode());
872 assertEquals("Mann", res.at("/query/operands/0/wrap/key").asText());
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000873
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000874 query = "{[base=Mann][orth=Frau]}";
875 qs.setQuery(query, "poliqarpplus");
876 res = mapper.readTree(qs.toJSON());
877 assertEquals("korap:group", res.at("/query/@type").asText());
878 assertEquals("operation:class", res.at("/query/operation").asText());
879 assertEquals(1, res.at("/query/classOut").asInt());
880 assertEquals(true, res.at("/query/classIn").isMissingNode());
881 assertEquals("Mann", res.at("/query/operands/0/operands/0/wrap/key").asText());
882 assertEquals("Frau", res.at("/query/operands/0/operands/1/wrap/key").asText());
883
884 query = "[p=NN]{[base=Mann][orth=Frau]}";
885 qs.setQuery(query, "poliqarpplus");
886 res = mapper.readTree(qs.toJSON());
887 assertEquals("korap:group", res.at("/query/@type").asText());
888 assertEquals("operation:sequence", res.at("/query/operation").asText());
889 assertEquals("korap:group", res.at("/query/operands/1/@type").asText());
890 assertEquals("operation:class", res.at("/query/operands/1/operation").asText());
891 assertEquals(1, res.at("/query/operands/1/classOut").asInt());
892 assertEquals(true, res.at("/query/operands/1/classIn").isMissingNode());
893 assertEquals("Mann", res.at("/query/operands/1/operands/0/operands/0/wrap/key").asText());
894 assertEquals("Frau", res.at("/query/operands/1/operands/0/operands/1/wrap/key").asText());
895
896 query = "{[base=Mann][orth=Frau]}[p=NN]";
897 qs.setQuery(query, "poliqarpplus");
898 res = mapper.readTree(qs.toJSON());
899 assertEquals("korap:group", res.at("/query/@type").asText());
900 assertEquals("operation:sequence", res.at("/query/operation").asText());
901 assertEquals("korap:group", res.at("/query/operands/0/@type").asText());
902 assertEquals("operation:class", res.at("/query/operands/0/operation").asText());
903 assertEquals(1, res.at("/query/operands/0/classOut").asInt());
904 assertEquals(true, res.at("/query/operands/0/classIn").isMissingNode());
905 assertEquals("Mann", res.at("/query/operands/0/operands/0/operands/0/wrap/key").asText());
906 assertEquals("Frau", res.at("/query/operands/0/operands/0/operands/1/wrap/key").asText());
907
908 query = "{2:{1:[tt/p=ADJA]}[mate/p=NN]}";
909 qs.setQuery(query, "poliqarpplus");
910 res = mapper.readTree(qs.toJSON());
911 assertEquals("korap:group", res.at("/query/@type").asText());
912 assertEquals("operation:class", res.at("/query/operation").asText());
913 assertEquals("operation:sequence", res.at("/query/operands/0/operation").asText());
914 assertEquals(2, res.at("/query/classOut").asInt());
915 assertEquals(1, res.at("/query/operands/0/operands/0/classOut").asInt());
916 }
917
918 @Test
919 public void testFocusSplit() throws QueryException, JsonProcessingException, IOException {
920 query = "focus([orth=Der]{[orth=Mann]})";
921 qs.setQuery(query, "poliqarpplus");
922 res = mapper.readTree(qs.toJSON());
923 assertEquals("korap:reference", res.at("/query/@type").asText());
924 assertEquals("operation:focus", res.at("/query/operation").asText());
925 assertEquals(1, res.at("/query/classRef/0").asInt());
926 assertEquals("operation:sequence", res.at("/query/operands/0/operation").asText());
927 assertEquals("operation:class", res.at("/query/operands/0/operands/1/operation").asText());
928 assertEquals(1, res.at("/query/operands/0/operands/1/classOut").asInt());
929 assertEquals("Mann", res.at("/query/operands/0/operands/1/operands/0/wrap/key").asText());
930
931 query = "focus([orth=Der]{[orth=Mann][orth=geht]})";
932 qs.setQuery(query, "poliqarpplus");
933 res = mapper.readTree(qs.toJSON());
934 assertEquals("operation:sequence", res.at("/query/operands/0/operands/1/operands/0/operation").asText());
935 assertEquals("Mann", res.at("/query/operands/0/operands/1/operands/0/operands/0/wrap/key").asText());
936 assertEquals("geht", res.at("/query/operands/0/operands/1/operands/0/operands/1/wrap/key").asText());
937
938 query = "focus(2:[orth=Der]{2:[orth=Mann][orth=geht]})";
939 qs.setQuery(query, "poliqarpplus");
940 res = mapper.readTree(qs.toJSON());
941 assertEquals(2, res.at("/query/classRef/0").asInt());
942 assertEquals(2, res.at("/query/operands/0/operands/1/classOut").asInt());
943
944 query = "focus(3:startswith(<s>,{3:<np>}))";
945 qs.setQuery(query, "poliqarpplus");
946 res = mapper.readTree(qs.toJSON());
947 assertEquals(3, res.at("/query/classRef/0").asInt());
948 assertEquals("korap:reference", res.at("/query/@type").asText());
949 assertEquals("operation:focus", res.at("/query/operation").asText());
950 assertEquals("operation:position", res.at("/query/operands/0/operation").asText());
951 assertEquals("operation:class", res.at("/query/operands/0/operands/1/operation").asText());
952 assertEquals(3, res.at("/query/operands/0/operands/1/classOut").asInt());
953 assertEquals("frames:startswith", res.at("/query/operands/0/frames/0").asText());
954
955 query = "focus(1000:startswith(<s>,{1000:<np>}))";
956 qs.setQuery(query, "poliqarpplus");
957 res = mapper.readTree(qs.toJSON());
958 assertEquals(127, res.at("/query/classRef/0").asInt());
959 assertEquals(127, res.at("/query/operands/0/operands/1/classOut").asInt());
960
961 query = "focus(3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))";
962 qs.setQuery(query, "poliqarpplus");
963 res = mapper.readTree(qs.toJSON());
964 assertEquals(3, res.at("/query/classRef/0").asInt());
965 assertEquals("korap:reference", res.at("/query/@type").asText());
966 assertEquals("operation:focus", res.at("/query/operation").asText());
967 assertEquals("operation:position", res.at("/query/operands/0/operation").asText());
968 assertEquals("frames:startswith", res.at("/query/operands/0/frames/0").asText());
969 assertEquals("operation:class", res.at("/query/operands/0/operands/1/operation").asText());
970 assertEquals(3, res.at("/query/operands/0/operands/1/classOut").asInt());
971 assertEquals("operation:sequence", res.at("/query/operands/0/operands/1/operands/0/operation").asText());
972 assertEquals("operation:class", res.at("/query/operands/0/operands/1/operands/0/operands/1/operation").asText());
973 assertEquals(1, res.at("/query/operands/0/operands/1/operands/0/operands/1/classOut").asInt());
974 assertEquals("operation:sequence", res.at("/query/operands/0/operands/1/operands/0/operands/1/operands/0/operation").asText());
975 assertEquals("operation:class", res.at("/query/operands/0/operands/1/operands/0/operands/1/operands/0/operands/1/operation").asText());
976 assertEquals(2, res.at("/query/operands/0/operands/1/operands/0/operands/1/operands/0/operands/1/classOut").asInt());
977
978 query = "split(3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))";
979 qs.setQuery(query, "poliqarpplus");
980 res = mapper.readTree(qs.toJSON());
981 assertEquals(3, res.at("/query/classRef/0").asInt());
982 assertEquals(true, res.at("/query/classRef/1").isMissingNode());
983 assertEquals("korap:reference", res.at("/query/@type").asText());
984 assertEquals("operation:split", res.at("/query/operation").asText());
985
986 query = "split(2|3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))";
987 qs.setQuery(query, "poliqarpplus");
988 res = mapper.readTree(qs.toJSON());
989 assertEquals(2, res.at("/query/classRef/0").asInt());
990 assertEquals(3, res.at("/query/classRef/1").asInt());
991 assertEquals("classRefOp:intersection", res.at("/query/classRefOp").asText());
992 assertEquals("korap:reference", res.at("/query/@type").asText());
993 assertEquals("operation:split", res.at("/query/operation").asText());
994
995 query = "focus(1:{[base=der]}{1:[pos=ADJA]})";
996 qs.setQuery(query, "poliqarpplus");
997 res = mapper.readTree(qs.toJSON());
998 assertEquals(1, res.at("/query/classRef/0").asInt());
999 assertEquals(1, res.at("/query/operands/0/operands/0/classOut").asInt());
1000 assertEquals(1, res.at("/query/operands/0/operands/1/classOut").asInt());
Joachim Bingel53333e62013-12-09 19:25:52 +00001001 }
1002
1003 @Test
Joachim Bingel7cc5f352014-12-03 09:40:04 +00001004 public void testSubmatch() throws QueryException, JsonProcessingException, IOException {
Joachim Bingel9bbd4fc2014-08-11 14:56:48 +00001005 query = "submatch(1,:<s>)";
Joachim Bingel7cc5f352014-12-03 09:40:04 +00001006 qs.setQuery(query, "poliqarpplus");
1007 res = mapper.readTree(qs.toJSON());
1008 assertEquals("korap:reference", res.at("/query/@type").asText());
1009 assertEquals("operation:focus", res.at("/query/operation").asText());
1010 assertEquals(1, res.at("/query/spanRef/0").asInt());
1011 assertEquals(true, res.at("/query/spanRef/1").isMissingNode());
1012 assertEquals("s", res.at("/query/operands/0/key").asText());
1013
Joachim Bingel9bbd4fc2014-08-11 14:56:48 +00001014 query = "submatch(1,4:<s>)";
Joachim Bingel7cc5f352014-12-03 09:40:04 +00001015 qs.setQuery(query, "poliqarpplus");
1016 res = mapper.readTree(qs.toJSON());
1017 assertEquals("korap:reference", res.at("/query/@type").asText());
1018 assertEquals("operation:focus", res.at("/query/operation").asText());
1019 assertEquals(1, res.at("/query/spanRef/0").asInt());
1020 assertEquals(4, res.at("/query/spanRef/1").asInt());
Joachim Bingel23c31ad2014-08-11 09:44:46 +00001021
Joachim Bingel9bbd4fc2014-08-11 14:56:48 +00001022 query = "submatch(1,4:contains(<s>,[base=Haus]))";
Joachim Bingel7cc5f352014-12-03 09:40:04 +00001023 qs.setQuery(query, "poliqarpplus");
1024 res = mapper.readTree(qs.toJSON());
1025 assertEquals("korap:reference", res.at("/query/@type").asText());
1026 assertEquals("operation:focus", res.at("/query/operation").asText());
1027 assertEquals(1, res.at("/query/spanRef/0").asInt());
1028 assertEquals(4, res.at("/query/spanRef/1").asInt());
1029 assertEquals("frames:contains", res.at("/query/operands/0/frames/0").asText());
1030 assertEquals("s", res.at("/query/operands/0/operands/0/key").asText());
1031 assertEquals("Haus", res.at("/query/operands/0/operands/1/wrap/key").asText());
Joachim Bingel23c31ad2014-08-11 09:44:46 +00001032 }
Joachim Bingel23c31ad2014-08-11 09:44:46 +00001033 @Test
Joachim Bingel7cc5f352014-12-03 09:40:04 +00001034 public void testRelations() throws QueryException, JsonProcessingException, IOException {
Joachim Bingel23c31ad2014-08-11 09:44:46 +00001035 query = "relatesTo(<s>,<np>)";
Joachim Bingel7cc5f352014-12-03 09:40:04 +00001036 qs.setQuery(query, "poliqarpplus");
1037 res = mapper.readTree(qs.toJSON());
1038 assertEquals("korap:group", res.at("/query/@type").asText());
1039 assertEquals("operation:relation", res.at("/query/operation").asText());
1040 assertEquals("korap:relation", res.at("/query/relation/@type").asText());
1041 assertEquals("s", res.at("/query/operands/0/key").asText());
1042 assertEquals("np", res.at("/query/operands/1/key").asText());
Joachim Bingel23c31ad2014-08-11 09:44:46 +00001043
1044 query = "relatesTo([base=Baum],<np>)";
Joachim Bingel7cc5f352014-12-03 09:40:04 +00001045 qs.setQuery(query, "poliqarpplus");
1046 res = mapper.readTree(qs.toJSON());
1047 assertEquals("korap:group", res.at("/query/@type").asText());
1048 assertEquals("operation:relation", res.at("/query/operation").asText());
1049 assertEquals("korap:relation", res.at("/query/relation/@type").asText());
1050 assertEquals("Baum", res.at("/query/operands/0/wrap/key").asText());
1051 assertEquals("np", res.at("/query/operands/1/key").asText());
Joachim Bingel23c31ad2014-08-11 09:44:46 +00001052
Joachim Bingel7cc5f352014-12-03 09:40:04 +00001053 query = "relatesTo(Baum,<np>)";
1054 qs.setQuery(query, "poliqarpplus");
1055 res = mapper.readTree(qs.toJSON());
1056 assertEquals("orth", res.at("/query/operands/0/wrap/layer").asText());
1057 assertEquals("Baum", res.at("/query/operands/0/wrap/key").asText());
Joachim Bingel23c31ad2014-08-11 09:44:46 +00001058
1059 query = "relatesTo(mate/d=HEAD:<np>,[base=Baum])";
Joachim Bingel7cc5f352014-12-03 09:40:04 +00001060 qs.setQuery(query, "poliqarpplus");
1061 res = mapper.readTree(qs.toJSON());
1062 assertEquals("lemma", res.at("/query/operands/1/wrap/layer").asText());
1063 assertEquals("Baum", res.at("/query/operands/1/wrap/key").asText());
1064 assertEquals("korap:relation", res.at("/query/relation/@type").asText());
1065 assertEquals("mate", res.at("/query/relation/foundry").asText());
1066 assertEquals("d", res.at("/query/relation/layer").asText());
1067 assertEquals("HEAD", res.at("/query/relation/key").asText());
Joachim Bingel23c31ad2014-08-11 09:44:46 +00001068
Joachim Bingel7cc5f352014-12-03 09:40:04 +00001069 query = "dominates(Baum,<np>)";
1070 qs.setQuery(query, "poliqarpplus");
1071 res = mapper.readTree(qs.toJSON());
1072 assertEquals("orth", res.at("/query/operands/0/wrap/layer").asText());
1073 assertEquals("Baum", res.at("/query/operands/0/wrap/key").asText());
1074 assertEquals("korap:relation", res.at("/query/relation/@type").asText());
1075 assertEquals("c", res.at("/query/relation/layer").asText());
Joachim Bingel53333e62013-12-09 19:25:52 +00001076
Joachim Bingel7cc5f352014-12-03 09:40:04 +00001077 query = "dominates(cnx/c:<vp>,<np>)";
1078 qs.setQuery(query, "poliqarpplus");
1079 res = mapper.readTree(qs.toJSON());
1080 assertEquals("cnx", res.at("/query/relation/foundry").asText());
1081 assertEquals("c", res.at("/query/relation/layer").asText());
1082
1083 query = "dominates(cnx/c*:<vp>,<np>)";
1084 qs.setQuery(query, "poliqarpplus");
1085 res = mapper.readTree(qs.toJSON());
1086 assertEquals("cnx", res.at("/query/relation/foundry").asText());
1087 assertEquals("c", res.at("/query/relation/layer").asText());
1088 assertEquals(0, res.at("/query/relation/boundary/min").asInt());
1089 assertEquals(true, res.at("/query/relation/boundary/max").isMissingNode());
1090
1091 query = "dominates(cnx/c{1,5}:<vp>,<np>)";
1092 qs.setQuery(query, "poliqarpplus");
1093 res = mapper.readTree(qs.toJSON());
1094 assertEquals(1, res.at("/query/relation/boundary/min").asInt());
1095 assertEquals(5, res.at("/query/relation/boundary/max").asInt());
1096
1097 query = "dominates(cnx/c{,5}:<vp>,<np>)";
1098 qs.setQuery(query, "poliqarpplus");
1099 res = mapper.readTree(qs.toJSON());
1100 assertEquals(0, res.at("/query/relation/boundary/min").asInt());
1101 assertEquals(5, res.at("/query/relation/boundary/max").asInt());
1102
1103 query = "dominates(cnx/c{5}:<vp>,<np>)";
1104 qs.setQuery(query, "poliqarpplus");
1105 res = mapper.readTree(qs.toJSON());
1106 assertEquals(5, res.at("/query/relation/boundary/min").asInt());
1107 assertEquals(5, res.at("/query/relation/boundary/max").asInt());
Joachim Bingel53333e62013-12-09 19:25:52 +00001108 }
Joachim Bingel16da4e12013-12-17 09:48:12 +00001109
1110 @Test
Joachim Bingel7cc5f352014-12-03 09:40:04 +00001111 public void testAlign() throws QueryException, JsonProcessingException, IOException {
Joachim Bingel832800e2014-10-17 14:46:39 +00001112 query = "[orth=der]^[orth=Mann]";
Joachim Bingel7cc5f352014-12-03 09:40:04 +00001113 qs.setQuery(query, "poliqarpplus");
1114 res = mapper.readTree(qs.toJSON());
1115 assertEquals("operation:sequence", res.at("/query/operation").asText());
1116 assertEquals("der", res.at("/query/operands/0/wrap/key").asText());
1117 assertEquals("operation:class", res.at("/query/operands/1/operation").asText());
1118 assertEquals(129, res.at("/query/operands/1/classOut").asInt());
1119 assertEquals(129, res.at("/meta/alignment").asInt());
Joachim Bingel16da4e12013-12-17 09:48:12 +00001120
Joachim Bingel832800e2014-10-17 14:46:39 +00001121 query = "[orth=der]^[orth=große][orth=Mann]";
Joachim Bingel7cc5f352014-12-03 09:40:04 +00001122 qs.setQuery(query, "poliqarpplus");
1123 res = mapper.readTree(qs.toJSON());
1124 assertEquals("operation:sequence", res.at("/query/operation").asText());
1125 assertEquals("operation:class", res.at("/query/operands/1/operation").asText());
1126 assertEquals("operation:sequence", res.at("/query/operands/1/operands/0/operation").asText());
1127 assertEquals("große", res.at("/query/operands/1/operands/0/operands/0/wrap/key").asText());
1128 assertEquals("Mann", res.at("/query/operands/1/operands/0/operands/1/wrap/key").asText());
1129 assertEquals(129, res.at("/query/operands/1/classOut").asInt());
1130 assertEquals(129, res.at("/meta/alignment").asInt());
Joachim Bingel84e33df2014-01-31 14:02:46 +00001131
Joachim Bingel832800e2014-10-17 14:46:39 +00001132 query = "([base=a]^[base=b])|[base=c]";
Joachim Bingel7cc5f352014-12-03 09:40:04 +00001133 qs.setQuery(query, "poliqarpplus");
1134 res = mapper.readTree(qs.toJSON());
1135 assertEquals("operation:or", res.at("/query/operation").asText());
1136 assertEquals("operation:sequence", res.at("/query/operands/0/operation").asText());
1137 assertEquals("operation:class", res.at("/query/operands/0/operands/1/operation").asText());
1138 assertEquals("a", res.at("/query/operands/0/operands/0/wrap/key").asText());
1139 assertEquals("b", res.at("/query/operands/0/operands/1/operands/0/wrap/key").asText());
1140 assertEquals("c", res.at("/query/operands/1/wrap/key").asText());
1141 assertEquals(129, res.at("/query/operands/0/operands/1/classOut").asInt());
1142 assertEquals(129, res.at("/meta/alignment").asInt());
Joachim Bingela67e6a32014-01-02 18:35:24 +00001143
Joachim Bingel832800e2014-10-17 14:46:39 +00001144 query = "([base=a]^[base=b][base=c])|[base=d]";
Joachim Bingel7cc5f352014-12-03 09:40:04 +00001145 qs.setQuery(query, "poliqarpplus");
1146 res = mapper.readTree(qs.toJSON());
1147 assertEquals("operation:sequence", res.at("/query/operands/0/operands/1/operands/0/operation").asText());
1148 assertEquals("b", res.at("/query/operands/0/operands/1/operands/0/operands/0/wrap/key").asText());
1149 assertEquals("c", res.at("/query/operands/0/operands/1/operands/0/operands/1/wrap/key").asText());
1150 assertEquals("d", res.at("/query/operands/1/wrap/key").asText());
Joachim Bingela67e6a32014-01-02 18:35:24 +00001151
Joachim Bingel832800e2014-10-17 14:46:39 +00001152 query = "([base=a]^[base=b]^[base=c])|[base=d]";
Joachim Bingel7cc5f352014-12-03 09:40:04 +00001153 qs.setQuery(query, "poliqarpplus");
1154 res = mapper.readTree(qs.toJSON());
1155 assertEquals("operation:sequence", res.at("/query/operands/0/operands/1/operands/0/operation").asText());
1156 assertEquals("b", res.at("/query/operands/0/operands/1/operands/0/operands/0/wrap/key").asText());
1157 assertEquals("c", res.at("/query/operands/0/operands/1/operands/0/operands/1/operands/0/wrap/key").asText());
1158 assertEquals("d", res.at("/query/operands/1/wrap/key").asText());
1159 assertEquals(129, res.at("/meta/alignment/0").asInt());
1160 assertEquals(130, res.at("/meta/alignment/1").asInt());
Joachim Bingel16da4e12013-12-17 09:48:12 +00001161 }
1162
1163 @Test
Joachim Bingel7cc5f352014-12-03 09:40:04 +00001164 public void testSimpleQueries() throws QueryException, JsonProcessingException, IOException {
1165 query = "Baum";
1166 qs.setQuery(query, "poliqarpplus");
1167 res = mapper.readTree(qs.toJSON());
1168 assertEquals("korap:token", res.at("/query/@type").asText());
1169 assertEquals("korap:term", res.at("/query/wrap/@type").asText());
1170 assertEquals("Baum", res.at("/query/wrap/key").asText());
1171 assertEquals("orth", res.at("/query/wrap/layer").asText());
1172 assertEquals("match:eq", res.at("/query/wrap/match").asText());
Joachim Bingel16da4e12013-12-17 09:48:12 +00001173
Joachim Bingel7cc5f352014-12-03 09:40:04 +00001174 query = "Der Baum";
1175 qs.setQuery(query, "poliqarpplus");
1176 res = mapper.readTree(qs.toJSON());
1177 assertEquals("korap:group", res.at("/query/@type").asText());
1178 assertEquals("operation:sequence", res.at("/query/operation").asText());
1179 assertEquals("korap:token", res.at("/query/operands/0/@type").asText());
1180 assertEquals("korap:term", res.at("/query/operands/0/wrap/@type").asText());
1181 assertEquals("Der", res.at("/query/operands/0/wrap/key").asText());
1182 assertEquals("Baum", res.at("/query/operands/1/wrap/key").asText());
1183 assertEquals("orth", res.at("/query/operands/0/wrap/layer").asText());
1184 assertEquals("match:eq", res.at("/query/operands/0/wrap/match").asText());
1185 assertEquals("orth", res.at("/query/operands/1/wrap/layer").asText());
1186 assertEquals("match:eq", res.at("/query/operands/1/wrap/match").asText());
Joachim Bingela67e6a32014-01-02 18:35:24 +00001187
Joachim Bingel7cc5f352014-12-03 09:40:04 +00001188 query = "Der große Baum";
1189 qs.setQuery(query, "poliqarpplus");
1190 res = mapper.readTree(qs.toJSON());
1191 assertEquals("Der", res.at("/query/operands/0/wrap/key").asText());
1192 assertEquals("große", res.at("/query/operands/1/wrap/key").asText());
1193 assertEquals("Baum", res.at("/query/operands/2/wrap/key").asText());
Joachim Bingel0900a892014-06-30 16:26:21 +00001194
Joachim Bingel7cc5f352014-12-03 09:40:04 +00001195 query = "Der (große|kleine) Baum";
1196 qs.setQuery(query, "poliqarpplus");
1197 res = mapper.readTree(qs.toJSON());
1198 assertEquals("Der", res.at("/query/operands/0/wrap/key").asText());
1199 assertEquals("operation:or", res.at("/query/operands/1/operation").asText());
1200 assertEquals("große", res.at("/query/operands/1/operands/0/wrap/key").asText());
1201 assertEquals("kleine", res.at("/query/operands/1/operands/1/wrap/key").asText());
1202 assertEquals("Baum", res.at("/query/operands/2/wrap/key").asText());
Joachim Bingela67e6a32014-01-02 18:35:24 +00001203
Joachim Bingel7cc5f352014-12-03 09:40:04 +00001204 query = "der große Baum | der kleine Baum";
1205 qs.setQuery(query, "poliqarpplus");
1206 res = mapper.readTree(qs.toJSON());
1207 assertEquals("operation:or", res.at("/query/operation").asText());
1208 assertEquals("der", res.at("/query/operands/0/operands/0/wrap/key").asText());
1209 assertEquals("große", res.at("/query/operands/0/operands/1/wrap/key").asText());
1210 assertEquals("Baum", res.at("/query/operands/0/operands/2/wrap/key").asText());
1211 assertEquals("der", res.at("/query/operands/1/operands/0/wrap/key").asText());
1212 assertEquals("kleine", res.at("/query/operands/1/operands/1/wrap/key").asText());
1213 assertEquals("Baum", res.at("/query/operands/1/operands/2/wrap/key").asText());
Joachim Bingel84e33df2014-01-31 14:02:46 +00001214
Joachim Bingel7cc5f352014-12-03 09:40:04 +00001215 query = "Der [p=ADJA] Baum";
1216 qs.setQuery(query, "poliqarpplus");
1217 res = mapper.readTree(qs.toJSON());
1218 assertEquals("Der", res.at("/query/operands/0/wrap/key").asText());
1219 assertEquals("ADJA", res.at("/query/operands/1/wrap/key").asText());
1220 assertEquals("p", res.at("/query/operands/1/wrap/layer").asText());
1221 assertEquals("Baum", res.at("/query/operands/2/wrap/key").asText());
Joachim Bingelb68361c2014-10-22 14:15:09 +00001222 }
Joachim Bingel53333e62013-12-09 19:25:52 +00001223}
1224
Joachim Bingel7cc5f352014-12-03 09:40:04 +00001225