blob: 35753d64039b1f1f9e01692413b54281bf503d90 [file] [log] [blame]
Joachim Bingel53333e62013-12-09 19:25:52 +00001import static org.junit.Assert.*;
2
3import org.junit.Test;
4
5import de.ids_mannheim.korap.query.serialize.PoliqarpPlusTree;
Joachim Bingel16da4e12013-12-17 09:48:12 +00006import de.ids_mannheim.korap.util.QueryException;
Joachim Bingel53333e62013-12-09 19:25:52 +00007
8public class PoliqarpPlusTreeTest {
9
10 PoliqarpPlusTree ppt;
11 String map;
12
13 private boolean equalsContent(String str, Object map) {
14 str = str.replaceAll(" ", "");
15 String mapStr = map.toString().replaceAll(" ", "");
16 return str.equals(mapStr);
17 }
18
Joachim Bingel16da4e12013-12-17 09:48:12 +000019 private boolean equalsQueryContent(String res, String query) throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +000020 res = res.replaceAll(" ", "");
21 ppt = new PoliqarpPlusTree(query);
22 String queryMap = ppt.getRequestMap().get("query").toString().replaceAll(" ", "");
23 return res.equals(queryMap);
24 }
25
26 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +000027 public void testContext() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +000028 String contextString = "{korap=http://korap.ids-mannheim.de/ns/query, @language=de, operands={@id=korap:operands, @container=@list}, relation={@id=korap:relation, @type=korap:relation#types}, class={@id=korap:class, @type=xsd:integer}, query=korap:query, filter=korap:filter, meta=korap:meta}";
29 ppt = new PoliqarpPlusTree("[base=test]");
30 assertTrue(equalsContent(contextString, ppt.getRequestMap().get("@context")));
31 }
32
33 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +000034 public void testSingleTokens() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +000035 // [base=Mann]
36 String token1 = "{@type=korap:token, @value={@type=korap:term, @value=base:Mann, relation==}}";
37 assertTrue(equalsQueryContent(token1, "[base=Mann]"));
38
39 // [orth!=Frau]
40 String token2 = "{@type=korap:token, @value={@type=korap:term, @value=orth:Frau, relation=!=}}";
41 assertTrue(equalsQueryContent(token2, "[orth!=Frau]"));
42
43 // [!p=NN]
44 String token3 = "{@type=korap:token, @value={@type=korap:term, @value=p:NN, relation=!=}}";
45 assertTrue(equalsQueryContent(token3, "[!p=NN]"));
46
47 // [!p!=NN]
48 String token4 = "{@type=korap:token, @value={@type=korap:term, @value=p:NN, relation==}}";
49 assertTrue(equalsQueryContent(token4, "[!p!=NN]"));
50 }
51
52 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +000053 public void testElements() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +000054 // <s>
55 String elem1 = "{@type=korap:element, @value=s}";
56 assertTrue(equalsQueryContent(elem1, "<s>"));
57
58 // <vp>
59 String elem2 = "{@type=korap:element, @value=vp}";
60 assertTrue(equalsQueryContent(elem2, "<vp>"));
61 }
Joachim Bingel87480d02014-01-17 14:07:46 +000062
63 @Test
64 public void testEmptyTokens() throws QueryException {
65 // [base=der][][base=Mann]
66 String et1 =
67 "{@type=korap:group, relation=distance, @subtype=incl, constraint=[" +
68 "{@type=korap:distance, measure=w, direction=plus, min=1, max=1}" +
69 "], " +
70 "operands=[" +
71 "{@type=korap:token, @value={@type=korap:term, @value=base:der, relation==}}," +
72 "{@type=korap:token, @value={@type=korap:term, @value=base:Mann, relation==}}" +
73 "]}";
74 ppt = new PoliqarpPlusTree("[base=der][][base=Mann]");
75 map = ppt.getRequestMap().get("query").toString();
76 assertEquals(et1.replaceAll(" ", ""), map.replaceAll(" ", ""));
77
78 // [base=der][][][base=Mann]
79 String et2 =
80 "{@type=korap:group, relation=distance, @subtype=incl, constraint=[" +
81 "{@type=korap:distance, measure=w, direction=plus, min=2, max=2}" +
82 "], " +
83 "operands=[" +
84 "{@type=korap:token, @value={@type=korap:term, @value=base:der, relation==}}," +
85 "{@type=korap:token, @value={@type=korap:term, @value=base:Mann, relation==}}" +
86 "]}";
87 ppt = new PoliqarpPlusTree("[base=der][][base=Mann]");
88 map = ppt.getRequestMap().get("query").toString();
89 assertEquals(et2.replaceAll(" ", ""), map.replaceAll(" ", ""));
90
91 // [base=der][][]?[base=Mann]
92 String et3 =
93 "{@type=korap:group, relation=distance, @subtype=incl, constraint=[" +
94 "{@type=korap:distance, measure=w, direction=plus, min=1, max=2}" +
95 "], " +
96 "operands=[" +
97 "{@type=korap:token, @value={@type=korap:term, @value=base:der, relation==}}," +
98 "{@type=korap:token, @value={@type=korap:term, @value=base:Mann, relation==}}" +
99 "]}";
100 ppt = new PoliqarpPlusTree("[base=der][][]?[base=Mann]");
101 map = ppt.getRequestMap().get("query").toString();
102 assertEquals(et3.replaceAll(" ", ""), map.replaceAll(" ", ""));
103
104 // [base=der][]*[base=Mann]
105 String et4 =
106 "{@type=korap:group, relation=distance, @subtype=incl, constraint=[" +
107 "{@type=korap:distance, measure=w, direction=plus, min=0, max=INF}" +
108 "], " +
109 "operands=[" +
110 "{@type=korap:token, @value={@type=korap:term, @value=base:der, relation==}}," +
111 "{@type=korap:token, @value={@type=korap:term, @value=base:Mann, relation==}}" +
112 "]}";
113 ppt = new PoliqarpPlusTree("[base=der][]*[base=Mann]");
114 map = ppt.getRequestMap().get("query").toString();
115 assertEquals(et4.replaceAll(" ", ""), map.replaceAll(" ", ""));
116
117 // startswith(<s>, [][base=Mann]
118 String et5 =
119 "{@type=korap:group, relation=position, position=startswith, @subtype=incl, operands=[" +
120 "{@type=korap:token, @value={@type=korap:elem, @value=s}," +
121 "{@type=korap:sequence, offset=1, operands=[" +
122 "{@type=korap:token, @value={@type=korap:term, @value=base:Mann, relation==}}" +
123 "]}" +
124 "]}";
125 ppt = new PoliqarpPlusTree("startswith(<s>, [][base=Mann]");
126 map = ppt.getRequestMap().get("query").toString();
127 assertEquals(et5.replaceAll(" ", ""), map.replaceAll(" ", ""));
128
129
130 }
Joachim Bingel53333e62013-12-09 19:25:52 +0000131
132 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000133 public void testCoordinatedFields() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000134 // [base=Mann&(cas=N|cas=A)]
135 String cof1 =
136 "{@type=korap:token, @value=" +
137 "{@type=korap:group, operands=[" +
138 "{@type=korap:term, @value=base:Mann, relation==}," +
139 "{@type=korap:group, operands=[" +
140 "{@type=korap:term, @value=cas:N, relation==}," +
141 "{@type=korap:term, @value=cas:A, relation==}" +
142 "], relation=or}" +
143 "], relation=and}" +
144 "}";
145 ppt = new PoliqarpPlusTree("[base=Mann&(cas=N|cas=A)]");
146 map = ppt.getRequestMap().get("query").toString();
147 assertEquals(cof1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Nils Diewald7d486c22013-12-13 16:32:18 +0000148
149
150 assertEquals(
151 new PoliqarpPlusTree(" [ base=Mann & ( cas=N | cas=A)] ").getRequestMap().get("query").toString(),
152 new PoliqarpPlusTree("[base=Mann &(cas=N|cas=A)]").getRequestMap().get("query").toString()
153 );
Joachim Bingel53333e62013-12-09 19:25:52 +0000154 }
155
156 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000157 public void testOccurrence() throws QueryException {
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000158 // [base=foo]*
159 String occ1 = "{@type=korap:group, operands=[" +
160 "{@type=korap:token, @value={@type=korap:term, @value=base:foo, relation==}}" +
161 "], relation=repetition, quantifier=* }";
162 ppt = new PoliqarpPlusTree("[base=foo]*");
163 map = ppt.getRequestMap().get("query").toString();
164 assertEquals(occ1.replaceAll(" ", ""), map.replaceAll(" ", ""));
165
166 // [base=foo]*[base=bar]
167 String occ2 =
168 "{@type=korap:sequence, operands=[" +
169 "{@type=korap:group, operands=[" +
170 "{@type=korap:token, @value={@type=korap:term, @value=base:foo, relation==}}" +
171 "], relation=repetition, quantifier=* }," +
172 "{@type=korap:token, @value={@type=korap:term, @value=base:bar, relation==}}" +
173 "]}";
174 ppt = new PoliqarpPlusTree("[base=foo]*[base=bar]");
175 map = ppt.getRequestMap().get("query").toString();
176 assertEquals(occ2.replaceAll(" ", ""), map.replaceAll(" ", ""));
177
178 // [base=bar][base=foo]*
179 String occ3 =
180 "{@type=korap:sequence, operands=[" +
181 "{@type=korap:token, @value={@type=korap:term, @value=base:bar, relation==}}," +
182 "{@type=korap:group, operands=[" +
183 "{@type=korap:token, @value={@type=korap:term, @value=base:foo, relation==}}" +
184 "], relation=repetition, quantifier=* }" +
185 "]}";
186 ppt = new PoliqarpPlusTree("[base=bar][base=foo]*");
187 map = ppt.getRequestMap().get("query").toString();
188 assertEquals(occ3.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb4da7022013-12-09 23:17:24 +0000189
190 // ([base=bar][base=foo])*
191 String occ4 =
192 "{@type=korap:group, operands=[" +
193 "{@type=korap:sequence, operands=[" +
194 "{@type=korap:token, @value={@type=korap:term, @value=base:bar, relation==}}," +
195 "{@type=korap:token, @value={@type=korap:term, @value=base:foo, relation==}}" +
196 "]}" +
197 "], relation=repetition, quantifier=* }" ;
198 ppt = new PoliqarpPlusTree("([base=bar][base=foo])*");
199 map = ppt.getRequestMap().get("query").toString();
200 assertEquals(occ4.replaceAll(" ", ""), map.replaceAll(" ", ""));
201
202 // <s>([base=bar][base=foo])*
203 String occ5 =
204 "{@type=korap:sequence, operands=[" +
205 "{@type=korap:element, @value=s}," +
206 "{@type=korap:group, operands=[" +
207 "{@type=korap:sequence, operands=[" +
208 "{@type=korap:token, @value={@type=korap:term, @value=base:bar, relation==}}," +
209 "{@type=korap:token, @value={@type=korap:term, @value=base:foo, relation==}}" +
210 "]}" +
211 "], relation=repetition, quantifier=* }" +
212 "]}" ;
213 ppt = new PoliqarpPlusTree("<s>([base=bar][base=foo])*");
214 map = ppt.getRequestMap().get("query").toString();
215 assertEquals(occ5.replaceAll(" ", ""), map.replaceAll(" ", ""));
216
217 // <s><np>([base=bar][base=foo])*
Joachim Bingelb4da7022013-12-09 23:17:24 +0000218 String occ6 =
219 "{@type=korap:sequence, operands=[" +
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000220 "{@type=korap:element, @value=s}," +
221 "{@type=korap:element, @value=np}," +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000222 "{@type=korap:group, operands=[" +
223 "{@type=korap:sequence, operands=[" +
224 "{@type=korap:token, @value={@type=korap:term, @value=base:bar, relation==}}," +
225 "{@type=korap:token, @value={@type=korap:term, @value=base:foo, relation==}}" +
226 "]}" +
227 "], relation=repetition, quantifier=* }" +
228 "]}" ;
229 ppt = new PoliqarpPlusTree("<s><np>([base=bar][base=foo])*");
230 map = ppt.getRequestMap().get("query").toString();
231 assertEquals(occ6.replaceAll(" ", ""), map.replaceAll(" ", ""));
232
233 // <s><np>([base=bar][base=foo])*[p=NN]
234 // comment: embedded sequence shouldn't really be here, but does not really hurt, either. (?)
235 // really hard to get this behaviour out of the PQPlus grammar...
236 String occ7 =
237 "{@type=korap:sequence, operands=[" +
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000238 "{@type=korap:element, @value=s}," +
239 "{@type=korap:element, @value=np}," +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000240 "{@type=korap:group, operands=[" +
241 "{@type=korap:sequence, operands=[" +
242 "{@type=korap:token, @value={@type=korap:term, @value=base:bar, relation==}}," +
243 "{@type=korap:token, @value={@type=korap:term, @value=base:foo, relation==}}" +
244 "]}" +
245 "], relation=repetition, quantifier=* }," +
246 "{@type=korap:token, @value={@type=korap:term, @value=p:NN, relation==}}" +
247 "]}" ;
248 ppt = new PoliqarpPlusTree("<s><np>([base=bar][base=foo])*[p=NN]");
249 map = ppt.getRequestMap().get("query").toString();
250 assertEquals(occ7.replaceAll(" ", ""), map.replaceAll(" ", ""));
251
252 // ([base=bar][base=foo])*[p=NN]
Joachim Bingelb4da7022013-12-09 23:17:24 +0000253 String occ8 =
254 "{@type=korap:sequence, operands=[" +
255 "{@type=korap:group, operands=[" +
256 "{@type=korap:sequence, operands=[" +
257 "{@type=korap:token, @value={@type=korap:term, @value=base:bar, relation==}}," +
258 "{@type=korap:token, @value={@type=korap:term, @value=base:foo, relation==}}" +
259 "]}" +
260 "], relation=repetition, quantifier=* }," +
261 "{@type=korap:token, @value={@type=korap:term, @value=p:NN, relation==}}" +
262 "]}" ;
263 ppt = new PoliqarpPlusTree("([base=bar][base=foo])*[p=NN]");
264 map = ppt.getRequestMap().get("query").toString();
265 assertEquals(occ8.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000266 }
267
268 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000269 public void testTokenSequence() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000270 // [base=Mann][orth=Frau]
271 String seq1 = "{@type=korap:sequence, operands=[" +
272 "{@type=korap:token, @value={@type=korap:term, @value=base:Mann, relation==}}, " +
273 "{@type=korap:token, @value={@type=korap:term, @value=orth:Frau, relation==}}" +
274 "]}";
275 assertTrue(equalsQueryContent(seq1, "[base=Mann][orth=Frau]"));
276
277 // [base=Mann][orth=Frau][p=NN]
278 String seq2 = "{@type=korap:sequence, operands=[" +
279 "{@type=korap:token, @value={@type=korap:term, @value=base:Mann, relation==}}, " +
280 "{@type=korap:token, @value={@type=korap:term, @value=orth:Frau, relation==}}, " +
281 "{@type=korap:token, @value={@type=korap:term, @value=p:NN, relation==}}" +
282 "]}";
283 assertTrue(equalsQueryContent(seq2, "[base=Mann][orth=Frau][p=NN]"));
284 }
285
286 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000287 public void testDisjSegments() throws QueryException {
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000288 // ([base=der]|[base=das])[base=Schild]
289 String disj1 =
290 "{@type=korap:sequence, operands=[" +
291 "{@type=korap:group, relation=or, operands=[" +
292 "{@type=korap:token, @value={@type=korap:term, @value=base:der, relation==}}," +
293 "{@type=korap:token, @value={@type=korap:term, @value=base:das, relation==}}" +
294 "]}," +
295 "{@type=korap:token, @value={@type=korap:term, @value=base:Schild, relation==}}" +
296 "]}";
297 ppt = new PoliqarpPlusTree("([base=der]|[base=das])[base=Schild]");
298 map = ppt.getRequestMap().get("query").toString();
299 assertEquals(disj1.replaceAll(" ", ""), map.replaceAll(" ", ""));
300
301 // [base=Schild]([base=der]|[base=das])
302 String disj2 =
303 "{@type=korap:sequence, operands=[" +
304 "{@type=korap:token, @value={@type=korap:term, @value=base:Schild, relation==}}," +
305 "{@type=korap:group, relation=or, operands=[" +
306 "{@type=korap:token, @value={@type=korap:term, @value=base:der, relation==}}," +
307 "{@type=korap:token, @value={@type=korap:term, @value=base:das, relation==}}" +
308 "]}" +
309 "]}";
310 ppt = new PoliqarpPlusTree("[base=Schild]([base=der]|[base=das])");
311 map = ppt.getRequestMap().get("query").toString();
312 assertEquals(disj2.replaceAll(" ", ""), map.replaceAll(" ", ""));
313 }
314
315 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000316 public void testTokenElemSequence() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000317 // [base=Mann]<vp>
318 String seq1 = "{@type=korap:sequence, operands=[" +
319 "{@type=korap:token, @value={@type=korap:term, @value=base:Mann, relation==}}, " +
320 "{@type=korap:element, @value=vp}" +
321 "]}";
322 assertTrue(equalsQueryContent(seq1, "[base=Mann]<vp>"));
323
324 // <vp>[base=Mann]
325 String seq2 = "{@type=korap:sequence, operands=[" +
326 "{@type=korap:element, @value=vp}, "+
327 "{@type=korap:token, @value={@type=korap:term, @value=base:Mann, relation==}} " +
328 "]}";
329 assertTrue(equalsQueryContent(seq2, "<vp>[base=Mann]"));
330
331 // <vp>[base=Mann]<pp>
332 String seq3 = "{@type=korap:sequence, operands=[" +
333 "{@type=korap:element, @value=vp}, "+
334 "{@type=korap:token, @value={@type=korap:term, @value=base:Mann, relation==}}, " +
335 "{@type=korap:element, @value=pp} "+
336 "]}";
337 assertTrue(equalsQueryContent(seq3, "<vp>[base=Mann]<pp>"));
338 }
339
340 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000341 public void testElemSequence() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000342 // <np><vp>
343 String seq1 = "{@type=korap:sequence, operands=[" +
344 "{@type=korap:element, @value=np}," +
345 "{@type=korap:element, @value=vp}" +
346 "]}";
347 assertTrue(equalsQueryContent(seq1, "<np><vp>"));
348
349 // <np><vp><pp>
350 String seq2 = "{@type=korap:sequence, operands=[" +
351 "{@type=korap:element, @value=np}," +
352 "{@type=korap:element, @value=vp}," +
353 "{@type=korap:element, @value=pp}" +
354 "]}";
355 assertTrue(equalsQueryContent(seq2, "<np><vp><pp>"));
356 }
357
358 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000359 public void testClasses() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000360 // {[base=Mann]}
361 String cls1 = "{@type=korap:group, class=0, operands=[" +
362 "{@type=korap:token, @value={@type=korap:term, @value=base:Mann, relation==}}" +
363 "]}";
364 assertTrue(equalsQueryContent(cls1, "{[base=Mann]}"));
365
366 // {[base=Mann][orth=Frau]}
367 String cls2 = "{@type=korap:group, class=0, operands=[" +
368 "{@type=korap:sequence, operands=[" +
369 "{@type=korap:token, @value={@type=korap:term, @value=base:Mann, relation==}}," +
370 "{@type=korap:token, @value={@type=korap:term, @value=orth:Frau, relation==}}" +
371 "]}" +
372 "]}";
373 assertTrue(equalsQueryContent(cls2, "{[base=Mann][orth=Frau]}"));
374
375 // [p=NN]{[base=Mann][orth=Frau]}
376 String cls3 = "{@type=korap:sequence, operands=[" +
377 "{@type=korap:token, @value={@type=korap:term, @value=p:NN, relation==}}," +
378 "{@type=korap:group, class=0, operands=[" +
379 "{@type=korap:sequence, operands=[" +
380 "{@type=korap:token, @value={@type=korap:term, @value=base:Mann, relation==}}," +
381 "{@type=korap:token, @value={@type=korap:term, @value=orth:Frau, relation==}}" +
382 "]}" +
383 "]}" +
384 "]}";
385 assertTrue(equalsQueryContent(cls3, "[p=NN]{[base=Mann][orth=Frau]}"));
386
387 // {[base=Mann][orth=Frau]}[p=NN]
388 String cls4 = "{@type=korap:sequence, operands=[" +
389 "{@type=korap:group, class=0, operands=[" +
390 "{@type=korap:sequence, operands=[" +
391 "{@type=korap:token, @value={@type=korap:term, @value=base:Mann, relation==}}," +
392 "{@type=korap:token, @value={@type=korap:term, @value=orth:Frau, relation==}}" +
393 "]}" +
394 "]}," +
395 "{@type=korap:token, @value={@type=korap:term, @value=p:NN, relation==}}" +
396 "]}";
397 assertTrue(equalsQueryContent(cls4, "{[base=Mann][orth=Frau]}[p=NN]"));
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000398
399 // {2:{1:[tt/p=ADJA]}[mate/p=NN]}"
400 String cls5 = "{@type=korap:group, class=2, operands=[" +
401 "{@type=korap:sequence, operands=[" +
402 "{@type=korap:group, class=1, operands=[" +
403 "{@type=korap:token, @value={@type=korap:term, @value=tt/p:ADJA, relation==}}" +
404 "]}," +
405 "{@type=korap:token, @value={@type=korap:term, @value=mate/p:NN, relation==}}" +
406 "]}" +
407 "]}";
408 ppt = new PoliqarpPlusTree("{2: {1:[tt/p=ADJA]}[mate/p=NN]}");
409 map = ppt.getRequestMap().get("query").toString();
410 assertEquals(cls5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000411 }
412
413 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000414 public void testPositions() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000415 // contains(<s>,<np>)
416 String pos1 = "{@type=korap:group, relation=position, position=contains, operands=[" +
417 "{@type=korap:element, @value=s}," +
418 "{@type=korap:element, @value=np}" +
419 "]}";
420 assertTrue(equalsQueryContent(pos1, "contains(<s>,<np>)"));
421
422 // contains(<s>,[base=Mann])
423 String pos2 = "{@type=korap:group, relation=position, position=contains, operands=[" +
424 "{@type=korap:element, @value=s}," +
425 "{@type=korap:token, @value= {@type=korap:term, @value=base:Mann, relation==}}" +
426 "]}";
427 assertTrue(equalsQueryContent(pos2, "contains(<s>,[base=Mann])"));
428
429 // contains(<s>,[orth=der][orth=Mann])
430 String pos3 = "{@type=korap:group, relation=position, position=contains, operands=[" +
431 "{@type=korap:element, @value=s}," +
432 "{@type=korap:sequence, operands=[" +
433 "{@type=korap:token, @value={@type=korap:term, @value=orth:der, relation==}}," +
434 "{@type=korap:token, @value={@type=korap:term, @value=orth:Mann, relation==}}" +
435 "]}" +
436 "]}";
437 ppt = new PoliqarpPlusTree("contains(<s>,[orth=der][orth=Mann])");
438 map = ppt.getRequestMap().get("query").toString();
439 assertEquals(pos3.replaceAll(" ", ""), map.replaceAll(" ", ""));
440
441 // [base=Auto]contains(<s>,[base=Mann])
442 String pos4 =
443 "{@type=korap:sequence, operands=[" +
444 "{@type=korap:token, @value={@type=korap:term, @value=base:Auto, relation==}}," +
445 "{@type=korap:group, relation=position, position=contains, operands=[" +
446 "{@type=korap:element, @value=s}," +
447 "{@type=korap:token, @value={@type=korap:term, @value=base:Mann, relation==}}" +
448 "]}" +
449 "]}";
450 ppt = new PoliqarpPlusTree("[base=Auto]contains(<s>,[base=Mann])");
451 map = ppt.getRequestMap().get("query").toString();
452 assertEquals(pos4.replaceAll(" ", ""), map.replaceAll(" ", ""));
453 }
454
455 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000456 public void testNestedPositions() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000457 // contains(<s>,startswith(<np>,[orth=Der]))
458 String npos1 =
459 "{@type=korap:group, relation=position, position=contains, operands=[" +
460 "{@type=korap:element, @value=s}," +
461 "{@type=korap:group, relation=position, position=startswith, operands=[" +
462 "{@type=korap:element, @value=np}," +
463 "{@type=korap:token, @value={@type=korap:term, @value=orth:Der, relation==}}" +
464 "]}" +
465 "]}";
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000466 ppt = new PoliqarpPlusTree("contains(<s>, startswith(<np>,[orth=Der]))");
Joachim Bingel53333e62013-12-09 19:25:52 +0000467 map = ppt.getRequestMap().get("query").toString();
468 assertEquals(npos1.replaceAll(" ", ""), map.replaceAll(" ", ""));
469 }
470
471 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000472 public void testShrinkSplit() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000473 // shrink([orth=Der]{[orth=Mann]})
474 String shr1 =
475 "{@type=korap:group, relation=shrink, shrink=0, operands=[" +
476 "{@type=korap:sequence, operands=[" +
477 "{@type=korap:token, @value={@type=korap:term, @value=orth:Der, relation==}}," +
478 "{@type=korap:group, class=0, operands=[" +
479 "{@type=korap:token, @value={@type=korap:term, @value=orth:Mann, relation==}}" +
480 "]}" +
481 "]}" +
482 "]}";
483 ppt = new PoliqarpPlusTree("shrink([orth=Der]{[orth=Mann]})");
484 map = ppt.getRequestMap().get("query").toString();
485 assertEquals(shr1.replaceAll(" ", ""), map.replaceAll(" ", ""));
486
487 // shrink([orth=Der]{[orth=Mann][orth=geht]})
488 String shr2 =
489 "{@type=korap:group, relation=shrink, shrink=0, operands=[" +
490 "{@type=korap:sequence, operands=[" +
491 "{@type=korap:token, @value={@type=korap:term, @value=orth:Der, relation==}}," +
492 "{@type=korap:group, class=0, operands=[" +
493 "{@type=korap:sequence, operands=[" +
494 "{@type=korap:token, @value={@type=korap:term, @value=orth:Mann, relation==}}," +
495 "{@type=korap:token, @value={@type=korap:term, @value=orth:geht, relation==}}" +
496 "]}" +
497 "]}" +
498 "]}" +
499 "]}";
500 ppt = new PoliqarpPlusTree("shrink([orth=Der]{[orth=Mann][orth=geht]})");
501 map = ppt.getRequestMap().get("query").toString();
502 assertEquals(shr2.replaceAll(" ", ""), map.replaceAll(" ", ""));
503
504 // shrink(1:[orth=Der]{1:[orth=Mann][orth=geht]})
505 String shr3 =
506 "{@type=korap:group, relation=shrink, shrink=1, operands=[" +
507 "{@type=korap:sequence, operands=[" +
508 "{@type=korap:token, @value={@type=korap:term, @value=orth:Der, relation==}}," +
509 "{@type=korap:group, class=1, operands=[" +
510 "{@type=korap:sequence, operands=[" +
511 "{@type=korap:token, @value={@type=korap:term, @value=orth:Mann, relation==}}," +
512 "{@type=korap:token, @value={@type=korap:term, @value=orth:geht, relation==}}" +
513 "]}" +
514 "]}" +
515 "]}" +
516 "]}";
517 ppt = new PoliqarpPlusTree("shrink(1:[orth=Der]{1:[orth=Mann][orth=geht]})");
518 map = ppt.getRequestMap().get("query").toString();
519 assertEquals(shr3.replaceAll(" ", ""), map.replaceAll(" ", ""));
520
521 // shrink(1:startswith(<s>,{1:<np>}))
522 String shr4 =
523 "{@type=korap:group, relation=shrink, shrink=1, operands=[" +
524 "{@type=korap:group, relation=position, position=startswith, operands=[" +
525 "{@type=korap:element, @value=s}," +
526 "{@type=korap:group, class=1, operands=[" +
527 "{@type=korap:element, @value=np}" +
528 "]}" +
529 "]}" +
530 "]}";
Joachim Bingeladefa622013-12-13 10:51:48 +0000531 ppt = new PoliqarpPlusTree("shrink(1:startswith(<s>,{1:<np>}))");
Joachim Bingel53333e62013-12-09 19:25:52 +0000532 map = ppt.getRequestMap().get("query").toString();
533 assertEquals(shr4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000534
535 // shrink(3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))
536 String shr5 =
537 "{@type=korap:group, relation=shrink, shrink=3, operands=[" +
538 "{@type=korap:group, relation=position, position=startswith, operands=[" +
539 "{@type=korap:element, @value=s}," +
540 "{@type=korap:group, class=3, operands=[" +
541 "{@type=korap:sequence, operands=[" +
542 "{@type=korap:token, @value={@type=korap:term, @value=base:der, relation==}}," +
543 "{@type=korap:group, class=1, operands=[" +
544 "{@type=korap:sequence, operands=[" +
545 "{@type=korap:token, @value={@type=korap:term, @value=mate/p:ADJA, relation==}}," +
546 "{@type=korap:group, class=2, operands=[" +
547 "{@type=korap:token, @value={@type=korap:term, @value=tt/p:NN, relation==}}" +
548 "]}" +
549 "]}" +
550 "]}" +
551 "]}" +
552 "]}" +
553 "]}" +
554 "]}";
Joachim Bingeladefa622013-12-13 10:51:48 +0000555 ppt = new PoliqarpPlusTree("shrink(3:startswith(<s>,{3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) ");
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000556 map = ppt.getRequestMap().get("query").toString();
557 assertEquals(shr5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000558 }
559
Joachim Bingel03882702013-12-31 19:53:05 +0000560
Joachim Bingel53333e62013-12-09 19:25:52 +0000561 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000562 public void testLayers() throws QueryException {
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000563 // [base=Mann]
564 String layer1 = "{@type=korap:token, @value={@type=korap:term, @value=tt/base:Mann, relation==}}";
565 assertTrue(equalsQueryContent(layer1, "[tt/base=Mann]"));
Joachim Bingel53333e62013-12-09 19:25:52 +0000566
567 }
Joachim Bingel16da4e12013-12-17 09:48:12 +0000568
569 @Test
570 public void testAlign() {
571 // [orth=der]^[orth=Mann]
572 String align1 =
Joachim Bingel03882702013-12-31 19:53:05 +0000573 "{@type=korap:sequence, operands=[" +
Joachim Bingel16da4e12013-12-17 09:48:12 +0000574 "{@type=korap:token, @value={@type=korap:term, @value=orth:der, relation==}}," +
Joachim Bingel03882702013-12-31 19:53:05 +0000575 "{@type=korap:group, relation=left-align, operands=[" +
576 "{@type=korap:token, @value={@type=korap:term, @value=orth:Mann, relation==}}" +
577 "]}" +
Joachim Bingel16da4e12013-12-17 09:48:12 +0000578 "]}";
579 ppt = new PoliqarpPlusTree("[orth=der]^[orth=Mann]");
580 map = ppt.getRequestMap().get("query").toString();
581 assertEquals(align1.replaceAll(" ", ""), map.replaceAll(" ", ""));
582
583 // "([base=a]^[base=b])|[base=c]",
584 String align2 =
585 "{@type=korap:group, relation=or, operands=[" +
Joachim Bingel03882702013-12-31 19:53:05 +0000586 "{@type=korap:sequence, operands=[" +
Joachim Bingel16da4e12013-12-17 09:48:12 +0000587 "{@type=korap:token, @value={@type=korap:term, @value=base:a, relation==}}," +
Joachim Bingel03882702013-12-31 19:53:05 +0000588 "{@type=korap:group, relation=left-align, operands=[" +
589 "{@type=korap:token, @value={@type=korap:term, @value=base:b, relation==}}" +
590 "]}" +
Joachim Bingel16da4e12013-12-17 09:48:12 +0000591 "]}," +
592 "{@type=korap:token, @value={@type=korap:term, @value=base:c, relation==}}" +
593 "]}";
594 ppt = new PoliqarpPlusTree("([base=a]^[base=b])|[base=c]");
595 map = ppt.getRequestMap().get("query").toString();
596 assertEquals(align2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingela67e6a32014-01-02 18:35:24 +0000597
598 // "([base=a]^[base=b][base=c])|[base=d]",
599 String align3 =
600 "{@type=korap:group, relation=or, operands=[" +
601 "{@type=korap:sequence, operands=[" +
602 "{@type=korap:token, @value={@type=korap:term, @value=base:a, relation==}}," +
603 "{@type=korap:group, relation=left-align, operands=[" +
604 "{@type=korap:token, @value={@type=korap:term, @value=base:b, relation==}}" +
605 "]}," +
606 "{@type=korap:token, @value={@type=korap:term, @value=base:c, relation==}}" +
607 "]}," +
608 "{@type=korap:token, @value={@type=korap:term, @value=base:d, relation==}}" +
609 "]}";
610 ppt = new PoliqarpPlusTree("([base=a]^[base=b][base=c])|[base=d]");
611 map = ppt.getRequestMap().get("query").toString();
612 assertEquals(align3.replaceAll(" ", ""), map.replaceAll(" ", ""));
613
614 // "([base=a]^[base=b]^[base=c])|[base=d]",
615 String align4 =
616 "{@type=korap:group, relation=or, operands=[" +
617 "{@type=korap:sequence, operands=[" +
618 "{@type=korap:token, @value={@type=korap:term, @value=base:a, relation==}}," +
619 "{@type=korap:group, relation=left-align, operands=[" +
620 "{@type=korap:token, @value={@type=korap:term, @value=base:b, relation==}}" +
621 "]}," +
622 "{@type=korap:group, relation=left-align, operands=[" +
623 "{@type=korap:token, @value={@type=korap:term, @value=base:c, relation==}}" +
624 "]}" +
625 "]}," +
626 "{@type=korap:token, @value={@type=korap:term, @value=base:d, relation==}}" +
627 "]}";
628 ppt = new PoliqarpPlusTree("([base=a]^[base=b]^[base=c])|[base=d]");
629 map = ppt.getRequestMap().get("query").toString();
630 assertEquals(align4.replaceAll(" ", ""), map.replaceAll(" ", ""));
631
632
Joachim Bingel16da4e12013-12-17 09:48:12 +0000633 }
634
635 @Test
636 public void testSimpleQueries() {
Joachim Bingela67e6a32014-01-02 18:35:24 +0000637 // Baum
638 String simple1 =
639 "{@type=korap:token, @value={@type=korap:term, @value=orth:Baum, relation==}}";
640 ppt = new PoliqarpPlusTree("Baum");
641 map = ppt.getRequestMap().get("query").toString();
642 assertEquals(simple1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel16da4e12013-12-17 09:48:12 +0000643
Joachim Bingela67e6a32014-01-02 18:35:24 +0000644 // Der Baum
645 String simple2 =
646 "{@type=korap:sequence, operands=[" +
647 "{@type=korap:token, @value={@type=korap:term, @value=orth:Der, relation==}}, " +
648 "{@type=korap:token, @value={@type=korap:term, @value=orth:Baum, relation==}}" +
649 "]}";
650 ppt = new PoliqarpPlusTree("Der Baum");
651 map = ppt.getRequestMap().get("query").toString();
652 assertEquals(simple2.replaceAll(" ", ""), map.replaceAll(" ", ""));
653
654 // Der große Baum
655 String simple3 =
656 "{@type=korap:sequence, operands=[" +
657 "{@type=korap:token, @value={@type=korap:term, @value=orth:Der, relation==}}, " +
658 "{@type=korap:token, @value={@type=korap:term, @value=orth:große, relation==}}, " +
659 "{@type=korap:token, @value={@type=korap:term, @value=orth:Baum, relation==}}" +
660 "]}";
661 ppt = new PoliqarpPlusTree("Der große Baum");
662 map = ppt.getRequestMap().get("query").toString();
663 assertEquals(simple3.replaceAll(" ", ""), map.replaceAll(" ", ""));
664
665 // Baum | Stein
666 String simple4 =
667 "{@type=korap:group, relation=or, operands=[" +
668 "{@type=korap:token, @value={@type=korap:term, @value=orth:Baum, relation==}}, " +
669 "{@type=korap:token, @value={@type=korap:term, @value=orth:Stein, relation==}}" +
670 "]}";
671 ppt = new PoliqarpPlusTree("Baum | Stein");
672 map = ppt.getRequestMap().get("query").toString();
673 assertEquals(simple4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel16da4e12013-12-17 09:48:12 +0000674 }
Joachim Bingel53333e62013-12-09 19:25:52 +0000675}
676