blob: 3dc24297b70d076847bdfc61958bb7d14f4f0b1c [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 Bingel14239d82014-07-22 09:55:04 +000024 String query;
Joachim Bingel7cc5f352014-12-03 09:40:04 +000025 ArrayList<JsonNode> operands;
26
27 QuerySerializer qs = new QuerySerializer();
28 ObjectMapper mapper = new ObjectMapper();
29 JsonNode res;
30
Joachim Bingel81812632014-02-18 08:55:22 +000031 @Test
Joachim Bingel7cc5f352014-12-03 09:40:04 +000032 public void testContext() throws QueryException, JsonProcessingException, IOException {
33 query = "foo";
Joachim Bingel832800e2014-10-17 14:46:39 +000034 String contextString = "http://ids-mannheim.de/ns/KorAP/json-ld/v0.2/context.jsonld";
Joachim Bingel7cc5f352014-12-03 09:40:04 +000035 qs.setQuery(query, "poliqarpplus");
36 res = mapper.readTree(qs.toJSON());
37 assertEquals(contextString, res.get("@context").asText());
Joachim Bingel53333e62013-12-09 19:25:52 +000038 }
Joachim Bingel7cc5f352014-12-03 09:40:04 +000039
Joachim Bingel53333e62013-12-09 19:25:52 +000040 @Test
Joachim Bingel7cc5f352014-12-03 09:40:04 +000041 public void testSingleTokens() throws QueryException, JsonProcessingException, IOException {
42 query = "[base=Mann]";
43 qs.setQuery(query, "poliqarpplus");
44 res = mapper.readTree(qs.toJSON());
45 assertEquals("korap:token", res.at("/query/@type").asText());
46 assertEquals("Mann", res.at("/query/wrap/key").asText());
47 assertEquals("lemma", res.at("/query/wrap/layer").asText());
48 assertEquals("match:eq", res.at("/query/wrap/match").asText());
49
50 query = "[orth!=Frau]";
51 qs.setQuery(query, "poliqarpplus");
52 res = mapper.readTree(qs.toJSON());
53 assertEquals("korap:token", res.at("/query/@type").asText());
54 assertEquals("Frau", res.at("/query/wrap/key").asText());
55 assertEquals("orth", res.at("/query/wrap/layer").asText());
56 assertEquals("match:ne", res.at("/query/wrap/match").asText());
57
58 query = "[p!=NN]";
59 qs.setQuery(query, "poliqarpplus");
60 res = mapper.readTree(qs.toJSON());
61 assertEquals("korap:token", res.at("/query/@type").asText());
62 assertEquals("NN", res.at("/query/wrap/key").asText());
63 assertEquals("p", res.at("/query/wrap/layer").asText());
64 assertEquals("match:ne", res.at("/query/wrap/match").asText());
65
Joachim Bingel0900a892014-06-30 16:26:21 +000066 query = "[!p!=NN]";
Joachim Bingel7cc5f352014-12-03 09:40:04 +000067 qs.setQuery(query, "poliqarpplus");
68 res = mapper.readTree(qs.toJSON());
69 assertEquals("korap:token", res.at("/query/@type").asText());
70 assertEquals("NN", res.at("/query/wrap/key").asText());
71 assertEquals("p", res.at("/query/wrap/layer").asText());
72 assertEquals("match:eq", res.at("/query/wrap/match").asText());
73
Joachim Bingeld1a3e712014-07-16 08:02:05 +000074 query = "[base=schland/x]";
Joachim Bingel7cc5f352014-12-03 09:40:04 +000075 qs.setQuery(query, "poliqarpplus");
76 res = mapper.readTree(qs.toJSON());
77 assertEquals("korap:token", res.at("/query/@type").asText());
78 assertEquals(".*?schland.*?", res.at("/query/wrap/key").asText());
79 assertEquals("lemma", res.at("/query/wrap/layer").asText());
80 assertEquals("type:regex", res.at("/query/wrap/type").asText());
81 assertEquals("match:eq", res.at("/query/wrap/match").asText());
Joachim Bingeld1a3e712014-07-16 08:02:05 +000082 }
Joachim Bingel7cc5f352014-12-03 09:40:04 +000083
Joachim Bingeld1a3e712014-07-16 08:02:05 +000084 @Test
Joachim Bingel7cc5f352014-12-03 09:40:04 +000085 public void testValue() throws QueryException, JsonProcessingException, IOException {
Joachim Bingeld1a3e712014-07-16 08:02:05 +000086 query = "[mate/m=temp:pres]";
Joachim Bingel7cc5f352014-12-03 09:40:04 +000087 qs.setQuery(query, "poliqarpplus");
88 res = mapper.readTree(qs.toJSON());
89 assertEquals("korap:token", res.at("/query/@type").asText());
90 assertEquals("korap:term", res.at("/query/wrap/@type").asText());
91 assertEquals("temp", res.at("/query/wrap/key").asText());
92 assertEquals("pres", res.at("/query/wrap/value").asText());
93 assertEquals("m", res.at("/query/wrap/layer").asText());
94 assertEquals("mate", res.at("/query/wrap/foundry").asText());
95 assertEquals("match:eq", res.at("/query/wrap/match").asText());
Joachim Bingel53333e62013-12-09 19:25:52 +000096 }
Joachim Bingel7cc5f352014-12-03 09:40:04 +000097
Joachim Bingel53333e62013-12-09 19:25:52 +000098 @Test
Joachim Bingel7cc5f352014-12-03 09:40:04 +000099 public void testRegex() throws QueryException, JsonProcessingException, IOException {
Joachim Bingel832800e2014-10-17 14:46:39 +0000100 query = "[orth=\"M(a|ä)nn(er)?\"]";
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000101 qs.setQuery(query, "poliqarpplus");
102 res = mapper.readTree(qs.toJSON());
103 assertEquals("korap:token", res.at("/query/@type").asText());
104 assertEquals("korap:term", res.at("/query/wrap/@type").asText());
105 assertEquals("M(a|ä)nn(er)?", res.at("/query/wrap/key").asText());
106 assertEquals("type:regex", res.at("/query/wrap/type").asText());
107 assertEquals("orth", res.at("/query/wrap/layer").asText());
108 assertEquals("match:eq", res.at("/query/wrap/match").asText());
109
Joachim Bingel0900a892014-06-30 16:26:21 +0000110 query = "[orth=\"M(a|ä)nn(er)?\"/x]";
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000111 qs.setQuery(query, "poliqarpplus");
112 res = mapper.readTree(qs.toJSON());
113 assertEquals("korap:token", res.at("/query/@type").asText());
114 assertEquals("korap:term", res.at("/query/wrap/@type").asText());
115 assertEquals(".*?M(a|ä)nn(er)?.*?", res.at("/query/wrap/key").asText());
116 assertEquals("type:regex", res.at("/query/wrap/type").asText());
117 assertEquals("orth", res.at("/query/wrap/layer").asText());
118 assertEquals("match:eq", res.at("/query/wrap/match").asText());
119
Joachim Bingeld1a3e712014-07-16 08:02:05 +0000120 query = "\".*?Mann.*?\"";
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000121 qs.setQuery(query, "poliqarpplus");
122 res = mapper.readTree(qs.toJSON());
123 assertEquals("korap:token", res.at("/query/@type").asText());
124 assertEquals("korap:term", res.at("/query/wrap/@type").asText());
125 assertEquals(".*?Mann.*?", res.at("/query/wrap/key").asText());
126 assertEquals("type:regex", res.at("/query/wrap/type").asText());
127 assertEquals("orth", res.at("/query/wrap/layer").asText());
128 assertEquals("match:eq", res.at("/query/wrap/match").asText());
129
Joachim Bingela83f8cc2014-08-05 14:12:59 +0000130 query = "z.B./x";
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000131 qs.setQuery(query, "poliqarpplus");
132 res = mapper.readTree(qs.toJSON());
133 assertEquals("korap:token", res.at("/query/@type").asText());
134 assertEquals("korap:term", res.at("/query/wrap/@type").asText());
135 assertEquals(".*?z\\.B\\..*?", res.at("/query/wrap/key").asText());
136 assertEquals("type:regex", res.at("/query/wrap/type").asText());
137 assertEquals("orth", res.at("/query/wrap/layer").asText());
138 assertEquals("match:eq", res.at("/query/wrap/match").asText());
139
Joachim Bingel41e112e2014-02-12 10:46:18 +0000140 }
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000141
Joachim Bingel41e112e2014-02-12 10:46:18 +0000142 @Test
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000143 public void testCaseSensitivityFlag() throws QueryException, JsonProcessingException, IOException {
144 query = "[orth=deutscher/i]";
145 qs.setQuery(query, "poliqarpplus");
146 res = mapper.readTree(qs.toJSON());
147 assertEquals("korap:token", res.at("/query/@type").asText());
148 assertEquals("korap:term", res.at("/query/wrap/@type").asText());
149 assertEquals("deutscher", res.at("/query/wrap/key").asText());
150 assertEquals("true", res.at("/query/wrap/caseInsensitive").asText());
151 assertEquals("orth", res.at("/query/wrap/layer").asText());
152 assertEquals("match:eq", res.at("/query/wrap/match").asText());
153
154 query = "deutscher/i";
155 qs.setQuery(query, "poliqarpplus");
156 res = mapper.readTree(qs.toJSON());
157 assertEquals("korap:token", res.at("/query/@type").asText());
158 assertEquals("korap:term", res.at("/query/wrap/@type").asText());
159 assertEquals("deutscher", res.at("/query/wrap/key").asText());
160 assertEquals("true", res.at("/query/wrap/caseInsensitive").asText());
161 assertEquals("orth", res.at("/query/wrap/layer").asText());
162 assertEquals("match:eq", res.at("/query/wrap/match").asText());
163
164 query = "deutscher/I";
165 qs.setQuery(query, "poliqarpplus");
166 res = mapper.readTree(qs.toJSON());
167 assertEquals("korap:token", res.at("/query/@type").asText());
168 assertEquals("korap:term", res.at("/query/wrap/@type").asText());
169 assertEquals("deutscher", res.at("/query/wrap/key").asText());
170 assertEquals("false", res.at("/query/wrap/caseInsensitive").asText());
171 assertEquals("orth", res.at("/query/wrap/layer").asText());
172 assertEquals("match:eq", res.at("/query/wrap/match").asText());
173
174 query = "[orth=deutscher/i][orth=Bundestag]";
175 qs.setQuery(query, "poliqarpplus");
176 res = mapper.readTree(qs.toJSON());
177 assertEquals("korap:group", res.at("/query/@type").asText());
178 assertEquals("operation:sequence", res.at("/query/operation").asText());
179 operands = Lists.newArrayList(res.at("/query/operands").elements());
180 assertEquals("korap:token", operands.get(0).at("/@type").asText());
181 assertEquals("deutscher", operands.get(0).at("/wrap/key").asText());
182 assertEquals("orth", operands.get(0).at("/wrap/layer").asText());
183 assertEquals("match:eq", operands.get(0).at("/wrap/match").asText());
184 assertEquals(true, operands.get(0).at("/wrap/caseInsensitive").asBoolean());
185 assertEquals("korap:token", operands.get(1).at("/@type").asText());
186 assertEquals("Bundestag", operands.get(1).at("/wrap/key").asText());
187 assertEquals("orth", operands.get(1).at("/wrap/layer").asText());
188 assertEquals("match:eq", operands.get(1).at("/wrap/match").asText());
189 assertEquals(true, operands.get(1).at("/wrap/caseInsensitive").isMissingNode());
190
191 query = "deutscher/i Bundestag";
192 qs.setQuery(query, "poliqarpplus");
193 res = mapper.readTree(qs.toJSON());
194 assertEquals("korap:group", res.at("/query/@type").asText());
195 assertEquals("operation:sequence", res.at("/query/operation").asText());
196 operands = Lists.newArrayList(res.at("/query/operands").elements());
197 assertEquals("korap:token", operands.get(0).at("/@type").asText());
198 assertEquals("deutscher", operands.get(0).at("/wrap/key").asText());
199 assertEquals("orth", operands.get(0).at("/wrap/layer").asText());
200 assertEquals("match:eq", operands.get(0).at("/wrap/match").asText());
201 assertEquals(true, operands.get(0).at("/wrap/caseInsensitive").asBoolean());
202 assertEquals("korap:token", operands.get(1).at("/@type").asText());
203 assertEquals("Bundestag", operands.get(1).at("/wrap/key").asText());
204 assertEquals("orth", operands.get(1).at("/wrap/layer").asText());
205 assertEquals("match:eq", operands.get(1).at("/wrap/match").asText());
206 assertEquals(true, operands.get(1).at("/wrap/caseInsensitive").isMissingNode());
Joachim Bingel0207d5e2014-02-12 14:18:41 +0000207 }
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000208
Joachim Bingel0207d5e2014-02-12 14:18:41 +0000209 @Test
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000210 public void testSpans() throws QueryException, JsonProcessingException, IOException {
211 query = "<s>";
212 qs.setQuery(query, "poliqarpplus");
213 res = mapper.readTree(qs.toJSON());
214 assertEquals("korap:span", res.at("/query/@type").asText());
215 assertEquals("s", res.at("/query/key").asText());
216
217 query = "<vp>";
218 qs.setQuery(query, "poliqarpplus");
219 res = mapper.readTree(qs.toJSON());
220 assertEquals("korap:span", res.at("/query/@type").asText());
221 assertEquals("vp", res.at("/query/key").asText());
222
Joachim Bingelfc1fb352014-02-26 14:40:27 +0000223 query = "<cnx/c=vp>";
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000224 qs.setQuery(query, "poliqarpplus");
225 res = mapper.readTree(qs.toJSON());
226 assertEquals("korap:span", res.at("/query/@type").asText());
227 assertEquals("vp", res.at("/query/key").asText());
228 assertEquals("cnx", res.at("/query/foundry").asText());
229 assertEquals("c", res.at("/query/layer").asText());
230
Joachim Bingel3a41a442014-07-22 12:16:16 +0000231 query = "<cnx/c!=vp>";
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000232 qs.setQuery(query, "poliqarpplus");
233 res = mapper.readTree(qs.toJSON());
234 assertEquals("korap:span", res.at("/query/@type").asText());
235 assertEquals("vp", res.at("/query/key").asText());
236 assertEquals("cnx", res.at("/query/foundry").asText());
237 assertEquals("c", res.at("/query/layer").asText());
238 assertEquals("match:ne", res.at("/query/match").asText());
239
240 query = "<cnx/c!=vp class!=header>";
241 qs.setQuery(query, "poliqarpplus");
242 res = mapper.readTree(qs.toJSON());
243 assertEquals("korap:span", res.at("/query/@type").asText());
244 assertEquals("vp", res.at("/query/key").asText());
245 assertEquals("cnx", res.at("/query/foundry").asText());
246 assertEquals("c", res.at("/query/layer").asText());
247 assertEquals("match:ne", res.at("/query/match").asText());
248 assertEquals("class", res.at("/query/attr/key").asText());
249 assertEquals("header", res.at("/query/attr/value").asText());
250 assertEquals("match:ne", res.at("/query/attr/match").asText());
251
252 query = "<cnx/c!=vp !(class!=header)>";
253 qs.setQuery(query, "poliqarpplus");
254 res = mapper.readTree(qs.toJSON());
255 assertEquals("korap:span", res.at("/query/@type").asText());
256 assertEquals("vp", res.at("/query/key").asText());
257 assertEquals("cnx", res.at("/query/foundry").asText());
258 assertEquals("c", res.at("/query/layer").asText());
259 assertEquals("match:ne", res.at("/query/match").asText());
260 assertEquals("class", res.at("/query/attr/key").asText());
261 assertEquals("header", res.at("/query/attr/value").asText());
262 assertEquals("match:eq", res.at("/query/attr/match").asText());
263
264 query = "<cnx/c!=vp !(class=header & id=7)>";
265 qs.setQuery(query, "poliqarpplus");
266 res = mapper.readTree(qs.toJSON());
267 assertEquals("korap:span", res.at("/query/@type").asText());
268 assertEquals("vp", res.at("/query/key").asText());
269 assertEquals("cnx", res.at("/query/foundry").asText());
270 assertEquals("c", res.at("/query/layer").asText());
271 assertEquals("match:ne", res.at("/query/match").asText());
272 assertEquals("korap:termGroup", res.at("/query/attr/@type").asText());
273 assertEquals("relation:and", res.at("/query/attr/relation").asText());
274 operands = Lists.newArrayList( res.at("/query/attr/operands").elements());
275 assertEquals("korap:term", operands.get(0).at("/@type").asText());
276 assertEquals("class", operands.get(0).at("/key").asText());
277 assertEquals("header", operands.get(0).at("/value").asText());
278 assertEquals("match:ne", operands.get(0).at("/match").asText());
279 assertEquals("korap:term", operands.get(1).at("/@type").asText());
280 assertEquals("id", operands.get(1).at("/key").asText());
281 assertEquals(7, operands.get(1).at("/value").asInt());
282 assertEquals("match:ne", operands.get(1).at("/match").asText());
Joachim Bingel53333e62013-12-09 19:25:52 +0000283 }
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000284
Joachim Bingel87480d02014-01-17 14:07:46 +0000285 @Test
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000286 public void testDistances() throws QueryException, JsonProcessingException, IOException {
287 query = "[base=der][][base=Mann]";
288 qs.setQuery(query, "poliqarpplus");
289 res = mapper.readTree(qs.toJSON());
290 assertEquals("korap:group", res.at("/query/@type").asText());
291 assertEquals("operation:sequence", res.at("/query/operation").asText());
292 assertEquals("true", res.at("/query/inOrder").asText());
293 assertEquals("korap:distance", res.at("/query/distances").elements().next().at("/@type").asText());
294 assertEquals("w", res.at("/query/distances").elements().next().at("/key").asText());
295 assertEquals("korap:boundary", res.at("/query/distances").elements().next().at("/boundary/@type").asText());
296 assertEquals(2, res.at("/query/distances").elements().next().at("/boundary/min").asInt());
297 assertEquals(2, res.at("/query/distances").elements().next().at("/boundary/max").asInt());
298 operands = Lists.newArrayList(res.at("/query/operands").elements());
299 assertEquals("korap:token", operands.get(0).at("/@type").asText());
300 assertEquals("der", operands.get(0).at("/wrap/key").asText());
301 assertEquals("lemma", operands.get(0).at("/wrap/layer").asText());
302 assertEquals("match:eq", operands.get(0).at("/wrap/match").asText());
303 assertEquals("korap:token", operands.get(1).at("/@type").asText());
304 assertEquals("Mann", operands.get(1).at("/wrap/key").asText());
305 assertEquals("lemma", operands.get(1).at("/wrap/layer").asText());
306 assertEquals("match:eq", operands.get(1).at("/wrap/match").asText());
307
308 query = "[base=der][][][base=Mann]";
309 qs.setQuery(query, "poliqarpplus");
310 res = mapper.readTree(qs.toJSON());
311 assertEquals("korap:group", res.at("/query/@type").asText());
312 assertEquals("operation:sequence", res.at("/query/operation").asText());
313 assertEquals("true", res.at("/query/inOrder").asText());
314 assertEquals("korap:distance", res.at("/query/distances").elements().next().at("/@type").asText());
315 assertEquals("w", res.at("/query/distances").elements().next().at("/key").asText());
316 assertEquals("korap:boundary", res.at("/query/distances").elements().next().at("/boundary/@type").asText());
317 assertEquals(3, res.at("/query/distances").elements().next().at("/boundary/min").asInt());
318 assertEquals(3, res.at("/query/distances").elements().next().at("/boundary/max").asInt());
319 operands = Lists.newArrayList(res.at("/query/operands").elements());
320 assertEquals("korap:token", operands.get(0).at("/@type").asText());
321 assertEquals("der", operands.get(0).at("/wrap/key").asText());
322 assertEquals("lemma", operands.get(0).at("/wrap/layer").asText());
323 assertEquals("match:eq", operands.get(0).at("/wrap/match").asText());
324 assertEquals("korap:token", operands.get(1).at("/@type").asText());
325 assertEquals("Mann", operands.get(1).at("/wrap/key").asText());
326 assertEquals("lemma", operands.get(1).at("/wrap/layer").asText());
327 assertEquals("match:eq", operands.get(1).at("/wrap/match").asText());
328
329 query = "[base=der][][]?[base=Mann]";
330 qs.setQuery(query, "poliqarpplus");
331 res = mapper.readTree(qs.toJSON());
332 assertEquals("korap:group", res.at("/query/@type").asText());
333 assertEquals("operation:sequence", res.at("/query/operation").asText());
334 assertEquals("true", res.at("/query/inOrder").asText());
335 assertEquals("korap:distance", res.at("/query/distances").elements().next().at("/@type").asText());
336 assertEquals("w", res.at("/query/distances").elements().next().at("/key").asText());
337 assertEquals("korap:boundary", res.at("/query/distances").elements().next().at("/boundary/@type").asText());
338 assertEquals(2, res.at("/query/distances").elements().next().at("/boundary/min").asInt());
339 assertEquals(3, res.at("/query/distances").elements().next().at("/boundary/max").asInt());
340 operands = Lists.newArrayList(res.at("/query/operands").elements());
341 assertEquals("korap:token", operands.get(0).at("/@type").asText());
342 assertEquals("der", operands.get(0).at("/wrap/key").asText());
343 assertEquals("lemma", operands.get(0).at("/wrap/layer").asText());
344 assertEquals("match:eq", operands.get(0).at("/wrap/match").asText());
345 assertEquals("korap:token", operands.get(1).at("/@type").asText());
346 assertEquals("Mann", operands.get(1).at("/wrap/key").asText());
347 assertEquals("lemma", operands.get(1).at("/wrap/layer").asText());
348 assertEquals("match:eq", operands.get(1).at("/wrap/match").asText());
349
350 query = "[base=der][]+[base=Mann]";
351 qs.setQuery(query, "poliqarpplus");
352 res = mapper.readTree(qs.toJSON());
353 assertEquals("korap:group", res.at("/query/@type").asText());
354 assertEquals("operation:sequence", res.at("/query/operation").asText());
355 assertEquals("true", res.at("/query/inOrder").asText());
356 assertEquals("korap:distance", res.at("/query/distances").elements().next().at("/@type").asText());
357 assertEquals("w", res.at("/query/distances").elements().next().at("/key").asText());
358 assertEquals("korap:boundary", res.at("/query/distances").elements().next().at("/boundary/@type").asText());
359 assertEquals(2, res.at("/query/distances").elements().next().at("/boundary/min").asInt());
360 assertEquals(true, res.at("/query/distances").elements().next().at("/boundary/max").isMissingNode());
361 operands = Lists.newArrayList(res.at("/query/operands").elements());
362 assertEquals("korap:token", operands.get(0).at("/@type").asText());
363 assertEquals("der", operands.get(0).at("/wrap/key").asText());
364 assertEquals("lemma", operands.get(0).at("/wrap/layer").asText());
365 assertEquals("match:eq", operands.get(0).at("/wrap/match").asText());
366 assertEquals("korap:token", operands.get(1).at("/@type").asText());
367 assertEquals("Mann", operands.get(1).at("/wrap/key").asText());
368 assertEquals("lemma", operands.get(1).at("/wrap/layer").asText());
369 assertEquals("match:eq", operands.get(1).at("/wrap/match").asText());
370
371 query = "[base=der][]*[base=Mann]";
372 qs.setQuery(query, "poliqarpplus");
373 res = mapper.readTree(qs.toJSON());
374 assertEquals("korap:group", res.at("/query/@type").asText());
375 assertEquals("operation:sequence", res.at("/query/operation").asText());
376 assertEquals("true", res.at("/query/inOrder").asText());
377 assertEquals("korap:distance", res.at("/query/distances").elements().next().at("/@type").asText());
378 assertEquals("w", res.at("/query/distances").elements().next().at("/key").asText());
379 assertEquals("korap:boundary", res.at("/query/distances").elements().next().at("/boundary/@type").asText());
380 assertEquals(1, res.at("/query/distances").elements().next().at("/boundary/min").asInt());
381 assertEquals(true, res.at("/query/distances").elements().next().at("/boundary/max").isMissingNode());
382
383 query = "[base=der][]{2,5}[base=Mann][]?[][base=Frau]";
384 qs.setQuery(query, "poliqarpplus");
385 res = mapper.readTree(qs.toJSON());
386 assertEquals("korap:group", res.at("/query/@type").asText());
387 assertEquals("operation:sequence", res.at("/query/operation").asText());
388 assertEquals("true", res.at("/query/inOrder").asText());
389 assertEquals("korap:distance", res.at("/query/distances").elements().next().at("/@type").asText());
390 assertEquals("w", res.at("/query/distances").elements().next().at("/key").asText());
391 assertEquals("korap:boundary", res.at("/query/distances").elements().next().at("/boundary/@type").asText());
392 assertEquals(3, res.at("/query/distances").elements().next().at("/boundary/min").asInt());
393 assertEquals(6, res.at("/query/distances").elements().next().at("/boundary/max").asInt());
394 operands = Lists.newArrayList(res.at("/query/operands").elements());
395 assertEquals("korap:token", operands.get(0).at("/@type").asText());
396 assertEquals("der", operands.get(0).at("/wrap/key").asText());
397 assertEquals("lemma", operands.get(0).at("/wrap/layer").asText());
398 assertEquals("match:eq", operands.get(0).at("/wrap/match").asText());
399 assertEquals("korap:group", operands.get(1).at("/@type").asText());
400 assertEquals("operation:sequence", operands.get(1).at("/operation").asText());
401 assertEquals("korap:distance", operands.get(1).get("distances").elements().next().at("/@type").asText());
402 assertEquals("w", operands.get(1).get("distances").elements().next().at("/key").asText());
403 assertEquals("korap:boundary", operands.get(1).get("distances").elements().next().at("/boundary/@type").asText());
404 assertEquals(2, operands.get(1).get("distances").elements().next().at("/boundary/min").asInt());
405 assertEquals(3, operands.get(1).get("distances").elements().next().at("/boundary/max").asInt());
406 operands = Lists.newArrayList(operands.get(1).get("operands").elements());
407 assertEquals("Mann", operands.get(0).at("/wrap/key").asText());
408 assertEquals("lemma", operands.get(0).at("/wrap/layer").asText());
409 assertEquals("match:eq", operands.get(0).at("/wrap/match").asText());
410 assertEquals("Frau", operands.get(1).at("/wrap/key").asText());
411 assertEquals("lemma", operands.get(1).at("/wrap/layer").asText());
412 assertEquals("match:eq", operands.get(1).at("/wrap/match").asText());
413
Joachim Bingel14239d82014-07-22 09:55:04 +0000414 query = "[base=geht][base=der][]*contains(<s>,<np>)";
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000415 qs.setQuery(query, "poliqarpplus");
416 res = mapper.readTree(qs.toJSON());
417 assertEquals("korap:group", res.at("/query/@type").asText());
418 assertEquals("operation:sequence", res.at("/query/operation").asText());
419 assertEquals(true, res.at("/query/inOrder").isMissingNode());
420 assertEquals(true, res.at("/query/distances").isMissingNode());
421 operands = Lists.newArrayList(res.at("/query/operands").elements());
422 assertEquals("korap:token", operands.get(0).at("/@type").asText());
423 assertEquals("geht", operands.get(0).at("/wrap/key").asText());
424 assertEquals("lemma", operands.get(0).at("/wrap/layer").asText());
425 assertEquals("match:eq", operands.get(0).at("/wrap/match").asText());
426 assertEquals("korap:group", operands.get(1).at("/@type").asText());
427 assertEquals("operation:sequence", operands.get(1).at("/operation").asText());
428 assertEquals("korap:distance", operands.get(1).get("distances").elements().next().at("/@type").asText());
429 assertEquals("w", operands.get(1).get("distances").elements().next().at("/key").asText());
430 assertEquals("korap:boundary", operands.get(1).get("distances").elements().next().at("/boundary/@type").asText());
431 assertEquals(1, operands.get(1).get("distances").elements().next().at("/boundary/min").asInt());
432 assertEquals(true, operands.get(1).get("distances").elements().next().at("/boundary/max").isMissingNode());
433 operands = Lists.newArrayList(operands.get(1).get("operands").elements());
434 assertEquals("der", operands.get(0).at("/wrap/key").asText());
435 assertEquals("lemma", operands.get(0).at("/wrap/layer").asText());
436 assertEquals("match:eq", operands.get(0).at("/wrap/match").asText());
437 assertEquals("korap:group", operands.get(1).at("/@type").asText());
438 assertEquals("operation:position", operands.get(1).at("/operation").asText());
Joachim Bingel87480d02014-01-17 14:07:46 +0000439 }
Joachim Bingel53333e62013-12-09 19:25:52 +0000440
441 @Test
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000442 public void testDistancesWithClass() throws QueryException, JsonProcessingException, IOException {
443 query = "[base=der]{[]}[base=Mann]";
444 qs.setQuery(query, "poliqarpplus");
445 res = mapper.readTree(qs.toJSON());
446 assertEquals("korap:group", res.at("/query/@type").asText());
447 assertEquals("operation:sequence", res.at("/query/operation").asText());
448 assertEquals(true, res.at("/query/inOrder").isMissingNode());
449 assertEquals(true, res.at("/query/distances").isMissingNode());
450 operands = Lists.newArrayList(res.at("/query/operands").elements());
451 assertEquals("der", operands.get(0).at("/wrap/key").asText());
452 assertEquals("Mann", operands.get(2).at("/wrap/key").asText());
453 assertEquals("korap:group", operands.get(1).at("/@type").asText());
454 assertEquals("operation:class", operands.get(1).at("/operation").asText());
455 assertEquals(1, operands.get(1).at("/classOut").asInt());
456 operands = Lists.newArrayList(operands.get(1).at("/operands").elements());
457 assertEquals("korap:token", operands.get(0).at("/@type").asText());
458 assertEquals(true, operands.get(0).at("/wrap").isMissingNode());
459
460 query = "[base=der]{2:[]}[base=Mann]";
461 qs.setQuery(query, "poliqarpplus");
462 res = mapper.readTree(qs.toJSON());
463 operands = Lists.newArrayList(res.at("/query/operands").elements());
464 assertEquals("operation:class", operands.get(1).at("/operation").asText());
465 assertEquals(2, operands.get(1).at("/classOut").asInt());
466
Joachim Bingelbd386362014-10-02 12:03:18 +0000467 query = "{1:[]}[base=der][base=Mann]";
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000468 qs.setQuery(query, "poliqarpplus");
469 res = mapper.readTree(qs.toJSON());
470 operands = Lists.newArrayList(res.at("/query/operands").elements());
471 assertEquals("operation:class", operands.get(0).at("/operation").asText());
472 assertEquals(1, operands.get(0).at("/classOut").asInt());
473
474 query = "{1:{2:der} {3:[]} Mann}";
475 qs.setQuery(query, "poliqarpplus");
476 res = mapper.readTree(qs.toJSON());
477 operands = Lists.newArrayList(res.at("/query/operands").elements());
478 assertEquals(1, operands.size()); // class operation may only have one operand (the sequence)
479 operands = Lists.newArrayList(operands.get(0).at("/operands").elements());
480 assertEquals(3, operands.size()); // the sequence has three operands ("der", "[]" and "Mann")
481
Joachim Bingelbd386362014-10-02 12:03:18 +0000482 }
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000483
Joachim Bingelbd386362014-10-02 12:03:18 +0000484 @Test
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000485 public void testLeadingTrailingEmptyTokens() throws QueryException, JsonProcessingException, IOException {
Joachim Bingel14239d82014-07-22 09:55:04 +0000486 query = "[][base=Mann]";
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000487 qs.setQuery(query, "poliqarpplus");
488 res = mapper.readTree(qs.toJSON());
489 operands = Lists.newArrayList(res.at("/query/operands").elements());
490 assertEquals("korap:token", operands.get(0).at("/@type").asText());
491 assertEquals(true, operands.get(0).at("/key").isMissingNode());
492
Joachim Bingel14239d82014-07-22 09:55:04 +0000493 query = "[][][base=Mann]";
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000494 qs.setQuery(query, "poliqarpplus");
495 res = mapper.readTree(qs.toJSON());
496 operands = Lists.newArrayList(res.at("/query/operands").elements());
497 assertEquals("korap:group", operands.get(0).at("/@type").asText());
498 assertEquals("operation:repetition",operands.get(0).at("/operation").asText());
499 assertEquals(2, operands.get(0).at("/boundary/min").asInt());
500 assertEquals(2, operands.get(0).at("/boundary/max").asInt());
501 operands = Lists.newArrayList(operands.get(0).at("/operands").elements());
502 assertEquals("korap:token", operands.get(0).at("/@type").asText());
503 assertEquals(true, operands.get(0).at("/key").isMissingNode());
Nils Diewald7d486c22013-12-13 16:32:18 +0000504
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000505 query = "startswith(<s>, [][base=Mann])";
506 qs.setQuery(query, "poliqarpplus");
507 res = mapper.readTree(qs.toJSON());
508 operands = Lists.newArrayList(res.at("/query/operands"));
509 operands = Lists.newArrayList(operands.get(1).at("/operands"));
510 assertEquals("korap:token", operands.get(0).at("/@type").asText());
511 assertEquals(true, operands.get(0).at("/key").isMissingNode());
512 }
Nils Diewald7d486c22013-12-13 16:32:18 +0000513
Joachim Bingel53333e62013-12-09 19:25:52 +0000514 @Test
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000515 public void testRepetition() throws QueryException, JsonProcessingException, IOException {
516 query = "der{3}";
517 qs.setQuery(query, "poliqarpplus");
518 res = mapper.readTree(qs.toJSON());
519 assertEquals("korap:group", res.at("/query/@type").asText());
520 assertEquals("operation:repetition", res.at("/query/operation").asText());
521 assertEquals("der", res.at("/query/operands/0/wrap/key").asText());
522 assertEquals(3, res.at("/query/boundary/min").asInt());
523 assertEquals(3, res.at("/query/boundary/max").asInt());
524
525 query = "der{,3}";
526 qs.setQuery(query, "poliqarpplus");
527 res = mapper.readTree(qs.toJSON());
528 assertEquals(0, res.at("/query/boundary/min").asInt());
529 assertEquals(3, res.at("/query/boundary/max").asInt());
530
531 query = "der{3,}";
532 qs.setQuery(query, "poliqarpplus");
533 res = mapper.readTree(qs.toJSON());
534 assertEquals(3, res.at("/query/boundary/min").asInt());
535 assertEquals(true, res.at("/query/boundary/max").isMissingNode());
536
537 query = "der{3,7}";
538 qs.setQuery(query, "poliqarpplus");
539 res = mapper.readTree(qs.toJSON());
540 assertEquals(3, res.at("/query/boundary/min").asInt());
541 assertEquals(7, res.at("/query/boundary/max").asInt());
542
543 query = "der*";
544 qs.setQuery(query, "poliqarpplus");
545 res = mapper.readTree(qs.toJSON());
546 assertEquals(0, res.at("/query/boundary/min").asInt());
547 assertEquals(true, res.at("/query/boundary/max").isMissingNode());
548
549 query = "der+";
550 qs.setQuery(query, "poliqarpplus");
551 res = mapper.readTree(qs.toJSON());
552 assertEquals(1, res.at("/query/boundary/min").asInt());
553 assertEquals(true, res.at("/query/boundary/max").isMissingNode());
554 };
555
Joachim Bingel53333e62013-12-09 19:25:52 +0000556 @Test
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000557 public void testGroupRepetition() throws QueryException, JsonProcessingException, IOException {
558 query = "contains(<s>, (der){3})";
559 qs.setQuery(query, "poliqarpplus");
560 res = mapper.readTree(qs.toJSON());
561 assertEquals("korap:group", res.at("/query/@type").asText());
562 assertEquals("operation:position", res.at("/query/operation").asText());
563 assertEquals("korap:span", res.at("/query/operands/0/@type").asText());
564 assertEquals("s", res.at("/query/operands/0/key").asText());
565 assertEquals("korap:group", res.at("/query/operands/1/@type").asText());
566 assertEquals("operation:repetition",res.at("/query/operands/1/operation").asText());
567
568 query = "contains(<s>, (der){3,})";
569 qs.setQuery(query, "poliqarpplus");
570 res = mapper.readTree(qs.toJSON());
571 assertEquals(3, res.at("/query/operands/1/boundary/min").asInt());
572 assertEquals(true, res.at("/query/operands/1/boundary/max").isMissingNode());
573
574 query = "contains(<s>, (der){,3})";
575 qs.setQuery(query, "poliqarpplus");
576 res = mapper.readTree(qs.toJSON());
577 assertEquals(0, res.at("/query/operands/1/boundary/min").asInt());
578 assertEquals(3, res.at("/query/operands/1/boundary/max").asInt());
579
580 query = "contains(<s>, (der){3,7})";
581 qs.setQuery(query, "poliqarpplus");
582 res = mapper.readTree(qs.toJSON());
583 assertEquals(3, res.at("/query/operands/1/boundary/min").asInt());
584 assertEquals(7, res.at("/query/operands/1/boundary/max").asInt());
585
586 query = "contains(<s>, (der)*)";
587 qs.setQuery(query, "poliqarpplus");
588 res = mapper.readTree(qs.toJSON());
589 assertEquals(0, res.at("/query/operands/1/boundary/min").asInt());
590 assertEquals(true, res.at("/query/operands/1/boundary/max").isMissingNode());
591 };
592
Joachim Bingel53333e62013-12-09 19:25:52 +0000593 @Test
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000594 public void testPositions() throws QueryException, JsonProcessingException, IOException {
595 query = "contains(<s>, der)";
596 qs.setQuery(query, "poliqarpplus");
597 res = mapper.readTree(qs.toJSON());
598 assertEquals("korap:group", res.at("/query/@type").asText());
599 assertEquals("operation:position", res.at("/query/operation").asText());
600 assertEquals("frames:contains", res.at("/query/frames/0").asText());
601 assertEquals(true, res.at("/query/frames/1").isMissingNode());
602 assertEquals("korap:span", res.at("/query/operands/0/@type").asText());
603 assertEquals("s", res.at("/query/operands/0/key").asText());
604 assertEquals("korap:token", res.at("/query/operands/1/@type").asText());
605
606 query = "contains(<s>,<np>)";
607 qs.setQuery(query, "poliqarpplus");
608 res = mapper.readTree(qs.toJSON());
609 assertEquals("s", res.at("/query/operands/0/key").asText());
610 assertEquals("np", res.at("/query/operands/1/key").asText());
611
612 query = "contains(<s>,[orth=der][orth=Mann])";
613 qs.setQuery(query, "poliqarpplus");
614 res = mapper.readTree(qs.toJSON());
615 assertEquals("korap:group", res.at("/query/@type").asText());
616 assertEquals("operation:position", res.at("/query/operation").asText());
617 assertEquals("frames:contains", res.at("/query/frames/0").asText());
618 assertEquals("s", res.at("/query/operands/0/key").asText());
619 assertEquals("korap:group", res.at("/query/operands/1/@type").asText());
620 assertEquals("operation:sequence", res.at("/query/operands/1/operation").asText());
621 assertEquals("der", res.at("/query/operands/1/operands/0/wrap/key").asText());
622 assertEquals("Mann", res.at("/query/operands/1/operands/1/wrap/key").asText());
623
624 query = "contains(<s>,[orth=der][orth=Mann]*)";
625 qs.setQuery(query, "poliqarpplus");
626 res = mapper.readTree(qs.toJSON());
627 assertEquals("korap:group", res.at("/query/@type").asText());
628 assertEquals("operation:position", res.at("/query/operation").asText());
629 assertEquals("frames:contains", res.at("/query/frames/0").asText());
630 assertEquals("s", res.at("/query/operands/0/key").asText());
631 assertEquals("korap:group", res.at("/query/operands/1/@type").asText());
632 assertEquals("operation:sequence", res.at("/query/operands/1/operation").asText());
633 assertEquals("der", res.at("/query/operands/1/operands/0/wrap/key").asText());
634 assertEquals("operation:repetition", res.at("/query/operands/1/operands/1/operation").asText());
635 assertEquals(0, res.at("/query/operands/1/operands/1/boundary/min").asInt());
636 assertEquals(true, res.at("/query/operands/1/operands/1/boundary/max").isMissingNode());
637 assertEquals("Mann", res.at("/query/operands/1/operands/1/operands/0/wrap/key").asText());
638
639 query = "contains(<s>,startswith(<np>,<pp>))";
640 qs.setQuery(query, "poliqarpplus");
641 res = mapper.readTree(qs.toJSON());
642 assertEquals("s", res.at("/query/operands/0/key").asText());
643 assertEquals("korap:group", res.at("/query/operands/1/@type").asText());
644 assertEquals("frames:startswith", res.at("/query/operands/1/frames/0").asText());
645 assertEquals("operation:position", res.at("/query/operands/1/operation").asText());
646 assertEquals("np", res.at("/query/operands/1/operands/0/key").asText());
647 assertEquals("pp", res.at("/query/operands/1/operands/1/key").asText());
648
649 query = "[base=Auto]overlaps(<s>, der)";
650 qs.setQuery(query, "poliqarpplus");
651 res = mapper.readTree(qs.toJSON());
652 assertEquals("korap:group", res.at("/query/@type").asText());
653 assertEquals("operation:sequence", res.at("/query/operation").asText());
654 assertEquals("korap:group", res.at("/query/operands/1/@type").asText());
655 assertEquals("operation:position", res.at("/query/operands/1/operation").asText());
656 assertEquals("frames:overlapsLeft", res.at("/query/operands/1/frames/0").asText());
657 assertEquals("frames:overlapsRight", res.at("/query/operands/1/frames/1").asText());
658 assertEquals("korap:span", res.at("/query/operands/1/operands/0/@type").asText());
659 assertEquals("s", res.at("/query/operands/1/operands/0/key").asText());
660 assertEquals("korap:token", res.at("/query/operands/1/operands/1/@type").asText());
661
662 query = "[base=Auto] overlaps(<s>, der)";
663 qs.setQuery(query, "poliqarpplus");
664 res = mapper.readTree(qs.toJSON());
665 assertEquals("korap:group", res.at("/query/@type").asText());
666 assertEquals("operation:sequence", res.at("/query/operation").asText());
667 assertEquals("korap:group", res.at("/query/operands/1/@type").asText());
668 assertEquals("operation:position", res.at("/query/operands/1/operation").asText());
669 assertEquals("frames:overlapsLeft", res.at("/query/operands/1/frames/0").asText());
670 assertEquals("frames:overlapsRight", res.at("/query/operands/1/frames/1").asText());
671 assertEquals("korap:span", res.at("/query/operands/1/operands/0/@type").asText());
672 assertEquals("s", res.at("/query/operands/1/operands/0/key").asText());
673 assertEquals("korap:token", res.at("/query/operands/1/operands/1/@type").asText());
674 };
675
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000676 @Test
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000677 public void testCoordinatedFields() throws QueryException, JsonProcessingException, IOException {
678 query = "[base=Mann&(cas=N|cas=A)]";
679 qs.setQuery(query, "poliqarpplus");
680 res = mapper.readTree(qs.toJSON());
681 assertEquals("korap:token", res.at("/query/@type").asText());
682 assertEquals("relation:and", res.at("/query/wrap/relation").asText());
683 assertEquals("Mann", res.at("/query/wrap/operands/0/key").asText());
684 assertEquals("lemma", res.at("/query/wrap/operands/0/layer").asText());
685 assertEquals("korap:termGroup", res.at("/query/wrap/operands/1/@type").asText());
686 assertEquals("relation:or", res.at("/query/wrap/operands/1/relation").asText());
687 assertEquals("N", res.at("/query/wrap/operands/1/operands/0/key").asText());
688 assertEquals("cas", res.at("/query/wrap/operands/1/operands/0/layer").asText());
689 assertEquals("A", res.at("/query/wrap/operands/1/operands/1/key").asText());
690 assertEquals("cas", res.at("/query/wrap/operands/1/operands/1/layer").asText());
691
692 query = "[base=Mann&cas=N&gen=m]";
693 qs.setQuery(query, "poliqarpplus");
694 res = mapper.readTree(qs.toJSON());
695 assertEquals("korap:token", res.at("/query/@type").asText());
696 assertEquals("relation:and", res.at("/query/wrap/relation").asText());
697 assertEquals("Mann", res.at("/query/wrap/operands/0/key").asText());
698 assertEquals("lemma", res.at("/query/wrap/operands/0/layer").asText());
699 assertEquals("korap:termGroup", res.at("/query/wrap/operands/1/@type").asText());
700 assertEquals("relation:and", res.at("/query/wrap/operands/1/relation").asText());
701 assertEquals("N", res.at("/query/wrap/operands/1/operands/0/key").asText());
702 assertEquals("cas", res.at("/query/wrap/operands/1/operands/0/layer").asText());
703 assertEquals("m", res.at("/query/wrap/operands/1/operands/1/key").asText());
704 assertEquals("gen", res.at("/query/wrap/operands/1/operands/1/layer").asText());
Joachim Bingel53333e62013-12-09 19:25:52 +0000705 }
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000706
Joachim Bingel53333e62013-12-09 19:25:52 +0000707 @Test
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000708 public void testTokenSequence() throws QueryException, JsonProcessingException, IOException {
709 query = "[base=Mann][orth=Frau]";
710 qs.setQuery(query, "poliqarpplus");
711 res = mapper.readTree(qs.toJSON());
712 assertEquals("korap:group", res.at("/query/@type").asText());
713 assertEquals("operation:sequence", res.at("/query/operation").asText());
714 assertEquals("Mann", res.at("/query/operands/0/wrap/key").asText());
715 assertEquals("lemma", res.at("/query/operands/0/wrap/layer").asText());
716 assertEquals("Frau", res.at("/query/operands/1/wrap/key").asText());
717 assertEquals("orth", res.at("/query/operands/1/wrap/layer").asText());
718
719 query = "[base=Mann][orth=Frau][p=NN]";
720 qs.setQuery(query, "poliqarpplus");
721 res = mapper.readTree(qs.toJSON());
722 assertEquals("NN", res.at("/query/operands/2/wrap/key").asText());
723 assertEquals("p", res.at("/query/operands/2/wrap/layer").asText());
724
725 query = "[base=Mann][orth=Frau][p=NN][foo=bar]";
726 qs.setQuery(query, "poliqarpplus");
727 res = mapper.readTree(qs.toJSON());
728 assertEquals("bar", res.at("/query/operands/3/wrap/key").asText());
729 assertEquals("foo", res.at("/query/operands/3/wrap/layer").asText());
Joachim Bingel53333e62013-12-09 19:25:52 +0000730 }
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000731
732 @Test
733 public void testDisjSegments() throws QueryException, JsonProcessingException, IOException {
734 query = "[base=der]|[base=das]";
735 qs.setQuery(query, "poliqarpplus");
736 res = mapper.readTree(qs.toJSON());
737 assertEquals("korap:group", res.at("/query/@type").asText());
738 assertEquals("operation:or", res.at("/query/operation").asText());
739 assertEquals("korap:token", res.at("/query/operands/0/@type").asText());
740 assertEquals("korap:token", res.at("/query/operands/1/@type").asText());
741 assertEquals("der", res.at("/query/operands/0/wrap/key").asText());
742 assertEquals("lemma", res.at("/query/operands/0/wrap/layer").asText());
743 assertEquals("das", res.at("/query/operands/1/wrap/key").asText());
744 assertEquals("lemma", res.at("/query/operands/1/wrap/layer").asText());
745
746 query = "([base=der]|[base=das])[base=Schild]";
747 qs.setQuery(query, "poliqarpplus");
748 res = mapper.readTree(qs.toJSON());
749 assertEquals("korap:group", res.at("/query/@type").asText());
750 assertEquals("operation:sequence", res.at("/query/operation").asText());
751 assertEquals("Schild", res.at("/query/operands/1/wrap/key").asText());
752 assertEquals("korap:group", res.at("/query/operands/0/@type").asText());
753 assertEquals("operation:or", res.at("/query/operands/0/operation").asText());
754
755 query = "[base=Schild]([base=der]|[base=das])";
756 qs.setQuery(query, "poliqarpplus");
757 res = mapper.readTree(qs.toJSON());
758 assertEquals("Schild", res.at("/query/operands/0/wrap/key").asText());
759 assertEquals("korap:group", res.at("/query/operands/1/@type").asText());
760 assertEquals("operation:or", res.at("/query/operands/1/operation").asText());
761
762 query = "([orth=der][base=katze])|([orth=eine][base=baum])";
763 qs.setQuery(query, "poliqarpplus");
764 res = mapper.readTree(qs.toJSON());
765 assertEquals("korap:group", res.at("/query/@type").asText());
766 assertEquals("operation:or", res.at("/query/operation").asText());
767 assertEquals("korap:group", res.at("/query/operands/0/@type").asText());
768 assertEquals("operation:sequence", res.at("/query/operands/0/operation").asText());
769 assertEquals("korap:token", res.at("/query/operands/0/operands/0/@type").asText());
770 assertEquals("der", res.at("/query/operands/0/operands/0/wrap/key").asText());
771 assertEquals("katze", res.at("/query/operands/0/operands/1/wrap/key").asText());
772 assertEquals("eine", res.at("/query/operands/1/operands/0/wrap/key").asText());
773 assertEquals("baum", res.at("/query/operands/1/operands/1/wrap/key").asText());
774
775 query = "[orth=der][base=katze]|[orth=eine][base=baum]";
776 qs.setQuery(query, "poliqarpplus");
777 res = mapper.readTree(qs.toJSON());
778 assertEquals("korap:group", res.at("/query/@type").asText());
779 assertEquals("operation:or", res.at("/query/operation").asText());
780 assertEquals("korap:group", res.at("/query/operands/0/@type").asText());
781 assertEquals("operation:sequence", res.at("/query/operands/0/operation").asText());
782 assertEquals("korap:token", res.at("/query/operands/0/operands/0/@type").asText());
783 assertEquals("der", res.at("/query/operands/0/operands/0/wrap/key").asText());
784 assertEquals("katze", res.at("/query/operands/0/operands/1/wrap/key").asText());
785 assertEquals("eine", res.at("/query/operands/1/operands/0/wrap/key").asText());
786 assertEquals("baum", res.at("/query/operands/1/operands/1/wrap/key").asText());
787
788 query = "[orth=der]([base=katze]|[orth=eine])[base=baum]";
789 qs.setQuery(query, "poliqarpplus");
790 res = mapper.readTree(qs.toJSON());
791 assertEquals("korap:group", res.at("/query/@type").asText());
792 assertEquals("operation:sequence", res.at("/query/operation").asText());
793 assertEquals("korap:group", res.at("/query/operands/1/@type").asText());
794 assertEquals("operation:or", res.at("/query/operands/1/operation").asText());
795 assertEquals("korap:token", res.at("/query/operands/0/@type").asText());
796 assertEquals("korap:token", res.at("/query/operands/2/@type").asText());
797 assertEquals("der", res.at("/query/operands/0/wrap/key").asText());
798 assertEquals("katze", res.at("/query/operands/1/operands/0/wrap/key").asText());
799 assertEquals("eine", res.at("/query/operands/1/operands/1/wrap/key").asText());
800 assertEquals("baum", res.at("/query/operands/2/wrap/key").asText());
801
802 query = "[orth=der][base=katze]|[orth=der][base=hund]|[orth=der][base=baum]";
803 qs.setQuery(query, "poliqarpplus");
804 res = mapper.readTree(qs.toJSON());
805 assertEquals("der", res.at("/query/operands/2/operands/0/wrap/key").asText());
806 assertEquals("baum", res.at("/query/operands/2/operands/1/wrap/key").asText());
807
808 query = "[orth=der]([base=katze]|[base=hund]|[base=baum])";
809 qs.setQuery(query, "poliqarpplus");
810 res = mapper.readTree(qs.toJSON());
811 assertEquals("korap:group", res.at("/query/@type").asText());
812 assertEquals("operation:sequence", res.at("/query/operation").asText());
813 assertEquals("korap:group", res.at("/query/operands/1/@type").asText());
814 assertEquals("operation:or", res.at("/query/operands/1/operation").asText());
815 assertEquals("korap:token", res.at("/query/operands/0/@type").asText());
816 assertEquals("korap:token", res.at("/query/operands/1/operands/0/@type").asText());
817 assertEquals("korap:token", res.at("/query/operands/1/operands/1/@type").asText());
818 assertEquals("korap:token", res.at("/query/operands/1/operands/2/@type").asText());
819 assertEquals("katze", res.at("/query/operands/1/operands/0/wrap/key").asText());
820 assertEquals("hund", res.at("/query/operands/1/operands/1/wrap/key").asText());
821 assertEquals("baum", res.at("/query/operands/1/operands/2/wrap/key").asText());
822 }
823
824 @Test
825 public void testTokenSpanSequence() throws QueryException, JsonProcessingException, IOException {
826 query = "[base=Mann]<vp>";
827 qs.setQuery(query, "poliqarpplus");
828 res = mapper.readTree(qs.toJSON());
829 assertEquals("korap:group", res.at("/query/@type").asText());
830 assertEquals("operation:sequence", res.at("/query/operation").asText());
831 assertEquals("korap:token", res.at("/query/operands/0/@type").asText());
832 assertEquals("Mann", res.at("/query/operands/0/wrap/key").asText());
833 assertEquals("korap:span", res.at("/query/operands/1/@type").asText());
834 assertEquals("vp", res.at("/query/operands/1/key").asText());
835
836 query = "<vp>[base=Mann]";
837 qs.setQuery(query, "poliqarpplus");
838 res = mapper.readTree(qs.toJSON());
839 assertEquals("korap:group", res.at("/query/@type").asText());
840 assertEquals("operation:sequence", res.at("/query/operation").asText());
841 assertEquals("korap:span", res.at("/query/operands/0/@type").asText());
842 assertEquals("vp", res.at("/query/operands/0/key").asText());
843 assertEquals("korap:token", res.at("/query/operands/1/@type").asText());
844 assertEquals("Mann", res.at("/query/operands/1/wrap/key").asText());
845
846 query = "<vp>[base=Mann]<pp>";
847 qs.setQuery(query, "poliqarpplus");
848 res = mapper.readTree(qs.toJSON());
849 assertEquals("korap:span", res.at("/query/operands/2/@type").asText());
850 assertEquals("pp", res.at("/query/operands/2/key").asText());
851
852 query = "<vp>[base=Mann]<pp><np>";
853 qs.setQuery(query, "poliqarpplus");
854 res = mapper.readTree(qs.toJSON());
855 assertEquals("pp", res.at("/query/operands/2/key").asText());
856 assertEquals("np", res.at("/query/operands/3/key").asText());
857 }
858
Joachim Bingel53333e62013-12-09 19:25:52 +0000859 @Test
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000860 public void testClasses() throws QueryException, JsonProcessingException, IOException {
861 query = "{[base=Mann]}";
862 qs.setQuery(query, "poliqarpplus");
863 res = mapper.readTree(qs.toJSON());
864 assertEquals("korap:group", res.at("/query/@type").asText());
865 assertEquals("operation:class", res.at("/query/operation").asText());
866 assertEquals(1, res.at("/query/classOut").asInt());
867 assertEquals(true, res.at("/query/classIn").isMissingNode());
868 assertEquals("Mann", res.at("/query/operands/0/wrap/key").asText());
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000869
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000870 query = "{[base=Mann][orth=Frau]}";
871 qs.setQuery(query, "poliqarpplus");
872 res = mapper.readTree(qs.toJSON());
873 assertEquals("korap:group", res.at("/query/@type").asText());
874 assertEquals("operation:class", res.at("/query/operation").asText());
875 assertEquals(1, res.at("/query/classOut").asInt());
876 assertEquals(true, res.at("/query/classIn").isMissingNode());
877 assertEquals("Mann", res.at("/query/operands/0/operands/0/wrap/key").asText());
878 assertEquals("Frau", res.at("/query/operands/0/operands/1/wrap/key").asText());
879
880 query = "[p=NN]{[base=Mann][orth=Frau]}";
881 qs.setQuery(query, "poliqarpplus");
882 res = mapper.readTree(qs.toJSON());
883 assertEquals("korap:group", res.at("/query/@type").asText());
884 assertEquals("operation:sequence", res.at("/query/operation").asText());
885 assertEquals("korap:group", res.at("/query/operands/1/@type").asText());
886 assertEquals("operation:class", res.at("/query/operands/1/operation").asText());
887 assertEquals(1, res.at("/query/operands/1/classOut").asInt());
888 assertEquals(true, res.at("/query/operands/1/classIn").isMissingNode());
889 assertEquals("Mann", res.at("/query/operands/1/operands/0/operands/0/wrap/key").asText());
890 assertEquals("Frau", res.at("/query/operands/1/operands/0/operands/1/wrap/key").asText());
891
892 query = "{[base=Mann][orth=Frau]}[p=NN]";
893 qs.setQuery(query, "poliqarpplus");
894 res = mapper.readTree(qs.toJSON());
895 assertEquals("korap:group", res.at("/query/@type").asText());
896 assertEquals("operation:sequence", res.at("/query/operation").asText());
897 assertEquals("korap:group", res.at("/query/operands/0/@type").asText());
898 assertEquals("operation:class", res.at("/query/operands/0/operation").asText());
899 assertEquals(1, res.at("/query/operands/0/classOut").asInt());
900 assertEquals(true, res.at("/query/operands/0/classIn").isMissingNode());
901 assertEquals("Mann", res.at("/query/operands/0/operands/0/operands/0/wrap/key").asText());
902 assertEquals("Frau", res.at("/query/operands/0/operands/0/operands/1/wrap/key").asText());
903
904 query = "{2:{1:[tt/p=ADJA]}[mate/p=NN]}";
905 qs.setQuery(query, "poliqarpplus");
906 res = mapper.readTree(qs.toJSON());
907 assertEquals("korap:group", res.at("/query/@type").asText());
908 assertEquals("operation:class", res.at("/query/operation").asText());
909 assertEquals("operation:sequence", res.at("/query/operands/0/operation").asText());
910 assertEquals(2, res.at("/query/classOut").asInt());
911 assertEquals(1, res.at("/query/operands/0/operands/0/classOut").asInt());
912 }
913
914 @Test
915 public void testFocusSplit() throws QueryException, JsonProcessingException, IOException {
916 query = "focus([orth=Der]{[orth=Mann]})";
917 qs.setQuery(query, "poliqarpplus");
918 res = mapper.readTree(qs.toJSON());
919 assertEquals("korap:reference", res.at("/query/@type").asText());
920 assertEquals("operation:focus", res.at("/query/operation").asText());
921 assertEquals(1, res.at("/query/classRef/0").asInt());
922 assertEquals("operation:sequence", res.at("/query/operands/0/operation").asText());
923 assertEquals("operation:class", res.at("/query/operands/0/operands/1/operation").asText());
924 assertEquals(1, res.at("/query/operands/0/operands/1/classOut").asInt());
925 assertEquals("Mann", res.at("/query/operands/0/operands/1/operands/0/wrap/key").asText());
Joachim Bingel8fbdfa72014-12-04 10:33:34 +0000926
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000927 query = "focus([orth=Der]{[orth=Mann][orth=geht]})";
928 qs.setQuery(query, "poliqarpplus");
929 res = mapper.readTree(qs.toJSON());
930 assertEquals("operation:sequence", res.at("/query/operands/0/operands/1/operands/0/operation").asText());
931 assertEquals("Mann", res.at("/query/operands/0/operands/1/operands/0/operands/0/wrap/key").asText());
932 assertEquals("geht", res.at("/query/operands/0/operands/1/operands/0/operands/1/wrap/key").asText());
Joachim Bingel8fbdfa72014-12-04 10:33:34 +0000933
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000934 query = "focus(2:[orth=Der]{2:[orth=Mann][orth=geht]})";
935 qs.setQuery(query, "poliqarpplus");
936 res = mapper.readTree(qs.toJSON());
937 assertEquals(2, res.at("/query/classRef/0").asInt());
938 assertEquals(2, res.at("/query/operands/0/operands/1/classOut").asInt());
Joachim Bingel8fbdfa72014-12-04 10:33:34 +0000939
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000940 query = "focus(3:startswith(<s>,{3:<np>}))";
941 qs.setQuery(query, "poliqarpplus");
942 res = mapper.readTree(qs.toJSON());
943 assertEquals(3, res.at("/query/classRef/0").asInt());
944 assertEquals("korap:reference", res.at("/query/@type").asText());
945 assertEquals("operation:focus", res.at("/query/operation").asText());
946 assertEquals("operation:position", res.at("/query/operands/0/operation").asText());
947 assertEquals("operation:class", res.at("/query/operands/0/operands/1/operation").asText());
948 assertEquals(3, res.at("/query/operands/0/operands/1/classOut").asInt());
949 assertEquals("frames:startswith", res.at("/query/operands/0/frames/0").asText());
Joachim Bingel8fbdfa72014-12-04 10:33:34 +0000950
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000951 query = "focus(1000:startswith(<s>,{1000:<np>}))";
952 qs.setQuery(query, "poliqarpplus");
953 res = mapper.readTree(qs.toJSON());
954 assertEquals(127, res.at("/query/classRef/0").asInt());
955 assertEquals(127, res.at("/query/operands/0/operands/1/classOut").asInt());
Joachim Bingel8fbdfa72014-12-04 10:33:34 +0000956
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000957 query = "focus(3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))";
958 qs.setQuery(query, "poliqarpplus");
959 res = mapper.readTree(qs.toJSON());
960 assertEquals(3, res.at("/query/classRef/0").asInt());
961 assertEquals("korap:reference", res.at("/query/@type").asText());
962 assertEquals("operation:focus", res.at("/query/operation").asText());
963 assertEquals("operation:position", res.at("/query/operands/0/operation").asText());
964 assertEquals("frames:startswith", res.at("/query/operands/0/frames/0").asText());
965 assertEquals("operation:class", res.at("/query/operands/0/operands/1/operation").asText());
966 assertEquals(3, res.at("/query/operands/0/operands/1/classOut").asInt());
967 assertEquals("operation:sequence", res.at("/query/operands/0/operands/1/operands/0/operation").asText());
968 assertEquals("operation:class", res.at("/query/operands/0/operands/1/operands/0/operands/1/operation").asText());
969 assertEquals(1, res.at("/query/operands/0/operands/1/operands/0/operands/1/classOut").asInt());
970 assertEquals("operation:sequence", res.at("/query/operands/0/operands/1/operands/0/operands/1/operands/0/operation").asText());
971 assertEquals("operation:class", res.at("/query/operands/0/operands/1/operands/0/operands/1/operands/0/operands/1/operation").asText());
972 assertEquals(2, res.at("/query/operands/0/operands/1/operands/0/operands/1/operands/0/operands/1/classOut").asInt());
Joachim Bingel8fbdfa72014-12-04 10:33:34 +0000973
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000974 query = "split(3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))";
975 qs.setQuery(query, "poliqarpplus");
976 res = mapper.readTree(qs.toJSON());
977 assertEquals(3, res.at("/query/classRef/0").asInt());
978 assertEquals(true, res.at("/query/classRef/1").isMissingNode());
979 assertEquals("korap:reference", res.at("/query/@type").asText());
980 assertEquals("operation:split", res.at("/query/operation").asText());
Joachim Bingel8fbdfa72014-12-04 10:33:34 +0000981
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000982 query = "split(2|3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))";
983 qs.setQuery(query, "poliqarpplus");
984 res = mapper.readTree(qs.toJSON());
985 assertEquals(2, res.at("/query/classRef/0").asInt());
986 assertEquals(3, res.at("/query/classRef/1").asInt());
987 assertEquals("classRefOp:intersection", res.at("/query/classRefOp").asText());
988 assertEquals("korap:reference", res.at("/query/@type").asText());
989 assertEquals("operation:split", res.at("/query/operation").asText());
Joachim Bingel8fbdfa72014-12-04 10:33:34 +0000990
Joachim Bingel7cc5f352014-12-03 09:40:04 +0000991 query = "focus(1:{[base=der]}{1:[pos=ADJA]})";
992 qs.setQuery(query, "poliqarpplus");
993 res = mapper.readTree(qs.toJSON());
994 assertEquals(1, res.at("/query/classRef/0").asInt());
995 assertEquals(1, res.at("/query/operands/0/operands/0/classOut").asInt());
996 assertEquals(1, res.at("/query/operands/0/operands/1/classOut").asInt());
Joachim Bingel53333e62013-12-09 19:25:52 +0000997 }
Joachim Bingel8fbdfa72014-12-04 10:33:34 +0000998
Joachim Bingel53333e62013-12-09 19:25:52 +0000999 @Test
Joachim Bingel7cc5f352014-12-03 09:40:04 +00001000 public void testSubmatch() throws QueryException, JsonProcessingException, IOException {
Joachim Bingel9bbd4fc2014-08-11 14:56:48 +00001001 query = "submatch(1,:<s>)";
Joachim Bingel7cc5f352014-12-03 09:40:04 +00001002 qs.setQuery(query, "poliqarpplus");
1003 res = mapper.readTree(qs.toJSON());
1004 assertEquals("korap:reference", res.at("/query/@type").asText());
1005 assertEquals("operation:focus", res.at("/query/operation").asText());
1006 assertEquals(1, res.at("/query/spanRef/0").asInt());
1007 assertEquals(true, res.at("/query/spanRef/1").isMissingNode());
1008 assertEquals("s", res.at("/query/operands/0/key").asText());
Joachim Bingel8fbdfa72014-12-04 10:33:34 +00001009
Joachim Bingel9bbd4fc2014-08-11 14:56:48 +00001010 query = "submatch(1,4:<s>)";
Joachim Bingel7cc5f352014-12-03 09:40:04 +00001011 qs.setQuery(query, "poliqarpplus");
1012 res = mapper.readTree(qs.toJSON());
1013 assertEquals("korap:reference", res.at("/query/@type").asText());
1014 assertEquals("operation:focus", res.at("/query/operation").asText());
1015 assertEquals(1, res.at("/query/spanRef/0").asInt());
1016 assertEquals(4, res.at("/query/spanRef/1").asInt());
Joachim Bingel8fbdfa72014-12-04 10:33:34 +00001017
Joachim Bingel9bbd4fc2014-08-11 14:56:48 +00001018 query = "submatch(1,4:contains(<s>,[base=Haus]))";
Joachim Bingel7cc5f352014-12-03 09:40:04 +00001019 qs.setQuery(query, "poliqarpplus");
1020 res = mapper.readTree(qs.toJSON());
1021 assertEquals("korap:reference", res.at("/query/@type").asText());
1022 assertEquals("operation:focus", res.at("/query/operation").asText());
1023 assertEquals(1, res.at("/query/spanRef/0").asInt());
1024 assertEquals(4, res.at("/query/spanRef/1").asInt());
1025 assertEquals("frames:contains", res.at("/query/operands/0/frames/0").asText());
1026 assertEquals("s", res.at("/query/operands/0/operands/0/key").asText());
1027 assertEquals("Haus", res.at("/query/operands/0/operands/1/wrap/key").asText());
Joachim Bingel23c31ad2014-08-11 09:44:46 +00001028 }
Joachim Bingel23c31ad2014-08-11 09:44:46 +00001029 @Test
Joachim Bingel7cc5f352014-12-03 09:40:04 +00001030 public void testRelations() throws QueryException, JsonProcessingException, IOException {
Joachim Bingel23c31ad2014-08-11 09:44:46 +00001031 query = "relatesTo(<s>,<np>)";
Joachim Bingel7cc5f352014-12-03 09:40:04 +00001032 qs.setQuery(query, "poliqarpplus");
1033 res = mapper.readTree(qs.toJSON());
1034 assertEquals("korap:group", res.at("/query/@type").asText());
1035 assertEquals("operation:relation", res.at("/query/operation").asText());
1036 assertEquals("korap:relation", res.at("/query/relation/@type").asText());
1037 assertEquals("s", res.at("/query/operands/0/key").asText());
1038 assertEquals("np", res.at("/query/operands/1/key").asText());
Joachim Bingel8fbdfa72014-12-04 10:33:34 +00001039
Joachim Bingel23c31ad2014-08-11 09:44:46 +00001040 query = "relatesTo([base=Baum],<np>)";
Joachim Bingel7cc5f352014-12-03 09:40:04 +00001041 qs.setQuery(query, "poliqarpplus");
1042 res = mapper.readTree(qs.toJSON());
1043 assertEquals("korap:group", res.at("/query/@type").asText());
1044 assertEquals("operation:relation", res.at("/query/operation").asText());
1045 assertEquals("korap:relation", res.at("/query/relation/@type").asText());
1046 assertEquals("Baum", res.at("/query/operands/0/wrap/key").asText());
1047 assertEquals("np", res.at("/query/operands/1/key").asText());
Joachim Bingel8fbdfa72014-12-04 10:33:34 +00001048
Joachim Bingel7cc5f352014-12-03 09:40:04 +00001049 query = "relatesTo(Baum,<np>)";
1050 qs.setQuery(query, "poliqarpplus");
1051 res = mapper.readTree(qs.toJSON());
1052 assertEquals("orth", res.at("/query/operands/0/wrap/layer").asText());
1053 assertEquals("Baum", res.at("/query/operands/0/wrap/key").asText());
Joachim Bingel8fbdfa72014-12-04 10:33:34 +00001054
Joachim Bingel23c31ad2014-08-11 09:44:46 +00001055 query = "relatesTo(mate/d=HEAD:<np>,[base=Baum])";
Joachim Bingel7cc5f352014-12-03 09:40:04 +00001056 qs.setQuery(query, "poliqarpplus");
1057 res = mapper.readTree(qs.toJSON());
1058 assertEquals("lemma", res.at("/query/operands/1/wrap/layer").asText());
1059 assertEquals("Baum", res.at("/query/operands/1/wrap/key").asText());
1060 assertEquals("korap:relation", res.at("/query/relation/@type").asText());
1061 assertEquals("mate", res.at("/query/relation/foundry").asText());
1062 assertEquals("d", res.at("/query/relation/layer").asText());
1063 assertEquals("HEAD", res.at("/query/relation/key").asText());
Joachim Bingel8fbdfa72014-12-04 10:33:34 +00001064
Joachim Bingel7cc5f352014-12-03 09:40:04 +00001065 query = "dominates(Baum,<np>)";
1066 qs.setQuery(query, "poliqarpplus");
1067 res = mapper.readTree(qs.toJSON());
1068 assertEquals("orth", res.at("/query/operands/0/wrap/layer").asText());
1069 assertEquals("Baum", res.at("/query/operands/0/wrap/key").asText());
1070 assertEquals("korap:relation", res.at("/query/relation/@type").asText());
1071 assertEquals("c", res.at("/query/relation/layer").asText());
Joachim Bingel8fbdfa72014-12-04 10:33:34 +00001072
Joachim Bingel7cc5f352014-12-03 09:40:04 +00001073 query = "dominates(cnx/c:<vp>,<np>)";
1074 qs.setQuery(query, "poliqarpplus");
1075 res = mapper.readTree(qs.toJSON());
1076 assertEquals("cnx", res.at("/query/relation/foundry").asText());
1077 assertEquals("c", res.at("/query/relation/layer").asText());
Joachim Bingel8fbdfa72014-12-04 10:33:34 +00001078
Joachim Bingel7cc5f352014-12-03 09:40:04 +00001079 query = "dominates(cnx/c*:<vp>,<np>)";
1080 qs.setQuery(query, "poliqarpplus");
1081 res = mapper.readTree(qs.toJSON());
1082 assertEquals("cnx", res.at("/query/relation/foundry").asText());
1083 assertEquals("c", res.at("/query/relation/layer").asText());
1084 assertEquals(0, res.at("/query/relation/boundary/min").asInt());
1085 assertEquals(true, res.at("/query/relation/boundary/max").isMissingNode());
Joachim Bingel8fbdfa72014-12-04 10:33:34 +00001086
Joachim Bingel7cc5f352014-12-03 09:40:04 +00001087 query = "dominates(cnx/c{1,5}:<vp>,<np>)";
1088 qs.setQuery(query, "poliqarpplus");
1089 res = mapper.readTree(qs.toJSON());
1090 assertEquals(1, res.at("/query/relation/boundary/min").asInt());
1091 assertEquals(5, res.at("/query/relation/boundary/max").asInt());
Joachim Bingel8fbdfa72014-12-04 10:33:34 +00001092
Joachim Bingel7cc5f352014-12-03 09:40:04 +00001093 query = "dominates(cnx/c{,5}:<vp>,<np>)";
1094 qs.setQuery(query, "poliqarpplus");
1095 res = mapper.readTree(qs.toJSON());
1096 assertEquals(0, res.at("/query/relation/boundary/min").asInt());
1097 assertEquals(5, res.at("/query/relation/boundary/max").asInt());
Joachim Bingel8fbdfa72014-12-04 10:33:34 +00001098
Joachim Bingel7cc5f352014-12-03 09:40:04 +00001099 query = "dominates(cnx/c{5}:<vp>,<np>)";
1100 qs.setQuery(query, "poliqarpplus");
1101 res = mapper.readTree(qs.toJSON());
1102 assertEquals(5, res.at("/query/relation/boundary/min").asInt());
1103 assertEquals(5, res.at("/query/relation/boundary/max").asInt());
Joachim Bingel53333e62013-12-09 19:25:52 +00001104 }
Joachim Bingel8fbdfa72014-12-04 10:33:34 +00001105
Joachim Bingel16da4e12013-12-17 09:48:12 +00001106 @Test
Joachim Bingel7cc5f352014-12-03 09:40:04 +00001107 public void testAlign() throws QueryException, JsonProcessingException, IOException {
Joachim Bingel832800e2014-10-17 14:46:39 +00001108 query = "[orth=der]^[orth=Mann]";
Joachim Bingel7cc5f352014-12-03 09:40:04 +00001109 qs.setQuery(query, "poliqarpplus");
1110 res = mapper.readTree(qs.toJSON());
1111 assertEquals("operation:sequence", res.at("/query/operation").asText());
1112 assertEquals("der", res.at("/query/operands/0/wrap/key").asText());
1113 assertEquals("operation:class", res.at("/query/operands/1/operation").asText());
1114 assertEquals(129, res.at("/query/operands/1/classOut").asInt());
1115 assertEquals(129, res.at("/meta/alignment").asInt());
Joachim Bingel8fbdfa72014-12-04 10:33:34 +00001116
Joachim Bingel832800e2014-10-17 14:46:39 +00001117 query = "[orth=der]^[orth=große][orth=Mann]";
Joachim Bingel7cc5f352014-12-03 09:40:04 +00001118 qs.setQuery(query, "poliqarpplus");
1119 res = mapper.readTree(qs.toJSON());
1120 assertEquals("operation:sequence", res.at("/query/operation").asText());
1121 assertEquals("operation:class", res.at("/query/operands/1/operation").asText());
1122 assertEquals("operation:sequence", res.at("/query/operands/1/operands/0/operation").asText());
1123 assertEquals("große", res.at("/query/operands/1/operands/0/operands/0/wrap/key").asText());
1124 assertEquals("Mann", res.at("/query/operands/1/operands/0/operands/1/wrap/key").asText());
1125 assertEquals(129, res.at("/query/operands/1/classOut").asInt());
1126 assertEquals(129, res.at("/meta/alignment").asInt());
Joachim Bingel8fbdfa72014-12-04 10:33:34 +00001127
Joachim Bingel832800e2014-10-17 14:46:39 +00001128 query = "([base=a]^[base=b])|[base=c]";
Joachim Bingel7cc5f352014-12-03 09:40:04 +00001129 qs.setQuery(query, "poliqarpplus");
1130 res = mapper.readTree(qs.toJSON());
1131 assertEquals("operation:or", res.at("/query/operation").asText());
1132 assertEquals("operation:sequence", res.at("/query/operands/0/operation").asText());
1133 assertEquals("operation:class", res.at("/query/operands/0/operands/1/operation").asText());
1134 assertEquals("a", res.at("/query/operands/0/operands/0/wrap/key").asText());
1135 assertEquals("b", res.at("/query/operands/0/operands/1/operands/0/wrap/key").asText());
1136 assertEquals("c", res.at("/query/operands/1/wrap/key").asText());
1137 assertEquals(129, res.at("/query/operands/0/operands/1/classOut").asInt());
1138 assertEquals(129, res.at("/meta/alignment").asInt());
Joachim Bingel8fbdfa72014-12-04 10:33:34 +00001139
Joachim Bingel832800e2014-10-17 14:46:39 +00001140 query = "([base=a]^[base=b][base=c])|[base=d]";
Joachim Bingel7cc5f352014-12-03 09:40:04 +00001141 qs.setQuery(query, "poliqarpplus");
1142 res = mapper.readTree(qs.toJSON());
1143 assertEquals("operation:sequence", res.at("/query/operands/0/operands/1/operands/0/operation").asText());
1144 assertEquals("b", res.at("/query/operands/0/operands/1/operands/0/operands/0/wrap/key").asText());
1145 assertEquals("c", res.at("/query/operands/0/operands/1/operands/0/operands/1/wrap/key").asText());
1146 assertEquals("d", res.at("/query/operands/1/wrap/key").asText());
Joachim Bingel8fbdfa72014-12-04 10:33:34 +00001147
Joachim Bingel832800e2014-10-17 14:46:39 +00001148 query = "([base=a]^[base=b]^[base=c])|[base=d]";
Joachim Bingel7cc5f352014-12-03 09:40:04 +00001149 qs.setQuery(query, "poliqarpplus");
1150 res = mapper.readTree(qs.toJSON());
1151 assertEquals("operation:sequence", res.at("/query/operands/0/operands/1/operands/0/operation").asText());
1152 assertEquals("b", res.at("/query/operands/0/operands/1/operands/0/operands/0/wrap/key").asText());
1153 assertEquals("c", res.at("/query/operands/0/operands/1/operands/0/operands/1/operands/0/wrap/key").asText());
1154 assertEquals("d", res.at("/query/operands/1/wrap/key").asText());
1155 assertEquals(129, res.at("/meta/alignment/0").asInt());
1156 assertEquals(130, res.at("/meta/alignment/1").asInt());
Joachim Bingel16da4e12013-12-17 09:48:12 +00001157 }
Joachim Bingel8fbdfa72014-12-04 10:33:34 +00001158
Joachim Bingel16da4e12013-12-17 09:48:12 +00001159 @Test
Joachim Bingel7cc5f352014-12-03 09:40:04 +00001160 public void testSimpleQueries() throws QueryException, JsonProcessingException, IOException {
1161 query = "Baum";
1162 qs.setQuery(query, "poliqarpplus");
1163 res = mapper.readTree(qs.toJSON());
1164 assertEquals("korap:token", res.at("/query/@type").asText());
1165 assertEquals("korap:term", res.at("/query/wrap/@type").asText());
1166 assertEquals("Baum", res.at("/query/wrap/key").asText());
1167 assertEquals("orth", res.at("/query/wrap/layer").asText());
1168 assertEquals("match:eq", res.at("/query/wrap/match").asText());
Joachim Bingel8fbdfa72014-12-04 10:33:34 +00001169
Joachim Bingel7cc5f352014-12-03 09:40:04 +00001170 query = "Der Baum";
1171 qs.setQuery(query, "poliqarpplus");
1172 res = mapper.readTree(qs.toJSON());
1173 assertEquals("korap:group", res.at("/query/@type").asText());
1174 assertEquals("operation:sequence", res.at("/query/operation").asText());
1175 assertEquals("korap:token", res.at("/query/operands/0/@type").asText());
1176 assertEquals("korap:term", res.at("/query/operands/0/wrap/@type").asText());
1177 assertEquals("Der", res.at("/query/operands/0/wrap/key").asText());
1178 assertEquals("Baum", res.at("/query/operands/1/wrap/key").asText());
1179 assertEquals("orth", res.at("/query/operands/0/wrap/layer").asText());
1180 assertEquals("match:eq", res.at("/query/operands/0/wrap/match").asText());
1181 assertEquals("orth", res.at("/query/operands/1/wrap/layer").asText());
1182 assertEquals("match:eq", res.at("/query/operands/1/wrap/match").asText());
Joachim Bingel8fbdfa72014-12-04 10:33:34 +00001183
Joachim Bingel7cc5f352014-12-03 09:40:04 +00001184 query = "Der große Baum";
1185 qs.setQuery(query, "poliqarpplus");
1186 res = mapper.readTree(qs.toJSON());
1187 assertEquals("Der", res.at("/query/operands/0/wrap/key").asText());
1188 assertEquals("große", res.at("/query/operands/1/wrap/key").asText());
1189 assertEquals("Baum", res.at("/query/operands/2/wrap/key").asText());
Joachim Bingel8fbdfa72014-12-04 10:33:34 +00001190
Joachim Bingel7cc5f352014-12-03 09:40:04 +00001191 query = "Der (große|kleine) Baum";
1192 qs.setQuery(query, "poliqarpplus");
1193 res = mapper.readTree(qs.toJSON());
1194 assertEquals("Der", res.at("/query/operands/0/wrap/key").asText());
1195 assertEquals("operation:or", res.at("/query/operands/1/operation").asText());
1196 assertEquals("große", res.at("/query/operands/1/operands/0/wrap/key").asText());
1197 assertEquals("kleine", res.at("/query/operands/1/operands/1/wrap/key").asText());
1198 assertEquals("Baum", res.at("/query/operands/2/wrap/key").asText());
Joachim Bingel8fbdfa72014-12-04 10:33:34 +00001199
Joachim Bingel7cc5f352014-12-03 09:40:04 +00001200 query = "der große Baum | der kleine Baum";
1201 qs.setQuery(query, "poliqarpplus");
1202 res = mapper.readTree(qs.toJSON());
1203 assertEquals("operation:or", res.at("/query/operation").asText());
1204 assertEquals("der", res.at("/query/operands/0/operands/0/wrap/key").asText());
1205 assertEquals("große", res.at("/query/operands/0/operands/1/wrap/key").asText());
1206 assertEquals("Baum", res.at("/query/operands/0/operands/2/wrap/key").asText());
1207 assertEquals("der", res.at("/query/operands/1/operands/0/wrap/key").asText());
1208 assertEquals("kleine", res.at("/query/operands/1/operands/1/wrap/key").asText());
1209 assertEquals("Baum", res.at("/query/operands/1/operands/2/wrap/key").asText());
Joachim Bingel8fbdfa72014-12-04 10:33:34 +00001210
Joachim Bingel7cc5f352014-12-03 09:40:04 +00001211 query = "Der [p=ADJA] Baum";
1212 qs.setQuery(query, "poliqarpplus");
1213 res = mapper.readTree(qs.toJSON());
1214 assertEquals("Der", res.at("/query/operands/0/wrap/key").asText());
1215 assertEquals("ADJA", res.at("/query/operands/1/wrap/key").asText());
1216 assertEquals("p", res.at("/query/operands/1/wrap/layer").asText());
1217 assertEquals("Baum", res.at("/query/operands/2/wrap/key").asText());
Joachim Bingelb68361c2014-10-22 14:15:09 +00001218 }
Joachim Bingel53333e62013-12-09 19:25:52 +00001219}
1220
Joachim Bingel7cc5f352014-12-03 09:40:04 +00001221