blob: 43da3a104e572ed8ebfc006c90abacfafa96245f [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 Bingel53333e62013-12-09 19:25:52 +0000225 }
Joachim Bingel87480d02014-01-17 14:07:46 +0000226
227 @Test
Joachim Bingel14239d82014-07-22 09:55:04 +0000228 public void testDistances() throws QueryException {
Joachim Bingel87480d02014-01-17 14:07:46 +0000229 // [base=der][][base=Mann]
230 String et1 =
Joachim Bingel0900a892014-06-30 16:26:21 +0000231 "{@type=korap:group, operation=operation:sequence, " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000232 "operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000233 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
234 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
235 "], inOrder=true, distances=[" +
236 "{@type=korap:distance, key=w, min=2, max=2}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000237 "]}";
238 ppt = new PoliqarpPlusTree("[base=der][][base=Mann]");
239 map = ppt.getRequestMap().get("query").toString();
240 assertEquals(et1.replaceAll(" ", ""), map.replaceAll(" ", ""));
241
242 // [base=der][][][base=Mann]
243 String et2 =
Joachim Bingel0900a892014-06-30 16:26:21 +0000244 "{@type=korap:group, operation=operation:sequence, " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000245 "operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000246 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
247 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
248 "], inOrder=true, distances=[" +
249 "{@type=korap:distance, key=w, min=3, max=3}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000250 "]}";
Joachim Bingelffd65e32014-01-22 14:22:57 +0000251 ppt = new PoliqarpPlusTree("[base=der][][][base=Mann]");
Joachim Bingel87480d02014-01-17 14:07:46 +0000252 map = ppt.getRequestMap().get("query").toString();
253 assertEquals(et2.replaceAll(" ", ""), map.replaceAll(" ", ""));
254
255 // [base=der][][]?[base=Mann]
256 String et3 =
Joachim Bingel0900a892014-06-30 16:26:21 +0000257 "{@type=korap:group, operation=operation:sequence, " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000258 "operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000259 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
260 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
261 "], inOrder=true, distances=[" +
262 "{@type=korap:distance, key=w, min=2, max=3}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000263 "]}";
264 ppt = new PoliqarpPlusTree("[base=der][][]?[base=Mann]");
265 map = ppt.getRequestMap().get("query").toString();
266 assertEquals(et3.replaceAll(" ", ""), map.replaceAll(" ", ""));
267
Joachim Bingel87480d02014-01-17 14:07:46 +0000268
Joachim Bingel14239d82014-07-22 09:55:04 +0000269
Joachim Bingelffd65e32014-01-22 14:22:57 +0000270
Joachim Bingel11d5b152014-02-11 21:33:47 +0000271 // [base=der][]{2,5}[base=Mann][]?[][base=Frau] nested distances=
Joachim Bingelffd65e32014-01-22 14:22:57 +0000272 String et5 =
Joachim Bingel0900a892014-06-30 16:26:21 +0000273 "{@type=korap:group, operation=operation:sequence," +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000274 "operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000275 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
276 "{@type=korap:group, operation=operation:sequence, " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000277 "operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000278 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}," +
279 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Frau, match=match:eq}}" +
280 "], inOrder=true, distances=[" +
281 "{@type=korap:distance, key=w, min=2, max=3}" +
Joachim Bingelffd65e32014-01-22 14:22:57 +0000282 "]}" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000283 "], inOrder=true, distances=[" +
284 "{@type=korap:distance, key=w, min=3, max=6}" +
Joachim Bingelffd65e32014-01-22 14:22:57 +0000285 "]}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000286 ppt = new PoliqarpPlusTree("[base=der][]{2,5}[base=Mann][]?[][base=Frau]");
Joachim Bingel87480d02014-01-17 14:07:46 +0000287 map = ppt.getRequestMap().get("query").toString();
288 assertEquals(et5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel87480d02014-01-17 14:07:46 +0000289
Joachim Bingelc15720f2014-05-07 14:37:23 +0000290 // [base=der][]*[base=Mann]
291 String et6 =
Joachim Bingel0900a892014-06-30 16:26:21 +0000292 "{@type=korap:group, operation=operation:sequence, " +
Joachim Bingelc15720f2014-05-07 14:37:23 +0000293 "operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000294 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
295 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
296 "], inOrder=true, distances=[" +
297 "{@type=korap:distance, key=w, min=1, max=100}" +
Joachim Bingelc15720f2014-05-07 14:37:23 +0000298 "]}";
299 ppt = new PoliqarpPlusTree("[base=der][]*[base=Mann]");
300 map = ppt.getRequestMap().get("query").toString();
301 assertEquals(et6.replaceAll(" ", ""), map.replaceAll(" ", ""));
302
Joachim Bingel0900a892014-06-30 16:26:21 +0000303 // [base=der][]+[base=Mann]
Joachim Bingelc15720f2014-05-07 14:37:23 +0000304 String et7 =
Joachim Bingel0900a892014-06-30 16:26:21 +0000305 "{@type=korap:group, operation=operation:sequence, " +
Joachim Bingelc15720f2014-05-07 14:37:23 +0000306 "operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000307 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
308 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
309 "], inOrder=true, distances=[" +
310 "{@type=korap:distance, key=w, min=2, max=100}" +
Joachim Bingelc15720f2014-05-07 14:37:23 +0000311 "]}";
312 ppt = new PoliqarpPlusTree("[base=der][]+[base=Mann]");
313 map = ppt.getRequestMap().get("query").toString();
314 assertEquals(et7.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel14239d82014-07-22 09:55:04 +0000315
316 // [base=der][]+[base=Mann]
317 String et8 =
318 "{@type=korap:group, operation=operation:sequence, " +
319 "operands=[" +
320 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
321 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
322 "], inOrder=true, distances=[" +
323 "{@type=korap:distance, key=w, min=2, max=100}" +
324 "]}";
325 ppt = new PoliqarpPlusTree("[base=der][]{1,102}[base=Mann]");
326 map = ppt.getRequestMap().get("query").toString();
327 assertEquals(et8.replaceAll(" ", ""), map.replaceAll(" ", ""));
328
329 // [base=geht][base=der][]*[base=Mann]
330 String et9 =
331 "{@type=korap:group, operation=operation:sequence, operands=[" +
332 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=geht, match=match:eq}}," +
333 "{@type=korap:group, operation=operation:sequence, " +
334 "operands=[" +
335 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
336 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
337 "], inOrder=true, distances=[" +
338 "{@type=korap:distance, key=w, min=1, max=100}" +
339 "]}" +
340 "]}";
341 ppt = new PoliqarpPlusTree("[base=geht][base=der][]*[base=Mann]");
342 map = ppt.getRequestMap().get("query").toString();
343 assertEquals(et9.replaceAll(" ", ""), map.replaceAll(" ", ""));
344
345 query = "[base=geht][base=der][]*[base=Mann][base=da]";
346 expected =
347 "{@type=korap:group, operation=operation:sequence, operands=[" +
348 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=geht, match=match:eq}}," +
349 "{@type=korap:group, operation=operation:sequence, " +
350 "operands=[" +
351 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
352 "{@type=korap:group, operation=operation:sequence, operands=[" +
353 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}," +
354 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=da, match=match:eq}}" +
355 "]}" +
356 "], inOrder=true, distances=[" +
357 "{@type=korap:distance, key=w, min=1, max=100}" +
358 "]}" +
359 "]}";
360 ppt = new PoliqarpPlusTree(query);
361 map = ppt.getRequestMap().get("query").toString();
362 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
363
364 query = "[base=geht][base=der][]*contains(<s>,<np>)";
365 expected =
366 "{@type=korap:group, operation=operation:sequence, operands=[" +
367 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=geht, match=match:eq}}," +
368 "{@type=korap:group, operation=operation:sequence, " +
369 "operands=[" +
370 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
371 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
372 "{@type=korap:span, key=s}," +
373 "{@type=korap:span, key=np}" +
374 "]}" +
375 "], inOrder=true, distances=[" +
376 "{@type=korap:distance, key=w, min=1, max=100}" +
377 "]}" +
378 "]}";
379 ppt = new PoliqarpPlusTree(query);
380 map = ppt.getRequestMap().get("query").toString();
381 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel87480d02014-01-17 14:07:46 +0000382 }
Joachim Bingel53333e62013-12-09 19:25:52 +0000383
384 @Test
Joachim Bingel14239d82014-07-22 09:55:04 +0000385 public void testLeadingTrailingEmptyTokens() throws QueryException {
386 // startswith(<s>, [][base=Mann]
387 String et1 =
388 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
389 "{@type=korap:span, key=s}," +
390 "{@type=korap:group, operation=operation:sequence, operands=[" +
391 "{@type=korap:token}," +
392 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
393 "]}" +
394 "]}";
395 ppt = new PoliqarpPlusTree("startswith(<s>, [][base=Mann])");
396 map = ppt.getRequestMap().get("query").toString();
397 assertEquals(et1.replaceAll(" ", ""), map.replaceAll(" ", ""));
398
399 query = "[][base=Mann]";
400 expected =
401 "{@type=korap:group, operation=operation:sequence, operands=[" +
402 "{@type=korap:token}," +
403 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
404 "]}";
405 ppt = new PoliqarpPlusTree(query);
406 map = ppt.getRequestMap().get("query").toString();
407 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
408
409 query = "[][][base=Mann]";
410 expected =
411 "{@type=korap:group, operation=operation:sequence, operands=[" +
412 "{@type=korap:group, operation=operation:repetition, operands=[" +
413 "{@type=korap:token}" +
414 "], min=2, max=2}," +
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}" +
426 "], min=1, max=100}," +
427 "{@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}" +
438 "], min=1, max=100}," +
439 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}," +
440 "{@type=korap:group, operation=operation:repetition, operands=[" +
441 "{@type=korap:token}" +
442 "], min=2, max=2}" +
443 "]}";
444 ppt = new PoliqarpPlusTree(query);
445 map = ppt.getRequestMap().get("query").toString();
446 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
447
448 query = "[][]*contains(<s>, <np>)[][]";
449 expected =
450 "{@type=korap:group, operation=operation:sequence, operands=[" +
451 "{@type=korap:group, operation=operation:repetition, operands=[" +
452 "{@type=korap:token}" +
453 "], min=1, max=100}," +
454 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
455 "{@type=korap:span, key=s}," +
456 "{@type=korap:span, key=np}" +
457 "]}," +
458 "{@type=korap:group, operation=operation:repetition, operands=[" +
459 "{@type=korap:token}" +
460 "], min=2, max=2}" +
461 "]}";
462 ppt = new PoliqarpPlusTree(query);
463 map = ppt.getRequestMap().get("query").toString();
464 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
465 }
466
467 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000468 public void testCoordinatedFields() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000469 // [base=Mann&(cas=N|cas=A)]
470 String cof1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000471 "{@type=korap:token, wrap=" +
Joachim Bingel2980bda2014-04-04 12:09:46 +0000472 "{@type=korap:termGroup, relation=relation:and, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000473 "{@type=korap:term, layer=lemma, key=Mann, match=match:eq}," +
Joachim Bingel2980bda2014-04-04 12:09:46 +0000474 "{@type=korap:termGroup, relation=relation:or, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000475 "{@type=korap:term, layer=cas, key=N, match=match:eq}," +
476 "{@type=korap:term, layer=cas, key=A, match=match:eq}" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000477 "]}" +
478 "]}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000479 "}";
480 ppt = new PoliqarpPlusTree("[base=Mann&(cas=N|cas=A)]");
481 map = ppt.getRequestMap().get("query").toString();
482 assertEquals(cof1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Nils Diewald7d486c22013-12-13 16:32:18 +0000483
484
485 assertEquals(
486 new PoliqarpPlusTree(" [ base=Mann & ( cas=N | cas=A)] ").getRequestMap().get("query").toString(),
487 new PoliqarpPlusTree("[base=Mann &(cas=N|cas=A)]").getRequestMap().get("query").toString()
488 );
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000489
490 // [base=Mann&cas=N&gen=m]
491 String cof2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000492 "{@type=korap:token, wrap=" +
Joachim Bingel2980bda2014-04-04 12:09:46 +0000493 "{@type=korap:termGroup, relation=relation:and, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000494 "{@type=korap:term, layer=lemma, key=Mann, match=match:eq}," +
495 "{@type=korap:termGroup, relation=relation:and, operands=[" +
496 "{@type=korap:term, layer=cas, key=N, match=match:eq}," +
497 "{@type=korap:term, layer=gen, key=m, match=match:eq}" +
498 "]}" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000499 "]}" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000500 "}";
501 ppt = new PoliqarpPlusTree("[base=Mann&cas=N&gen=m]");
502 map = ppt.getRequestMap().get("query").toString();
503 assertEquals(cof2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000504 }
505
506 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000507 public void testOccurrence() throws QueryException {
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000508 // [base=foo]*
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000509 String occ1 = "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000510 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000511 "], min=0, max=100}";
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000512 ppt = new PoliqarpPlusTree("[base=foo]*");
513 map = ppt.getRequestMap().get("query").toString();
514 assertEquals(occ1.replaceAll(" ", ""), map.replaceAll(" ", ""));
515
516 // [base=foo]*[base=bar]
517 String occ2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000518 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000519 "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000520 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000521 "], min=0, max=100 }," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000522 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000523 "]}";
524 ppt = new PoliqarpPlusTree("[base=foo]*[base=bar]");
525 map = ppt.getRequestMap().get("query").toString();
526 assertEquals(occ2.replaceAll(" ", ""), map.replaceAll(" ", ""));
527
528 // [base=bar][base=foo]*
529 String occ3 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000530 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000531 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000532 "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000533 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000534 "], min=0, max=100 }" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000535 "]}";
536 ppt = new PoliqarpPlusTree("[base=bar][base=foo]*");
537 map = ppt.getRequestMap().get("query").toString();
538 assertEquals(occ3.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb4da7022013-12-09 23:17:24 +0000539
540 // ([base=bar][base=foo])*
541 String occ4 =
Joachim Bingel0900a892014-06-30 16:26:21 +0000542 "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000543 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000544 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," +
545 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000546 "]}" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000547 "], min=0, max=100}" ;
Joachim Bingelb4da7022013-12-09 23:17:24 +0000548 ppt = new PoliqarpPlusTree("([base=bar][base=foo])*");
549 map = ppt.getRequestMap().get("query").toString();
550 assertEquals(occ4.replaceAll(" ", ""), map.replaceAll(" ", ""));
551
552 // <s>([base=bar][base=foo])*
553 String occ5 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000554 "{@type=korap:group, operation=operation:sequence, operands=[" +
555 "{@type=korap:span, key=s}," +
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 }" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000562 "]}" ;
563 ppt = new PoliqarpPlusTree("<s>([base=bar][base=foo])*");
564 map = ppt.getRequestMap().get("query").toString();
565 assertEquals(occ5.replaceAll(" ", ""), map.replaceAll(" ", ""));
566
567 // <s><np>([base=bar][base=foo])*
Joachim Bingelb4da7022013-12-09 23:17:24 +0000568 String occ6 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000569 "{@type=korap:group, operation=operation:sequence, operands=[" +
570 "{@type=korap:span, key=s}," +
571 "{@type=korap:span, key=np}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000572 "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000573 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000574 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," +
575 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000576 "]}" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000577 "], min=0, max=100 }" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000578 "]}" ;
579 ppt = new PoliqarpPlusTree("<s><np>([base=bar][base=foo])*");
580 map = ppt.getRequestMap().get("query").toString();
581 assertEquals(occ6.replaceAll(" ", ""), map.replaceAll(" ", ""));
582
583 // <s><np>([base=bar][base=foo])*[p=NN]
584 // comment: embedded sequence shouldn't really be here, but does not really hurt, either. (?)
585 // really hard to get this behaviour out of the PQPlus grammar...
586 String occ7 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000587 "{@type=korap:group, operation=operation:sequence, operands=[" +
588 "{@type=korap:span, key=s}," +
589 "{@type=korap:span, key=np}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000590 "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000591 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000592 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," +
593 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000594 "]}" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000595 "], min=0, max=100 }," +
596 "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000597 "]}" ;
598 ppt = new PoliqarpPlusTree("<s><np>([base=bar][base=foo])*[p=NN]");
599 map = ppt.getRequestMap().get("query").toString();
600 assertEquals(occ7.replaceAll(" ", ""), map.replaceAll(" ", ""));
601
602 // ([base=bar][base=foo])*[p=NN]
Joachim Bingelb4da7022013-12-09 23:17:24 +0000603 String occ8 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000604 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000605 "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000606 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000607 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," +
608 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000609 "]}" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000610 "], min=0, max=100 }," +
611 "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000612 "]}" ;
613 ppt = new PoliqarpPlusTree("([base=bar][base=foo])*[p=NN]");
614 map = ppt.getRequestMap().get("query").toString();
615 assertEquals(occ8.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000616
617 // [base=foo]+
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000618 String occ9 = "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000619 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000620 "], min=1, max=100}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000621 ppt = new PoliqarpPlusTree("[base=foo]+");
622 map = ppt.getRequestMap().get("query").toString();
623 assertEquals(occ9.replaceAll(" ", ""), map.replaceAll(" ", ""));
624
625 // [base=foo]?
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000626 String occ10 = "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000627 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000628 "], min=0, max=1}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000629 ppt = new PoliqarpPlusTree("[base=foo]?");
630 map = ppt.getRequestMap().get("query").toString();
631 assertEquals(occ10.replaceAll(" ", ""), map.replaceAll(" ", ""));
632
633 // [base=foo]{2,5}
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000634 String occ11 = "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000635 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000636 "], min=2, max=5}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000637 ppt = new PoliqarpPlusTree("[base=foo]{2,5}");
638 map = ppt.getRequestMap().get("query").toString();
639 assertEquals(occ11.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel2980bda2014-04-04 12:09:46 +0000640
641 // [base=foo]{2}
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000642 String occ12 = "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000643 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000644 "], min=2, max=2}";
Joachim Bingel2980bda2014-04-04 12:09:46 +0000645 ppt = new PoliqarpPlusTree("[base=foo]{2}");
646 map = ppt.getRequestMap().get("query").toString();
647 assertEquals(occ12.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb2aa1c72014-07-01 12:48:46 +0000648
649 // [base=foo]{2}
650 String occ13 = "{@type=korap:group, operation=operation:repetition, operands=[" +
651 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
652 "], min=2, max=100}";
653 ppt = new PoliqarpPlusTree("[base=foo]{2,}");
654 map = ppt.getRequestMap().get("query").toString();
655 assertEquals(occ13.replaceAll(" ", ""), map.replaceAll(" ", ""));
656
657 // [base=foo]{2}
658 String occ14 = "{@type=korap:group, operation=operation:repetition, operands=[" +
659 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
660 "], min=0, max=2}";
661 ppt = new PoliqarpPlusTree("[base=foo]{,2}");
662 map = ppt.getRequestMap().get("query").toString();
663 assertEquals(occ14.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000664 }
665
666 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000667 public void testTokenSequence() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000668 // [base=Mann][orth=Frau]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000669 String seq1 = "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000670 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}, " +
671 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000672 "]}";
673 assertTrue(equalsQueryContent(seq1, "[base=Mann][orth=Frau]"));
674
675 // [base=Mann][orth=Frau][p=NN]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000676 String seq2 = "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000677 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}, " +
678 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}, " +
679 "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000680 "]}";
681 assertTrue(equalsQueryContent(seq2, "[base=Mann][orth=Frau][p=NN]"));
682 }
683
684 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000685 public void testDisjSegments() throws QueryException {
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000686 // ([base=der]|[base=das])[base=Schild]
687 String disj1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000688 "{@type=korap:group, operation=operation:sequence, operands=[" +
689 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000690 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
691 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=das, match=match:eq}}" +
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000692 "]}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000693 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Schild, match=match:eq}}" +
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000694 "]}";
695 ppt = new PoliqarpPlusTree("([base=der]|[base=das])[base=Schild]");
696 map = ppt.getRequestMap().get("query").toString();
697 assertEquals(disj1.replaceAll(" ", ""), map.replaceAll(" ", ""));
698
699 // [base=Schild]([base=der]|[base=das])
700 String disj2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000701 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000702 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Schild, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000703 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000704 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
705 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=das, match=match:eq}}" +
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000706 "]}" +
707 "]}";
708 ppt = new PoliqarpPlusTree("[base=Schild]([base=der]|[base=das])");
709 map = ppt.getRequestMap().get("query").toString();
710 assertEquals(disj2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel76b498d2014-06-06 12:06:46 +0000711
712 // "([orth=der][base=katze])|([orth=eine][base=baum])"
713 String disj3 =
714 "{@type=korap:group, operation=operation:or, operands=[" +
715 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000716 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
717 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=katze, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000718 "]}," +
719 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000720 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=eine, match=match:eq}}," +
721 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=baum, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000722 "]}" +
723 "]}";
724 ppt = new PoliqarpPlusTree("([orth=der][base=katze])|([orth=eine][base=baum])");
725 map = ppt.getRequestMap().get("query").toString();
726 assertEquals(disj3.replaceAll(" ", ""), map.replaceAll(" ", ""));
727
728 // "[orth=der][base=katze]|[orth=eine][base=baum]"
729 String disj4 =
730 "{@type=korap:group, operation=operation:or, operands=[" +
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=der, match=match:eq}}," +
733 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=katze, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000734 "]}," +
735 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000736 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=eine, match=match:eq}}," +
737 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=baum, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000738 "]}" +
739 "]}";
740 ppt = new PoliqarpPlusTree("[orth=der][base=katze]|[orth=eine][base=baum]");
741 map = ppt.getRequestMap().get("query").toString();
742 assertEquals(disj4.replaceAll(" ", ""), map.replaceAll(" ", ""));
743
744 PoliqarpPlusTree ppt1 = new PoliqarpPlusTree("[orth=der][base=katze]|[orth=eine][base=baum]");
745 PoliqarpPlusTree ppt2 = new PoliqarpPlusTree("([orth=der][base=katze])|([orth=eine][base=baum])");
746 assertEquals(ppt1.getRequestMap().toString(), ppt2.getRequestMap().toString());
747
748 // "[orth=der][base=katze]|[orth=der][base=hund]|[orth=der][base=baum]"
749 String disj5 =
750 "{@type=korap:group, operation=operation:or, operands=[" +
751 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000752 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
753 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=katze, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000754 "]}," +
755 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000756 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
757 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=hund, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000758 "]}," +
759 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000760 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
761 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=baum, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000762 "]}" +
763 "]}";
764 ppt = new PoliqarpPlusTree("[orth=der][base=katze]|[orth=der][base=hund]|[orth=der][base=baum]");
765 map = ppt.getRequestMap().get("query").toString();
766 assertEquals(disj5.replaceAll(" ", ""), map.replaceAll(" ", ""));
767
768 // [orth=der]([base=katze]|[base=hund]|[base=baum])
769 String disj6 =
770 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000771 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000772 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000773 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=katze, match=match:eq}}," +
774 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=hund, match=match:eq}}," +
775 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=baum, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000776 "]}" +
777 "]}";
778 ppt = new PoliqarpPlusTree("[orth=der]([base=katze]|[base=hund]|[base=baum])");
779 map = ppt.getRequestMap().get("query").toString();
780 assertEquals(disj6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000781 }
782
783 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000784 public void testTokenElemSequence() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000785 // [base=Mann]<vp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000786 String seq1 = "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000787 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}, " +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000788 "{@type=korap:span, key=vp}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000789 "]}";
790 assertTrue(equalsQueryContent(seq1, "[base=Mann]<vp>"));
791
792 // <vp>[base=Mann]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000793 String seq2 = "{@type=korap:group, operation=operation:sequence, operands=[" +
794 "{@type=korap:span, key=vp}, "+
Joachim Bingel0900a892014-06-30 16:26:21 +0000795 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}} " +
Joachim Bingel53333e62013-12-09 19:25:52 +0000796 "]}";
797 assertTrue(equalsQueryContent(seq2, "<vp>[base=Mann]"));
798
799 // <vp>[base=Mann]<pp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000800 String seq3 = "{@type=korap:group, operation=operation:sequence, operands=[" +
801 "{@type=korap:span, key=vp}, "+
Joachim Bingel0900a892014-06-30 16:26:21 +0000802 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}, " +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000803 "{@type=korap:span, key=pp} "+
Joachim Bingel53333e62013-12-09 19:25:52 +0000804 "]}";
805 assertTrue(equalsQueryContent(seq3, "<vp>[base=Mann]<pp>"));
806 }
807
808 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000809 public void testElemSequence() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000810 // <np><vp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000811 String seq1 = "{@type=korap:group, operation=operation:sequence, operands=[" +
812 "{@type=korap:span, key=np}," +
813 "{@type=korap:span, key=vp}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000814 "]}";
815 assertTrue(equalsQueryContent(seq1, "<np><vp>"));
816
817 // <np><vp><pp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000818 String seq2 = "{@type=korap:group, operation=operation:sequence, operands=[" +
819 "{@type=korap:span, key=np}," +
820 "{@type=korap:span, key=vp}," +
821 "{@type=korap:span, key=pp}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000822 "]}";
823 assertTrue(equalsQueryContent(seq2, "<np><vp><pp>"));
824 }
825
826 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000827 public void testClasses() throws QueryException {
Joachim Bingel0900a892014-06-30 16:26:21 +0000828 String query;
Joachim Bingel53333e62013-12-09 19:25:52 +0000829 // {[base=Mann]}
Joachim Bingel2daf9862014-02-12 10:18:54 +0000830 String cls1 = "{@type=korap:group, operation=operation:class, class=0, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000831 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000832 "]}";
Joachim Bingel8c640e42014-02-07 16:20:47 +0000833 ppt = new PoliqarpPlusTree("{[base=Mann]}");
834 map = ppt.getRequestMap().get("query").toString();
835 assertEquals(cls1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000836
837 // {[base=Mann][orth=Frau]}
Joachim Bingel0900a892014-06-30 16:26:21 +0000838 query = "{[base=Mann][orth=Frau]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000839 String cls2 = "{@type=korap:group, operation=operation:class, class=0, operands=[" +
840 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000841 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}," +
842 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000843 "]}" +
844 "]}";
Joachim Bingel0900a892014-06-30 16:26:21 +0000845 ppt = new PoliqarpPlusTree(query);
846 map = ppt.getRequestMap().get("query").toString();
847 assertEquals(cls2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000848
849 // [p=NN]{[base=Mann][orth=Frau]}
Joachim Bingel2daf9862014-02-12 10:18:54 +0000850 String cls3 = "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000851 "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000852 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
853 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000854 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}," +
855 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000856 "]}" +
857 "]}" +
858 "]}";
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000859 ppt = new PoliqarpPlusTree("[p=NN]{[base=Mann][orth=Frau]}");
860 map = ppt.getRequestMap().get("query").toString();
861 assertEquals(cls3.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000862
863 // {[base=Mann][orth=Frau]}[p=NN]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000864 String cls4 = "{@type=korap:group, operation=operation:sequence, operands=[" +
865 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
866 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000867 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}," +
868 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000869 "]}" +
870 "]}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000871 "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000872 "]}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000873 ppt = new PoliqarpPlusTree("{[base=Mann][orth=Frau]}[p=NN]");
874 map = ppt.getRequestMap().get("query").toString();
875 assertEquals(cls4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000876
877 // {2:{1:[tt/p=ADJA]}[mate/p=NN]}"
Joachim Bingel2daf9862014-02-12 10:18:54 +0000878 String cls5 = "{@type=korap:group, operation=operation:class, class=2, operands=[" +
879 "{@type=korap:group, operation=operation:sequence, operands=[" +
880 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000881 "{@type=korap:token, wrap={@type=korap:term, foundry=tt, layer=p, key=ADJA, match=match:eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000882 "]}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000883 "{@type=korap:token, wrap={@type=korap:term, foundry=mate, layer=p, key=NN, match=match:eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000884 "]}" +
885 "]}";
886 ppt = new PoliqarpPlusTree("{2: {1:[tt/p=ADJA]}[mate/p=NN]}");
887 map = ppt.getRequestMap().get("query").toString();
888 assertEquals(cls5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000889 }
890
891 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000892 public void testPositions() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000893 // contains(<s>,<np>)
Joachim Bingel2daf9862014-02-12 10:18:54 +0000894 String pos1 = "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
895 "{@type=korap:span, key=s}," +
896 "{@type=korap:span, key=np}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000897 "]}";
898 assertTrue(equalsQueryContent(pos1, "contains(<s>,<np>)"));
899
900 // contains(<s>,[base=Mann])
Joachim Bingel2daf9862014-02-12 10:18:54 +0000901 String pos2 = "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
902 "{@type=korap:span, key=s}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000903 "{@type=korap:token, wrap= {@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000904 "]}";
905 assertTrue(equalsQueryContent(pos2, "contains(<s>,[base=Mann])"));
906
907 // contains(<s>,[orth=der][orth=Mann])
Joachim Bingel2daf9862014-02-12 10:18:54 +0000908 String pos3 = "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
909 "{@type=korap:span, key=s}," +
910 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000911 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
912 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000913 "]}" +
914 "]}";
915 ppt = new PoliqarpPlusTree("contains(<s>,[orth=der][orth=Mann])");
916 map = ppt.getRequestMap().get("query").toString();
917 assertEquals(pos3.replaceAll(" ", ""), map.replaceAll(" ", ""));
918
919 // [base=Auto]contains(<s>,[base=Mann])
920 String pos4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000921 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000922 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Auto, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000923 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
924 "{@type=korap:span, key=s}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000925 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000926 "]}" +
927 "]}";
928 ppt = new PoliqarpPlusTree("[base=Auto]contains(<s>,[base=Mann])");
929 map = ppt.getRequestMap().get("query").toString();
930 assertEquals(pos4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelef7059b2014-04-22 13:44:19 +0000931
932 // contains(<s>,[pos=N]*)
933 String pos5 =
934 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
935 "{@type=korap:span, key=s}," +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000936 "{@type=korap:group, operation=operation:repetition, " +
Joachim Bingel0900a892014-06-30 16:26:21 +0000937 "operands=[{@type=korap:token, wrap={@type=korap:term, layer=pos, key=N, match=match:eq}}" +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000938 "], min=0, max=100" +
Joachim Bingelef7059b2014-04-22 13:44:19 +0000939 "}" +
940 "]}";
941 ppt = new PoliqarpPlusTree("contains(<s>,[pos=N]*)");
942 map = ppt.getRequestMap().get("query").toString();
943 assertEquals(pos5.replaceAll(" ", ""), map.replaceAll(" ", ""));
944
945 // [base=Auto]contains(<s>,[pos=N]*)
946 String pos6 =
947 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000948 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Auto, match=match:eq}}," +
Joachim Bingelef7059b2014-04-22 13:44:19 +0000949 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
950 "{@type=korap:span, key=s}," +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000951 "{@type=korap:group, operation=operation:repetition, " +
Joachim Bingel0900a892014-06-30 16:26:21 +0000952 "operands=[{@type=korap:token, wrap={@type=korap:term, layer=pos, key=N, match=match:eq}}" +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000953 "], min=0, max=100" +
Joachim Bingelef7059b2014-04-22 13:44:19 +0000954 "}" +
955 "]}" +
956 "]}";
957 ppt = new PoliqarpPlusTree("[base=Auto]contains(<s>,[pos=N]*)");
958 map = ppt.getRequestMap().get("query").toString();
959 assertEquals(pos6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000960 }
961
962 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000963 public void testNestedPositions() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000964 // contains(<s>,startswith(<np>,[orth=Der]))
965 String npos1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000966 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
967 "{@type=korap:span, key=s}," +
968 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
969 "{@type=korap:span, key=np}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000970 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000971 "]}" +
972 "]}";
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000973 ppt = new PoliqarpPlusTree("contains(<s>, startswith(<np>,[orth=Der]))");
Joachim Bingel53333e62013-12-09 19:25:52 +0000974 map = ppt.getRequestMap().get("query").toString();
975 assertEquals(npos1.replaceAll(" ", ""), map.replaceAll(" ", ""));
976 }
977
978 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000979 public void testShrinkSplit() throws QueryException {
Joachim Bingel0900a892014-06-30 16:26:21 +0000980 // focus([orth=Der]{[orth=Mann]})
Joachim Bingel53333e62013-12-09 19:25:52 +0000981 String shr1 =
Joachim Bingeld1a3e712014-07-16 08:02:05 +0000982 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000983 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000984 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000985 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000986 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000987 "]}" +
988 "]}" +
989 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000990 ppt = new PoliqarpPlusTree("focus([orth=Der]{[orth=Mann]})");
Joachim Bingel53333e62013-12-09 19:25:52 +0000991 map = ppt.getRequestMap().get("query").toString();
992 assertEquals(shr1.replaceAll(" ", ""), map.replaceAll(" ", ""));
993
Joachim Bingel0900a892014-06-30 16:26:21 +0000994 // focus([orth=Der]{[orth=Mann][orth=geht]})
Joachim Bingel53333e62013-12-09 19:25:52 +0000995 String shr2 =
Joachim Bingeld1a3e712014-07-16 08:02:05 +0000996 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000997 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000998 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000999 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
1000 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001001 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}," +
1002 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=geht, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +00001003 "]}" +
1004 "]}" +
1005 "]}" +
1006 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +00001007 ppt = new PoliqarpPlusTree("focus([orth=Der]{[orth=Mann][orth=geht]})");
Joachim Bingel53333e62013-12-09 19:25:52 +00001008 map = ppt.getRequestMap().get("query").toString();
1009 assertEquals(shr2.replaceAll(" ", ""), map.replaceAll(" ", ""));
1010
Joachim Bingel0900a892014-06-30 16:26:21 +00001011 // focus(1:[orth=Der]{1:[orth=Mann][orth=geht]})
Joachim Bingel53333e62013-12-09 19:25:52 +00001012 String shr3 =
Joachim Bingeld1a3e712014-07-16 08:02:05 +00001013 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001014 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001015 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001016 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
1017 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001018 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}," +
1019 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=geht, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +00001020 "]}" +
1021 "]}" +
1022 "]}" +
1023 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +00001024 ppt = new PoliqarpPlusTree("focus(1:[orth=Der]{1:[orth=Mann][orth=geht]})");
Joachim Bingel53333e62013-12-09 19:25:52 +00001025 map = ppt.getRequestMap().get("query").toString();
1026 assertEquals(shr3.replaceAll(" ", ""), map.replaceAll(" ", ""));
1027
Joachim Bingel0900a892014-06-30 16:26:21 +00001028 // focus(1:startswith(<s>,{1:<np>}))
Joachim Bingel53333e62013-12-09 19:25:52 +00001029 String shr4 =
Joachim Bingeld1a3e712014-07-16 08:02:05 +00001030 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001031 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
1032 "{@type=korap:span, key=s}," +
1033 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
1034 "{@type=korap:span, key=np}" +
Joachim Bingel53333e62013-12-09 19:25:52 +00001035 "]}" +
1036 "]}" +
1037 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +00001038 ppt = new PoliqarpPlusTree("focus(1:startswith(<s>,{1:<np>}))");
Joachim Bingel53333e62013-12-09 19:25:52 +00001039 map = ppt.getRequestMap().get("query").toString();
1040 assertEquals(shr4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelcd9ed332013-12-09 21:01:35 +00001041
Joachim Bingel0900a892014-06-30 16:26:21 +00001042 // focus(3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))
Joachim Bingelcd9ed332013-12-09 21:01:35 +00001043 String shr5 =
Joachim Bingeld1a3e712014-07-16 08:02:05 +00001044 "{@type=korap:reference, operation=operation:focus, classRef=[3], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001045 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
1046 "{@type=korap:span, key=s}," +
1047 "{@type=korap:group, operation=operation:class, class=3, operands=[" +
1048 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001049 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001050 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
1051 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001052 "{@type=korap:token, wrap={@type=korap:term, foundry=mate, layer=p, key=ADJA, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001053 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001054 "{@type=korap:token, wrap={@type=korap:term, foundry=tt, layer=p, key=NN, match=match:eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +00001055 "]}" +
1056 "]}" +
1057 "]}" +
1058 "]}" +
1059 "]}" +
1060 "]}" +
1061 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +00001062 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 +00001063 map = ppt.getRequestMap().get("query").toString();
1064 assertEquals(shr5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelba9a0ab2014-01-29 10:12:25 +00001065
1066 // split(3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))
1067 String shr6 =
Joachim Bingeld1a3e712014-07-16 08:02:05 +00001068 "{@type=korap:reference, operation=operation:split, classRef=[3], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001069 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
1070 "{@type=korap:span, key=s}," +
1071 "{@type=korap:group, operation=operation:class, class=3, operands=[" +
1072 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001073 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001074 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
1075 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001076 "{@type=korap:token, wrap={@type=korap:term, foundry=mate, layer=p, key=ADJA, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001077 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001078 "{@type=korap:token, wrap={@type=korap:term, foundry=tt, layer=p, key=NN, match=match:eq}}" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +00001079 "]}" +
1080 "]}" +
1081 "]}" +
1082 "]}" +
1083 "]}" +
1084 "]}" +
1085 "]}";
1086 ppt = new PoliqarpPlusTree("split(3:startswith(<s>,{3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) ");
1087 map = ppt.getRequestMap().get("query").toString();
1088 assertEquals(shr6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel8c640e42014-02-07 16:20:47 +00001089
1090 // split(2|3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))
1091 String shr7 =
Joachim Bingeld1a3e712014-07-16 08:02:05 +00001092 "{@type=korap:reference, operation=operation:split, classRef=[2, 3], classRefOp=classRefOp:intersection, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001093 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
1094 "{@type=korap:span, key=s}," +
1095 "{@type=korap:group, operation=operation:class, class=3, operands=[" +
1096 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001097 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001098 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
1099 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001100 "{@type=korap:token, wrap={@type=korap:term, foundry=mate, layer=p, key=ADJA, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001101 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001102 "{@type=korap:token, wrap={@type=korap:term, foundry=tt, layer=p, key=NN, match=match:eq}}" +
Joachim Bingel8c640e42014-02-07 16:20:47 +00001103 "]}" +
1104 "]}" +
1105 "]}" +
1106 "]}" +
1107 "]}" +
1108 "]}" +
1109 "]}";
1110 ppt = new PoliqarpPlusTree("split(2|3:startswith(<s>,{3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) ");
1111 map = ppt.getRequestMap().get("query").toString();
1112 assertEquals(shr7.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel5146ebe2014-06-12 08:49:21 +00001113
1114
1115 String shr8 =
Joachim Bingeld1a3e712014-07-16 08:02:05 +00001116 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingeladd0fb12014-06-24 08:54:14 +00001117 "{@type=korap:group, operation=operation:sequence, operands=[" +
1118 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001119 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}" +
Joachim Bingeladd0fb12014-06-24 08:54:14 +00001120 "]}," +
1121 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001122 "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=ADJA, match=match:eq}}" +
Joachim Bingel5146ebe2014-06-12 08:49:21 +00001123 "]}" +
Joachim Bingeladd0fb12014-06-24 08:54:14 +00001124 "]}" +
1125 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +00001126 ppt = new PoliqarpPlusTree("focus(1:{[base=der]}{1:[pos=ADJA]})");
Joachim Bingeladd0fb12014-06-24 08:54:14 +00001127 map = ppt.getRequestMap().get("query").toString();
1128 assertEquals(shr8.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel5146ebe2014-06-12 08:49:21 +00001129
Joachim Bingel53333e62013-12-09 19:25:52 +00001130 }
1131
Joachim Bingel03882702013-12-31 19:53:05 +00001132
Joachim Bingel53333e62013-12-09 19:25:52 +00001133 @Test
Joachim Bingelba9a0ab2014-01-29 10:12:25 +00001134 public void testFoundries() throws QueryException {
1135 // [tt/base=Mann]
Joachim Bingel0900a892014-06-30 16:26:21 +00001136 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 +00001137 ppt = new PoliqarpPlusTree("[tt/base=Mann]");
1138 map = ppt.getRequestMap().get("query").toString();
1139 assertEquals(layer1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +00001140
1141 }
Joachim Bingel16da4e12013-12-17 09:48:12 +00001142
1143 @Test
Joachim Bingel8c640e42014-02-07 16:20:47 +00001144 public void testAlign() throws QueryException {
Joachim Bingel16da4e12013-12-17 09:48:12 +00001145 // [orth=der]^[orth=Mann]
1146 String align1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001147 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001148 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
1149 "{@type=korap:group, operation=operation:alignment, operands=[" +
1150 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" +
1151 "], align=align:left}" +
Joachim Bingel16da4e12013-12-17 09:48:12 +00001152 "]}";
1153 ppt = new PoliqarpPlusTree("[orth=der]^[orth=Mann]");
1154 map = ppt.getRequestMap().get("query").toString();
1155 assertEquals(align1.replaceAll(" ", ""), map.replaceAll(" ", ""));
1156
Joachim Bingel84e33df2014-01-31 14:02:46 +00001157 // [orth=der]^[orth=große][orth=Mann]
1158 String query = "[orth=der]^[orth=große][orth=Mann]";
1159 String align1b =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001160 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001161 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, 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=orth, key=große, match=match:eq}}," +
1165 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +00001166 "]}" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001167 "], align=align:left}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +00001168 "]}";
1169 ppt = new PoliqarpPlusTree(query);
1170 map = ppt.getRequestMap().get("query").toString();
1171 assertEquals(align1b.replaceAll(" ", ""), map.replaceAll(" ", ""));
1172
Joachim Bingel16da4e12013-12-17 09:48:12 +00001173 // "([base=a]^[base=b])|[base=c]",
1174 String align2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001175 "{@type=korap:group, operation=operation:or, operands=[" +
1176 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001177 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=a, match=match:eq}}," +
1178 "{@type=korap:group, operation=operation:alignment, operands=[" +
1179 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=b, match=match:eq}}" +
1180 "], align=align:left}" +
Joachim Bingel16da4e12013-12-17 09:48:12 +00001181 "]}," +
Joachim Bingel0900a892014-06-30 16:26:21 +00001182 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=c, match=match:eq}}" +
Joachim Bingel16da4e12013-12-17 09:48:12 +00001183 "]}";
1184 ppt = new PoliqarpPlusTree("([base=a]^[base=b])|[base=c]");
1185 map = ppt.getRequestMap().get("query").toString();
1186 assertEquals(align2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingela67e6a32014-01-02 18:35:24 +00001187
1188 // "([base=a]^[base=b][base=c])|[base=d]",
1189 String align3 =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001190 "{@type=korap:group, operation=operation:or, operands=[" +
1191 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001192 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=a, match=match:eq}}," +
1193 "{@type=korap:group, operation=operation:alignment, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001194 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001195 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=b, match=match:eq}}," +
1196 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=c, match=match:eq}}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +00001197 "]}" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001198 "], align=align:left}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +00001199 "]}," +
Joachim Bingel0900a892014-06-30 16:26:21 +00001200 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=d, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +00001201 "]}";
1202 ppt = new PoliqarpPlusTree("([base=a]^[base=b][base=c])|[base=d]");
1203 map = ppt.getRequestMap().get("query").toString();
1204 assertEquals(align3.replaceAll(" ", ""), map.replaceAll(" ", ""));
1205
1206 // "([base=a]^[base=b]^[base=c])|[base=d]",
1207 String align4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001208 "{@type=korap:group, operation=operation:or, operands=[" +
1209 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001210 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=a, match=match:eq}}," +
1211 "{@type=korap:group, operation=operation:alignment, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001212 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001213 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=b, match=match:eq}}," +
1214 "{@type=korap:group, operation=operation:alignment, operands=[" +
1215 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=c, match=match:eq}}" +
1216 "], align=align:left}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +00001217 "]}" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001218 "], align=align:left}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +00001219 "]}," +
Joachim Bingel0900a892014-06-30 16:26:21 +00001220 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=d, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +00001221 "]}";
1222 ppt = new PoliqarpPlusTree("([base=a]^[base=b]^[base=c])|[base=d]");
1223 map = ppt.getRequestMap().get("query").toString();
1224 assertEquals(align4.replaceAll(" ", ""), map.replaceAll(" ", ""));
1225
1226
Joachim Bingel16da4e12013-12-17 09:48:12 +00001227 }
1228
1229 @Test
Joachim Bingel8c640e42014-02-07 16:20:47 +00001230 public void testSimpleQueries() throws QueryException {
Joachim Bingela67e6a32014-01-02 18:35:24 +00001231 // Baum
1232 String simple1 =
Joachim Bingel0900a892014-06-30 16:26:21 +00001233 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq}}";
Joachim Bingela67e6a32014-01-02 18:35:24 +00001234 ppt = new PoliqarpPlusTree("Baum");
1235 map = ppt.getRequestMap().get("query").toString();
1236 assertEquals(simple1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel0900a892014-06-30 16:26:21 +00001237
1238 // Baum/i
1239 String simple1b =
1240 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq, caseInsensitive=true}}";
1241 ppt = new PoliqarpPlusTree("Baum/i");
1242 map = ppt.getRequestMap().get("query").toString();
1243 assertEquals(simple1b.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel16da4e12013-12-17 09:48:12 +00001244
Joachim Bingela67e6a32014-01-02 18:35:24 +00001245 // Der Baum
1246 String simple2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001247 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001248 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}, " +
1249 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +00001250 "]}";
1251 ppt = new PoliqarpPlusTree("Der Baum");
1252 map = ppt.getRequestMap().get("query").toString();
1253 assertEquals(simple2.replaceAll(" ", ""), map.replaceAll(" ", ""));
1254
Joachim Bingel0900a892014-06-30 16:26:21 +00001255 // Der Baum/i
1256 String simple2b =
1257 "{@type=korap:group, operation=operation:sequence, operands=[" +
1258 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}, " +
1259 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq, caseInsensitive=true}}" +
1260 "]}";
1261 ppt = new PoliqarpPlusTree("Der Baum/i");
1262 map = ppt.getRequestMap().get("query").toString();
1263 assertEquals(simple2b.replaceAll(" ", ""), map.replaceAll(" ", ""));
1264
Joachim Bingela67e6a32014-01-02 18:35:24 +00001265 // Der große Baum
1266 String simple3 =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001267 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001268 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}, " +
1269 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=große, match=match:eq}}, " +
1270 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +00001271 "]}";
1272 ppt = new PoliqarpPlusTree("Der große Baum");
1273 map = ppt.getRequestMap().get("query").toString();
1274 assertEquals(simple3.replaceAll(" ", ""), map.replaceAll(" ", ""));
1275
1276 // Baum | Stein
1277 String simple4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001278 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001279 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq}}, " +
1280 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Stein, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +00001281 "]}";
1282 ppt = new PoliqarpPlusTree("Baum | Stein");
1283 map = ppt.getRequestMap().get("query").toString();
1284 assertEquals(simple4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel84e33df2014-01-31 14:02:46 +00001285
1286 // Baum | Stein Haus
1287 String query = "(Baum | Stein) Haus";
1288 String simple5 =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001289 "{@type=korap:group, operation=operation:sequence, operands=[" +
1290 "{@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 Bingel84e33df2014-01-31 14:02:46 +00001293 "]}," +
Joachim Bingel0900a892014-06-30 16:26:21 +00001294 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Haus, match=match:eq}} " +
Joachim Bingel84e33df2014-01-31 14:02:46 +00001295 "]}";
1296 ppt = new PoliqarpPlusTree(query);
1297 map = ppt.getRequestMap().get("query").toString();
1298 assertEquals(simple5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel16da4e12013-12-17 09:48:12 +00001299 }
Joachim Bingel53333e62013-12-09 19:25:52 +00001300}
1301