blob: 1319e18a26a0dae33c1cb5f4b71b80086ef10f09 [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 Bingel3a41a442014-07-22 12:16:16 +0000153 public void testSpans() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000154 // <s>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000155 String elem1 = "{@type=korap:span, key=s}";
Joachim Bingel53333e62013-12-09 19:25:52 +0000156 assertTrue(equalsQueryContent(elem1, "<s>"));
157
158 // <vp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000159 String elem2 = "{@type=korap:span, key=vp}";
Joachim Bingel53333e62013-12-09 19:25:52 +0000160 assertTrue(equalsQueryContent(elem2, "<vp>"));
Joachim Bingelfc1fb352014-02-26 14:40:27 +0000161
162 // <cnx/c=vp>
163 query = "<c=vp>";
164 String span3 = "{@type=korap:span, layer=c, key=vp}";
165 ppt = new PoliqarpPlusTree(query);
166 map = ppt.getRequestMap().get("query").toString();
167 assertEquals(span3.replaceAll(" ", ""), map.replaceAll(" ", ""));
168
169 // <cnx/c=vp>
170 query = "<cnx/c=vp>";
171 String span4 = "{@type=korap:span, foundry=cnx, layer=c, key=vp}";
172 ppt = new PoliqarpPlusTree(query);
173 map = ppt.getRequestMap().get("query").toString();
174 assertEquals(span4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel3a41a442014-07-22 12:16:16 +0000175
176 // span negation
177 query = "<cnx/c!=vp>";
178 expected = "{@type=korap:span, foundry=cnx, layer=c, key=vp, match=match:ne}";
179 ppt = new PoliqarpPlusTree(query);
180 map = ppt.getRequestMap().get("query").toString();
181 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
182
183 // span negation
184 query = "<cnx/c!=vp>";
185 expected = "{@type=korap:span, foundry=cnx, layer=c, key=vp, match=match:ne}";
186 ppt = new PoliqarpPlusTree(query);
187 map = ppt.getRequestMap().get("query").toString();
188 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
189
190 query = "<cnx/c=vp class!=header>";
191 expected = "{@type=korap:span, foundry=cnx, layer=c, key=vp, attr={@type=korap:term, key=class, value=header, match=match:ne}}";
192 ppt = new PoliqarpPlusTree(query);
193 map = ppt.getRequestMap().get("query").toString();
194 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
195
196 query = "<cnx/c=vp !(class=header&id=7)>";
197 expected =
198 "{@type=korap:span, foundry=cnx, layer=c, key=vp, attr=" +
199 "{@type=korap:termGroup, relation=relation:and, operands=[" +
200 "{@type=korap:term, key=class, value=header, match=match:ne}," +
201 "{@type=korap:term, key=id, value=7, match=match:ne}" +
202 "]}" +
203 "}";
204 ppt = new PoliqarpPlusTree(query);
205 map = ppt.getRequestMap().get("query").toString();
206 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
207
208 query = "<cnx/c!=vp (class=header&id=7)>";
209 expected =
210 "{@type=korap:span, foundry=cnx, layer=c, key=vp, match=match:ne, attr=" +
211 "{@type=korap:termGroup, relation=relation:and, operands=[" +
212 "{@type=korap:term, key=class, value=header, match=match:eq}," +
213 "{@type=korap:term, key=id, value=7, match=match:eq}" +
214 "]}" +
215 "}";
216 ppt = new PoliqarpPlusTree(query);
217 map = ppt.getRequestMap().get("query").toString();
218 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
219
220 query = "<cnx/c=vp !!class=header>";
221 expected = "{@type=korap:span, foundry=cnx, layer=c, key=vp, attr={@type=korap:term, key=class, value=header, match=match:eq}}";
222 ppt = new PoliqarpPlusTree(query);
223 map = ppt.getRequestMap().get("query").toString();
224 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingela0ef08f2014-07-24 08:27:57 +0000225
226 query = "<cnx/c!=vp (foundry/class=header&id=7)>";
227 expected =
228 "{@type=korap:span, foundry=cnx, layer=c, key=vp, match=match:ne, attr=" +
229 "{@type=korap:termGroup, relation=relation:and, operands=[" +
230 "{@type=korap:term, foundry=foundry, key=class, value=header, match=match:eq}," +
231 "{@type=korap:term, key=id, value=7, match=match:eq}" +
232 "]}" +
233 "}";
234 ppt = new PoliqarpPlusTree(query);
235 map = ppt.getRequestMap().get("query").toString();
236 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000237 }
Joachim Bingel87480d02014-01-17 14:07:46 +0000238
239 @Test
Joachim Bingel14239d82014-07-22 09:55:04 +0000240 public void testDistances() throws QueryException {
Joachim Bingel87480d02014-01-17 14:07:46 +0000241 // [base=der][][base=Mann]
242 String et1 =
Joachim Bingel0900a892014-06-30 16:26:21 +0000243 "{@type=korap:group, operation=operation:sequence, " +
Joachim Bingel11d5b152014-02-11 21:33:47 +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=2, max=2}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000249 "]}";
250 ppt = new PoliqarpPlusTree("[base=der][][base=Mann]");
251 map = ppt.getRequestMap().get("query").toString();
252 assertEquals(et1.replaceAll(" ", ""), map.replaceAll(" ", ""));
253
254 // [base=der][][][base=Mann]
255 String et2 =
Joachim Bingel0900a892014-06-30 16:26:21 +0000256 "{@type=korap:group, operation=operation:sequence, " +
Joachim Bingel11d5b152014-02-11 21:33:47 +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=3, max=3}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000262 "]}";
Joachim Bingelffd65e32014-01-22 14:22:57 +0000263 ppt = new PoliqarpPlusTree("[base=der][][][base=Mann]");
Joachim Bingel87480d02014-01-17 14:07:46 +0000264 map = ppt.getRequestMap().get("query").toString();
265 assertEquals(et2.replaceAll(" ", ""), map.replaceAll(" ", ""));
266
267 // [base=der][][]?[base=Mann]
268 String et3 =
Joachim Bingel0900a892014-06-30 16:26:21 +0000269 "{@type=korap:group, operation=operation:sequence, " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000270 "operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000271 "{@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=3}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000275 "]}";
276 ppt = new PoliqarpPlusTree("[base=der][][]?[base=Mann]");
277 map = ppt.getRequestMap().get("query").toString();
278 assertEquals(et3.replaceAll(" ", ""), map.replaceAll(" ", ""));
279
Joachim Bingel87480d02014-01-17 14:07:46 +0000280
Joachim Bingel14239d82014-07-22 09:55:04 +0000281
Joachim Bingelffd65e32014-01-22 14:22:57 +0000282
Joachim Bingel11d5b152014-02-11 21:33:47 +0000283 // [base=der][]{2,5}[base=Mann][]?[][base=Frau] nested distances=
Joachim Bingelffd65e32014-01-22 14:22:57 +0000284 String et5 =
Joachim Bingel0900a892014-06-30 16:26:21 +0000285 "{@type=korap:group, operation=operation:sequence," +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000286 "operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000287 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
288 "{@type=korap:group, operation=operation:sequence, " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000289 "operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000290 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}," +
291 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Frau, match=match:eq}}" +
292 "], inOrder=true, distances=[" +
293 "{@type=korap:distance, key=w, min=2, max=3}" +
Joachim Bingelffd65e32014-01-22 14:22:57 +0000294 "]}" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000295 "], inOrder=true, distances=[" +
296 "{@type=korap:distance, key=w, min=3, max=6}" +
Joachim Bingelffd65e32014-01-22 14:22:57 +0000297 "]}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000298 ppt = new PoliqarpPlusTree("[base=der][]{2,5}[base=Mann][]?[][base=Frau]");
Joachim Bingel87480d02014-01-17 14:07:46 +0000299 map = ppt.getRequestMap().get("query").toString();
300 assertEquals(et5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel87480d02014-01-17 14:07:46 +0000301
Joachim Bingelc15720f2014-05-07 14:37:23 +0000302 // [base=der][]*[base=Mann]
303 String et6 =
Joachim Bingel0900a892014-06-30 16:26:21 +0000304 "{@type=korap:group, operation=operation:sequence, " +
Joachim Bingelc15720f2014-05-07 14:37:23 +0000305 "operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000306 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
307 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
308 "], inOrder=true, distances=[" +
309 "{@type=korap:distance, key=w, min=1, max=100}" +
Joachim Bingelc15720f2014-05-07 14:37:23 +0000310 "]}";
311 ppt = new PoliqarpPlusTree("[base=der][]*[base=Mann]");
312 map = ppt.getRequestMap().get("query").toString();
313 assertEquals(et6.replaceAll(" ", ""), map.replaceAll(" ", ""));
314
Joachim Bingel0900a892014-06-30 16:26:21 +0000315 // [base=der][]+[base=Mann]
Joachim Bingelc15720f2014-05-07 14:37:23 +0000316 String et7 =
Joachim Bingel0900a892014-06-30 16:26:21 +0000317 "{@type=korap:group, operation=operation:sequence, " +
Joachim Bingelc15720f2014-05-07 14:37:23 +0000318 "operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000319 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
320 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
321 "], inOrder=true, distances=[" +
322 "{@type=korap:distance, key=w, min=2, max=100}" +
Joachim Bingelc15720f2014-05-07 14:37:23 +0000323 "]}";
324 ppt = new PoliqarpPlusTree("[base=der][]+[base=Mann]");
325 map = ppt.getRequestMap().get("query").toString();
326 assertEquals(et7.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel14239d82014-07-22 09:55:04 +0000327
328 // [base=der][]+[base=Mann]
329 String et8 =
330 "{@type=korap:group, operation=operation:sequence, " +
331 "operands=[" +
332 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
333 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
334 "], inOrder=true, distances=[" +
335 "{@type=korap:distance, key=w, min=2, max=100}" +
336 "]}";
337 ppt = new PoliqarpPlusTree("[base=der][]{1,102}[base=Mann]");
338 map = ppt.getRequestMap().get("query").toString();
339 assertEquals(et8.replaceAll(" ", ""), map.replaceAll(" ", ""));
340
341 // [base=geht][base=der][]*[base=Mann]
342 String et9 =
343 "{@type=korap:group, operation=operation:sequence, operands=[" +
344 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=geht, match=match:eq}}," +
345 "{@type=korap:group, operation=operation:sequence, " +
346 "operands=[" +
347 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
348 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
349 "], inOrder=true, distances=[" +
350 "{@type=korap:distance, key=w, min=1, max=100}" +
351 "]}" +
352 "]}";
353 ppt = new PoliqarpPlusTree("[base=geht][base=der][]*[base=Mann]");
354 map = ppt.getRequestMap().get("query").toString();
355 assertEquals(et9.replaceAll(" ", ""), map.replaceAll(" ", ""));
356
357 query = "[base=geht][base=der][]*[base=Mann][base=da]";
358 expected =
359 "{@type=korap:group, operation=operation:sequence, operands=[" +
360 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=geht, match=match:eq}}," +
361 "{@type=korap:group, operation=operation:sequence, " +
362 "operands=[" +
363 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
364 "{@type=korap:group, operation=operation:sequence, operands=[" +
365 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}," +
366 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=da, match=match:eq}}" +
367 "]}" +
368 "], inOrder=true, distances=[" +
369 "{@type=korap:distance, key=w, min=1, max=100}" +
370 "]}" +
371 "]}";
372 ppt = new PoliqarpPlusTree(query);
373 map = ppt.getRequestMap().get("query").toString();
374 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
375
376 query = "[base=geht][base=der][]*contains(<s>,<np>)";
377 expected =
378 "{@type=korap:group, operation=operation:sequence, operands=[" +
379 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=geht, match=match:eq}}," +
380 "{@type=korap:group, operation=operation:sequence, " +
381 "operands=[" +
382 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
383 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
384 "{@type=korap:span, key=s}," +
385 "{@type=korap:span, key=np}" +
386 "]}" +
387 "], inOrder=true, distances=[" +
388 "{@type=korap:distance, key=w, min=1, max=100}" +
389 "]}" +
390 "]}";
391 ppt = new PoliqarpPlusTree(query);
392 map = ppt.getRequestMap().get("query").toString();
393 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel87480d02014-01-17 14:07:46 +0000394 }
Joachim Bingel53333e62013-12-09 19:25:52 +0000395
396 @Test
Joachim Bingel14239d82014-07-22 09:55:04 +0000397 public void testLeadingTrailingEmptyTokens() throws QueryException {
398 // startswith(<s>, [][base=Mann]
399 String et1 =
400 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
401 "{@type=korap:span, key=s}," +
402 "{@type=korap:group, operation=operation:sequence, operands=[" +
403 "{@type=korap:token}," +
404 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
405 "]}" +
406 "]}";
407 ppt = new PoliqarpPlusTree("startswith(<s>, [][base=Mann])");
408 map = ppt.getRequestMap().get("query").toString();
409 assertEquals(et1.replaceAll(" ", ""), map.replaceAll(" ", ""));
410
411 query = "[][base=Mann]";
412 expected =
413 "{@type=korap:group, operation=operation:sequence, operands=[" +
414 "{@type=korap:token}," +
415 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
416 "]}";
417 ppt = new PoliqarpPlusTree(query);
418 map = ppt.getRequestMap().get("query").toString();
419 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
420
421 query = "[][][base=Mann]";
422 expected =
423 "{@type=korap:group, operation=operation:sequence, operands=[" +
424 "{@type=korap:group, operation=operation:repetition, operands=[" +
425 "{@type=korap:token}" +
Joachim Bingel61631562014-07-24 14:26:02 +0000426 "], boundary={@type=korap:boundary, min=2, max=2}, min=2, max=2}," +
Joachim Bingel14239d82014-07-22 09:55:04 +0000427 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
428 "]}";
429 ppt = new PoliqarpPlusTree(query);
430 map = ppt.getRequestMap().get("query").toString();
431 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
432
433 query = "[][]*[base=Mann]";
434 expected =
435 "{@type=korap:group, operation=operation:sequence, operands=[" +
436 "{@type=korap:group, operation=operation:repetition, operands=[" +
437 "{@type=korap:token}" +
Joachim Bingel61631562014-07-24 14:26:02 +0000438 "], boundary={@type=korap:boundary, min=1, max=100}, min=1, max=100}," +
Joachim Bingel14239d82014-07-22 09:55:04 +0000439 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
440 "]}";
441 ppt = new PoliqarpPlusTree(query);
442 map = ppt.getRequestMap().get("query").toString();
443 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
444
445 query = "[][]*[base=Mann][][]";
446 expected =
447 "{@type=korap:group, operation=operation:sequence, operands=[" +
448 "{@type=korap:group, operation=operation:repetition, operands=[" +
449 "{@type=korap:token}" +
Joachim Bingel61631562014-07-24 14:26:02 +0000450 "], boundary={@type=korap:boundary, min=1, max=100}, min=1, max=100}," +
Joachim Bingel14239d82014-07-22 09:55:04 +0000451 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}," +
452 "{@type=korap:group, operation=operation:repetition, operands=[" +
453 "{@type=korap:token}" +
Joachim Bingel61631562014-07-24 14:26:02 +0000454 "], boundary={@type=korap:boundary, min=2, max=2}, min=2, max=2}" +
Joachim Bingel14239d82014-07-22 09:55:04 +0000455 "]}";
456 ppt = new PoliqarpPlusTree(query);
457 map = ppt.getRequestMap().get("query").toString();
458 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
459
460 query = "[][]*contains(<s>, <np>)[][]";
461 expected =
462 "{@type=korap:group, operation=operation:sequence, operands=[" +
463 "{@type=korap:group, operation=operation:repetition, operands=[" +
464 "{@type=korap:token}" +
Joachim Bingel61631562014-07-24 14:26:02 +0000465 "], boundary={@type=korap:boundary, min=1, max=100}, min=1, max=100}," +
Joachim Bingel14239d82014-07-22 09:55:04 +0000466 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
467 "{@type=korap:span, key=s}," +
468 "{@type=korap:span, key=np}" +
469 "]}," +
470 "{@type=korap:group, operation=operation:repetition, operands=[" +
471 "{@type=korap:token}" +
Joachim Bingel61631562014-07-24 14:26:02 +0000472 "], boundary={@type=korap:boundary, min=2, max=2}, min=2, max=2}" +
Joachim Bingel14239d82014-07-22 09:55:04 +0000473 "]}";
474 ppt = new PoliqarpPlusTree(query);
475 map = ppt.getRequestMap().get("query").toString();
476 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
477 }
478
479 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000480 public void testCoordinatedFields() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000481 // [base=Mann&(cas=N|cas=A)]
482 String cof1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000483 "{@type=korap:token, wrap=" +
Joachim Bingel2980bda2014-04-04 12:09:46 +0000484 "{@type=korap:termGroup, relation=relation:and, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000485 "{@type=korap:term, layer=lemma, key=Mann, match=match:eq}," +
Joachim Bingel2980bda2014-04-04 12:09:46 +0000486 "{@type=korap:termGroup, relation=relation:or, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000487 "{@type=korap:term, layer=cas, key=N, match=match:eq}," +
488 "{@type=korap:term, layer=cas, key=A, match=match:eq}" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000489 "]}" +
490 "]}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000491 "}";
492 ppt = new PoliqarpPlusTree("[base=Mann&(cas=N|cas=A)]");
493 map = ppt.getRequestMap().get("query").toString();
494 assertEquals(cof1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Nils Diewald7d486c22013-12-13 16:32:18 +0000495
496
497 assertEquals(
498 new PoliqarpPlusTree(" [ base=Mann & ( cas=N | cas=A)] ").getRequestMap().get("query").toString(),
499 new PoliqarpPlusTree("[base=Mann &(cas=N|cas=A)]").getRequestMap().get("query").toString()
500 );
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000501
502 // [base=Mann&cas=N&gen=m]
503 String cof2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000504 "{@type=korap:token, wrap=" +
Joachim Bingel2980bda2014-04-04 12:09:46 +0000505 "{@type=korap:termGroup, relation=relation:and, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000506 "{@type=korap:term, layer=lemma, key=Mann, match=match:eq}," +
507 "{@type=korap:termGroup, relation=relation:and, operands=[" +
508 "{@type=korap:term, layer=cas, key=N, match=match:eq}," +
509 "{@type=korap:term, layer=gen, key=m, match=match:eq}" +
510 "]}" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000511 "]}" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000512 "}";
513 ppt = new PoliqarpPlusTree("[base=Mann&cas=N&gen=m]");
514 map = ppt.getRequestMap().get("query").toString();
515 assertEquals(cof2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000516 }
517
518 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000519 public void testOccurrence() throws QueryException {
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000520 // [base=foo]*
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000521 String occ1 = "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000522 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingel61631562014-07-24 14:26:02 +0000523 "], boundary={@type=korap:boundary, min=0, max=100}, min=0, max=100}";
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000524 ppt = new PoliqarpPlusTree("[base=foo]*");
525 map = ppt.getRequestMap().get("query").toString();
526 assertEquals(occ1.replaceAll(" ", ""), map.replaceAll(" ", ""));
527
528 // [base=foo]*[base=bar]
529 String occ2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000530 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000531 "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000532 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingel61631562014-07-24 14:26:02 +0000533 "], boundary={@type=korap:boundary, min=0, max=100}, min=0, max=100 }," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000534 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000535 "]}";
536 ppt = new PoliqarpPlusTree("[base=foo]*[base=bar]");
537 map = ppt.getRequestMap().get("query").toString();
538 assertEquals(occ2.replaceAll(" ", ""), map.replaceAll(" ", ""));
539
540 // [base=bar][base=foo]*
541 String occ3 =
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}}," +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000544 "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000545 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingel61631562014-07-24 14:26:02 +0000546 "], boundary={@type=korap:boundary, min=0, max=100}, min=0, max=100 }" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000547 "]}";
548 ppt = new PoliqarpPlusTree("[base=bar][base=foo]*");
549 map = ppt.getRequestMap().get("query").toString();
550 assertEquals(occ3.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb4da7022013-12-09 23:17:24 +0000551
552 // ([base=bar][base=foo])*
553 String occ4 =
Joachim Bingel0900a892014-06-30 16:26:21 +0000554 "{@type=korap:group, operation=operation:repetition, operands=[" +
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:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," +
557 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000558 "]}" +
Joachim Bingel61631562014-07-24 14:26:02 +0000559 "], boundary={@type=korap:boundary, min=0, max=100}, min=0, max=100}" ;
Joachim Bingelb4da7022013-12-09 23:17:24 +0000560 ppt = new PoliqarpPlusTree("([base=bar][base=foo])*");
561 map = ppt.getRequestMap().get("query").toString();
562 assertEquals(occ4.replaceAll(" ", ""), map.replaceAll(" ", ""));
563
564 // <s>([base=bar][base=foo])*
565 String occ5 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000566 "{@type=korap:group, operation=operation:sequence, operands=[" +
567 "{@type=korap:span, key=s}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000568 "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000569 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000570 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," +
571 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000572 "]}" +
Joachim Bingel61631562014-07-24 14:26:02 +0000573 "], boundary={@type=korap:boundary, min=0, max=100}, min=0, max=100 }" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000574 "]}" ;
575 ppt = new PoliqarpPlusTree("<s>([base=bar][base=foo])*");
576 map = ppt.getRequestMap().get("query").toString();
577 assertEquals(occ5.replaceAll(" ", ""), map.replaceAll(" ", ""));
578
579 // <s><np>([base=bar][base=foo])*
Joachim Bingelb4da7022013-12-09 23:17:24 +0000580 String occ6 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000581 "{@type=korap:group, operation=operation:sequence, operands=[" +
582 "{@type=korap:span, key=s}," +
583 "{@type=korap:span, key=np}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000584 "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000585 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000586 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," +
587 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000588 "]}" +
Joachim Bingel61631562014-07-24 14:26:02 +0000589 "], boundary={@type=korap:boundary, min=0, max=100}, min=0, max=100 }" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000590 "]}" ;
591 ppt = new PoliqarpPlusTree("<s><np>([base=bar][base=foo])*");
592 map = ppt.getRequestMap().get("query").toString();
593 assertEquals(occ6.replaceAll(" ", ""), map.replaceAll(" ", ""));
594
595 // <s><np>([base=bar][base=foo])*[p=NN]
596 // comment: embedded sequence shouldn't really be here, but does not really hurt, either. (?)
597 // really hard to get this behaviour out of the PQPlus grammar...
598 String occ7 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000599 "{@type=korap:group, operation=operation:sequence, operands=[" +
600 "{@type=korap:span, key=s}," +
601 "{@type=korap:span, key=np}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000602 "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000603 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000604 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," +
605 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000606 "]}" +
Joachim Bingel61631562014-07-24 14:26:02 +0000607 "], boundary={@type=korap:boundary, min=0, max=100}, min=0, max=100 }," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000608 "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000609 "]}" ;
610 ppt = new PoliqarpPlusTree("<s><np>([base=bar][base=foo])*[p=NN]");
611 map = ppt.getRequestMap().get("query").toString();
612 assertEquals(occ7.replaceAll(" ", ""), map.replaceAll(" ", ""));
613
614 // ([base=bar][base=foo])*[p=NN]
Joachim Bingelb4da7022013-12-09 23:17:24 +0000615 String occ8 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000616 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000617 "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000618 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000619 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," +
620 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000621 "]}" +
Joachim Bingel61631562014-07-24 14:26:02 +0000622 "], boundary={@type=korap:boundary, min=0, max=100}, min=0, max=100 }," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000623 "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000624 "]}" ;
625 ppt = new PoliqarpPlusTree("([base=bar][base=foo])*[p=NN]");
626 map = ppt.getRequestMap().get("query").toString();
627 assertEquals(occ8.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000628
629 // [base=foo]+
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000630 String occ9 = "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000631 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingel61631562014-07-24 14:26:02 +0000632 "], boundary={@type=korap:boundary, min=1, max=100}, min=1, max=100}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000633 ppt = new PoliqarpPlusTree("[base=foo]+");
634 map = ppt.getRequestMap().get("query").toString();
635 assertEquals(occ9.replaceAll(" ", ""), map.replaceAll(" ", ""));
636
637 // [base=foo]?
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000638 String occ10 = "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000639 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingel61631562014-07-24 14:26:02 +0000640 "], boundary={@type=korap:boundary, min=0, max=1}, min=0, max=1}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000641 ppt = new PoliqarpPlusTree("[base=foo]?");
642 map = ppt.getRequestMap().get("query").toString();
643 assertEquals(occ10.replaceAll(" ", ""), map.replaceAll(" ", ""));
644
645 // [base=foo]{2,5}
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000646 String occ11 = "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000647 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingel61631562014-07-24 14:26:02 +0000648 "], boundary={@type=korap:boundary, min=2, max=5}, min=2, max=5}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000649 ppt = new PoliqarpPlusTree("[base=foo]{2,5}");
650 map = ppt.getRequestMap().get("query").toString();
651 assertEquals(occ11.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel2980bda2014-04-04 12:09:46 +0000652
653 // [base=foo]{2}
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000654 String occ12 = "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000655 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingel61631562014-07-24 14:26:02 +0000656 "], boundary={@type=korap:boundary, min=2, max=2}, min=2, max=2}";
Joachim Bingel2980bda2014-04-04 12:09:46 +0000657 ppt = new PoliqarpPlusTree("[base=foo]{2}");
658 map = ppt.getRequestMap().get("query").toString();
659 assertEquals(occ12.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb2aa1c72014-07-01 12:48:46 +0000660
661 // [base=foo]{2}
662 String occ13 = "{@type=korap:group, operation=operation:repetition, operands=[" +
663 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingel61631562014-07-24 14:26:02 +0000664 "], boundary={@type=korap:boundary, min=2, max=100}, min=2, max=100}";
Joachim Bingelb2aa1c72014-07-01 12:48:46 +0000665 ppt = new PoliqarpPlusTree("[base=foo]{2,}");
666 map = ppt.getRequestMap().get("query").toString();
667 assertEquals(occ13.replaceAll(" ", ""), map.replaceAll(" ", ""));
668
669 // [base=foo]{2}
670 String occ14 = "{@type=korap:group, operation=operation:repetition, operands=[" +
671 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingel61631562014-07-24 14:26:02 +0000672 "], boundary={@type=korap:boundary, min=0, max=2}, min=0, max=2}";
Joachim Bingelb2aa1c72014-07-01 12:48:46 +0000673 ppt = new PoliqarpPlusTree("[base=foo]{,2}");
674 map = ppt.getRequestMap().get("query").toString();
675 assertEquals(occ14.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000676 }
677
678 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000679 public void testTokenSequence() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000680 // [base=Mann][orth=Frau]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000681 String seq1 = "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000682 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}, " +
683 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000684 "]}";
685 assertTrue(equalsQueryContent(seq1, "[base=Mann][orth=Frau]"));
686
687 // [base=Mann][orth=Frau][p=NN]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000688 String seq2 = "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000689 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}, " +
690 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}, " +
691 "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000692 "]}";
693 assertTrue(equalsQueryContent(seq2, "[base=Mann][orth=Frau][p=NN]"));
694 }
695
696 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000697 public void testDisjSegments() throws QueryException {
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000698 // ([base=der]|[base=das])[base=Schild]
699 String disj1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000700 "{@type=korap:group, operation=operation:sequence, operands=[" +
701 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000702 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
703 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=das, match=match:eq}}" +
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000704 "]}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000705 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Schild, match=match:eq}}" +
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000706 "]}";
707 ppt = new PoliqarpPlusTree("([base=der]|[base=das])[base=Schild]");
708 map = ppt.getRequestMap().get("query").toString();
709 assertEquals(disj1.replaceAll(" ", ""), map.replaceAll(" ", ""));
710
711 // [base=Schild]([base=der]|[base=das])
712 String disj2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000713 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000714 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Schild, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000715 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000716 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
717 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=das, match=match:eq}}" +
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000718 "]}" +
719 "]}";
720 ppt = new PoliqarpPlusTree("[base=Schild]([base=der]|[base=das])");
721 map = ppt.getRequestMap().get("query").toString();
722 assertEquals(disj2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel76b498d2014-06-06 12:06:46 +0000723
724 // "([orth=der][base=katze])|([orth=eine][base=baum])"
725 String disj3 =
726 "{@type=korap:group, operation=operation:or, operands=[" +
727 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000728 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
729 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=katze, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000730 "]}," +
731 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000732 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=eine, match=match:eq}}," +
733 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=baum, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000734 "]}" +
735 "]}";
736 ppt = new PoliqarpPlusTree("([orth=der][base=katze])|([orth=eine][base=baum])");
737 map = ppt.getRequestMap().get("query").toString();
738 assertEquals(disj3.replaceAll(" ", ""), map.replaceAll(" ", ""));
739
740 // "[orth=der][base=katze]|[orth=eine][base=baum]"
741 String disj4 =
742 "{@type=korap:group, operation=operation:or, operands=[" +
743 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000744 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
745 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=katze, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000746 "]}," +
747 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000748 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=eine, match=match:eq}}," +
749 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=baum, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000750 "]}" +
751 "]}";
752 ppt = new PoliqarpPlusTree("[orth=der][base=katze]|[orth=eine][base=baum]");
753 map = ppt.getRequestMap().get("query").toString();
754 assertEquals(disj4.replaceAll(" ", ""), map.replaceAll(" ", ""));
755
756 PoliqarpPlusTree ppt1 = new PoliqarpPlusTree("[orth=der][base=katze]|[orth=eine][base=baum]");
757 PoliqarpPlusTree ppt2 = new PoliqarpPlusTree("([orth=der][base=katze])|([orth=eine][base=baum])");
758 assertEquals(ppt1.getRequestMap().toString(), ppt2.getRequestMap().toString());
759
760 // "[orth=der][base=katze]|[orth=der][base=hund]|[orth=der][base=baum]"
761 String disj5 =
762 "{@type=korap:group, operation=operation:or, operands=[" +
763 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000764 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
765 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=katze, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000766 "]}," +
767 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000768 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
769 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=hund, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000770 "]}," +
771 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000772 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
773 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=baum, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000774 "]}" +
775 "]}";
776 ppt = new PoliqarpPlusTree("[orth=der][base=katze]|[orth=der][base=hund]|[orth=der][base=baum]");
777 map = ppt.getRequestMap().get("query").toString();
778 assertEquals(disj5.replaceAll(" ", ""), map.replaceAll(" ", ""));
779
780 // [orth=der]([base=katze]|[base=hund]|[base=baum])
781 String disj6 =
782 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000783 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000784 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000785 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=katze, match=match:eq}}," +
786 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=hund, match=match:eq}}," +
787 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=baum, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000788 "]}" +
789 "]}";
790 ppt = new PoliqarpPlusTree("[orth=der]([base=katze]|[base=hund]|[base=baum])");
791 map = ppt.getRequestMap().get("query").toString();
792 assertEquals(disj6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000793 }
794
795 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000796 public void testTokenElemSequence() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000797 // [base=Mann]<vp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000798 String seq1 = "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000799 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}, " +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000800 "{@type=korap:span, key=vp}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000801 "]}";
802 assertTrue(equalsQueryContent(seq1, "[base=Mann]<vp>"));
803
804 // <vp>[base=Mann]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000805 String seq2 = "{@type=korap:group, operation=operation:sequence, operands=[" +
806 "{@type=korap:span, key=vp}, "+
Joachim Bingel0900a892014-06-30 16:26:21 +0000807 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}} " +
Joachim Bingel53333e62013-12-09 19:25:52 +0000808 "]}";
809 assertTrue(equalsQueryContent(seq2, "<vp>[base=Mann]"));
810
811 // <vp>[base=Mann]<pp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000812 String seq3 = "{@type=korap:group, operation=operation:sequence, operands=[" +
813 "{@type=korap:span, key=vp}, "+
Joachim Bingel0900a892014-06-30 16:26:21 +0000814 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}, " +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000815 "{@type=korap:span, key=pp} "+
Joachim Bingel53333e62013-12-09 19:25:52 +0000816 "]}";
817 assertTrue(equalsQueryContent(seq3, "<vp>[base=Mann]<pp>"));
818 }
819
820 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000821 public void testElemSequence() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000822 // <np><vp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000823 String seq1 = "{@type=korap:group, operation=operation:sequence, operands=[" +
824 "{@type=korap:span, key=np}," +
825 "{@type=korap:span, key=vp}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000826 "]}";
827 assertTrue(equalsQueryContent(seq1, "<np><vp>"));
828
829 // <np><vp><pp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000830 String seq2 = "{@type=korap:group, operation=operation:sequence, operands=[" +
831 "{@type=korap:span, key=np}," +
832 "{@type=korap:span, key=vp}," +
833 "{@type=korap:span, key=pp}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000834 "]}";
835 assertTrue(equalsQueryContent(seq2, "<np><vp><pp>"));
836 }
837
838 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000839 public void testClasses() throws QueryException {
Joachim Bingel0900a892014-06-30 16:26:21 +0000840 String query;
Joachim Bingel53333e62013-12-09 19:25:52 +0000841 // {[base=Mann]}
Joachim Bingel2daf9862014-02-12 10:18:54 +0000842 String cls1 = "{@type=korap:group, operation=operation:class, class=0, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000843 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000844 "]}";
Joachim Bingel8c640e42014-02-07 16:20:47 +0000845 ppt = new PoliqarpPlusTree("{[base=Mann]}");
846 map = ppt.getRequestMap().get("query").toString();
847 assertEquals(cls1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000848
849 // {[base=Mann][orth=Frau]}
Joachim Bingel0900a892014-06-30 16:26:21 +0000850 query = "{[base=Mann][orth=Frau]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000851 String cls2 = "{@type=korap:group, operation=operation:class, class=0, operands=[" +
852 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000853 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}," +
854 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000855 "]}" +
856 "]}";
Joachim Bingel0900a892014-06-30 16:26:21 +0000857 ppt = new PoliqarpPlusTree(query);
858 map = ppt.getRequestMap().get("query").toString();
859 assertEquals(cls2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000860
861 // [p=NN]{[base=Mann][orth=Frau]}
Joachim Bingel2daf9862014-02-12 10:18:54 +0000862 String cls3 = "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000863 "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000864 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
865 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000866 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}," +
867 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000868 "]}" +
869 "]}" +
870 "]}";
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000871 ppt = new PoliqarpPlusTree("[p=NN]{[base=Mann][orth=Frau]}");
872 map = ppt.getRequestMap().get("query").toString();
873 assertEquals(cls3.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000874
875 // {[base=Mann][orth=Frau]}[p=NN]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000876 String cls4 = "{@type=korap:group, operation=operation:sequence, operands=[" +
877 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
878 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000879 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}," +
880 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000881 "]}" +
882 "]}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000883 "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000884 "]}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000885 ppt = new PoliqarpPlusTree("{[base=Mann][orth=Frau]}[p=NN]");
886 map = ppt.getRequestMap().get("query").toString();
887 assertEquals(cls4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000888
889 // {2:{1:[tt/p=ADJA]}[mate/p=NN]}"
Joachim Bingel2daf9862014-02-12 10:18:54 +0000890 String cls5 = "{@type=korap:group, operation=operation:class, class=2, operands=[" +
891 "{@type=korap:group, operation=operation:sequence, operands=[" +
892 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000893 "{@type=korap:token, wrap={@type=korap:term, foundry=tt, layer=p, key=ADJA, match=match:eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000894 "]}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000895 "{@type=korap:token, wrap={@type=korap:term, foundry=mate, layer=p, key=NN, match=match:eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000896 "]}" +
897 "]}";
898 ppt = new PoliqarpPlusTree("{2: {1:[tt/p=ADJA]}[mate/p=NN]}");
899 map = ppt.getRequestMap().get("query").toString();
900 assertEquals(cls5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000901 }
902
903 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000904 public void testPositions() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000905 // contains(<s>,<np>)
Joachim Bingel2daf9862014-02-12 10:18:54 +0000906 String pos1 = "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
907 "{@type=korap:span, key=s}," +
908 "{@type=korap:span, key=np}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000909 "]}";
910 assertTrue(equalsQueryContent(pos1, "contains(<s>,<np>)"));
911
912 // contains(<s>,[base=Mann])
Joachim Bingel2daf9862014-02-12 10:18:54 +0000913 String pos2 = "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
914 "{@type=korap:span, key=s}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000915 "{@type=korap:token, wrap= {@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000916 "]}";
917 assertTrue(equalsQueryContent(pos2, "contains(<s>,[base=Mann])"));
918
919 // contains(<s>,[orth=der][orth=Mann])
Joachim Bingel2daf9862014-02-12 10:18:54 +0000920 String pos3 = "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
921 "{@type=korap:span, key=s}," +
922 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000923 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
924 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000925 "]}" +
926 "]}";
927 ppt = new PoliqarpPlusTree("contains(<s>,[orth=der][orth=Mann])");
928 map = ppt.getRequestMap().get("query").toString();
929 assertEquals(pos3.replaceAll(" ", ""), map.replaceAll(" ", ""));
930
931 // [base=Auto]contains(<s>,[base=Mann])
932 String pos4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000933 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000934 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Auto, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000935 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
936 "{@type=korap:span, key=s}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000937 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000938 "]}" +
939 "]}";
940 ppt = new PoliqarpPlusTree("[base=Auto]contains(<s>,[base=Mann])");
941 map = ppt.getRequestMap().get("query").toString();
942 assertEquals(pos4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelef7059b2014-04-22 13:44:19 +0000943
944 // contains(<s>,[pos=N]*)
945 String pos5 =
946 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
947 "{@type=korap:span, key=s}," +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000948 "{@type=korap:group, operation=operation:repetition, " +
Joachim Bingel0900a892014-06-30 16:26:21 +0000949 "operands=[{@type=korap:token, wrap={@type=korap:term, layer=pos, key=N, match=match:eq}}" +
Joachim Bingel61631562014-07-24 14:26:02 +0000950 "], boundary={@type=korap:boundary, min=0, max=100}, min=0, max=100" +
Joachim Bingelef7059b2014-04-22 13:44:19 +0000951 "}" +
952 "]}";
953 ppt = new PoliqarpPlusTree("contains(<s>,[pos=N]*)");
954 map = ppt.getRequestMap().get("query").toString();
955 assertEquals(pos5.replaceAll(" ", ""), map.replaceAll(" ", ""));
956
957 // [base=Auto]contains(<s>,[pos=N]*)
958 String pos6 =
959 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000960 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Auto, match=match:eq}}," +
Joachim Bingelef7059b2014-04-22 13:44:19 +0000961 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
962 "{@type=korap:span, key=s}," +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000963 "{@type=korap:group, operation=operation:repetition, " +
Joachim Bingel0900a892014-06-30 16:26:21 +0000964 "operands=[{@type=korap:token, wrap={@type=korap:term, layer=pos, key=N, match=match:eq}}" +
Joachim Bingel61631562014-07-24 14:26:02 +0000965 "], boundary={@type=korap:boundary, min=0, max=100}, min=0, max=100" +
Joachim Bingelef7059b2014-04-22 13:44:19 +0000966 "}" +
967 "]}" +
968 "]}";
969 ppt = new PoliqarpPlusTree("[base=Auto]contains(<s>,[pos=N]*)");
970 map = ppt.getRequestMap().get("query").toString();
971 assertEquals(pos6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000972 }
973
974 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000975 public void testNestedPositions() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000976 // contains(<s>,startswith(<np>,[orth=Der]))
977 String npos1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000978 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
979 "{@type=korap:span, key=s}," +
980 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
981 "{@type=korap:span, key=np}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000982 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000983 "]}" +
984 "]}";
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000985 ppt = new PoliqarpPlusTree("contains(<s>, startswith(<np>,[orth=Der]))");
Joachim Bingel53333e62013-12-09 19:25:52 +0000986 map = ppt.getRequestMap().get("query").toString();
987 assertEquals(npos1.replaceAll(" ", ""), map.replaceAll(" ", ""));
988 }
989
990 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000991 public void testShrinkSplit() throws QueryException {
Joachim Bingel0900a892014-06-30 16:26:21 +0000992 // focus([orth=Der]{[orth=Mann]})
Joachim Bingel53333e62013-12-09 19:25:52 +0000993 String shr1 =
Joachim Bingeld1a3e712014-07-16 08:02:05 +0000994 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000995 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000996 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000997 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000998 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000999 "]}" +
1000 "]}" +
1001 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +00001002 ppt = new PoliqarpPlusTree("focus([orth=Der]{[orth=Mann]})");
Joachim Bingel53333e62013-12-09 19:25:52 +00001003 map = ppt.getRequestMap().get("query").toString();
1004 assertEquals(shr1.replaceAll(" ", ""), map.replaceAll(" ", ""));
1005
Joachim Bingel0900a892014-06-30 16:26:21 +00001006 // focus([orth=Der]{[orth=Mann][orth=geht]})
Joachim Bingel53333e62013-12-09 19:25:52 +00001007 String shr2 =
Joachim Bingeld1a3e712014-07-16 08:02:05 +00001008 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001009 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001010 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001011 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
1012 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001013 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}," +
1014 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=geht, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +00001015 "]}" +
1016 "]}" +
1017 "]}" +
1018 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +00001019 ppt = new PoliqarpPlusTree("focus([orth=Der]{[orth=Mann][orth=geht]})");
Joachim Bingel53333e62013-12-09 19:25:52 +00001020 map = ppt.getRequestMap().get("query").toString();
1021 assertEquals(shr2.replaceAll(" ", ""), map.replaceAll(" ", ""));
1022
Joachim Bingel0900a892014-06-30 16:26:21 +00001023 // focus(1:[orth=Der]{1:[orth=Mann][orth=geht]})
Joachim Bingel53333e62013-12-09 19:25:52 +00001024 String shr3 =
Joachim Bingeld1a3e712014-07-16 08:02:05 +00001025 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001026 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001027 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001028 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
1029 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001030 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}," +
1031 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=geht, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +00001032 "]}" +
1033 "]}" +
1034 "]}" +
1035 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +00001036 ppt = new PoliqarpPlusTree("focus(1:[orth=Der]{1:[orth=Mann][orth=geht]})");
Joachim Bingel53333e62013-12-09 19:25:52 +00001037 map = ppt.getRequestMap().get("query").toString();
1038 assertEquals(shr3.replaceAll(" ", ""), map.replaceAll(" ", ""));
1039
Joachim Bingel0900a892014-06-30 16:26:21 +00001040 // focus(1:startswith(<s>,{1:<np>}))
Joachim Bingel53333e62013-12-09 19:25:52 +00001041 String shr4 =
Joachim Bingeld1a3e712014-07-16 08:02:05 +00001042 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001043 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
1044 "{@type=korap:span, key=s}," +
1045 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
1046 "{@type=korap:span, key=np}" +
Joachim Bingel53333e62013-12-09 19:25:52 +00001047 "]}" +
1048 "]}" +
1049 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +00001050 ppt = new PoliqarpPlusTree("focus(1:startswith(<s>,{1:<np>}))");
Joachim Bingel53333e62013-12-09 19:25:52 +00001051 map = ppt.getRequestMap().get("query").toString();
1052 assertEquals(shr4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelcd9ed332013-12-09 21:01:35 +00001053
Joachim Bingel0900a892014-06-30 16:26:21 +00001054 // focus(3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))
Joachim Bingelcd9ed332013-12-09 21:01:35 +00001055 String shr5 =
Joachim Bingeld1a3e712014-07-16 08:02:05 +00001056 "{@type=korap:reference, operation=operation:focus, classRef=[3], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001057 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
1058 "{@type=korap:span, key=s}," +
1059 "{@type=korap:group, operation=operation:class, class=3, operands=[" +
1060 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001061 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001062 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
1063 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001064 "{@type=korap:token, wrap={@type=korap:term, foundry=mate, layer=p, key=ADJA, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001065 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001066 "{@type=korap:token, wrap={@type=korap:term, foundry=tt, layer=p, key=NN, match=match:eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +00001067 "]}" +
1068 "]}" +
1069 "]}" +
1070 "]}" +
1071 "]}" +
1072 "]}" +
1073 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +00001074 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 +00001075 map = ppt.getRequestMap().get("query").toString();
1076 assertEquals(shr5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelba9a0ab2014-01-29 10:12:25 +00001077
1078 // split(3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))
1079 String shr6 =
Joachim Bingeld1a3e712014-07-16 08:02:05 +00001080 "{@type=korap:reference, operation=operation:split, classRef=[3], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001081 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
1082 "{@type=korap:span, key=s}," +
1083 "{@type=korap:group, operation=operation:class, class=3, operands=[" +
1084 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001085 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001086 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
1087 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001088 "{@type=korap:token, wrap={@type=korap:term, foundry=mate, layer=p, key=ADJA, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001089 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001090 "{@type=korap:token, wrap={@type=korap:term, foundry=tt, layer=p, key=NN, match=match:eq}}" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +00001091 "]}" +
1092 "]}" +
1093 "]}" +
1094 "]}" +
1095 "]}" +
1096 "]}" +
1097 "]}";
1098 ppt = new PoliqarpPlusTree("split(3:startswith(<s>,{3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) ");
1099 map = ppt.getRequestMap().get("query").toString();
1100 assertEquals(shr6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel8c640e42014-02-07 16:20:47 +00001101
1102 // split(2|3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))
1103 String shr7 =
Joachim Bingeld1a3e712014-07-16 08:02:05 +00001104 "{@type=korap:reference, operation=operation:split, classRef=[2, 3], classRefOp=classRefOp:intersection, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001105 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
1106 "{@type=korap:span, key=s}," +
1107 "{@type=korap:group, operation=operation:class, class=3, operands=[" +
1108 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001109 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001110 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
1111 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001112 "{@type=korap:token, wrap={@type=korap:term, foundry=mate, layer=p, key=ADJA, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001113 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001114 "{@type=korap:token, wrap={@type=korap:term, foundry=tt, layer=p, key=NN, match=match:eq}}" +
Joachim Bingel8c640e42014-02-07 16:20:47 +00001115 "]}" +
1116 "]}" +
1117 "]}" +
1118 "]}" +
1119 "]}" +
1120 "]}" +
1121 "]}";
1122 ppt = new PoliqarpPlusTree("split(2|3:startswith(<s>,{3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) ");
1123 map = ppt.getRequestMap().get("query").toString();
1124 assertEquals(shr7.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel5146ebe2014-06-12 08:49:21 +00001125
1126
1127 String shr8 =
Joachim Bingeld1a3e712014-07-16 08:02:05 +00001128 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingeladd0fb12014-06-24 08:54:14 +00001129 "{@type=korap:group, operation=operation:sequence, operands=[" +
1130 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001131 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}" +
Joachim Bingeladd0fb12014-06-24 08:54:14 +00001132 "]}," +
1133 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001134 "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=ADJA, match=match:eq}}" +
Joachim Bingel5146ebe2014-06-12 08:49:21 +00001135 "]}" +
Joachim Bingeladd0fb12014-06-24 08:54:14 +00001136 "]}" +
1137 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +00001138 ppt = new PoliqarpPlusTree("focus(1:{[base=der]}{1:[pos=ADJA]})");
Joachim Bingeladd0fb12014-06-24 08:54:14 +00001139 map = ppt.getRequestMap().get("query").toString();
1140 assertEquals(shr8.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel5146ebe2014-06-12 08:49:21 +00001141
Joachim Bingel53333e62013-12-09 19:25:52 +00001142 }
1143
Joachim Bingel03882702013-12-31 19:53:05 +00001144
Joachim Bingel53333e62013-12-09 19:25:52 +00001145 @Test
Joachim Bingelba9a0ab2014-01-29 10:12:25 +00001146 public void testFoundries() throws QueryException {
1147 // [tt/base=Mann]
Joachim Bingel0900a892014-06-30 16:26:21 +00001148 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 +00001149 ppt = new PoliqarpPlusTree("[tt/base=Mann]");
1150 map = ppt.getRequestMap().get("query").toString();
1151 assertEquals(layer1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +00001152
1153 }
Joachim Bingel16da4e12013-12-17 09:48:12 +00001154
1155 @Test
Joachim Bingel8c640e42014-02-07 16:20:47 +00001156 public void testAlign() throws QueryException {
Joachim Bingel16da4e12013-12-17 09:48:12 +00001157 // [orth=der]^[orth=Mann]
1158 String align1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001159 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001160 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
1161 "{@type=korap:group, operation=operation:alignment, operands=[" +
1162 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" +
1163 "], align=align:left}" +
Joachim Bingel16da4e12013-12-17 09:48:12 +00001164 "]}";
1165 ppt = new PoliqarpPlusTree("[orth=der]^[orth=Mann]");
1166 map = ppt.getRequestMap().get("query").toString();
1167 assertEquals(align1.replaceAll(" ", ""), map.replaceAll(" ", ""));
1168
Joachim Bingel84e33df2014-01-31 14:02:46 +00001169 // [orth=der]^[orth=große][orth=Mann]
1170 String query = "[orth=der]^[orth=große][orth=Mann]";
1171 String align1b =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001172 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001173 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
1174 "{@type=korap:group, operation=operation:alignment, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001175 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001176 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=große, match=match:eq}}," +
1177 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +00001178 "]}" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001179 "], align=align:left}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +00001180 "]}";
1181 ppt = new PoliqarpPlusTree(query);
1182 map = ppt.getRequestMap().get("query").toString();
1183 assertEquals(align1b.replaceAll(" ", ""), map.replaceAll(" ", ""));
1184
Joachim Bingel16da4e12013-12-17 09:48:12 +00001185 // "([base=a]^[base=b])|[base=c]",
1186 String align2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001187 "{@type=korap:group, operation=operation:or, operands=[" +
1188 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001189 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=a, match=match:eq}}," +
1190 "{@type=korap:group, operation=operation:alignment, operands=[" +
1191 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=b, match=match:eq}}" +
1192 "], align=align:left}" +
Joachim Bingel16da4e12013-12-17 09:48:12 +00001193 "]}," +
Joachim Bingel0900a892014-06-30 16:26:21 +00001194 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=c, match=match:eq}}" +
Joachim Bingel16da4e12013-12-17 09:48:12 +00001195 "]}";
1196 ppt = new PoliqarpPlusTree("([base=a]^[base=b])|[base=c]");
1197 map = ppt.getRequestMap().get("query").toString();
1198 assertEquals(align2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingela67e6a32014-01-02 18:35:24 +00001199
1200 // "([base=a]^[base=b][base=c])|[base=d]",
1201 String align3 =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001202 "{@type=korap:group, operation=operation:or, operands=[" +
1203 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001204 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=a, match=match:eq}}," +
1205 "{@type=korap:group, operation=operation:alignment, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001206 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001207 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=b, match=match:eq}}," +
1208 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=c, match=match:eq}}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +00001209 "]}" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001210 "], align=align:left}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +00001211 "]}," +
Joachim Bingel0900a892014-06-30 16:26:21 +00001212 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=d, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +00001213 "]}";
1214 ppt = new PoliqarpPlusTree("([base=a]^[base=b][base=c])|[base=d]");
1215 map = ppt.getRequestMap().get("query").toString();
1216 assertEquals(align3.replaceAll(" ", ""), map.replaceAll(" ", ""));
1217
1218 // "([base=a]^[base=b]^[base=c])|[base=d]",
1219 String align4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001220 "{@type=korap:group, operation=operation:or, operands=[" +
1221 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001222 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=a, match=match:eq}}," +
1223 "{@type=korap:group, operation=operation:alignment, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001224 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001225 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=b, match=match:eq}}," +
1226 "{@type=korap:group, operation=operation:alignment, operands=[" +
1227 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=c, match=match:eq}}" +
1228 "], align=align:left}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +00001229 "]}" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001230 "], align=align:left}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +00001231 "]}," +
Joachim Bingel0900a892014-06-30 16:26:21 +00001232 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=d, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +00001233 "]}";
1234 ppt = new PoliqarpPlusTree("([base=a]^[base=b]^[base=c])|[base=d]");
1235 map = ppt.getRequestMap().get("query").toString();
1236 assertEquals(align4.replaceAll(" ", ""), map.replaceAll(" ", ""));
1237
1238
Joachim Bingel16da4e12013-12-17 09:48:12 +00001239 }
1240
1241 @Test
Joachim Bingel8c640e42014-02-07 16:20:47 +00001242 public void testSimpleQueries() throws QueryException {
Joachim Bingela67e6a32014-01-02 18:35:24 +00001243 // Baum
1244 String simple1 =
Joachim Bingel0900a892014-06-30 16:26:21 +00001245 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq}}";
Joachim Bingela67e6a32014-01-02 18:35:24 +00001246 ppt = new PoliqarpPlusTree("Baum");
1247 map = ppt.getRequestMap().get("query").toString();
1248 assertEquals(simple1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel0900a892014-06-30 16:26:21 +00001249
1250 // Baum/i
1251 String simple1b =
1252 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq, caseInsensitive=true}}";
1253 ppt = new PoliqarpPlusTree("Baum/i");
1254 map = ppt.getRequestMap().get("query").toString();
1255 assertEquals(simple1b.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel16da4e12013-12-17 09:48:12 +00001256
Joachim Bingela67e6a32014-01-02 18:35:24 +00001257 // Der Baum
1258 String simple2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001259 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001260 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}, " +
1261 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +00001262 "]}";
1263 ppt = new PoliqarpPlusTree("Der Baum");
1264 map = ppt.getRequestMap().get("query").toString();
1265 assertEquals(simple2.replaceAll(" ", ""), map.replaceAll(" ", ""));
1266
Joachim Bingel0900a892014-06-30 16:26:21 +00001267 // Der Baum/i
1268 String simple2b =
1269 "{@type=korap:group, operation=operation:sequence, operands=[" +
1270 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}, " +
1271 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq, caseInsensitive=true}}" +
1272 "]}";
1273 ppt = new PoliqarpPlusTree("Der Baum/i");
1274 map = ppt.getRequestMap().get("query").toString();
1275 assertEquals(simple2b.replaceAll(" ", ""), map.replaceAll(" ", ""));
1276
Joachim Bingela67e6a32014-01-02 18:35:24 +00001277 // Der große Baum
1278 String simple3 =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001279 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001280 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}, " +
1281 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=große, match=match:eq}}, " +
1282 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +00001283 "]}";
1284 ppt = new PoliqarpPlusTree("Der große Baum");
1285 map = ppt.getRequestMap().get("query").toString();
1286 assertEquals(simple3.replaceAll(" ", ""), map.replaceAll(" ", ""));
1287
1288 // Baum | Stein
1289 String simple4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001290 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001291 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq}}, " +
1292 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Stein, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +00001293 "]}";
1294 ppt = new PoliqarpPlusTree("Baum | Stein");
1295 map = ppt.getRequestMap().get("query").toString();
1296 assertEquals(simple4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel84e33df2014-01-31 14:02:46 +00001297
1298 // Baum | Stein Haus
1299 String query = "(Baum | Stein) Haus";
1300 String simple5 =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001301 "{@type=korap:group, operation=operation:sequence, operands=[" +
1302 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001303 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq}}, " +
1304 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Stein, match=match:eq}}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +00001305 "]}," +
Joachim Bingel0900a892014-06-30 16:26:21 +00001306 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Haus, match=match:eq}} " +
Joachim Bingel84e33df2014-01-31 14:02:46 +00001307 "]}";
1308 ppt = new PoliqarpPlusTree(query);
1309 map = ppt.getRequestMap().get("query").toString();
1310 assertEquals(simple5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel16da4e12013-12-17 09:48:12 +00001311 }
Joachim Bingel53333e62013-12-09 19:25:52 +00001312}
1313