blob: 1837a1bdf4570f1f2424909e5c0d51eebca76529 [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
Joachim Bingel11d5b152014-02-11 21:33:47 +000026// @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +000027 public void testContext() throws QueryException {
Joachim Bingel11d5b152014-02-11 21:33:47 +000028 String contextString = "{korap=http://korap.ids-mannheim.de/ns/query, @language=de, operands={@id=korap:operands, @container=@list}, operation={@id=korap:relation, type=korap:relation#types}, class={@id=korap:class, type=xsd:integer}, query=korap:query, filter=korap:filter, meta=korap:meta}";
Joachim Bingel53333e62013-12-09 19:25:52 +000029 ppt = new PoliqarpPlusTree("[base=test]");
Joachim Bingel11d5b152014-02-11 21:33:47 +000030// assertTrue(equalsContent(contextString, ppt.getRequestMap().get("@context")));
31 assertEquals(contextString, ppt.getRequestMap().get("@context"));
Joachim Bingel53333e62013-12-09 19:25:52 +000032 }
33
34 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +000035 public void testSingleTokens() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +000036 // [base=Mann]
Joachim Bingel11d5b152014-02-11 21:33:47 +000037 String token1 = "{type=token, key={type=term, key=Mann, layer=lemma, match=eq}}";
Joachim Bingel53333e62013-12-09 19:25:52 +000038 assertTrue(equalsQueryContent(token1, "[base=Mann]"));
39
40 // [orth!=Frau]
Joachim Bingel11d5b152014-02-11 21:33:47 +000041 String token2 = "{type=token, key={type=term, key=Frau, layer=orth, match=ne}}";
Joachim Bingel53333e62013-12-09 19:25:52 +000042 assertTrue(equalsQueryContent(token2, "[orth!=Frau]"));
43
44 // [!p=NN]
Joachim Bingel11d5b152014-02-11 21:33:47 +000045 String token3 = "{type=token, key={type=term, key=NN, layer=p, match=ne}}";
Joachim Bingel53333e62013-12-09 19:25:52 +000046 assertTrue(equalsQueryContent(token3, "[!p=NN]"));
47
48 // [!p!=NN]
Joachim Bingel11d5b152014-02-11 21:33:47 +000049 String token4 = "{type=token, key={type=term, key=NN, layer=p, match=eq}}";
Joachim Bingel53333e62013-12-09 19:25:52 +000050 assertTrue(equalsQueryContent(token4, "[!p!=NN]"));
51 }
52
53 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +000054 public void testElements() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +000055 // <s>
Joachim Bingel11d5b152014-02-11 21:33:47 +000056 String elem1 = "{type=span, key=s}";
Joachim Bingel53333e62013-12-09 19:25:52 +000057 assertTrue(equalsQueryContent(elem1, "<s>"));
58
59 // <vp>
Joachim Bingel11d5b152014-02-11 21:33:47 +000060 String elem2 = "{type=span, key=vp}";
Joachim Bingel53333e62013-12-09 19:25:52 +000061 assertTrue(equalsQueryContent(elem2, "<vp>"));
62 }
Joachim Bingel87480d02014-01-17 14:07:46 +000063
64 @Test
65 public void testEmptyTokens() throws QueryException {
66 // [base=der][][base=Mann]
67 String et1 =
Joachim Bingel11d5b152014-02-11 21:33:47 +000068 "{type=group, operation=sequence, inOrder=true, distances=[" +
69 "{type=distance, measure=w, min=1, max=1}" +
Joachim Bingel87480d02014-01-17 14:07:46 +000070 "], " +
Joachim Bingel11d5b152014-02-11 21:33:47 +000071 "operands=[" +
72 "{type=token, key={type=term, key=der, layer=lemma, match=eq}}," +
73 "{type=token, key={type=term, key=Mann, layer=lemma, match=eq}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +000074 "]}";
75 ppt = new PoliqarpPlusTree("[base=der][][base=Mann]");
76 map = ppt.getRequestMap().get("query").toString();
77 assertEquals(et1.replaceAll(" ", ""), map.replaceAll(" ", ""));
78
79 // [base=der][][][base=Mann]
80 String et2 =
Joachim Bingel11d5b152014-02-11 21:33:47 +000081 "{type=group, operation=sequence, inOrder=true, distances=[" +
82 "{type=distance, measure=w, min=2, max=2}" +
Joachim Bingel87480d02014-01-17 14:07:46 +000083 "], " +
Joachim Bingel11d5b152014-02-11 21:33:47 +000084 "operands=[" +
85 "{type=token, key={type=term, key=der, layer=lemma, match=eq}}," +
86 "{type=token, key={type=term, key=Mann, layer=lemma, match=eq}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +000087 "]}";
Joachim Bingelffd65e32014-01-22 14:22:57 +000088 ppt = new PoliqarpPlusTree("[base=der][][][base=Mann]");
Joachim Bingel87480d02014-01-17 14:07:46 +000089 map = ppt.getRequestMap().get("query").toString();
90 assertEquals(et2.replaceAll(" ", ""), map.replaceAll(" ", ""));
91
92 // [base=der][][]?[base=Mann]
93 String et3 =
Joachim Bingel11d5b152014-02-11 21:33:47 +000094 "{type=group, operation=sequence, inOrder=true, distances=[" +
95 "{type=distance, measure=w, min=1, max=2}" +
Joachim Bingel87480d02014-01-17 14:07:46 +000096 "], " +
Joachim Bingel11d5b152014-02-11 21:33:47 +000097 "operands=[" +
98 "{type=token, key={type=term, key=der, layer=lemma, match=eq}}," +
99 "{type=token, key={type=term, key=Mann, layer=lemma, match=eq}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000100 "]}";
101 ppt = new PoliqarpPlusTree("[base=der][][]?[base=Mann]");
102 map = ppt.getRequestMap().get("query").toString();
103 assertEquals(et3.replaceAll(" ", ""), map.replaceAll(" ", ""));
104
Joachim Bingel87480d02014-01-17 14:07:46 +0000105
106 // startswith(<s>, [][base=Mann]
Joachim Bingelffd65e32014-01-22 14:22:57 +0000107 String et4 =
Joachim Bingel11d5b152014-02-11 21:33:47 +0000108 "{type=group, operation=position, frame=startswith, operands=[" +
109 "{type=span, key=s}," +
110 "{type=group, operation=sequence, offset-min=1, offset-max=1, operands=[" +
111 "{type=token, key={type=term, key=Mann, layer=lemma, match=eq}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000112 "]}" +
113 "]}";
Joachim Bingelffd65e32014-01-22 14:22:57 +0000114 ppt = new PoliqarpPlusTree("startswith(<s>, [][base=Mann])");
115 map = ppt.getRequestMap().get("query").toString();
116 assertEquals(et4.replaceAll(" ", ""), map.replaceAll(" ", ""));
117
Joachim Bingel11d5b152014-02-11 21:33:47 +0000118 // [base=der][]{2,5}[base=Mann][]?[][base=Frau] nested distances=
Joachim Bingelffd65e32014-01-22 14:22:57 +0000119 String et5 =
Joachim Bingel11d5b152014-02-11 21:33:47 +0000120 "{type=group, operation=sequence, inOrder=true, distances=[" +
121 "{type=distance, measure=w, min=2, max=5}" +
Joachim Bingelffd65e32014-01-22 14:22:57 +0000122 "], " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000123 "operands=[" +
124 "{type=token, key={type=term, key=der, layer=lemma, match=eq}}," +
125 "{type=group, operation=sequence, inOrder=true, distances=[" +
126 "{type=distance, measure=w, min=1, max=2}" +
Joachim Bingelffd65e32014-01-22 14:22:57 +0000127 "], " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000128 "operands=[" +
129 "{type=token, key={type=term, key=Mann, layer=lemma, match=eq}}," +
130 "{type=token, key={type=term, key=Frau, layer=lemma, match=eq}}" +
Joachim Bingelffd65e32014-01-22 14:22:57 +0000131 "]}" +
132 "]}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000133 ppt = new PoliqarpPlusTree("[base=der][]{2,5}[base=Mann][]?[][base=Frau]");
Joachim Bingel87480d02014-01-17 14:07:46 +0000134 map = ppt.getRequestMap().get("query").toString();
135 assertEquals(et5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel87480d02014-01-17 14:07:46 +0000136
137 }
Joachim Bingel53333e62013-12-09 19:25:52 +0000138
139 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000140 public void testCoordinatedFields() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000141 // [base=Mann&(cas=N|cas=A)]
142 String cof1 =
Joachim Bingel11d5b152014-02-11 21:33:47 +0000143 "{type=token, key=" +
144 "{type=group, operands=[" +
145 "{type=term, key=Mann, layer=lemma, match=eq}," +
146 "{type=group, operands=[" +
147 "{type=term, key=N, layer=cas, match=eq}," +
148 "{type=term, key=A, layer=cas, match=eq}" +
149 "], operation=or}" +
150 "], operation=and}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000151 "}";
152 ppt = new PoliqarpPlusTree("[base=Mann&(cas=N|cas=A)]");
153 map = ppt.getRequestMap().get("query").toString();
154 assertEquals(cof1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Nils Diewald7d486c22013-12-13 16:32:18 +0000155
156
157 assertEquals(
158 new PoliqarpPlusTree(" [ base=Mann & ( cas=N | cas=A)] ").getRequestMap().get("query").toString(),
159 new PoliqarpPlusTree("[base=Mann &(cas=N|cas=A)]").getRequestMap().get("query").toString()
160 );
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000161
162 // [base=Mann&cas=N&gen=m]
163 String cof2 =
Joachim Bingel11d5b152014-02-11 21:33:47 +0000164 "{type=token, key=" +
165 "{type=group, operands=[" +
166 "{type=term, key=Mann, layer=lemma, match=eq}," +
167 "{type=term, key=N, layer=cas, match=eq}," +
168 "{type=term, key=m, layer=gen, match=eq}" +
169 "], operation=and}" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000170 "}";
171 ppt = new PoliqarpPlusTree("[base=Mann&cas=N&gen=m]");
172 map = ppt.getRequestMap().get("query").toString();
173 assertEquals(cof2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000174 }
175
176 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000177 public void testOccurrence() throws QueryException {
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000178 // [base=foo]*
Joachim Bingel11d5b152014-02-11 21:33:47 +0000179 String occ1 = "{type=group, operands=[" +
180 "{type=token, key={type=term, key=foo, layer=lemma, match=eq}}" +
181 "], operation=repetition, @min=0, @max=100}";
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000182 ppt = new PoliqarpPlusTree("[base=foo]*");
183 map = ppt.getRequestMap().get("query").toString();
184 assertEquals(occ1.replaceAll(" ", ""), map.replaceAll(" ", ""));
185
186 // [base=foo]*[base=bar]
187 String occ2 =
Joachim Bingel11d5b152014-02-11 21:33:47 +0000188 "{type=group, operation=sequence, operands=[" +
189 "{type=group, operands=[" +
190 "{type=token, key={type=term, key=foo, layer=lemma, match=eq}}" +
191 "], operation=repetition, @min=0, @max=100 }," +
192 "{type=token, key={type=term, key=bar, layer=lemma, match=eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000193 "]}";
194 ppt = new PoliqarpPlusTree("[base=foo]*[base=bar]");
195 map = ppt.getRequestMap().get("query").toString();
196 assertEquals(occ2.replaceAll(" ", ""), map.replaceAll(" ", ""));
197
198 // [base=bar][base=foo]*
199 String occ3 =
Joachim Bingel11d5b152014-02-11 21:33:47 +0000200 "{type=group, operation=sequence, operands=[" +
201 "{type=token, key={type=term, key=bar, layer=lemma, match=eq}}," +
202 "{type=group, operands=[" +
203 "{type=token, key={type=term, key=foo, layer=lemma, match=eq}}" +
204 "], operation=repetition, @min=0, @max=100 }" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000205 "]}";
206 ppt = new PoliqarpPlusTree("[base=bar][base=foo]*");
207 map = ppt.getRequestMap().get("query").toString();
208 assertEquals(occ3.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb4da7022013-12-09 23:17:24 +0000209
210 // ([base=bar][base=foo])*
211 String occ4 =
Joachim Bingel11d5b152014-02-11 21:33:47 +0000212 "{type=group, operands=[" +
213 "{type=group, operation=sequence, operands=[" +
214 "{type=token, key={type=term, key=bar, layer=lemma, match=eq}}," +
215 "{type=token, key={type=term, key=foo, layer=lemma, match=eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000216 "]}" +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000217 "], operation=repetition, @min=0, @max=100 }" ;
Joachim Bingelb4da7022013-12-09 23:17:24 +0000218 ppt = new PoliqarpPlusTree("([base=bar][base=foo])*");
219 map = ppt.getRequestMap().get("query").toString();
220 assertEquals(occ4.replaceAll(" ", ""), map.replaceAll(" ", ""));
221
222 // <s>([base=bar][base=foo])*
223 String occ5 =
Joachim Bingel11d5b152014-02-11 21:33:47 +0000224 "{type=group, operation=sequence, operands=[" +
225 "{type=span, key=s}," +
226 "{type=group, operands=[" +
227 "{type=group, operation=sequence, operands=[" +
228 "{type=token, key={type=term, key=bar, layer=lemma, match=eq}}," +
229 "{type=token, key={type=term, key=foo, layer=lemma, match=eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000230 "]}" +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000231 "], operation=repetition, @min=0, @max=100 }" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000232 "]}" ;
233 ppt = new PoliqarpPlusTree("<s>([base=bar][base=foo])*");
234 map = ppt.getRequestMap().get("query").toString();
235 assertEquals(occ5.replaceAll(" ", ""), map.replaceAll(" ", ""));
236
237 // <s><np>([base=bar][base=foo])*
Joachim Bingelb4da7022013-12-09 23:17:24 +0000238 String occ6 =
Joachim Bingel11d5b152014-02-11 21:33:47 +0000239 "{type=group, operation=sequence, operands=[" +
240 "{type=span, key=s}," +
241 "{type=span, key=np}," +
242 "{type=group, operands=[" +
243 "{type=group, operation=sequence, operands=[" +
244 "{type=token, key={type=term, key=bar, layer=lemma, match=eq}}," +
245 "{type=token, key={type=term, key=foo, layer=lemma, match=eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000246 "]}" +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000247 "], operation=repetition, @min=0, @max=100 }" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000248 "]}" ;
249 ppt = new PoliqarpPlusTree("<s><np>([base=bar][base=foo])*");
250 map = ppt.getRequestMap().get("query").toString();
251 assertEquals(occ6.replaceAll(" ", ""), map.replaceAll(" ", ""));
252
253 // <s><np>([base=bar][base=foo])*[p=NN]
254 // comment: embedded sequence shouldn't really be here, but does not really hurt, either. (?)
255 // really hard to get this behaviour out of the PQPlus grammar...
256 String occ7 =
Joachim Bingel11d5b152014-02-11 21:33:47 +0000257 "{type=group, operation=sequence, operands=[" +
258 "{type=span, key=s}," +
259 "{type=span, key=np}," +
260 "{type=group, operands=[" +
261 "{type=group, operation=sequence, operands=[" +
262 "{type=token, key={type=term, key=bar, layer=lemma, match=eq}}," +
263 "{type=token, key={type=term, key=foo, layer=lemma, match=eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000264 "]}" +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000265 "], operation=repetition, @min=0, @max=100 }," +
266 "{type=token, key={type=term, key=NN, layer=p, match=eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000267 "]}" ;
268 ppt = new PoliqarpPlusTree("<s><np>([base=bar][base=foo])*[p=NN]");
269 map = ppt.getRequestMap().get("query").toString();
270 assertEquals(occ7.replaceAll(" ", ""), map.replaceAll(" ", ""));
271
272 // ([base=bar][base=foo])*[p=NN]
Joachim Bingelb4da7022013-12-09 23:17:24 +0000273 String occ8 =
Joachim Bingel11d5b152014-02-11 21:33:47 +0000274 "{type=group, operation=sequence, operands=[" +
275 "{type=group, operands=[" +
276 "{type=group, operation=sequence, operands=[" +
277 "{type=token, key={type=term, key=bar, layer=lemma, match=eq}}," +
278 "{type=token, key={type=term, key=foo, layer=lemma, match=eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000279 "]}" +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000280 "], operation=repetition, @min=0, @max=100 }," +
281 "{type=token, key={type=term, key=NN, layer=p, match=eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000282 "]}" ;
283 ppt = new PoliqarpPlusTree("([base=bar][base=foo])*[p=NN]");
284 map = ppt.getRequestMap().get("query").toString();
285 assertEquals(occ8.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000286
287 // [base=foo]+
Joachim Bingel11d5b152014-02-11 21:33:47 +0000288 String occ9 = "{type=group, operands=[" +
289 "{type=token, key={type=term, key=foo, layer=lemma, match=eq}}" +
290 "], operation=repetition, @min=1, @max=100}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000291 ppt = new PoliqarpPlusTree("[base=foo]+");
292 map = ppt.getRequestMap().get("query").toString();
293 assertEquals(occ9.replaceAll(" ", ""), map.replaceAll(" ", ""));
294
295 // [base=foo]?
Joachim Bingel11d5b152014-02-11 21:33:47 +0000296 String occ10 = "{type=group, operands=[" +
297 "{type=token, key={type=term, key=foo, layer=lemma, match=eq}}" +
298 "], operation=repetition, @min=0, @max=1}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000299 ppt = new PoliqarpPlusTree("[base=foo]?");
300 map = ppt.getRequestMap().get("query").toString();
301 assertEquals(occ10.replaceAll(" ", ""), map.replaceAll(" ", ""));
302
303 // [base=foo]{2,5}
Joachim Bingel11d5b152014-02-11 21:33:47 +0000304 String occ11 = "{type=group, operands=[" +
305 "{type=token, key={type=term, key=foo, layer=lemma, match=eq}}" +
306 "], operation=repetition, @min=2, @max=5}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000307 ppt = new PoliqarpPlusTree("[base=foo]{2,5}");
308 map = ppt.getRequestMap().get("query").toString();
309 assertEquals(occ11.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000310 }
311
312 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000313 public void testTokenSequence() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000314 // [base=Mann][orth=Frau]
Joachim Bingel11d5b152014-02-11 21:33:47 +0000315 String seq1 = "{type=group, operation=sequence, operands=[" +
316 "{type=token, key={type=term, key=Mann, layer=lemma, match=eq}}, " +
317 "{type=token, key={type=term, key=Frau, layer=orth, match=eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000318 "]}";
319 assertTrue(equalsQueryContent(seq1, "[base=Mann][orth=Frau]"));
320
321 // [base=Mann][orth=Frau][p=NN]
Joachim Bingel11d5b152014-02-11 21:33:47 +0000322 String seq2 = "{type=group, operation=sequence, operands=[" +
323 "{type=token, key={type=term, key=Mann, layer=lemma, match=eq}}, " +
324 "{type=token, key={type=term, key=Frau, layer=orth, match=eq}}, " +
325 "{type=token, key={type=term, key=NN,layer=p, match=eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000326 "]}";
327 assertTrue(equalsQueryContent(seq2, "[base=Mann][orth=Frau][p=NN]"));
328 }
329
330 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000331 public void testDisjSegments() throws QueryException {
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000332 // ([base=der]|[base=das])[base=Schild]
333 String disj1 =
Joachim Bingel11d5b152014-02-11 21:33:47 +0000334 "{type=group, operation=sequence, operands=[" +
335 "{type=group, operation=or, operands=[" +
336 "{type=token, key={type=term, key=der, layer=lemma, match=eq}}," +
337 "{type=token, key={type=term, key=das, layer=lemma, match=eq}}" +
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000338 "]}," +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000339 "{type=token, key={type=term, key=Schild, layer=lemma, match=eq}}" +
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000340 "]}";
341 ppt = new PoliqarpPlusTree("([base=der]|[base=das])[base=Schild]");
342 map = ppt.getRequestMap().get("query").toString();
343 assertEquals(disj1.replaceAll(" ", ""), map.replaceAll(" ", ""));
344
345 // [base=Schild]([base=der]|[base=das])
346 String disj2 =
Joachim Bingel11d5b152014-02-11 21:33:47 +0000347 "{type=group, operation=sequence, operands=[" +
348 "{type=token, key={type=term, key=Schild, layer=lemma, match=eq}}," +
349 "{type=group, operation=or, operands=[" +
350 "{type=token, key={type=term, key=der, layer=lemma, match=eq}}," +
351 "{type=token, key={type=term, key=das, layer=lemma, match=eq}}" +
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000352 "]}" +
353 "]}";
354 ppt = new PoliqarpPlusTree("[base=Schild]([base=der]|[base=das])");
355 map = ppt.getRequestMap().get("query").toString();
356 assertEquals(disj2.replaceAll(" ", ""), map.replaceAll(" ", ""));
357 }
358
359 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000360 public void testTokenElemSequence() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000361 // [base=Mann]<vp>
Joachim Bingel11d5b152014-02-11 21:33:47 +0000362 String seq1 = "{type=group, operation=sequence, operands=[" +
363 "{type=token, key={type=term, key=Mann, layer=lemma, match=eq}}, " +
364 "{type=span, key=vp}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000365 "]}";
366 assertTrue(equalsQueryContent(seq1, "[base=Mann]<vp>"));
367
368 // <vp>[base=Mann]
Joachim Bingel11d5b152014-02-11 21:33:47 +0000369 String seq2 = "{type=group, operation=sequence, operands=[" +
370 "{type=span, key=vp}, "+
371 "{type=token, key={type=term, key=Mann, layer=lemma, match=eq}} " +
Joachim Bingel53333e62013-12-09 19:25:52 +0000372 "]}";
373 assertTrue(equalsQueryContent(seq2, "<vp>[base=Mann]"));
374
375 // <vp>[base=Mann]<pp>
Joachim Bingel11d5b152014-02-11 21:33:47 +0000376 String seq3 = "{type=group, operation=sequence, operands=[" +
377 "{type=span, key=vp}, "+
378 "{type=token, key={type=term, key=Mann, layer=lemma, match=eq}}, " +
379 "{type=span, key=pp} "+
Joachim Bingel53333e62013-12-09 19:25:52 +0000380 "]}";
381 assertTrue(equalsQueryContent(seq3, "<vp>[base=Mann]<pp>"));
382 }
383
384 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000385 public void testElemSequence() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000386 // <np><vp>
Joachim Bingel11d5b152014-02-11 21:33:47 +0000387 String seq1 = "{type=group, operation=sequence, operands=[" +
388 "{type=span, key=np}," +
389 "{type=span, key=vp}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000390 "]}";
391 assertTrue(equalsQueryContent(seq1, "<np><vp>"));
392
393 // <np><vp><pp>
Joachim Bingel11d5b152014-02-11 21:33:47 +0000394 String seq2 = "{type=group, operation=sequence, operands=[" +
395 "{type=span, key=np}," +
396 "{type=span, key=vp}," +
397 "{type=span, key=pp}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000398 "]}";
399 assertTrue(equalsQueryContent(seq2, "<np><vp><pp>"));
400 }
401
402 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000403 public void testClasses() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000404 // {[base=Mann]}
Joachim Bingel11d5b152014-02-11 21:33:47 +0000405 String cls1 = "{type=group, operation=class, class=0, operands=[" +
406 "{type=token, key={type=term, key=Mann, layer=lemma, match=eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000407 "]}";
Joachim Bingel8c640e42014-02-07 16:20:47 +0000408 ppt = new PoliqarpPlusTree("{[base=Mann]}");
409 map = ppt.getRequestMap().get("query").toString();
410 assertEquals(cls1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000411
412 // {[base=Mann][orth=Frau]}
Joachim Bingel11d5b152014-02-11 21:33:47 +0000413 String cls2 = "{type=group, operation=class, class=0, operands=[" +
414 "{type=group, operation=sequence, operands=[" +
415 "{type=token, key={type=term, key=Mann, layer=lemma, match=eq}}," +
416 "{type=token, key={type=term, key=Frau, layer=orth, match=eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000417 "]}" +
418 "]}";
419 assertTrue(equalsQueryContent(cls2, "{[base=Mann][orth=Frau]}"));
420
421 // [p=NN]{[base=Mann][orth=Frau]}
Joachim Bingel11d5b152014-02-11 21:33:47 +0000422 String cls3 = "{type=group, operation=sequence, operands=[" +
423 "{type=token, key={type=term, key=NN, layer=p, match=eq}}," +
424 "{type=group, operation=class, class=0, operands=[" +
425 "{type=group, operation=sequence, operands=[" +
426 "{type=token, key={type=term, key=Mann, layer=lemma, match=eq}}," +
427 "{type=token, key={type=term, key=Frau, layer=orth, match=eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000428 "]}" +
429 "]}" +
430 "]}";
431 assertTrue(equalsQueryContent(cls3, "[p=NN]{[base=Mann][orth=Frau]}"));
432
433 // {[base=Mann][orth=Frau]}[p=NN]
Joachim Bingel11d5b152014-02-11 21:33:47 +0000434 String cls4 = "{type=group, operation=sequence, operands=[" +
435 "{type=group, operation=class, class=0, operands=[" +
436 "{type=group, operation=sequence, operands=[" +
437 "{type=token, key={type=term, key=Mann, layer=lemma, match=eq}}," +
438 "{type=token, key={type=term, key=Frau, layer=orth, match=eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000439 "]}" +
440 "]}," +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000441 "{type=token, key={type=term, key=NN, layer=p, match=eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000442 "]}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000443 ppt = new PoliqarpPlusTree("{[base=Mann][orth=Frau]}[p=NN]");
444 map = ppt.getRequestMap().get("query").toString();
445 assertEquals(cls4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000446
447 // {2:{1:[tt/p=ADJA]}[mate/p=NN]}"
Joachim Bingel11d5b152014-02-11 21:33:47 +0000448 String cls5 = "{type=group, operation=class, class=2, operands=[" +
449 "{type=group, operation=sequence, operands=[" +
450 "{type=group, operation=class, class=1, operands=[" +
451 "{type=token, key={type=term, key=ADJA, layer=p, foundry=tt, match=eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000452 "]}," +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000453 "{type=token, key={type=term, key=NN, layer=p, foundry=mate, match=eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000454 "]}" +
455 "]}";
456 ppt = new PoliqarpPlusTree("{2: {1:[tt/p=ADJA]}[mate/p=NN]}");
457 map = ppt.getRequestMap().get("query").toString();
458 assertEquals(cls5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000459 }
460
461 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000462 public void testPositions() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000463 // contains(<s>,<np>)
Joachim Bingel11d5b152014-02-11 21:33:47 +0000464 String pos1 = "{type=group, operation=position, frame=contains, operands=[" +
465 "{type=span, key=s}," +
466 "{type=span, key=np}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000467 "]}";
468 assertTrue(equalsQueryContent(pos1, "contains(<s>,<np>)"));
469
470 // contains(<s>,[base=Mann])
Joachim Bingel11d5b152014-02-11 21:33:47 +0000471 String pos2 = "{type=group, operation=position, frame=contains, operands=[" +
472 "{type=span, key=s}," +
473 "{type=token, key= {type=term, key=Mann, layer=lemma, match=eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000474 "]}";
475 assertTrue(equalsQueryContent(pos2, "contains(<s>,[base=Mann])"));
476
477 // contains(<s>,[orth=der][orth=Mann])
Joachim Bingel11d5b152014-02-11 21:33:47 +0000478 String pos3 = "{type=group, operation=position, frame=contains, operands=[" +
479 "{type=span, key=s}," +
480 "{type=group, operation=sequence, operands=[" +
481 "{type=token, key={type=term, key=der, layer=orth, match=eq}}," +
482 "{type=token, key={type=term, key=Mann, layer=orth, match=eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000483 "]}" +
484 "]}";
485 ppt = new PoliqarpPlusTree("contains(<s>,[orth=der][orth=Mann])");
486 map = ppt.getRequestMap().get("query").toString();
487 assertEquals(pos3.replaceAll(" ", ""), map.replaceAll(" ", ""));
488
489 // [base=Auto]contains(<s>,[base=Mann])
490 String pos4 =
Joachim Bingel11d5b152014-02-11 21:33:47 +0000491 "{type=group, operation=sequence, operands=[" +
492 "{type=token, key={type=term, key=Auto, layer=lemma, match=eq}}," +
493 "{type=group, operation=position, frame=contains, operands=[" +
494 "{type=span, key=s}," +
495 "{type=token, key={type=term, key=Mann, layer=lemma, match=eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000496 "]}" +
497 "]}";
498 ppt = new PoliqarpPlusTree("[base=Auto]contains(<s>,[base=Mann])");
499 map = ppt.getRequestMap().get("query").toString();
500 assertEquals(pos4.replaceAll(" ", ""), map.replaceAll(" ", ""));
501 }
502
503 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000504 public void testNestedPositions() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000505 // contains(<s>,startswith(<np>,[orth=Der]))
506 String npos1 =
Joachim Bingel11d5b152014-02-11 21:33:47 +0000507 "{type=group, operation=position, frame=contains, operands=[" +
508 "{type=span, key=s}," +
509 "{type=group, operation=position, frame=startswith, operands=[" +
510 "{type=span, key=np}," +
511 "{type=token, key={type=term, key=Der, layer=orth, match=eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000512 "]}" +
513 "]}";
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000514 ppt = new PoliqarpPlusTree("contains(<s>, startswith(<np>,[orth=Der]))");
Joachim Bingel53333e62013-12-09 19:25:52 +0000515 map = ppt.getRequestMap().get("query").toString();
516 assertEquals(npos1.replaceAll(" ", ""), map.replaceAll(" ", ""));
517 }
518
519 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000520 public void testShrinkSplit() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000521 // shrink([orth=Der]{[orth=Mann]})
522 String shr1 =
Joachim Bingel11d5b152014-02-11 21:33:47 +0000523 "{type=group, operation=submatch, classRef=[0], operands=[" +
524 "{type=group, operation=sequence, operands=[" +
525 "{type=token, key={type=term, key=Der, layer=orth, match=eq}}," +
526 "{type=group, operation=class, class=0, operands=[" +
527 "{type=token, key={type=term, key=Mann, layer=orth, match=eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000528 "]}" +
529 "]}" +
530 "]}";
531 ppt = new PoliqarpPlusTree("shrink([orth=Der]{[orth=Mann]})");
532 map = ppt.getRequestMap().get("query").toString();
533 assertEquals(shr1.replaceAll(" ", ""), map.replaceAll(" ", ""));
534
535 // shrink([orth=Der]{[orth=Mann][orth=geht]})
536 String shr2 =
Joachim Bingel11d5b152014-02-11 21:33:47 +0000537 "{type=group, operation=submatch, classRef=[0], operands=[" +
538 "{type=group, operation=sequence, operands=[" +
539 "{type=token, key={type=term, key=Der, layer=orth, match=eq}}," +
540 "{type=group, operation=class, class=0, operands=[" +
541 "{type=group, operation=sequence, operands=[" +
542 "{type=token, key={type=term, key=Mann, layer=orth, match=eq}}," +
543 "{type=token, key={type=term, key=geht, layer=orth, match=eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000544 "]}" +
545 "]}" +
546 "]}" +
547 "]}";
548 ppt = new PoliqarpPlusTree("shrink([orth=Der]{[orth=Mann][orth=geht]})");
549 map = ppt.getRequestMap().get("query").toString();
550 assertEquals(shr2.replaceAll(" ", ""), map.replaceAll(" ", ""));
551
552 // shrink(1:[orth=Der]{1:[orth=Mann][orth=geht]})
553 String shr3 =
Joachim Bingel11d5b152014-02-11 21:33:47 +0000554 "{type=group, operation=submatch, classRef=[1], operands=[" +
555 "{type=group, operation=sequence, operands=[" +
556 "{type=token, key={type=term, key=Der, layer=orth, match=eq}}," +
557 "{type=group, operation=class, class=1, operands=[" +
558 "{type=group, operation=sequence, operands=[" +
559 "{type=token, key={type=term, key=Mann, layer=orth, match=eq}}," +
560 "{type=token, key={type=term, key=geht, layer=orth, match=eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000561 "]}" +
562 "]}" +
563 "]}" +
564 "]}";
565 ppt = new PoliqarpPlusTree("shrink(1:[orth=Der]{1:[orth=Mann][orth=geht]})");
566 map = ppt.getRequestMap().get("query").toString();
567 assertEquals(shr3.replaceAll(" ", ""), map.replaceAll(" ", ""));
568
569 // shrink(1:startswith(<s>,{1:<np>}))
570 String shr4 =
Joachim Bingel11d5b152014-02-11 21:33:47 +0000571 "{type=group, operation=submatch, classRef=[1], operands=[" +
572 "{type=group, operation=position, frame=startswith, operands=[" +
573 "{type=span, key=s}," +
574 "{type=group, operation=class, class=1, operands=[" +
575 "{type=span, key=np}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000576 "]}" +
577 "]}" +
578 "]}";
Joachim Bingeladefa622013-12-13 10:51:48 +0000579 ppt = new PoliqarpPlusTree("shrink(1:startswith(<s>,{1:<np>}))");
Joachim Bingel53333e62013-12-09 19:25:52 +0000580 map = ppt.getRequestMap().get("query").toString();
581 assertEquals(shr4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000582
583 // shrink(3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))
584 String shr5 =
Joachim Bingel11d5b152014-02-11 21:33:47 +0000585 "{type=group, operation=submatch, classRef=[3], operands=[" +
586 "{type=group, operation=position, frame=startswith, operands=[" +
587 "{type=span, key=s}," +
588 "{type=group, operation=class, class=3, operands=[" +
589 "{type=group, operation=sequence, operands=[" +
590 "{type=token, key={type=term, key=der, layer=lemma, match=eq}}," +
591 "{type=group, operation=class, class=1, operands=[" +
592 "{type=group, operation=sequence, operands=[" +
593 "{type=token, key={type=term, key=ADJA, layer=p, foundry=mate, match=eq}}," +
594 "{type=group, operation=class, class=2, operands=[" +
595 "{type=token, key={type=term, key=NN, layer=p, foundry=tt, match=eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000596 "]}" +
597 "]}" +
598 "]}" +
599 "]}" +
600 "]}" +
601 "]}" +
602 "]}";
Joachim Bingeladefa622013-12-13 10:51:48 +0000603 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 +0000604 map = ppt.getRequestMap().get("query").toString();
605 assertEquals(shr5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000606
607 // split(3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))
608 String shr6 =
Joachim Bingel11d5b152014-02-11 21:33:47 +0000609 "{type=group, operation=split, classRef=[3], operands=[" +
610 "{type=group, operation=position, frame=startswith, operands=[" +
611 "{type=span, key=s}," +
612 "{type=group, operation=class, class=3, operands=[" +
613 "{type=group, operation=sequence, operands=[" +
614 "{type=token, key={type=term, key=der, layer=lemma, match=eq}}," +
615 "{type=group, operation=class, class=1, operands=[" +
616 "{type=group, operation=sequence, operands=[" +
617 "{type=token, key={type=term, key=ADJA, layer=p, foundry=mate, match=eq}}," +
618 "{type=group, operation=class, class=2, operands=[" +
619 "{type=token, key={type=term, key=NN, layer=p, foundry=tt, match=eq}}" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000620 "]}" +
621 "]}" +
622 "]}" +
623 "]}" +
624 "]}" +
625 "]}" +
626 "]}";
627 ppt = new PoliqarpPlusTree("split(3:startswith(<s>,{3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) ");
628 map = ppt.getRequestMap().get("query").toString();
629 assertEquals(shr6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel8c640e42014-02-07 16:20:47 +0000630
631 // split(2|3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))
632 String shr7 =
Joachim Bingel11d5b152014-02-11 21:33:47 +0000633 "{type=group, operation=split, classRef=[2, 3], classRefOp=intersection, operands=[" +
634 "{type=group, operation=position, frame=startswith, operands=[" +
635 "{type=span, key=s}," +
636 "{type=group, operation=class, class=3, operands=[" +
637 "{type=group, operation=sequence, operands=[" +
638 "{type=token, key={type=term, key=der, layer=lemma, match=eq}}," +
639 "{type=group, operation=class, class=1, operands=[" +
640 "{type=group, operation=sequence, operands=[" +
641 "{type=token, key={type=term, key=ADJA, layer=p, foundry=mate, match=eq}}," +
642 "{type=group, operation=class, class=2, operands=[" +
643 "{type=token, key={type=term, key=NN, layer=p, foundry=tt, match=eq}}" +
Joachim Bingel8c640e42014-02-07 16:20:47 +0000644 "]}" +
645 "]}" +
646 "]}" +
647 "]}" +
648 "]}" +
649 "]}" +
650 "]}";
651 ppt = new PoliqarpPlusTree("split(2|3:startswith(<s>,{3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) ");
652 map = ppt.getRequestMap().get("query").toString();
653 assertEquals(shr7.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000654 }
655
Joachim Bingel03882702013-12-31 19:53:05 +0000656
Joachim Bingel53333e62013-12-09 19:25:52 +0000657 @Test
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000658 public void testFoundries() throws QueryException {
659 // [tt/base=Mann]
Joachim Bingel11d5b152014-02-11 21:33:47 +0000660 String layer1 = "{type=token, key={type=term, key=Mann, layer=base, foundry=tt, match=eq}}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000661 ppt = new PoliqarpPlusTree("[tt/base=Mann]");
662 map = ppt.getRequestMap().get("query").toString();
663 assertEquals(layer1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000664
665 }
Joachim Bingel16da4e12013-12-17 09:48:12 +0000666
667 @Test
Joachim Bingel8c640e42014-02-07 16:20:47 +0000668 public void testAlign() throws QueryException {
Joachim Bingel16da4e12013-12-17 09:48:12 +0000669 // [orth=der]^[orth=Mann]
670 String align1 =
Joachim Bingel11d5b152014-02-11 21:33:47 +0000671 "{type=group, operation=sequence, operands=[" +
672 "{type=token, key={type=term, key=der, layer=orth, match=eq}}," +
673 "{type=group, alignment=left, operands=[" +
674 "{type=token, key={type=term, key=Mann, layer=orth, match=eq}}" +
Joachim Bingel03882702013-12-31 19:53:05 +0000675 "]}" +
Joachim Bingel16da4e12013-12-17 09:48:12 +0000676 "]}";
677 ppt = new PoliqarpPlusTree("[orth=der]^[orth=Mann]");
678 map = ppt.getRequestMap().get("query").toString();
679 assertEquals(align1.replaceAll(" ", ""), map.replaceAll(" ", ""));
680
Joachim Bingel84e33df2014-01-31 14:02:46 +0000681 // [orth=der]^[orth=große][orth=Mann]
682 String query = "[orth=der]^[orth=große][orth=Mann]";
683 String align1b =
Joachim Bingel11d5b152014-02-11 21:33:47 +0000684 "{type=group, operation=sequence, operands=[" +
685 "{type=token, key={type=term, key=der, layer=orth, match=eq}}," +
686 "{type=group, alignment=left, operands=[" +
687 "{type=group, operation=sequence, operands=[" +
688 "{type=token, key={type=term, key=große, layer=orth, match=eq}}," +
689 "{type=token, key={type=term, key=Mann, layer=orth, match=eq}}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +0000690 "]}" +
691 "]}" +
692 "]}";
693 ppt = new PoliqarpPlusTree(query);
694 map = ppt.getRequestMap().get("query").toString();
695 assertEquals(align1b.replaceAll(" ", ""), map.replaceAll(" ", ""));
696
Joachim Bingel16da4e12013-12-17 09:48:12 +0000697 // "([base=a]^[base=b])|[base=c]",
698 String align2 =
Joachim Bingel11d5b152014-02-11 21:33:47 +0000699 "{type=group, operation=or, operands=[" +
700 "{type=group, operation=sequence, operands=[" +
701 "{type=token, key={type=term, key=a, layer=lemma, match=eq}}," +
702 "{type=group, alignment=left, operands=[" +
703 "{type=token, key={type=term, key=b, layer=lemma, match=eq}}" +
Joachim Bingel03882702013-12-31 19:53:05 +0000704 "]}" +
Joachim Bingel16da4e12013-12-17 09:48:12 +0000705 "]}," +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000706 "{type=token, key={type=term, key=c, layer=lemma, match=eq}}" +
Joachim Bingel16da4e12013-12-17 09:48:12 +0000707 "]}";
708 ppt = new PoliqarpPlusTree("([base=a]^[base=b])|[base=c]");
709 map = ppt.getRequestMap().get("query").toString();
710 assertEquals(align2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingela67e6a32014-01-02 18:35:24 +0000711
712 // "([base=a]^[base=b][base=c])|[base=d]",
713 String align3 =
Joachim Bingel11d5b152014-02-11 21:33:47 +0000714 "{type=group, operation=or, operands=[" +
715 "{type=group, operation=sequence, operands=[" +
716 "{type=token, key={type=term, key=a, layer=lemma, match=eq}}," +
717 "{type=group, alignment=left, operands=[" +
718 "{type=group, operation=sequence, operands=[" +
719 "{type=token, key={type=term, key=b, layer=lemma, match=eq}}," +
720 "{type=token, key={type=term, key=c, layer=lemma, match=eq}}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +0000721 "]}" +
722 "]}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000723 "]}," +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000724 "{type=token, key={type=term, key=d, layer=lemma, match=eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000725 "]}";
726 ppt = new PoliqarpPlusTree("([base=a]^[base=b][base=c])|[base=d]");
727 map = ppt.getRequestMap().get("query").toString();
728 assertEquals(align3.replaceAll(" ", ""), map.replaceAll(" ", ""));
729
730 // "([base=a]^[base=b]^[base=c])|[base=d]",
731 String align4 =
Joachim Bingel11d5b152014-02-11 21:33:47 +0000732 "{type=group, operation=or, operands=[" +
733 "{type=group, operation=sequence, operands=[" +
734 "{type=token, key={type=term, key=a, layer=lemma, match=eq}}," +
735 "{type=group, alignment=left, operands=[" +
736 "{type=group, operation=sequence, operands=[" +
737 "{type=token, key={type=term, key=b, layer=lemma, match=eq}}," +
738 "{type=group, alignment=left, operands=[" +
739 "{type=token, key={type=term, key=c, layer=lemma, match=eq}}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +0000740 "]}" +
741 "]}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000742 "]}" +
743 "]}," +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000744 "{type=token, key={type=term, key=d, layer=lemma, match=eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000745 "]}";
746 ppt = new PoliqarpPlusTree("([base=a]^[base=b]^[base=c])|[base=d]");
747 map = ppt.getRequestMap().get("query").toString();
748 assertEquals(align4.replaceAll(" ", ""), map.replaceAll(" ", ""));
749
750
Joachim Bingel16da4e12013-12-17 09:48:12 +0000751 }
752
753 @Test
Joachim Bingel8c640e42014-02-07 16:20:47 +0000754 public void testSimpleQueries() throws QueryException {
Joachim Bingela67e6a32014-01-02 18:35:24 +0000755 // Baum
756 String simple1 =
Joachim Bingel11d5b152014-02-11 21:33:47 +0000757 "{type=token, key={type=term, key=Baum, layer=orth, match=eq}}";
Joachim Bingela67e6a32014-01-02 18:35:24 +0000758 ppt = new PoliqarpPlusTree("Baum");
759 map = ppt.getRequestMap().get("query").toString();
760 assertEquals(simple1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel16da4e12013-12-17 09:48:12 +0000761
Joachim Bingela67e6a32014-01-02 18:35:24 +0000762 // Der Baum
763 String simple2 =
Joachim Bingel11d5b152014-02-11 21:33:47 +0000764 "{type=group, operation=sequence, operands=[" +
765 "{type=token, key={type=term, key=Der, layer=orth, match=eq}}, " +
766 "{type=token, key={type=term, key=Baum, layer=orth, match=eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000767 "]}";
768 ppt = new PoliqarpPlusTree("Der Baum");
769 map = ppt.getRequestMap().get("query").toString();
770 assertEquals(simple2.replaceAll(" ", ""), map.replaceAll(" ", ""));
771
772 // Der große Baum
773 String simple3 =
Joachim Bingel11d5b152014-02-11 21:33:47 +0000774 "{type=group, operation=sequence, operands=[" +
775 "{type=token, key={type=term, key=Der, layer=orth, match=eq}}, " +
776 "{type=token, key={type=term, key=große, layer=orth, match=eq}}, " +
777 "{type=token, key={type=term, key=Baum, layer=orth, match=eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000778 "]}";
779 ppt = new PoliqarpPlusTree("Der große Baum");
780 map = ppt.getRequestMap().get("query").toString();
781 assertEquals(simple3.replaceAll(" ", ""), map.replaceAll(" ", ""));
782
783 // Baum | Stein
784 String simple4 =
Joachim Bingel11d5b152014-02-11 21:33:47 +0000785 "{type=group, operation=or, operands=[" +
786 "{type=token, key={type=term, key=Baum, layer=orth, match=eq}}, " +
787 "{type=token, key={type=term, key=Stein, layer=orth, match=eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000788 "]}";
789 ppt = new PoliqarpPlusTree("Baum | Stein");
790 map = ppt.getRequestMap().get("query").toString();
791 assertEquals(simple4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel84e33df2014-01-31 14:02:46 +0000792
793 // Baum | Stein Haus
794 String query = "(Baum | Stein) Haus";
795 String simple5 =
Joachim Bingel11d5b152014-02-11 21:33:47 +0000796 "{type=group, operation=sequence, operands=[" +
797 "{type=group, operation=or, operands=[" +
798 "{type=token, key={type=term, key=Baum, layer=orth, match=eq}}, " +
799 "{type=token, key={type=term, key=Stein, layer=orth, match=eq}}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +0000800 "]}," +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000801 "{type=token, key={type=term, key=Haus, layer=orth, match=eq}} " +
Joachim Bingel84e33df2014-01-31 14:02:46 +0000802 "]}";
803 ppt = new PoliqarpPlusTree(query);
804 map = ppt.getRequestMap().get("query").toString();
805 assertEquals(simple5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel16da4e12013-12-17 09:48:12 +0000806 }
Joachim Bingel53333e62013-12-09 19:25:52 +0000807}
808