blob: 18f2612d452e095b1f67b932306d8dea4dc5a199 [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;
Joachim Bingel14239d82014-07-22 09:55:04 +000012 String expected;
13 String query;
Joachim Bingel53333e62013-12-09 19:25:52 +000014
Joachim Bingel16da4e12013-12-17 09:48:12 +000015 private boolean equalsQueryContent(String res, String query) throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +000016 res = res.replaceAll(" ", "");
17 ppt = new PoliqarpPlusTree(query);
18 String queryMap = ppt.getRequestMap().get("query").toString().replaceAll(" ", "");
19 return res.equals(queryMap);
20 }
21
Joachim Bingel81812632014-02-18 08:55:22 +000022 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +000023 public void testContext() throws QueryException {
Joachim Bingel81812632014-02-18 08:55:22 +000024 String contextString = "http://ids-mannheim.de/ns/KorAP/json-ld/v0.1/context.jsonld";
Joachim Bingel2daf9862014-02-12 10:18:54 +000025 ppt = new PoliqarpPlusTree("Test");
26 assertEquals(contextString.replaceAll(" ", ""), ppt.getRequestMap().get("@context").toString().replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +000027 }
28
29 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +000030 public void testSingleTokens() throws QueryException {
Joachim Bingel0900a892014-06-30 16:26:21 +000031 String query;
Joachim Bingel53333e62013-12-09 19:25:52 +000032 // [base=Mann]
Joachim Bingel0900a892014-06-30 16:26:21 +000033 String token1 = "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}";
Joachim Bingel53333e62013-12-09 19:25:52 +000034 assertTrue(equalsQueryContent(token1, "[base=Mann]"));
35
36 // [orth!=Frau]
Joachim Bingel0900a892014-06-30 16:26:21 +000037 String token2 = "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:ne}}";
Joachim Bingel53333e62013-12-09 19:25:52 +000038 assertTrue(equalsQueryContent(token2, "[orth!=Frau]"));
39
40 // [!p=NN]
Joachim Bingel0900a892014-06-30 16:26:21 +000041 query = "[!p=NN]";
42 String token3 = "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:ne}}";
43 ppt = new PoliqarpPlusTree(query);
44 map = ppt.getRequestMap().get("query").toString();
45 assertEquals(token3.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +000046
47 // [!p!=NN]
Joachim Bingel0900a892014-06-30 16:26:21 +000048 query = "[!p!=NN]";
49 String token4 = "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}";
50 ppt = new PoliqarpPlusTree(query);
51 map = ppt.getRequestMap().get("query").toString();
52 assertEquals(token4.replaceAll(" ", ""), map.replaceAll(" ", ""));
53
Joachim Bingeld1a3e712014-07-16 08:02:05 +000054 query = "[base=schland/x]";
55 String token5 = "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=.*?\\Qschland\\E.*?, match=match:eq, type=type:regex}}";
56 ppt = new PoliqarpPlusTree(query);
57 map = ppt.getRequestMap().get("query").toString();
58 assertEquals(token5.replaceAll(" ", ""), map.replaceAll(" ", ""));
59 }
60
61 @Test
62 public void testValue() throws QueryException {
63 String query;
64
65 query = "[mate/m=temp:pres]";
66 String value1 = "{@type=korap:token, wrap={@type=korap:term, foundry=mate, layer=m, key=temp, value=pres, match=match:eq}}";
67 ppt = new PoliqarpPlusTree(query);
68 map = ppt.getRequestMap().get("query").toString();
69 assertEquals(value1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +000070 }
71
72 @Test
Joachim Bingel41e112e2014-02-12 10:46:18 +000073 public void testRegex() throws QueryException {
74 String query = "[orth=\"M(a|ä)nn(er)?\"]";
Joachim Bingel0900a892014-06-30 16:26:21 +000075 String re1 = "{@type=korap:token, wrap={@type=korap:term, layer=orth, type=type:regex, key=M(a|ä)nn(er)?, match=match:eq}}";
Joachim Bingel41e112e2014-02-12 10:46:18 +000076 ppt = new PoliqarpPlusTree(query);
77 map = ppt.getRequestMap().get("query").toString();
78 assertEquals(re1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel0900a892014-06-30 16:26:21 +000079
80 query = "[orth=\"M(a|ä)nn(er)?\"/x]";
81 String re2 = "{@type=korap:token, wrap={@type=korap:term, layer=orth, type=type:regex, key=.*?M(a|ä)nn(er)?.*?, match=match:eq}}";
82 ppt = new PoliqarpPlusTree(query);
83 map = ppt.getRequestMap().get("query").toString();
84 assertEquals(re2.replaceAll(" ", ""), map.replaceAll(" ", ""));
85
86 query = "\"M(a|ä)nn(er)?\"/x";
87 String re3 = "{@type=korap:token, wrap={@type=korap:term, type=type:regex, layer=orth, key=.*?M(a|ä)nn(er)?.*?, match=match:eq}}";
88 ppt = new PoliqarpPlusTree(query);
89 map = ppt.getRequestMap().get("query").toString();
90 assertEquals(re3.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeld1a3e712014-07-16 08:02:05 +000091
92 query = "schland/x";
93 String re4 = "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=.*?\\Qschland\\E.*?, match=match:eq, type=type:regex}}";
94 ppt = new PoliqarpPlusTree(query);
95 map = ppt.getRequestMap().get("query").toString();
96 assertEquals(re4.replaceAll(" ", ""), map.replaceAll(" ", ""));
97
98 query = "\".*?Mann.*?\"";
99 String re5 = "{@type=korap:token, wrap={@type=korap:term, type=type:regex, layer=orth, key=.*?Mann.*?, match=match:eq}}";
100 ppt = new PoliqarpPlusTree(query);
101 map = ppt.getRequestMap().get("query").toString();
102 assertEquals(re5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel41e112e2014-02-12 10:46:18 +0000103 }
104
105 @Test
Joachim Bingel0207d5e2014-02-12 14:18:41 +0000106 public void testCaseSensitivityFlag() throws QueryException {
107 String query="[orth=deutscher/i]";
108 String cs1 =
Joachim Bingel0900a892014-06-30 16:26:21 +0000109 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=deutscher, match=match:eq, caseInsensitive=true}}";
Joachim Bingel0207d5e2014-02-12 14:18:41 +0000110 ppt = new PoliqarpPlusTree(query);
111 map = ppt.getRequestMap().get("query").toString();
112 assertEquals(cs1.replaceAll(" ", ""), map.replaceAll(" ", ""));
113
114 query="[orth=deutscher/i][orth=Bundestag]";
115 String cs2 =
116 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000117 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=deutscher, match=match:eq, caseInsensitive=true}}," +
118 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Bundestag, match=match:eq}}" +
Joachim Bingel0207d5e2014-02-12 14:18:41 +0000119 "]}";
120 ppt = new PoliqarpPlusTree(query);
121 map = ppt.getRequestMap().get("query").toString();
122 assertEquals(cs2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeladd0fb12014-06-24 08:54:14 +0000123
124 query="deutscher/i";
125 String cs3 =
Joachim Bingel0900a892014-06-30 16:26:21 +0000126 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=deutscher, match=match:eq, caseInsensitive=true}}";
Joachim Bingeladd0fb12014-06-24 08:54:14 +0000127 ppt = new PoliqarpPlusTree(query);
128 map = ppt.getRequestMap().get("query").toString();
129 assertEquals(cs3.replaceAll(" ", ""), map.replaceAll(" ", ""));
130
131 query="deutscher/i Bundestag";
132 String cs4 =
133 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000134 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=deutscher, match=match:eq, caseInsensitive=true}}," +
135 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Bundestag, match=match:eq}}" +
Joachim Bingeladd0fb12014-06-24 08:54:14 +0000136 "]}";
137 ppt = new PoliqarpPlusTree(query);
138 map = ppt.getRequestMap().get("query").toString();
139 assertEquals(cs4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000140
141 query="deutscher Bundestag/i";
142 String cs5 =
143 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000144 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=deutscher, match=match:eq}}," +
145 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Bundestag, match=match:eq, caseInsensitive=true}}" +
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000146 "]}";
147 ppt = new PoliqarpPlusTree(query);
148 map = ppt.getRequestMap().get("query").toString();
149 assertEquals(cs5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel0207d5e2014-02-12 14:18:41 +0000150 }
151
152 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000153 public void testElements() throws QueryException {
Joachim Bingelfc1fb352014-02-26 14:40:27 +0000154 String query;
Joachim Bingel53333e62013-12-09 19:25:52 +0000155 // <s>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000156 String elem1 = "{@type=korap:span, key=s}";
Joachim Bingel53333e62013-12-09 19:25:52 +0000157 assertTrue(equalsQueryContent(elem1, "<s>"));
158
159 // <vp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000160 String elem2 = "{@type=korap:span, key=vp}";
Joachim Bingel53333e62013-12-09 19:25:52 +0000161 assertTrue(equalsQueryContent(elem2, "<vp>"));
Joachim Bingelfc1fb352014-02-26 14:40:27 +0000162
163 // <cnx/c=vp>
164 query = "<c=vp>";
165 String span3 = "{@type=korap:span, layer=c, key=vp}";
166 ppt = new PoliqarpPlusTree(query);
167 map = ppt.getRequestMap().get("query").toString();
168 assertEquals(span3.replaceAll(" ", ""), map.replaceAll(" ", ""));
169
170 // <cnx/c=vp>
171 query = "<cnx/c=vp>";
172 String span4 = "{@type=korap:span, foundry=cnx, layer=c, key=vp}";
173 ppt = new PoliqarpPlusTree(query);
174 map = ppt.getRequestMap().get("query").toString();
175 assertEquals(span4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000176 }
Joachim Bingel87480d02014-01-17 14:07:46 +0000177
178 @Test
Joachim Bingel14239d82014-07-22 09:55:04 +0000179 public void testDistances() throws QueryException {
Joachim Bingel87480d02014-01-17 14:07:46 +0000180 // [base=der][][base=Mann]
181 String et1 =
Joachim Bingel0900a892014-06-30 16:26:21 +0000182 "{@type=korap:group, operation=operation:sequence, " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000183 "operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000184 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
185 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
186 "], inOrder=true, distances=[" +
187 "{@type=korap:distance, key=w, min=2, max=2}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000188 "]}";
189 ppt = new PoliqarpPlusTree("[base=der][][base=Mann]");
190 map = ppt.getRequestMap().get("query").toString();
191 assertEquals(et1.replaceAll(" ", ""), map.replaceAll(" ", ""));
192
193 // [base=der][][][base=Mann]
194 String et2 =
Joachim Bingel0900a892014-06-30 16:26:21 +0000195 "{@type=korap:group, operation=operation:sequence, " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000196 "operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000197 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
198 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
199 "], inOrder=true, distances=[" +
200 "{@type=korap:distance, key=w, min=3, max=3}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000201 "]}";
Joachim Bingelffd65e32014-01-22 14:22:57 +0000202 ppt = new PoliqarpPlusTree("[base=der][][][base=Mann]");
Joachim Bingel87480d02014-01-17 14:07:46 +0000203 map = ppt.getRequestMap().get("query").toString();
204 assertEquals(et2.replaceAll(" ", ""), map.replaceAll(" ", ""));
205
206 // [base=der][][]?[base=Mann]
207 String et3 =
Joachim Bingel0900a892014-06-30 16:26:21 +0000208 "{@type=korap:group, operation=operation:sequence, " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000209 "operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000210 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
211 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
212 "], inOrder=true, distances=[" +
213 "{@type=korap:distance, key=w, min=2, max=3}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000214 "]}";
215 ppt = new PoliqarpPlusTree("[base=der][][]?[base=Mann]");
216 map = ppt.getRequestMap().get("query").toString();
217 assertEquals(et3.replaceAll(" ", ""), map.replaceAll(" ", ""));
218
Joachim Bingel87480d02014-01-17 14:07:46 +0000219
Joachim Bingel14239d82014-07-22 09:55:04 +0000220
Joachim Bingelffd65e32014-01-22 14:22:57 +0000221
Joachim Bingel11d5b152014-02-11 21:33:47 +0000222 // [base=der][]{2,5}[base=Mann][]?[][base=Frau] nested distances=
Joachim Bingelffd65e32014-01-22 14:22:57 +0000223 String et5 =
Joachim Bingel0900a892014-06-30 16:26:21 +0000224 "{@type=korap:group, operation=operation:sequence," +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000225 "operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000226 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
227 "{@type=korap:group, operation=operation:sequence, " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000228 "operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000229 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}," +
230 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Frau, match=match:eq}}" +
231 "], inOrder=true, distances=[" +
232 "{@type=korap:distance, key=w, min=2, max=3}" +
Joachim Bingelffd65e32014-01-22 14:22:57 +0000233 "]}" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000234 "], inOrder=true, distances=[" +
235 "{@type=korap:distance, key=w, min=3, max=6}" +
Joachim Bingelffd65e32014-01-22 14:22:57 +0000236 "]}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000237 ppt = new PoliqarpPlusTree("[base=der][]{2,5}[base=Mann][]?[][base=Frau]");
Joachim Bingel87480d02014-01-17 14:07:46 +0000238 map = ppt.getRequestMap().get("query").toString();
239 assertEquals(et5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel87480d02014-01-17 14:07:46 +0000240
Joachim Bingelc15720f2014-05-07 14:37:23 +0000241 // [base=der][]*[base=Mann]
242 String et6 =
Joachim Bingel0900a892014-06-30 16:26:21 +0000243 "{@type=korap:group, operation=operation:sequence, " +
Joachim Bingelc15720f2014-05-07 14:37:23 +0000244 "operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000245 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
246 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
247 "], inOrder=true, distances=[" +
248 "{@type=korap:distance, key=w, min=1, max=100}" +
Joachim Bingelc15720f2014-05-07 14:37:23 +0000249 "]}";
250 ppt = new PoliqarpPlusTree("[base=der][]*[base=Mann]");
251 map = ppt.getRequestMap().get("query").toString();
252 assertEquals(et6.replaceAll(" ", ""), map.replaceAll(" ", ""));
253
Joachim Bingel0900a892014-06-30 16:26:21 +0000254 // [base=der][]+[base=Mann]
Joachim Bingelc15720f2014-05-07 14:37:23 +0000255 String et7 =
Joachim Bingel0900a892014-06-30 16:26:21 +0000256 "{@type=korap:group, operation=operation:sequence, " +
Joachim Bingelc15720f2014-05-07 14:37:23 +0000257 "operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000258 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
259 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
260 "], inOrder=true, distances=[" +
261 "{@type=korap:distance, key=w, min=2, max=100}" +
Joachim Bingelc15720f2014-05-07 14:37:23 +0000262 "]}";
263 ppt = new PoliqarpPlusTree("[base=der][]+[base=Mann]");
264 map = ppt.getRequestMap().get("query").toString();
265 assertEquals(et7.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel14239d82014-07-22 09:55:04 +0000266
267 // [base=der][]+[base=Mann]
268 String et8 =
269 "{@type=korap:group, operation=operation:sequence, " +
270 "operands=[" +
271 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
272 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
273 "], inOrder=true, distances=[" +
274 "{@type=korap:distance, key=w, min=2, max=100}" +
275 "]}";
276 ppt = new PoliqarpPlusTree("[base=der][]{1,102}[base=Mann]");
277 map = ppt.getRequestMap().get("query").toString();
278 assertEquals(et8.replaceAll(" ", ""), map.replaceAll(" ", ""));
279
280 // [base=geht][base=der][]*[base=Mann]
281 String et9 =
282 "{@type=korap:group, operation=operation:sequence, operands=[" +
283 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=geht, match=match:eq}}," +
284 "{@type=korap:group, operation=operation:sequence, " +
285 "operands=[" +
286 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
287 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
288 "], inOrder=true, distances=[" +
289 "{@type=korap:distance, key=w, min=1, max=100}" +
290 "]}" +
291 "]}";
292 ppt = new PoliqarpPlusTree("[base=geht][base=der][]*[base=Mann]");
293 map = ppt.getRequestMap().get("query").toString();
294 assertEquals(et9.replaceAll(" ", ""), map.replaceAll(" ", ""));
295
296 query = "[base=geht][base=der][]*[base=Mann][base=da]";
297 expected =
298 "{@type=korap:group, operation=operation:sequence, operands=[" +
299 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=geht, match=match:eq}}," +
300 "{@type=korap:group, operation=operation:sequence, " +
301 "operands=[" +
302 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
303 "{@type=korap:group, operation=operation:sequence, operands=[" +
304 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}," +
305 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=da, match=match:eq}}" +
306 "]}" +
307 "], inOrder=true, distances=[" +
308 "{@type=korap:distance, key=w, min=1, max=100}" +
309 "]}" +
310 "]}";
311 ppt = new PoliqarpPlusTree(query);
312 map = ppt.getRequestMap().get("query").toString();
313 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
314
315 query = "[base=geht][base=der][]*contains(<s>,<np>)";
316 expected =
317 "{@type=korap:group, operation=operation:sequence, operands=[" +
318 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=geht, match=match:eq}}," +
319 "{@type=korap:group, operation=operation:sequence, " +
320 "operands=[" +
321 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
322 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
323 "{@type=korap:span, key=s}," +
324 "{@type=korap:span, key=np}" +
325 "]}" +
326 "], inOrder=true, distances=[" +
327 "{@type=korap:distance, key=w, min=1, max=100}" +
328 "]}" +
329 "]}";
330 ppt = new PoliqarpPlusTree(query);
331 map = ppt.getRequestMap().get("query").toString();
332 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel87480d02014-01-17 14:07:46 +0000333 }
Joachim Bingel53333e62013-12-09 19:25:52 +0000334
335 @Test
Joachim Bingel14239d82014-07-22 09:55:04 +0000336 public void testLeadingTrailingEmptyTokens() throws QueryException {
337 // startswith(<s>, [][base=Mann]
338 String et1 =
339 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
340 "{@type=korap:span, key=s}," +
341 "{@type=korap:group, operation=operation:sequence, operands=[" +
342 "{@type=korap:token}," +
343 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
344 "]}" +
345 "]}";
346 ppt = new PoliqarpPlusTree("startswith(<s>, [][base=Mann])");
347 map = ppt.getRequestMap().get("query").toString();
348 assertEquals(et1.replaceAll(" ", ""), map.replaceAll(" ", ""));
349
350 query = "[][base=Mann]";
351 expected =
352 "{@type=korap:group, operation=operation:sequence, operands=[" +
353 "{@type=korap:token}," +
354 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
355 "]}";
356 ppt = new PoliqarpPlusTree(query);
357 map = ppt.getRequestMap().get("query").toString();
358 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
359
360 query = "[][][base=Mann]";
361 expected =
362 "{@type=korap:group, operation=operation:sequence, operands=[" +
363 "{@type=korap:group, operation=operation:repetition, operands=[" +
364 "{@type=korap:token}" +
365 "], min=2, max=2}," +
366 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
367 "]}";
368 ppt = new PoliqarpPlusTree(query);
369 map = ppt.getRequestMap().get("query").toString();
370 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
371
372 query = "[][]*[base=Mann]";
373 expected =
374 "{@type=korap:group, operation=operation:sequence, operands=[" +
375 "{@type=korap:group, operation=operation:repetition, operands=[" +
376 "{@type=korap:token}" +
377 "], min=1, max=100}," +
378 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
379 "]}";
380 ppt = new PoliqarpPlusTree(query);
381 map = ppt.getRequestMap().get("query").toString();
382 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
383
384 query = "[][]*[base=Mann][][]";
385 expected =
386 "{@type=korap:group, operation=operation:sequence, operands=[" +
387 "{@type=korap:group, operation=operation:repetition, operands=[" +
388 "{@type=korap:token}" +
389 "], min=1, max=100}," +
390 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}," +
391 "{@type=korap:group, operation=operation:repetition, operands=[" +
392 "{@type=korap:token}" +
393 "], min=2, max=2}" +
394 "]}";
395 ppt = new PoliqarpPlusTree(query);
396 map = ppt.getRequestMap().get("query").toString();
397 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
398
399 query = "[][]*contains(<s>, <np>)[][]";
400 expected =
401 "{@type=korap:group, operation=operation:sequence, operands=[" +
402 "{@type=korap:group, operation=operation:repetition, operands=[" +
403 "{@type=korap:token}" +
404 "], min=1, max=100}," +
405 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
406 "{@type=korap:span, key=s}," +
407 "{@type=korap:span, key=np}" +
408 "]}," +
409 "{@type=korap:group, operation=operation:repetition, operands=[" +
410 "{@type=korap:token}" +
411 "], min=2, max=2}" +
412 "]}";
413 ppt = new PoliqarpPlusTree(query);
414 map = ppt.getRequestMap().get("query").toString();
415 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
416 }
417
418 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000419 public void testCoordinatedFields() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000420 // [base=Mann&(cas=N|cas=A)]
421 String cof1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000422 "{@type=korap:token, wrap=" +
Joachim Bingel2980bda2014-04-04 12:09:46 +0000423 "{@type=korap:termGroup, relation=relation:and, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000424 "{@type=korap:term, layer=lemma, key=Mann, match=match:eq}," +
Joachim Bingel2980bda2014-04-04 12:09:46 +0000425 "{@type=korap:termGroup, relation=relation:or, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000426 "{@type=korap:term, layer=cas, key=N, match=match:eq}," +
427 "{@type=korap:term, layer=cas, key=A, match=match:eq}" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000428 "]}" +
429 "]}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000430 "}";
431 ppt = new PoliqarpPlusTree("[base=Mann&(cas=N|cas=A)]");
432 map = ppt.getRequestMap().get("query").toString();
433 assertEquals(cof1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Nils Diewald7d486c22013-12-13 16:32:18 +0000434
435
436 assertEquals(
437 new PoliqarpPlusTree(" [ base=Mann & ( cas=N | cas=A)] ").getRequestMap().get("query").toString(),
438 new PoliqarpPlusTree("[base=Mann &(cas=N|cas=A)]").getRequestMap().get("query").toString()
439 );
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000440
441 // [base=Mann&cas=N&gen=m]
442 String cof2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000443 "{@type=korap:token, wrap=" +
Joachim Bingel2980bda2014-04-04 12:09:46 +0000444 "{@type=korap:termGroup, relation=relation:and, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000445 "{@type=korap:term, layer=lemma, key=Mann, match=match:eq}," +
446 "{@type=korap:termGroup, relation=relation:and, operands=[" +
447 "{@type=korap:term, layer=cas, key=N, match=match:eq}," +
448 "{@type=korap:term, layer=gen, key=m, match=match:eq}" +
449 "]}" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000450 "]}" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000451 "}";
452 ppt = new PoliqarpPlusTree("[base=Mann&cas=N&gen=m]");
453 map = ppt.getRequestMap().get("query").toString();
454 assertEquals(cof2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000455 }
456
457 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000458 public void testOccurrence() throws QueryException {
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000459 // [base=foo]*
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000460 String occ1 = "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000461 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000462 "], min=0, max=100}";
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000463 ppt = new PoliqarpPlusTree("[base=foo]*");
464 map = ppt.getRequestMap().get("query").toString();
465 assertEquals(occ1.replaceAll(" ", ""), map.replaceAll(" ", ""));
466
467 // [base=foo]*[base=bar]
468 String occ2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000469 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000470 "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000471 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000472 "], min=0, max=100 }," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000473 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000474 "]}";
475 ppt = new PoliqarpPlusTree("[base=foo]*[base=bar]");
476 map = ppt.getRequestMap().get("query").toString();
477 assertEquals(occ2.replaceAll(" ", ""), map.replaceAll(" ", ""));
478
479 // [base=bar][base=foo]*
480 String occ3 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000481 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000482 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000483 "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000484 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000485 "], min=0, max=100 }" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000486 "]}";
487 ppt = new PoliqarpPlusTree("[base=bar][base=foo]*");
488 map = ppt.getRequestMap().get("query").toString();
489 assertEquals(occ3.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb4da7022013-12-09 23:17:24 +0000490
491 // ([base=bar][base=foo])*
492 String occ4 =
Joachim Bingel0900a892014-06-30 16:26:21 +0000493 "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000494 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000495 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," +
496 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000497 "]}" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000498 "], min=0, max=100}" ;
Joachim Bingelb4da7022013-12-09 23:17:24 +0000499 ppt = new PoliqarpPlusTree("([base=bar][base=foo])*");
500 map = ppt.getRequestMap().get("query").toString();
501 assertEquals(occ4.replaceAll(" ", ""), map.replaceAll(" ", ""));
502
503 // <s>([base=bar][base=foo])*
504 String occ5 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000505 "{@type=korap:group, operation=operation:sequence, operands=[" +
506 "{@type=korap:span, key=s}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000507 "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000508 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000509 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," +
510 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000511 "]}" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000512 "], min=0, max=100 }" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000513 "]}" ;
514 ppt = new PoliqarpPlusTree("<s>([base=bar][base=foo])*");
515 map = ppt.getRequestMap().get("query").toString();
516 assertEquals(occ5.replaceAll(" ", ""), map.replaceAll(" ", ""));
517
518 // <s><np>([base=bar][base=foo])*
Joachim Bingelb4da7022013-12-09 23:17:24 +0000519 String occ6 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000520 "{@type=korap:group, operation=operation:sequence, operands=[" +
521 "{@type=korap:span, key=s}," +
522 "{@type=korap:span, key=np}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000523 "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000524 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000525 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," +
526 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000527 "]}" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000528 "], min=0, max=100 }" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000529 "]}" ;
530 ppt = new PoliqarpPlusTree("<s><np>([base=bar][base=foo])*");
531 map = ppt.getRequestMap().get("query").toString();
532 assertEquals(occ6.replaceAll(" ", ""), map.replaceAll(" ", ""));
533
534 // <s><np>([base=bar][base=foo])*[p=NN]
535 // comment: embedded sequence shouldn't really be here, but does not really hurt, either. (?)
536 // really hard to get this behaviour out of the PQPlus grammar...
537 String occ7 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000538 "{@type=korap:group, operation=operation:sequence, operands=[" +
539 "{@type=korap:span, key=s}," +
540 "{@type=korap:span, key=np}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000541 "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000542 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000543 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," +
544 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000545 "]}" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000546 "], min=0, max=100 }," +
547 "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000548 "]}" ;
549 ppt = new PoliqarpPlusTree("<s><np>([base=bar][base=foo])*[p=NN]");
550 map = ppt.getRequestMap().get("query").toString();
551 assertEquals(occ7.replaceAll(" ", ""), map.replaceAll(" ", ""));
552
553 // ([base=bar][base=foo])*[p=NN]
Joachim Bingelb4da7022013-12-09 23:17:24 +0000554 String occ8 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000555 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000556 "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000557 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000558 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," +
559 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000560 "]}" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000561 "], min=0, max=100 }," +
562 "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000563 "]}" ;
564 ppt = new PoliqarpPlusTree("([base=bar][base=foo])*[p=NN]");
565 map = ppt.getRequestMap().get("query").toString();
566 assertEquals(occ8.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000567
568 // [base=foo]+
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000569 String occ9 = "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000570 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000571 "], min=1, max=100}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000572 ppt = new PoliqarpPlusTree("[base=foo]+");
573 map = ppt.getRequestMap().get("query").toString();
574 assertEquals(occ9.replaceAll(" ", ""), map.replaceAll(" ", ""));
575
576 // [base=foo]?
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000577 String occ10 = "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000578 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000579 "], min=0, max=1}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000580 ppt = new PoliqarpPlusTree("[base=foo]?");
581 map = ppt.getRequestMap().get("query").toString();
582 assertEquals(occ10.replaceAll(" ", ""), map.replaceAll(" ", ""));
583
584 // [base=foo]{2,5}
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000585 String occ11 = "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000586 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000587 "], min=2, max=5}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000588 ppt = new PoliqarpPlusTree("[base=foo]{2,5}");
589 map = ppt.getRequestMap().get("query").toString();
590 assertEquals(occ11.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel2980bda2014-04-04 12:09:46 +0000591
592 // [base=foo]{2}
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000593 String occ12 = "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000594 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000595 "], min=2, max=2}";
Joachim Bingel2980bda2014-04-04 12:09:46 +0000596 ppt = new PoliqarpPlusTree("[base=foo]{2}");
597 map = ppt.getRequestMap().get("query").toString();
598 assertEquals(occ12.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb2aa1c72014-07-01 12:48:46 +0000599
600 // [base=foo]{2}
601 String occ13 = "{@type=korap:group, operation=operation:repetition, operands=[" +
602 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
603 "], min=2, max=100}";
604 ppt = new PoliqarpPlusTree("[base=foo]{2,}");
605 map = ppt.getRequestMap().get("query").toString();
606 assertEquals(occ13.replaceAll(" ", ""), map.replaceAll(" ", ""));
607
608 // [base=foo]{2}
609 String occ14 = "{@type=korap:group, operation=operation:repetition, operands=[" +
610 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
611 "], min=0, max=2}";
612 ppt = new PoliqarpPlusTree("[base=foo]{,2}");
613 map = ppt.getRequestMap().get("query").toString();
614 assertEquals(occ14.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000615 }
616
617 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000618 public void testTokenSequence() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000619 // [base=Mann][orth=Frau]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000620 String seq1 = "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000621 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}, " +
622 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000623 "]}";
624 assertTrue(equalsQueryContent(seq1, "[base=Mann][orth=Frau]"));
625
626 // [base=Mann][orth=Frau][p=NN]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000627 String seq2 = "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000628 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}, " +
629 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}, " +
630 "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000631 "]}";
632 assertTrue(equalsQueryContent(seq2, "[base=Mann][orth=Frau][p=NN]"));
633 }
634
635 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000636 public void testDisjSegments() throws QueryException {
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000637 // ([base=der]|[base=das])[base=Schild]
638 String disj1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000639 "{@type=korap:group, operation=operation:sequence, operands=[" +
640 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000641 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
642 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=das, match=match:eq}}" +
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000643 "]}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000644 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Schild, match=match:eq}}" +
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000645 "]}";
646 ppt = new PoliqarpPlusTree("([base=der]|[base=das])[base=Schild]");
647 map = ppt.getRequestMap().get("query").toString();
648 assertEquals(disj1.replaceAll(" ", ""), map.replaceAll(" ", ""));
649
650 // [base=Schild]([base=der]|[base=das])
651 String disj2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000652 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000653 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Schild, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000654 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000655 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
656 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=das, match=match:eq}}" +
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000657 "]}" +
658 "]}";
659 ppt = new PoliqarpPlusTree("[base=Schild]([base=der]|[base=das])");
660 map = ppt.getRequestMap().get("query").toString();
661 assertEquals(disj2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel76b498d2014-06-06 12:06:46 +0000662
663 // "([orth=der][base=katze])|([orth=eine][base=baum])"
664 String disj3 =
665 "{@type=korap:group, operation=operation:or, operands=[" +
666 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000667 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
668 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=katze, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000669 "]}," +
670 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000671 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=eine, match=match:eq}}," +
672 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=baum, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000673 "]}" +
674 "]}";
675 ppt = new PoliqarpPlusTree("([orth=der][base=katze])|([orth=eine][base=baum])");
676 map = ppt.getRequestMap().get("query").toString();
677 assertEquals(disj3.replaceAll(" ", ""), map.replaceAll(" ", ""));
678
679 // "[orth=der][base=katze]|[orth=eine][base=baum]"
680 String disj4 =
681 "{@type=korap:group, operation=operation:or, operands=[" +
682 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000683 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
684 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=katze, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000685 "]}," +
686 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000687 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=eine, match=match:eq}}," +
688 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=baum, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000689 "]}" +
690 "]}";
691 ppt = new PoliqarpPlusTree("[orth=der][base=katze]|[orth=eine][base=baum]");
692 map = ppt.getRequestMap().get("query").toString();
693 assertEquals(disj4.replaceAll(" ", ""), map.replaceAll(" ", ""));
694
695 PoliqarpPlusTree ppt1 = new PoliqarpPlusTree("[orth=der][base=katze]|[orth=eine][base=baum]");
696 PoliqarpPlusTree ppt2 = new PoliqarpPlusTree("([orth=der][base=katze])|([orth=eine][base=baum])");
697 assertEquals(ppt1.getRequestMap().toString(), ppt2.getRequestMap().toString());
698
699 // "[orth=der][base=katze]|[orth=der][base=hund]|[orth=der][base=baum]"
700 String disj5 =
701 "{@type=korap:group, operation=operation:or, operands=[" +
702 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000703 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
704 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=katze, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000705 "]}," +
706 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000707 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
708 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=hund, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000709 "]}," +
710 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000711 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
712 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=baum, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000713 "]}" +
714 "]}";
715 ppt = new PoliqarpPlusTree("[orth=der][base=katze]|[orth=der][base=hund]|[orth=der][base=baum]");
716 map = ppt.getRequestMap().get("query").toString();
717 assertEquals(disj5.replaceAll(" ", ""), map.replaceAll(" ", ""));
718
719 // [orth=der]([base=katze]|[base=hund]|[base=baum])
720 String disj6 =
721 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000722 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000723 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000724 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=katze, match=match:eq}}," +
725 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=hund, match=match:eq}}," +
726 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=baum, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000727 "]}" +
728 "]}";
729 ppt = new PoliqarpPlusTree("[orth=der]([base=katze]|[base=hund]|[base=baum])");
730 map = ppt.getRequestMap().get("query").toString();
731 assertEquals(disj6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000732 }
733
734 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000735 public void testTokenElemSequence() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000736 // [base=Mann]<vp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000737 String seq1 = "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000738 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}, " +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000739 "{@type=korap:span, key=vp}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000740 "]}";
741 assertTrue(equalsQueryContent(seq1, "[base=Mann]<vp>"));
742
743 // <vp>[base=Mann]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000744 String seq2 = "{@type=korap:group, operation=operation:sequence, operands=[" +
745 "{@type=korap:span, key=vp}, "+
Joachim Bingel0900a892014-06-30 16:26:21 +0000746 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}} " +
Joachim Bingel53333e62013-12-09 19:25:52 +0000747 "]}";
748 assertTrue(equalsQueryContent(seq2, "<vp>[base=Mann]"));
749
750 // <vp>[base=Mann]<pp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000751 String seq3 = "{@type=korap:group, operation=operation:sequence, operands=[" +
752 "{@type=korap:span, key=vp}, "+
Joachim Bingel0900a892014-06-30 16:26:21 +0000753 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}, " +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000754 "{@type=korap:span, key=pp} "+
Joachim Bingel53333e62013-12-09 19:25:52 +0000755 "]}";
756 assertTrue(equalsQueryContent(seq3, "<vp>[base=Mann]<pp>"));
757 }
758
759 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000760 public void testElemSequence() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000761 // <np><vp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000762 String seq1 = "{@type=korap:group, operation=operation:sequence, operands=[" +
763 "{@type=korap:span, key=np}," +
764 "{@type=korap:span, key=vp}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000765 "]}";
766 assertTrue(equalsQueryContent(seq1, "<np><vp>"));
767
768 // <np><vp><pp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000769 String seq2 = "{@type=korap:group, operation=operation:sequence, operands=[" +
770 "{@type=korap:span, key=np}," +
771 "{@type=korap:span, key=vp}," +
772 "{@type=korap:span, key=pp}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000773 "]}";
774 assertTrue(equalsQueryContent(seq2, "<np><vp><pp>"));
775 }
776
777 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000778 public void testClasses() throws QueryException {
Joachim Bingel0900a892014-06-30 16:26:21 +0000779 String query;
Joachim Bingel53333e62013-12-09 19:25:52 +0000780 // {[base=Mann]}
Joachim Bingel2daf9862014-02-12 10:18:54 +0000781 String cls1 = "{@type=korap:group, operation=operation:class, class=0, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000782 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000783 "]}";
Joachim Bingel8c640e42014-02-07 16:20:47 +0000784 ppt = new PoliqarpPlusTree("{[base=Mann]}");
785 map = ppt.getRequestMap().get("query").toString();
786 assertEquals(cls1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000787
788 // {[base=Mann][orth=Frau]}
Joachim Bingel0900a892014-06-30 16:26:21 +0000789 query = "{[base=Mann][orth=Frau]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000790 String cls2 = "{@type=korap:group, operation=operation:class, class=0, operands=[" +
791 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000792 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}," +
793 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000794 "]}" +
795 "]}";
Joachim Bingel0900a892014-06-30 16:26:21 +0000796 ppt = new PoliqarpPlusTree(query);
797 map = ppt.getRequestMap().get("query").toString();
798 assertEquals(cls2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000799
800 // [p=NN]{[base=Mann][orth=Frau]}
Joachim Bingel2daf9862014-02-12 10:18:54 +0000801 String cls3 = "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000802 "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000803 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
804 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000805 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}," +
806 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000807 "]}" +
808 "]}" +
809 "]}";
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000810 ppt = new PoliqarpPlusTree("[p=NN]{[base=Mann][orth=Frau]}");
811 map = ppt.getRequestMap().get("query").toString();
812 assertEquals(cls3.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000813
814 // {[base=Mann][orth=Frau]}[p=NN]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000815 String cls4 = "{@type=korap:group, operation=operation:sequence, operands=[" +
816 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
817 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000818 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}," +
819 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000820 "]}" +
821 "]}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000822 "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000823 "]}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000824 ppt = new PoliqarpPlusTree("{[base=Mann][orth=Frau]}[p=NN]");
825 map = ppt.getRequestMap().get("query").toString();
826 assertEquals(cls4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000827
828 // {2:{1:[tt/p=ADJA]}[mate/p=NN]}"
Joachim Bingel2daf9862014-02-12 10:18:54 +0000829 String cls5 = "{@type=korap:group, operation=operation:class, class=2, operands=[" +
830 "{@type=korap:group, operation=operation:sequence, operands=[" +
831 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000832 "{@type=korap:token, wrap={@type=korap:term, foundry=tt, layer=p, key=ADJA, match=match:eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000833 "]}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000834 "{@type=korap:token, wrap={@type=korap:term, foundry=mate, layer=p, key=NN, match=match:eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000835 "]}" +
836 "]}";
837 ppt = new PoliqarpPlusTree("{2: {1:[tt/p=ADJA]}[mate/p=NN]}");
838 map = ppt.getRequestMap().get("query").toString();
839 assertEquals(cls5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000840 }
841
842 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000843 public void testPositions() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000844 // contains(<s>,<np>)
Joachim Bingel2daf9862014-02-12 10:18:54 +0000845 String pos1 = "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
846 "{@type=korap:span, key=s}," +
847 "{@type=korap:span, key=np}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000848 "]}";
849 assertTrue(equalsQueryContent(pos1, "contains(<s>,<np>)"));
850
851 // contains(<s>,[base=Mann])
Joachim Bingel2daf9862014-02-12 10:18:54 +0000852 String pos2 = "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
853 "{@type=korap:span, key=s}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000854 "{@type=korap:token, wrap= {@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000855 "]}";
856 assertTrue(equalsQueryContent(pos2, "contains(<s>,[base=Mann])"));
857
858 // contains(<s>,[orth=der][orth=Mann])
Joachim Bingel2daf9862014-02-12 10:18:54 +0000859 String pos3 = "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
860 "{@type=korap:span, key=s}," +
861 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000862 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
863 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000864 "]}" +
865 "]}";
866 ppt = new PoliqarpPlusTree("contains(<s>,[orth=der][orth=Mann])");
867 map = ppt.getRequestMap().get("query").toString();
868 assertEquals(pos3.replaceAll(" ", ""), map.replaceAll(" ", ""));
869
870 // [base=Auto]contains(<s>,[base=Mann])
871 String pos4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000872 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000873 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Auto, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000874 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
875 "{@type=korap:span, key=s}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000876 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000877 "]}" +
878 "]}";
879 ppt = new PoliqarpPlusTree("[base=Auto]contains(<s>,[base=Mann])");
880 map = ppt.getRequestMap().get("query").toString();
881 assertEquals(pos4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelef7059b2014-04-22 13:44:19 +0000882
883 // contains(<s>,[pos=N]*)
884 String pos5 =
885 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
886 "{@type=korap:span, key=s}," +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000887 "{@type=korap:group, operation=operation:repetition, " +
Joachim Bingel0900a892014-06-30 16:26:21 +0000888 "operands=[{@type=korap:token, wrap={@type=korap:term, layer=pos, key=N, match=match:eq}}" +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000889 "], min=0, max=100" +
Joachim Bingelef7059b2014-04-22 13:44:19 +0000890 "}" +
891 "]}";
892 ppt = new PoliqarpPlusTree("contains(<s>,[pos=N]*)");
893 map = ppt.getRequestMap().get("query").toString();
894 assertEquals(pos5.replaceAll(" ", ""), map.replaceAll(" ", ""));
895
896 // [base=Auto]contains(<s>,[pos=N]*)
897 String pos6 =
898 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000899 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Auto, match=match:eq}}," +
Joachim Bingelef7059b2014-04-22 13:44:19 +0000900 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
901 "{@type=korap:span, key=s}," +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000902 "{@type=korap:group, operation=operation:repetition, " +
Joachim Bingel0900a892014-06-30 16:26:21 +0000903 "operands=[{@type=korap:token, wrap={@type=korap:term, layer=pos, key=N, match=match:eq}}" +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000904 "], min=0, max=100" +
Joachim Bingelef7059b2014-04-22 13:44:19 +0000905 "}" +
906 "]}" +
907 "]}";
908 ppt = new PoliqarpPlusTree("[base=Auto]contains(<s>,[pos=N]*)");
909 map = ppt.getRequestMap().get("query").toString();
910 assertEquals(pos6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000911 }
912
913 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000914 public void testNestedPositions() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000915 // contains(<s>,startswith(<np>,[orth=Der]))
916 String npos1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000917 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
918 "{@type=korap:span, key=s}," +
919 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
920 "{@type=korap:span, key=np}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000921 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000922 "]}" +
923 "]}";
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000924 ppt = new PoliqarpPlusTree("contains(<s>, startswith(<np>,[orth=Der]))");
Joachim Bingel53333e62013-12-09 19:25:52 +0000925 map = ppt.getRequestMap().get("query").toString();
926 assertEquals(npos1.replaceAll(" ", ""), map.replaceAll(" ", ""));
927 }
928
929 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000930 public void testShrinkSplit() throws QueryException {
Joachim Bingel0900a892014-06-30 16:26:21 +0000931 // focus([orth=Der]{[orth=Mann]})
Joachim Bingel53333e62013-12-09 19:25:52 +0000932 String shr1 =
Joachim Bingeld1a3e712014-07-16 08:02:05 +0000933 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000934 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000935 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000936 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000937 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000938 "]}" +
939 "]}" +
940 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000941 ppt = new PoliqarpPlusTree("focus([orth=Der]{[orth=Mann]})");
Joachim Bingel53333e62013-12-09 19:25:52 +0000942 map = ppt.getRequestMap().get("query").toString();
943 assertEquals(shr1.replaceAll(" ", ""), map.replaceAll(" ", ""));
944
Joachim Bingel0900a892014-06-30 16:26:21 +0000945 // focus([orth=Der]{[orth=Mann][orth=geht]})
Joachim Bingel53333e62013-12-09 19:25:52 +0000946 String shr2 =
Joachim Bingeld1a3e712014-07-16 08:02:05 +0000947 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000948 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000949 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000950 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
951 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000952 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}," +
953 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=geht, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000954 "]}" +
955 "]}" +
956 "]}" +
957 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000958 ppt = new PoliqarpPlusTree("focus([orth=Der]{[orth=Mann][orth=geht]})");
Joachim Bingel53333e62013-12-09 19:25:52 +0000959 map = ppt.getRequestMap().get("query").toString();
960 assertEquals(shr2.replaceAll(" ", ""), map.replaceAll(" ", ""));
961
Joachim Bingel0900a892014-06-30 16:26:21 +0000962 // focus(1:[orth=Der]{1:[orth=Mann][orth=geht]})
Joachim Bingel53333e62013-12-09 19:25:52 +0000963 String shr3 =
Joachim Bingeld1a3e712014-07-16 08:02:05 +0000964 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000965 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000966 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000967 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
968 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000969 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}," +
970 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=geht, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000971 "]}" +
972 "]}" +
973 "]}" +
974 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000975 ppt = new PoliqarpPlusTree("focus(1:[orth=Der]{1:[orth=Mann][orth=geht]})");
Joachim Bingel53333e62013-12-09 19:25:52 +0000976 map = ppt.getRequestMap().get("query").toString();
977 assertEquals(shr3.replaceAll(" ", ""), map.replaceAll(" ", ""));
978
Joachim Bingel0900a892014-06-30 16:26:21 +0000979 // focus(1:startswith(<s>,{1:<np>}))
Joachim Bingel53333e62013-12-09 19:25:52 +0000980 String shr4 =
Joachim Bingeld1a3e712014-07-16 08:02:05 +0000981 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000982 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
983 "{@type=korap:span, key=s}," +
984 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
985 "{@type=korap:span, key=np}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000986 "]}" +
987 "]}" +
988 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000989 ppt = new PoliqarpPlusTree("focus(1:startswith(<s>,{1:<np>}))");
Joachim Bingel53333e62013-12-09 19:25:52 +0000990 map = ppt.getRequestMap().get("query").toString();
991 assertEquals(shr4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000992
Joachim Bingel0900a892014-06-30 16:26:21 +0000993 // focus(3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000994 String shr5 =
Joachim Bingeld1a3e712014-07-16 08:02:05 +0000995 "{@type=korap:reference, operation=operation:focus, classRef=[3], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000996 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
997 "{@type=korap:span, key=s}," +
998 "{@type=korap:group, operation=operation:class, class=3, operands=[" +
999 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001000 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001001 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
1002 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001003 "{@type=korap:token, wrap={@type=korap:term, foundry=mate, layer=p, key=ADJA, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001004 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001005 "{@type=korap:token, wrap={@type=korap:term, foundry=tt, layer=p, key=NN, match=match:eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +00001006 "]}" +
1007 "]}" +
1008 "]}" +
1009 "]}" +
1010 "]}" +
1011 "]}" +
1012 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +00001013 ppt = new PoliqarpPlusTree("focus(3:startswith(<s>,{3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) ");
Joachim Bingelcd9ed332013-12-09 21:01:35 +00001014 map = ppt.getRequestMap().get("query").toString();
1015 assertEquals(shr5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelba9a0ab2014-01-29 10:12:25 +00001016
1017 // split(3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))
1018 String shr6 =
Joachim Bingeld1a3e712014-07-16 08:02:05 +00001019 "{@type=korap:reference, operation=operation:split, classRef=[3], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001020 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
1021 "{@type=korap:span, key=s}," +
1022 "{@type=korap:group, operation=operation:class, class=3, operands=[" +
1023 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001024 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001025 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
1026 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001027 "{@type=korap:token, wrap={@type=korap:term, foundry=mate, layer=p, key=ADJA, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001028 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001029 "{@type=korap:token, wrap={@type=korap:term, foundry=tt, layer=p, key=NN, match=match:eq}}" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +00001030 "]}" +
1031 "]}" +
1032 "]}" +
1033 "]}" +
1034 "]}" +
1035 "]}" +
1036 "]}";
1037 ppt = new PoliqarpPlusTree("split(3:startswith(<s>,{3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) ");
1038 map = ppt.getRequestMap().get("query").toString();
1039 assertEquals(shr6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel8c640e42014-02-07 16:20:47 +00001040
1041 // split(2|3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))
1042 String shr7 =
Joachim Bingeld1a3e712014-07-16 08:02:05 +00001043 "{@type=korap:reference, operation=operation:split, classRef=[2, 3], classRefOp=classRefOp:intersection, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001044 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
1045 "{@type=korap:span, key=s}," +
1046 "{@type=korap:group, operation=operation:class, class=3, operands=[" +
1047 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001048 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001049 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
1050 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001051 "{@type=korap:token, wrap={@type=korap:term, foundry=mate, layer=p, key=ADJA, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001052 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001053 "{@type=korap:token, wrap={@type=korap:term, foundry=tt, layer=p, key=NN, match=match:eq}}" +
Joachim Bingel8c640e42014-02-07 16:20:47 +00001054 "]}" +
1055 "]}" +
1056 "]}" +
1057 "]}" +
1058 "]}" +
1059 "]}" +
1060 "]}";
1061 ppt = new PoliqarpPlusTree("split(2|3:startswith(<s>,{3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) ");
1062 map = ppt.getRequestMap().get("query").toString();
1063 assertEquals(shr7.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel5146ebe2014-06-12 08:49:21 +00001064
1065
1066 String shr8 =
Joachim Bingeld1a3e712014-07-16 08:02:05 +00001067 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingeladd0fb12014-06-24 08:54:14 +00001068 "{@type=korap:group, operation=operation:sequence, operands=[" +
1069 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001070 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}" +
Joachim Bingeladd0fb12014-06-24 08:54:14 +00001071 "]}," +
1072 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001073 "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=ADJA, match=match:eq}}" +
Joachim Bingel5146ebe2014-06-12 08:49:21 +00001074 "]}" +
Joachim Bingeladd0fb12014-06-24 08:54:14 +00001075 "]}" +
1076 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +00001077 ppt = new PoliqarpPlusTree("focus(1:{[base=der]}{1:[pos=ADJA]})");
Joachim Bingeladd0fb12014-06-24 08:54:14 +00001078 map = ppt.getRequestMap().get("query").toString();
1079 assertEquals(shr8.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel5146ebe2014-06-12 08:49:21 +00001080
Joachim Bingel53333e62013-12-09 19:25:52 +00001081 }
1082
Joachim Bingel03882702013-12-31 19:53:05 +00001083
Joachim Bingel53333e62013-12-09 19:25:52 +00001084 @Test
Joachim Bingelba9a0ab2014-01-29 10:12:25 +00001085 public void testFoundries() throws QueryException {
1086 // [tt/base=Mann]
Joachim Bingel0900a892014-06-30 16:26:21 +00001087 String layer1 = "{@type=korap:token, wrap={@type=korap:term, foundry=tt, layer=lemma, key=Mann, match=match:eq}}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +00001088 ppt = new PoliqarpPlusTree("[tt/base=Mann]");
1089 map = ppt.getRequestMap().get("query").toString();
1090 assertEquals(layer1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +00001091
1092 }
Joachim Bingel16da4e12013-12-17 09:48:12 +00001093
1094 @Test
Joachim Bingel8c640e42014-02-07 16:20:47 +00001095 public void testAlign() throws QueryException {
Joachim Bingel16da4e12013-12-17 09:48:12 +00001096 // [orth=der]^[orth=Mann]
1097 String align1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001098 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001099 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
1100 "{@type=korap:group, operation=operation:alignment, operands=[" +
1101 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" +
1102 "], align=align:left}" +
Joachim Bingel16da4e12013-12-17 09:48:12 +00001103 "]}";
1104 ppt = new PoliqarpPlusTree("[orth=der]^[orth=Mann]");
1105 map = ppt.getRequestMap().get("query").toString();
1106 assertEquals(align1.replaceAll(" ", ""), map.replaceAll(" ", ""));
1107
Joachim Bingel84e33df2014-01-31 14:02:46 +00001108 // [orth=der]^[orth=große][orth=Mann]
1109 String query = "[orth=der]^[orth=große][orth=Mann]";
1110 String align1b =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001111 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001112 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
1113 "{@type=korap:group, operation=operation:alignment, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001114 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001115 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=große, match=match:eq}}," +
1116 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +00001117 "]}" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001118 "], align=align:left}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +00001119 "]}";
1120 ppt = new PoliqarpPlusTree(query);
1121 map = ppt.getRequestMap().get("query").toString();
1122 assertEquals(align1b.replaceAll(" ", ""), map.replaceAll(" ", ""));
1123
Joachim Bingel16da4e12013-12-17 09:48:12 +00001124 // "([base=a]^[base=b])|[base=c]",
1125 String align2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001126 "{@type=korap:group, operation=operation:or, operands=[" +
1127 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001128 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=a, match=match:eq}}," +
1129 "{@type=korap:group, operation=operation:alignment, operands=[" +
1130 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=b, match=match:eq}}" +
1131 "], align=align:left}" +
Joachim Bingel16da4e12013-12-17 09:48:12 +00001132 "]}," +
Joachim Bingel0900a892014-06-30 16:26:21 +00001133 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=c, match=match:eq}}" +
Joachim Bingel16da4e12013-12-17 09:48:12 +00001134 "]}";
1135 ppt = new PoliqarpPlusTree("([base=a]^[base=b])|[base=c]");
1136 map = ppt.getRequestMap().get("query").toString();
1137 assertEquals(align2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingela67e6a32014-01-02 18:35:24 +00001138
1139 // "([base=a]^[base=b][base=c])|[base=d]",
1140 String align3 =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001141 "{@type=korap:group, operation=operation:or, operands=[" +
1142 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001143 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=a, match=match:eq}}," +
1144 "{@type=korap:group, operation=operation:alignment, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001145 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001146 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=b, match=match:eq}}," +
1147 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=c, match=match:eq}}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +00001148 "]}" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001149 "], align=align:left}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +00001150 "]}," +
Joachim Bingel0900a892014-06-30 16:26:21 +00001151 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=d, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +00001152 "]}";
1153 ppt = new PoliqarpPlusTree("([base=a]^[base=b][base=c])|[base=d]");
1154 map = ppt.getRequestMap().get("query").toString();
1155 assertEquals(align3.replaceAll(" ", ""), map.replaceAll(" ", ""));
1156
1157 // "([base=a]^[base=b]^[base=c])|[base=d]",
1158 String align4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001159 "{@type=korap:group, operation=operation:or, operands=[" +
1160 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001161 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=a, match=match:eq}}," +
1162 "{@type=korap:group, operation=operation:alignment, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001163 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001164 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=b, match=match:eq}}," +
1165 "{@type=korap:group, operation=operation:alignment, operands=[" +
1166 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=c, match=match:eq}}" +
1167 "], align=align:left}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +00001168 "]}" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001169 "], align=align:left}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +00001170 "]}," +
Joachim Bingel0900a892014-06-30 16:26:21 +00001171 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=d, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +00001172 "]}";
1173 ppt = new PoliqarpPlusTree("([base=a]^[base=b]^[base=c])|[base=d]");
1174 map = ppt.getRequestMap().get("query").toString();
1175 assertEquals(align4.replaceAll(" ", ""), map.replaceAll(" ", ""));
1176
1177
Joachim Bingel16da4e12013-12-17 09:48:12 +00001178 }
1179
1180 @Test
Joachim Bingel8c640e42014-02-07 16:20:47 +00001181 public void testSimpleQueries() throws QueryException {
Joachim Bingela67e6a32014-01-02 18:35:24 +00001182 // Baum
1183 String simple1 =
Joachim Bingel0900a892014-06-30 16:26:21 +00001184 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq}}";
Joachim Bingela67e6a32014-01-02 18:35:24 +00001185 ppt = new PoliqarpPlusTree("Baum");
1186 map = ppt.getRequestMap().get("query").toString();
1187 assertEquals(simple1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel0900a892014-06-30 16:26:21 +00001188
1189 // Baum/i
1190 String simple1b =
1191 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq, caseInsensitive=true}}";
1192 ppt = new PoliqarpPlusTree("Baum/i");
1193 map = ppt.getRequestMap().get("query").toString();
1194 assertEquals(simple1b.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel16da4e12013-12-17 09:48:12 +00001195
Joachim Bingela67e6a32014-01-02 18:35:24 +00001196 // Der Baum
1197 String simple2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001198 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001199 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}, " +
1200 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +00001201 "]}";
1202 ppt = new PoliqarpPlusTree("Der Baum");
1203 map = ppt.getRequestMap().get("query").toString();
1204 assertEquals(simple2.replaceAll(" ", ""), map.replaceAll(" ", ""));
1205
Joachim Bingel0900a892014-06-30 16:26:21 +00001206 // Der Baum/i
1207 String simple2b =
1208 "{@type=korap:group, operation=operation:sequence, operands=[" +
1209 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}, " +
1210 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq, caseInsensitive=true}}" +
1211 "]}";
1212 ppt = new PoliqarpPlusTree("Der Baum/i");
1213 map = ppt.getRequestMap().get("query").toString();
1214 assertEquals(simple2b.replaceAll(" ", ""), map.replaceAll(" ", ""));
1215
Joachim Bingela67e6a32014-01-02 18:35:24 +00001216 // Der große Baum
1217 String simple3 =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001218 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001219 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}, " +
1220 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=große, match=match:eq}}, " +
1221 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +00001222 "]}";
1223 ppt = new PoliqarpPlusTree("Der große Baum");
1224 map = ppt.getRequestMap().get("query").toString();
1225 assertEquals(simple3.replaceAll(" ", ""), map.replaceAll(" ", ""));
1226
1227 // Baum | Stein
1228 String simple4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001229 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001230 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq}}, " +
1231 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Stein, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +00001232 "]}";
1233 ppt = new PoliqarpPlusTree("Baum | Stein");
1234 map = ppt.getRequestMap().get("query").toString();
1235 assertEquals(simple4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel84e33df2014-01-31 14:02:46 +00001236
1237 // Baum | Stein Haus
1238 String query = "(Baum | Stein) Haus";
1239 String simple5 =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001240 "{@type=korap:group, operation=operation:sequence, operands=[" +
1241 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001242 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq}}, " +
1243 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Stein, match=match:eq}}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +00001244 "]}," +
Joachim Bingel0900a892014-06-30 16:26:21 +00001245 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Haus, match=match:eq}} " +
Joachim Bingel84e33df2014-01-31 14:02:46 +00001246 "]}";
1247 ppt = new PoliqarpPlusTree(query);
1248 map = ppt.getRequestMap().get("query").toString();
1249 assertEquals(simple5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel16da4e12013-12-17 09:48:12 +00001250 }
Joachim Bingel53333e62013-12-09 19:25:52 +00001251}
1252