blob: fa9fda0946a64ee223c8dc87921601b180381ef9 [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;
Joachim Bingel832800e2014-10-17 14:46:39 +000013 String metaExpected;
14 String metaMap;
Joachim Bingel14239d82014-07-22 09:55:04 +000015 String query;
Joachim Bingel53333e62013-12-09 19:25:52 +000016
Joachim Bingel16da4e12013-12-17 09:48:12 +000017 private boolean equalsQueryContent(String res, String query) throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +000018 res = res.replaceAll(" ", "");
19 ppt = new PoliqarpPlusTree(query);
20 String queryMap = ppt.getRequestMap().get("query").toString().replaceAll(" ", "");
21 return res.equals(queryMap);
22 }
23
Joachim Bingel81812632014-02-18 08:55:22 +000024 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +000025 public void testContext() throws QueryException {
Joachim Bingel832800e2014-10-17 14:46:39 +000026 String contextString = "http://ids-mannheim.de/ns/KorAP/json-ld/v0.2/context.jsonld";
Joachim Bingel2daf9862014-02-12 10:18:54 +000027 ppt = new PoliqarpPlusTree("Test");
28 assertEquals(contextString.replaceAll(" ", ""), ppt.getRequestMap().get("@context").toString().replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +000029 }
30
31 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +000032 public void testSingleTokens() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +000033 // [base=Mann]
Joachim Bingel0900a892014-06-30 16:26:21 +000034 String token1 = "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}";
Joachim Bingel53333e62013-12-09 19:25:52 +000035 assertTrue(equalsQueryContent(token1, "[base=Mann]"));
36
37 // [orth!=Frau]
Joachim Bingel0900a892014-06-30 16:26:21 +000038 String token2 = "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:ne}}";
Joachim Bingel53333e62013-12-09 19:25:52 +000039 assertTrue(equalsQueryContent(token2, "[orth!=Frau]"));
40
41 // [!p=NN]
Joachim Bingel0900a892014-06-30 16:26:21 +000042 query = "[!p=NN]";
43 String token3 = "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:ne}}";
44 ppt = new PoliqarpPlusTree(query);
45 map = ppt.getRequestMap().get("query").toString();
46 assertEquals(token3.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +000047
48 // [!p!=NN]
Joachim Bingel0900a892014-06-30 16:26:21 +000049 query = "[!p!=NN]";
50 String token4 = "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}";
51 ppt = new PoliqarpPlusTree(query);
52 map = ppt.getRequestMap().get("query").toString();
53 assertEquals(token4.replaceAll(" ", ""), map.replaceAll(" ", ""));
54
Joachim Bingeld1a3e712014-07-16 08:02:05 +000055 query = "[base=schland/x]";
Joachim Bingela83f8cc2014-08-05 14:12:59 +000056 String token5 = "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=.*?schland.*?, match=match:eq, type=type:regex}}";
Joachim Bingeld1a3e712014-07-16 08:02:05 +000057 ppt = new PoliqarpPlusTree(query);
58 map = ppt.getRequestMap().get("query").toString();
59 assertEquals(token5.replaceAll(" ", ""), map.replaceAll(" ", ""));
60 }
61
62 @Test
63 public void testValue() throws QueryException {
Joachim Bingeld1a3e712014-07-16 08:02:05 +000064 query = "[mate/m=temp:pres]";
65 String value1 = "{@type=korap:token, wrap={@type=korap:term, foundry=mate, layer=m, key=temp, value=pres, match=match:eq}}";
66 ppt = new PoliqarpPlusTree(query);
67 map = ppt.getRequestMap().get("query").toString();
68 assertEquals(value1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +000069 }
70
71 @Test
Joachim Bingel41e112e2014-02-12 10:46:18 +000072 public void testRegex() throws QueryException {
Joachim Bingel832800e2014-10-17 14:46:39 +000073 query = "[orth=\"M(a|ä)nn(er)?\"]";
Joachim Bingel0900a892014-06-30 16:26:21 +000074 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 +000075 ppt = new PoliqarpPlusTree(query);
76 map = ppt.getRequestMap().get("query").toString();
77 assertEquals(re1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel0900a892014-06-30 16:26:21 +000078
79 query = "[orth=\"M(a|ä)nn(er)?\"/x]";
80 String re2 = "{@type=korap:token, wrap={@type=korap:term, layer=orth, type=type:regex, key=.*?M(a|ä)nn(er)?.*?, match=match:eq}}";
81 ppt = new PoliqarpPlusTree(query);
82 map = ppt.getRequestMap().get("query").toString();
83 assertEquals(re2.replaceAll(" ", ""), map.replaceAll(" ", ""));
84
85 query = "\"M(a|ä)nn(er)?\"/x";
86 String re3 = "{@type=korap:token, wrap={@type=korap:term, type=type:regex, layer=orth, key=.*?M(a|ä)nn(er)?.*?, match=match:eq}}";
87 ppt = new PoliqarpPlusTree(query);
88 map = ppt.getRequestMap().get("query").toString();
89 assertEquals(re3.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeld1a3e712014-07-16 08:02:05 +000090
91 query = "schland/x";
Joachim Bingela83f8cc2014-08-05 14:12:59 +000092 String re4 = "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=.*?schland.*?, match=match:eq, type=type:regex}}";
Joachim Bingeld1a3e712014-07-16 08:02:05 +000093 ppt = new PoliqarpPlusTree(query);
94 map = ppt.getRequestMap().get("query").toString();
95 assertEquals(re4.replaceAll(" ", ""), map.replaceAll(" ", ""));
96
97 query = "\".*?Mann.*?\"";
98 String re5 = "{@type=korap:token, wrap={@type=korap:term, type=type:regex, layer=orth, key=.*?Mann.*?, match=match:eq}}";
99 ppt = new PoliqarpPlusTree(query);
100 map = ppt.getRequestMap().get("query").toString();
101 assertEquals(re5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingela83f8cc2014-08-05 14:12:59 +0000102
103 query = "z.B./x";
104 String re6 = "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=.*?z\\.B\\..*?, match=match:eq, type=type:regex}}";
105 ppt = new PoliqarpPlusTree(query);
106 map = ppt.getRequestMap().get("query").toString();
107 assertEquals(re6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel41e112e2014-02-12 10:46:18 +0000108 }
109
110 @Test
Joachim Bingel0207d5e2014-02-12 14:18:41 +0000111 public void testCaseSensitivityFlag() throws QueryException {
Joachim Bingel832800e2014-10-17 14:46:39 +0000112 query="[orth=deutscher/i]";
Joachim Bingel0207d5e2014-02-12 14:18:41 +0000113 String cs1 =
Joachim Bingel0900a892014-06-30 16:26:21 +0000114 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=deutscher, match=match:eq, caseInsensitive=true}}";
Joachim Bingel0207d5e2014-02-12 14:18:41 +0000115 ppt = new PoliqarpPlusTree(query);
116 map = ppt.getRequestMap().get("query").toString();
117 assertEquals(cs1.replaceAll(" ", ""), map.replaceAll(" ", ""));
118
119 query="[orth=deutscher/i][orth=Bundestag]";
120 String cs2 =
121 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000122 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=deutscher, match=match:eq, caseInsensitive=true}}," +
123 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Bundestag, match=match:eq}}" +
Joachim Bingel0207d5e2014-02-12 14:18:41 +0000124 "]}";
125 ppt = new PoliqarpPlusTree(query);
126 map = ppt.getRequestMap().get("query").toString();
127 assertEquals(cs2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeladd0fb12014-06-24 08:54:14 +0000128
129 query="deutscher/i";
130 String cs3 =
Joachim Bingel0900a892014-06-30 16:26:21 +0000131 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=deutscher, match=match:eq, caseInsensitive=true}}";
Joachim Bingeladd0fb12014-06-24 08:54:14 +0000132 ppt = new PoliqarpPlusTree(query);
133 map = ppt.getRequestMap().get("query").toString();
134 assertEquals(cs3.replaceAll(" ", ""), map.replaceAll(" ", ""));
135
136 query="deutscher/i Bundestag";
137 String cs4 =
138 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000139 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=deutscher, match=match:eq, caseInsensitive=true}}," +
140 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Bundestag, match=match:eq}}" +
Joachim Bingeladd0fb12014-06-24 08:54:14 +0000141 "]}";
142 ppt = new PoliqarpPlusTree(query);
143 map = ppt.getRequestMap().get("query").toString();
144 assertEquals(cs4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000145
146 query="deutscher Bundestag/i";
147 String cs5 =
148 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000149 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=deutscher, match=match:eq}}," +
150 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Bundestag, match=match:eq, caseInsensitive=true}}" +
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000151 "]}";
152 ppt = new PoliqarpPlusTree(query);
153 map = ppt.getRequestMap().get("query").toString();
154 assertEquals(cs5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel0207d5e2014-02-12 14:18:41 +0000155 }
156
157 @Test
Joachim Bingel3a41a442014-07-22 12:16:16 +0000158 public void testSpans() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000159 // <s>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000160 String elem1 = "{@type=korap:span, key=s}";
Joachim Bingel53333e62013-12-09 19:25:52 +0000161 assertTrue(equalsQueryContent(elem1, "<s>"));
162
163 // <vp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000164 String elem2 = "{@type=korap:span, key=vp}";
Joachim Bingel53333e62013-12-09 19:25:52 +0000165 assertTrue(equalsQueryContent(elem2, "<vp>"));
Joachim Bingelfc1fb352014-02-26 14:40:27 +0000166
167 // <cnx/c=vp>
168 query = "<c=vp>";
169 String span3 = "{@type=korap:span, layer=c, key=vp}";
170 ppt = new PoliqarpPlusTree(query);
171 map = ppt.getRequestMap().get("query").toString();
172 assertEquals(span3.replaceAll(" ", ""), map.replaceAll(" ", ""));
173
174 // <cnx/c=vp>
175 query = "<cnx/c=vp>";
176 String span4 = "{@type=korap:span, foundry=cnx, layer=c, key=vp}";
177 ppt = new PoliqarpPlusTree(query);
178 map = ppt.getRequestMap().get("query").toString();
179 assertEquals(span4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel3a41a442014-07-22 12:16:16 +0000180
181 // span negation
182 query = "<cnx/c!=vp>";
183 expected = "{@type=korap:span, foundry=cnx, layer=c, key=vp, match=match:ne}";
184 ppt = new PoliqarpPlusTree(query);
185 map = ppt.getRequestMap().get("query").toString();
186 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
187
188 // span negation
189 query = "<cnx/c!=vp>";
190 expected = "{@type=korap:span, foundry=cnx, layer=c, key=vp, match=match:ne}";
191 ppt = new PoliqarpPlusTree(query);
192 map = ppt.getRequestMap().get("query").toString();
193 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
194
195 query = "<cnx/c=vp class!=header>";
196 expected = "{@type=korap:span, foundry=cnx, layer=c, key=vp, attr={@type=korap:term, key=class, value=header, match=match:ne}}";
197 ppt = new PoliqarpPlusTree(query);
198 map = ppt.getRequestMap().get("query").toString();
199 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
200
201 query = "<cnx/c=vp !(class=header&id=7)>";
202 expected =
203 "{@type=korap:span, foundry=cnx, layer=c, key=vp, attr=" +
204 "{@type=korap:termGroup, relation=relation:and, operands=[" +
205 "{@type=korap:term, key=class, value=header, match=match:ne}," +
206 "{@type=korap:term, key=id, value=7, match=match:ne}" +
207 "]}" +
208 "}";
209 ppt = new PoliqarpPlusTree(query);
210 map = ppt.getRequestMap().get("query").toString();
211 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
212
213 query = "<cnx/c!=vp (class=header&id=7)>";
214 expected =
215 "{@type=korap:span, foundry=cnx, layer=c, key=vp, match=match:ne, attr=" +
216 "{@type=korap:termGroup, relation=relation:and, operands=[" +
217 "{@type=korap:term, key=class, value=header, match=match:eq}," +
218 "{@type=korap:term, key=id, value=7, match=match:eq}" +
219 "]}" +
220 "}";
221 ppt = new PoliqarpPlusTree(query);
222 map = ppt.getRequestMap().get("query").toString();
223 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
224
225 query = "<cnx/c=vp !!class=header>";
226 expected = "{@type=korap:span, foundry=cnx, layer=c, key=vp, attr={@type=korap:term, key=class, value=header, match=match:eq}}";
227 ppt = new PoliqarpPlusTree(query);
228 map = ppt.getRequestMap().get("query").toString();
229 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingela0ef08f2014-07-24 08:27:57 +0000230
231 query = "<cnx/c!=vp (foundry/class=header&id=7)>";
232 expected =
233 "{@type=korap:span, foundry=cnx, layer=c, key=vp, match=match:ne, attr=" +
234 "{@type=korap:termGroup, relation=relation:and, operands=[" +
235 "{@type=korap:term, foundry=foundry, key=class, value=header, match=match:eq}," +
236 "{@type=korap:term, key=id, value=7, match=match:eq}" +
237 "]}" +
238 "}";
239 ppt = new PoliqarpPlusTree(query);
240 map = ppt.getRequestMap().get("query").toString();
241 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000242 }
Joachim Bingel87480d02014-01-17 14:07:46 +0000243
244 @Test
Joachim Bingel14239d82014-07-22 09:55:04 +0000245 public void testDistances() throws QueryException {
Joachim Bingel87480d02014-01-17 14:07:46 +0000246 // [base=der][][base=Mann]
247 String et1 =
Joachim Bingel0900a892014-06-30 16:26:21 +0000248 "{@type=korap:group, operation=operation:sequence, " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000249 "operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000250 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
251 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
252 "], inOrder=true, distances=[" +
Joachim Bingel5a146cd2014-07-24 14:44:57 +0000253 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=2, max=2}, min=2, max=2}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000254 "]}";
255 ppt = new PoliqarpPlusTree("[base=der][][base=Mann]");
256 map = ppt.getRequestMap().get("query").toString();
257 assertEquals(et1.replaceAll(" ", ""), map.replaceAll(" ", ""));
258
259 // [base=der][][][base=Mann]
260 String et2 =
Joachim Bingel0900a892014-06-30 16:26:21 +0000261 "{@type=korap:group, operation=operation:sequence, " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000262 "operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000263 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
264 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
265 "], inOrder=true, distances=[" +
Joachim Bingel5a146cd2014-07-24 14:44:57 +0000266 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=3, max=3}, min=3, max=3}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000267 "]}";
Joachim Bingelffd65e32014-01-22 14:22:57 +0000268 ppt = new PoliqarpPlusTree("[base=der][][][base=Mann]");
Joachim Bingel87480d02014-01-17 14:07:46 +0000269 map = ppt.getRequestMap().get("query").toString();
270 assertEquals(et2.replaceAll(" ", ""), map.replaceAll(" ", ""));
271
272 // [base=der][][]?[base=Mann]
273 String et3 =
Joachim Bingel0900a892014-06-30 16:26:21 +0000274 "{@type=korap:group, operation=operation:sequence, " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000275 "operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000276 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
277 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
278 "], inOrder=true, distances=[" +
Joachim Bingel5a146cd2014-07-24 14:44:57 +0000279 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=2, max=3}, min=2, max=3}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000280 "]}";
281 ppt = new PoliqarpPlusTree("[base=der][][]?[base=Mann]");
282 map = ppt.getRequestMap().get("query").toString();
283 assertEquals(et3.replaceAll(" ", ""), map.replaceAll(" ", ""));
284
Joachim Bingel87480d02014-01-17 14:07:46 +0000285
Joachim Bingel14239d82014-07-22 09:55:04 +0000286
Joachim Bingelffd65e32014-01-22 14:22:57 +0000287
Joachim Bingel11d5b152014-02-11 21:33:47 +0000288 // [base=der][]{2,5}[base=Mann][]?[][base=Frau] nested distances=
Joachim Bingelffd65e32014-01-22 14:22:57 +0000289 String et5 =
Joachim Bingel0900a892014-06-30 16:26:21 +0000290 "{@type=korap:group, operation=operation:sequence," +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000291 "operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000292 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
293 "{@type=korap:group, operation=operation:sequence, " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000294 "operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000295 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}," +
296 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Frau, match=match:eq}}" +
297 "], inOrder=true, distances=[" +
Joachim Bingel5a146cd2014-07-24 14:44:57 +0000298 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=2, max=3}, min=2, max=3}" +
Joachim Bingelffd65e32014-01-22 14:22:57 +0000299 "]}" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000300 "], inOrder=true, distances=[" +
Joachim Bingel5a146cd2014-07-24 14:44:57 +0000301 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=3, max=6}, min=3, max=6}" +
Joachim Bingelffd65e32014-01-22 14:22:57 +0000302 "]}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000303 ppt = new PoliqarpPlusTree("[base=der][]{2,5}[base=Mann][]?[][base=Frau]");
Joachim Bingel87480d02014-01-17 14:07:46 +0000304 map = ppt.getRequestMap().get("query").toString();
305 assertEquals(et5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel87480d02014-01-17 14:07:46 +0000306
Joachim Bingelc15720f2014-05-07 14:37:23 +0000307 // [base=der][]*[base=Mann]
308 String et6 =
Joachim Bingel0900a892014-06-30 16:26:21 +0000309 "{@type=korap:group, operation=operation:sequence, " +
Joachim Bingelc15720f2014-05-07 14:37:23 +0000310 "operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000311 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
312 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
313 "], inOrder=true, distances=[" +
Joachim Bingel687e4d42014-07-30 09:34:18 +0000314 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1}, min=1}" +
Joachim Bingelc15720f2014-05-07 14:37:23 +0000315 "]}";
316 ppt = new PoliqarpPlusTree("[base=der][]*[base=Mann]");
317 map = ppt.getRequestMap().get("query").toString();
318 assertEquals(et6.replaceAll(" ", ""), map.replaceAll(" ", ""));
319
Joachim Bingel0900a892014-06-30 16:26:21 +0000320 // [base=der][]+[base=Mann]
Joachim Bingelc15720f2014-05-07 14:37:23 +0000321 String et7 =
Joachim Bingel0900a892014-06-30 16:26:21 +0000322 "{@type=korap:group, operation=operation:sequence, " +
Joachim Bingelc15720f2014-05-07 14:37:23 +0000323 "operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000324 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
325 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
326 "], inOrder=true, distances=[" +
Joachim Bingel687e4d42014-07-30 09:34:18 +0000327 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=2}, min=2}" +
Joachim Bingelc15720f2014-05-07 14:37:23 +0000328 "]}";
329 ppt = new PoliqarpPlusTree("[base=der][]+[base=Mann]");
330 map = ppt.getRequestMap().get("query").toString();
331 assertEquals(et7.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel14239d82014-07-22 09:55:04 +0000332
333 // [base=der][]+[base=Mann]
334 String et8 =
335 "{@type=korap:group, operation=operation:sequence, " +
336 "operands=[" +
337 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
338 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
339 "], inOrder=true, distances=[" +
Joachim Bingel687e4d42014-07-30 09:34:18 +0000340 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=2, max=103}, min=2, max=103}" +
Joachim Bingel14239d82014-07-22 09:55:04 +0000341 "]}";
342 ppt = new PoliqarpPlusTree("[base=der][]{1,102}[base=Mann]");
343 map = ppt.getRequestMap().get("query").toString();
344 assertEquals(et8.replaceAll(" ", ""), map.replaceAll(" ", ""));
345
346 // [base=geht][base=der][]*[base=Mann]
347 String et9 =
348 "{@type=korap:group, operation=operation:sequence, operands=[" +
349 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=geht, match=match:eq}}," +
350 "{@type=korap:group, operation=operation:sequence, " +
351 "operands=[" +
352 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
353 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
354 "], inOrder=true, distances=[" +
Joachim Bingel687e4d42014-07-30 09:34:18 +0000355 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1}, min=1}" +
Joachim Bingel14239d82014-07-22 09:55:04 +0000356 "]}" +
357 "]}";
358 ppt = new PoliqarpPlusTree("[base=geht][base=der][]*[base=Mann]");
359 map = ppt.getRequestMap().get("query").toString();
360 assertEquals(et9.replaceAll(" ", ""), map.replaceAll(" ", ""));
361
362 query = "[base=geht][base=der][]*[base=Mann][base=da]";
363 expected =
364 "{@type=korap:group, operation=operation:sequence, operands=[" +
365 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=geht, match=match:eq}}," +
366 "{@type=korap:group, operation=operation:sequence, " +
367 "operands=[" +
368 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
369 "{@type=korap:group, operation=operation:sequence, operands=[" +
370 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}," +
371 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=da, match=match:eq}}" +
372 "]}" +
373 "], inOrder=true, distances=[" +
Joachim Bingel687e4d42014-07-30 09:34:18 +0000374 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1}, min=1}" +
Joachim Bingel14239d82014-07-22 09:55:04 +0000375 "]}" +
376 "]}";
377 ppt = new PoliqarpPlusTree(query);
378 map = ppt.getRequestMap().get("query").toString();
379 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
380
381 query = "[base=geht][base=der][]*contains(<s>,<np>)";
382 expected =
383 "{@type=korap:group, operation=operation:sequence, operands=[" +
384 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=geht, match=match:eq}}," +
385 "{@type=korap:group, operation=operation:sequence, " +
386 "operands=[" +
387 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
Joachim Bingel832800e2014-10-17 14:46:39 +0000388 "{@type=korap:group, operation=operation:position, frames=[frames:contains], operands=[" +
Joachim Bingel14239d82014-07-22 09:55:04 +0000389 "{@type=korap:span, key=s}," +
390 "{@type=korap:span, key=np}" +
Joachim Bingel6b52d762014-09-30 15:29:11 +0000391 "], frame=frame:contains}" +
Joachim Bingel14239d82014-07-22 09:55:04 +0000392 "], inOrder=true, distances=[" +
Joachim Bingel687e4d42014-07-30 09:34:18 +0000393 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1}, min=1}" +
Joachim Bingel14239d82014-07-22 09:55:04 +0000394 "]}" +
395 "]}";
396 ppt = new PoliqarpPlusTree(query);
397 map = ppt.getRequestMap().get("query").toString();
398 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel87480d02014-01-17 14:07:46 +0000399 }
Joachim Bingel53333e62013-12-09 19:25:52 +0000400
401 @Test
Joachim Bingelbd386362014-10-02 12:03:18 +0000402 public void testDistancesWithClass() throws QueryException {
403 query = "[base=der]{1:[]}[base=Mann]";
404 expected =
405 "{@type=korap:group, operation=operation:sequence, operands=[" +
406 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
Joachim Bingel832800e2014-10-17 14:46:39 +0000407 "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" +
Joachim Bingelbd386362014-10-02 12:03:18 +0000408 "{@type=korap:token}" +
409 "]}," +
410 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
411 "]}";
412 ppt = new PoliqarpPlusTree(query);
413 map = ppt.getRequestMap().get("query").toString();
414 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
415
416 query = "{1:[]}[base=der][base=Mann]";
417 expected =
418 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel832800e2014-10-17 14:46:39 +0000419 "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" +
Joachim Bingelbd386362014-10-02 12:03:18 +0000420 "{@type=korap:token}" +
421 "]}," +
422 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
423 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
424 "]}";
425 ppt = new PoliqarpPlusTree(query);
426 map = ppt.getRequestMap().get("query").toString();
427 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
428 }
429
430 @Test
Joachim Bingel14239d82014-07-22 09:55:04 +0000431 public void testLeadingTrailingEmptyTokens() throws QueryException {
432 // startswith(<s>, [][base=Mann]
433 String et1 =
Joachim Bingel832800e2014-10-17 14:46:39 +0000434 "{@type=korap:group, operation=operation:position, frames=[frames:startswith], operands=[" +
Joachim Bingel14239d82014-07-22 09:55:04 +0000435 "{@type=korap:span, key=s}," +
436 "{@type=korap:group, operation=operation:sequence, operands=[" +
437 "{@type=korap:token}," +
438 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
439 "]}" +
Joachim Bingel6b52d762014-09-30 15:29:11 +0000440 "], frame=frame:startswith}";
Joachim Bingel14239d82014-07-22 09:55:04 +0000441 ppt = new PoliqarpPlusTree("startswith(<s>, [][base=Mann])");
442 map = ppt.getRequestMap().get("query").toString();
443 assertEquals(et1.replaceAll(" ", ""), map.replaceAll(" ", ""));
444
445 query = "[][base=Mann]";
446 expected =
447 "{@type=korap:group, operation=operation:sequence, operands=[" +
448 "{@type=korap:token}," +
449 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
450 "]}";
451 ppt = new PoliqarpPlusTree(query);
452 map = ppt.getRequestMap().get("query").toString();
453 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
454
Joachim Bingelf8e8b542014-10-22 14:58:27 +0000455 query = "{[]}[base=Mann]";
456 expected =
457 "{@type=korap:group, operation=operation:sequence, operands=[" +
458 "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" +
459 "{@type=korap:token}" +
460 "]}," +
461 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
462 "]}";
463 ppt = new PoliqarpPlusTree(query);
464 map = ppt.getRequestMap().get("query").toString();
465 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
466
Joachim Bingel14239d82014-07-22 09:55:04 +0000467 query = "[][][base=Mann]";
468 expected =
469 "{@type=korap:group, operation=operation:sequence, operands=[" +
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 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
474 "]}";
475 ppt = new PoliqarpPlusTree(query);
476 map = ppt.getRequestMap().get("query").toString();
477 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
478
479 query = "[][]*[base=Mann]";
480 expected =
481 "{@type=korap:group, operation=operation:sequence, operands=[" +
482 "{@type=korap:group, operation=operation:repetition, operands=[" +
483 "{@type=korap:token}" +
Joachim Bingel687e4d42014-07-30 09:34:18 +0000484 "], boundary={@type=korap:boundary, min=1}, min=1}," +
Joachim Bingel14239d82014-07-22 09:55:04 +0000485 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
486 "]}";
487 ppt = new PoliqarpPlusTree(query);
488 map = ppt.getRequestMap().get("query").toString();
489 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
490
491 query = "[][]*[base=Mann][][]";
492 expected =
493 "{@type=korap:group, operation=operation:sequence, operands=[" +
494 "{@type=korap:group, operation=operation:repetition, operands=[" +
495 "{@type=korap:token}" +
Joachim Bingel687e4d42014-07-30 09:34:18 +0000496 "], boundary={@type=korap:boundary, min=1}, min=1}," +
Joachim Bingel14239d82014-07-22 09:55:04 +0000497 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}," +
498 "{@type=korap:group, operation=operation:repetition, operands=[" +
499 "{@type=korap:token}" +
Joachim Bingel61631562014-07-24 14:26:02 +0000500 "], boundary={@type=korap:boundary, min=2, max=2}, min=2, max=2}" +
Joachim Bingel14239d82014-07-22 09:55:04 +0000501 "]}";
502 ppt = new PoliqarpPlusTree(query);
503 map = ppt.getRequestMap().get("query").toString();
504 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
505
506 query = "[][]*contains(<s>, <np>)[][]";
507 expected =
508 "{@type=korap:group, operation=operation:sequence, operands=[" +
509 "{@type=korap:group, operation=operation:repetition, operands=[" +
510 "{@type=korap:token}" +
Joachim Bingel687e4d42014-07-30 09:34:18 +0000511 "], boundary={@type=korap:boundary, min=1}, min=1}," +
Joachim Bingel832800e2014-10-17 14:46:39 +0000512 "{@type=korap:group, operation=operation:position, frames=[frames:contains], operands=[" +
Joachim Bingel14239d82014-07-22 09:55:04 +0000513 "{@type=korap:span, key=s}," +
514 "{@type=korap:span, key=np}" +
Joachim Bingel6b52d762014-09-30 15:29:11 +0000515 "], frame=frame:contains}," +
Joachim Bingel14239d82014-07-22 09:55:04 +0000516 "{@type=korap:group, operation=operation:repetition, operands=[" +
517 "{@type=korap:token}" +
Joachim Bingel61631562014-07-24 14:26:02 +0000518 "], boundary={@type=korap:boundary, min=2, max=2}, min=2, max=2}" +
Joachim Bingel14239d82014-07-22 09:55:04 +0000519 "]}";
520 ppt = new PoliqarpPlusTree(query);
521 map = ppt.getRequestMap().get("query").toString();
522 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb46e1082014-11-05 13:00:01 +0000523
524 query = "[base=Mann][]{2}";
525 expected =
526 "{@type=korap:group, operation=operation:sequence, operands=[" +
527 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}," +
528 "{@type=korap:group, operation=operation:repetition, operands=[" +
529 "{@type=korap:token}" +
530 "], boundary={@type=korap:boundary, min=2, max=2}, min=2, max=2}" +
531 "]}";
532 ppt = new PoliqarpPlusTree(query);
533 map = ppt.getRequestMap().get("query").toString();
534 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel14239d82014-07-22 09:55:04 +0000535 }
536
537 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000538 public void testCoordinatedFields() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000539 // [base=Mann&(cas=N|cas=A)]
540 String cof1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000541 "{@type=korap:token, wrap=" +
Joachim Bingel2980bda2014-04-04 12:09:46 +0000542 "{@type=korap:termGroup, relation=relation:and, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000543 "{@type=korap:term, layer=lemma, key=Mann, match=match:eq}," +
Joachim Bingel2980bda2014-04-04 12:09:46 +0000544 "{@type=korap:termGroup, relation=relation:or, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000545 "{@type=korap:term, layer=cas, key=N, match=match:eq}," +
546 "{@type=korap:term, layer=cas, key=A, match=match:eq}" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000547 "]}" +
548 "]}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000549 "}";
550 ppt = new PoliqarpPlusTree("[base=Mann&(cas=N|cas=A)]");
551 map = ppt.getRequestMap().get("query").toString();
552 assertEquals(cof1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Nils Diewald7d486c22013-12-13 16:32:18 +0000553
554
555 assertEquals(
556 new PoliqarpPlusTree(" [ base=Mann & ( cas=N | cas=A)] ").getRequestMap().get("query").toString(),
557 new PoliqarpPlusTree("[base=Mann &(cas=N|cas=A)]").getRequestMap().get("query").toString()
558 );
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000559
560 // [base=Mann&cas=N&gen=m]
561 String cof2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000562 "{@type=korap:token, wrap=" +
Joachim Bingel2980bda2014-04-04 12:09:46 +0000563 "{@type=korap:termGroup, relation=relation:and, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000564 "{@type=korap:term, layer=lemma, key=Mann, match=match:eq}," +
565 "{@type=korap:termGroup, relation=relation:and, operands=[" +
566 "{@type=korap:term, layer=cas, key=N, match=match:eq}," +
567 "{@type=korap:term, layer=gen, key=m, match=match:eq}" +
568 "]}" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000569 "]}" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000570 "}";
571 ppt = new PoliqarpPlusTree("[base=Mann&cas=N&gen=m]");
572 map = ppt.getRequestMap().get("query").toString();
573 assertEquals(cof2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000574 }
575
576 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000577 public void testOccurrence() throws QueryException {
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000578 // [base=foo]*
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000579 String occ1 = "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000580 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingel687e4d42014-07-30 09:34:18 +0000581 "], boundary={@type=korap:boundary, min=0}, min=0}";
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000582 ppt = new PoliqarpPlusTree("[base=foo]*");
583 map = ppt.getRequestMap().get("query").toString();
584 assertEquals(occ1.replaceAll(" ", ""), map.replaceAll(" ", ""));
585
586 // [base=foo]*[base=bar]
587 String occ2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000588 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000589 "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000590 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingel687e4d42014-07-30 09:34:18 +0000591 "], boundary={@type=korap:boundary, min=0}, min=0 }," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000592 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000593 "]}";
594 ppt = new PoliqarpPlusTree("[base=foo]*[base=bar]");
595 map = ppt.getRequestMap().get("query").toString();
596 assertEquals(occ2.replaceAll(" ", ""), map.replaceAll(" ", ""));
597
598 // [base=bar][base=foo]*
599 String occ3 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000600 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000601 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000602 "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000603 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingel687e4d42014-07-30 09:34:18 +0000604 "], boundary={@type=korap:boundary, min=0}, min=0 }" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000605 "]}";
606 ppt = new PoliqarpPlusTree("[base=bar][base=foo]*");
607 map = ppt.getRequestMap().get("query").toString();
608 assertEquals(occ3.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb4da7022013-12-09 23:17:24 +0000609
610 // ([base=bar][base=foo])*
611 String occ4 =
Joachim Bingel0900a892014-06-30 16:26:21 +0000612 "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000613 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000614 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," +
615 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000616 "]}" +
Joachim Bingel687e4d42014-07-30 09:34:18 +0000617 "], boundary={@type=korap:boundary, min=0}, min=0}" ;
Joachim Bingelb4da7022013-12-09 23:17:24 +0000618 ppt = new PoliqarpPlusTree("([base=bar][base=foo])*");
619 map = ppt.getRequestMap().get("query").toString();
620 assertEquals(occ4.replaceAll(" ", ""), map.replaceAll(" ", ""));
621
622 // <s>([base=bar][base=foo])*
623 String occ5 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000624 "{@type=korap:group, operation=operation:sequence, operands=[" +
625 "{@type=korap:span, key=s}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000626 "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000627 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000628 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," +
629 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000630 "]}" +
Joachim Bingel687e4d42014-07-30 09:34:18 +0000631 "], boundary={@type=korap:boundary, min=0}, min=0 }" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000632 "]}" ;
633 ppt = new PoliqarpPlusTree("<s>([base=bar][base=foo])*");
634 map = ppt.getRequestMap().get("query").toString();
635 assertEquals(occ5.replaceAll(" ", ""), map.replaceAll(" ", ""));
636
637 // <s><np>([base=bar][base=foo])*
Joachim Bingelb4da7022013-12-09 23:17:24 +0000638 String occ6 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000639 "{@type=korap:group, operation=operation:sequence, operands=[" +
640 "{@type=korap:span, key=s}," +
641 "{@type=korap:span, key=np}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000642 "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000643 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000644 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," +
645 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000646 "]}" +
Joachim Bingel687e4d42014-07-30 09:34:18 +0000647 "], boundary={@type=korap:boundary, min=0}, min=0 }" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000648 "]}" ;
649 ppt = new PoliqarpPlusTree("<s><np>([base=bar][base=foo])*");
650 map = ppt.getRequestMap().get("query").toString();
651 assertEquals(occ6.replaceAll(" ", ""), map.replaceAll(" ", ""));
652
653 // <s><np>([base=bar][base=foo])*[p=NN]
654 // comment: embedded sequence shouldn't really be here, but does not really hurt, either. (?)
655 // really hard to get this behaviour out of the PQPlus grammar...
656 String occ7 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000657 "{@type=korap:group, operation=operation:sequence, operands=[" +
658 "{@type=korap:span, key=s}," +
659 "{@type=korap:span, key=np}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000660 "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000661 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000662 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," +
663 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000664 "]}" +
Joachim Bingel687e4d42014-07-30 09:34:18 +0000665 "], boundary={@type=korap:boundary, min=0}, min=0 }," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000666 "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000667 "]}" ;
668 ppt = new PoliqarpPlusTree("<s><np>([base=bar][base=foo])*[p=NN]");
669 map = ppt.getRequestMap().get("query").toString();
670 assertEquals(occ7.replaceAll(" ", ""), map.replaceAll(" ", ""));
671
672 // ([base=bar][base=foo])*[p=NN]
Joachim Bingelb4da7022013-12-09 23:17:24 +0000673 String occ8 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000674 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000675 "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000676 "{@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=bar, match=match:eq}}," +
678 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000679 "]}" +
Joachim Bingel687e4d42014-07-30 09:34:18 +0000680 "], boundary={@type=korap:boundary, min=0}, min=0 }," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000681 "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000682 "]}" ;
683 ppt = new PoliqarpPlusTree("([base=bar][base=foo])*[p=NN]");
684 map = ppt.getRequestMap().get("query").toString();
685 assertEquals(occ8.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000686
687 // [base=foo]+
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000688 String occ9 = "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000689 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingel687e4d42014-07-30 09:34:18 +0000690 "], boundary={@type=korap:boundary, min=1}, min=1}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000691 ppt = new PoliqarpPlusTree("[base=foo]+");
692 map = ppt.getRequestMap().get("query").toString();
693 assertEquals(occ9.replaceAll(" ", ""), map.replaceAll(" ", ""));
694
695 // [base=foo]?
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000696 String occ10 = "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000697 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingel61631562014-07-24 14:26:02 +0000698 "], boundary={@type=korap:boundary, min=0, max=1}, min=0, max=1}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000699 ppt = new PoliqarpPlusTree("[base=foo]?");
700 map = ppt.getRequestMap().get("query").toString();
701 assertEquals(occ10.replaceAll(" ", ""), map.replaceAll(" ", ""));
702
703 // [base=foo]{2,5}
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000704 String occ11 = "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000705 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingel61631562014-07-24 14:26:02 +0000706 "], boundary={@type=korap:boundary, min=2, max=5}, min=2, max=5}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000707 ppt = new PoliqarpPlusTree("[base=foo]{2,5}");
708 map = ppt.getRequestMap().get("query").toString();
709 assertEquals(occ11.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel2980bda2014-04-04 12:09:46 +0000710
711 // [base=foo]{2}
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000712 String occ12 = "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000713 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingel61631562014-07-24 14:26:02 +0000714 "], boundary={@type=korap:boundary, min=2, max=2}, min=2, max=2}";
Joachim Bingel2980bda2014-04-04 12:09:46 +0000715 ppt = new PoliqarpPlusTree("[base=foo]{2}");
716 map = ppt.getRequestMap().get("query").toString();
717 assertEquals(occ12.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb2aa1c72014-07-01 12:48:46 +0000718
719 // [base=foo]{2}
720 String occ13 = "{@type=korap:group, operation=operation:repetition, operands=[" +
721 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingel687e4d42014-07-30 09:34:18 +0000722 "], boundary={@type=korap:boundary, min=2}, min=2}";
Joachim Bingelb2aa1c72014-07-01 12:48:46 +0000723 ppt = new PoliqarpPlusTree("[base=foo]{2,}");
724 map = ppt.getRequestMap().get("query").toString();
725 assertEquals(occ13.replaceAll(" ", ""), map.replaceAll(" ", ""));
726
727 // [base=foo]{2}
728 String occ14 = "{@type=korap:group, operation=operation:repetition, operands=[" +
729 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingel61631562014-07-24 14:26:02 +0000730 "], boundary={@type=korap:boundary, min=0, max=2}, min=0, max=2}";
Joachim Bingelb2aa1c72014-07-01 12:48:46 +0000731 ppt = new PoliqarpPlusTree("[base=foo]{,2}");
732 map = ppt.getRequestMap().get("query").toString();
733 assertEquals(occ14.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000734 }
735
736 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000737 public void testTokenSequence() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000738 // [base=Mann][orth=Frau]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000739 String seq1 = "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000740 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}, " +
741 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000742 "]}";
743 assertTrue(equalsQueryContent(seq1, "[base=Mann][orth=Frau]"));
744
745 // [base=Mann][orth=Frau][p=NN]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000746 String seq2 = "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000747 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}, " +
748 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}, " +
749 "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000750 "]}";
751 assertTrue(equalsQueryContent(seq2, "[base=Mann][orth=Frau][p=NN]"));
752 }
753
754 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000755 public void testDisjSegments() throws QueryException {
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000756 // ([base=der]|[base=das])[base=Schild]
757 String disj1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000758 "{@type=korap:group, operation=operation:sequence, operands=[" +
759 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000760 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
761 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=das, match=match:eq}}" +
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000762 "]}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000763 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Schild, match=match:eq}}" +
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000764 "]}";
765 ppt = new PoliqarpPlusTree("([base=der]|[base=das])[base=Schild]");
766 map = ppt.getRequestMap().get("query").toString();
767 assertEquals(disj1.replaceAll(" ", ""), map.replaceAll(" ", ""));
768
769 // [base=Schild]([base=der]|[base=das])
770 String disj2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000771 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000772 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Schild, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000773 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000774 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
775 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=das, match=match:eq}}" +
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000776 "]}" +
777 "]}";
778 ppt = new PoliqarpPlusTree("[base=Schild]([base=der]|[base=das])");
779 map = ppt.getRequestMap().get("query").toString();
780 assertEquals(disj2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel76b498d2014-06-06 12:06:46 +0000781
782 // "([orth=der][base=katze])|([orth=eine][base=baum])"
783 String disj3 =
784 "{@type=korap:group, operation=operation:or, operands=[" +
785 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000786 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
787 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=katze, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000788 "]}," +
789 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000790 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=eine, match=match:eq}}," +
791 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=baum, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000792 "]}" +
793 "]}";
794 ppt = new PoliqarpPlusTree("([orth=der][base=katze])|([orth=eine][base=baum])");
795 map = ppt.getRequestMap().get("query").toString();
796 assertEquals(disj3.replaceAll(" ", ""), map.replaceAll(" ", ""));
797
798 // "[orth=der][base=katze]|[orth=eine][base=baum]"
799 String disj4 =
800 "{@type=korap:group, operation=operation:or, operands=[" +
801 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000802 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
803 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=katze, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000804 "]}," +
805 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000806 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=eine, match=match:eq}}," +
807 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=baum, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000808 "]}" +
809 "]}";
810 ppt = new PoliqarpPlusTree("[orth=der][base=katze]|[orth=eine][base=baum]");
811 map = ppt.getRequestMap().get("query").toString();
812 assertEquals(disj4.replaceAll(" ", ""), map.replaceAll(" ", ""));
813
814 PoliqarpPlusTree ppt1 = new PoliqarpPlusTree("[orth=der][base=katze]|[orth=eine][base=baum]");
815 PoliqarpPlusTree ppt2 = new PoliqarpPlusTree("([orth=der][base=katze])|([orth=eine][base=baum])");
816 assertEquals(ppt1.getRequestMap().toString(), ppt2.getRequestMap().toString());
817
818 // "[orth=der][base=katze]|[orth=der][base=hund]|[orth=der][base=baum]"
819 String disj5 =
820 "{@type=korap:group, operation=operation:or, operands=[" +
821 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000822 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
823 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=katze, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000824 "]}," +
825 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000826 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
827 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=hund, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000828 "]}," +
829 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000830 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
831 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=baum, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000832 "]}" +
833 "]}";
834 ppt = new PoliqarpPlusTree("[orth=der][base=katze]|[orth=der][base=hund]|[orth=der][base=baum]");
835 map = ppt.getRequestMap().get("query").toString();
836 assertEquals(disj5.replaceAll(" ", ""), map.replaceAll(" ", ""));
837
838 // [orth=der]([base=katze]|[base=hund]|[base=baum])
839 String disj6 =
840 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000841 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000842 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000843 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=katze, match=match:eq}}," +
844 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=hund, match=match:eq}}," +
845 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=baum, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000846 "]}" +
847 "]}";
848 ppt = new PoliqarpPlusTree("[orth=der]([base=katze]|[base=hund]|[base=baum])");
849 map = ppt.getRequestMap().get("query").toString();
850 assertEquals(disj6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000851 }
852
853 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000854 public void testTokenElemSequence() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000855 // [base=Mann]<vp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000856 String seq1 = "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000857 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}, " +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000858 "{@type=korap:span, key=vp}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000859 "]}";
860 assertTrue(equalsQueryContent(seq1, "[base=Mann]<vp>"));
861
862 // <vp>[base=Mann]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000863 String seq2 = "{@type=korap:group, operation=operation:sequence, operands=[" +
864 "{@type=korap:span, key=vp}, "+
Joachim Bingel0900a892014-06-30 16:26:21 +0000865 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}} " +
Joachim Bingel53333e62013-12-09 19:25:52 +0000866 "]}";
867 assertTrue(equalsQueryContent(seq2, "<vp>[base=Mann]"));
868
869 // <vp>[base=Mann]<pp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000870 String seq3 = "{@type=korap:group, operation=operation:sequence, operands=[" +
871 "{@type=korap:span, key=vp}, "+
Joachim Bingel0900a892014-06-30 16:26:21 +0000872 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}, " +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000873 "{@type=korap:span, key=pp} "+
Joachim Bingel53333e62013-12-09 19:25:52 +0000874 "]}";
875 assertTrue(equalsQueryContent(seq3, "<vp>[base=Mann]<pp>"));
876 }
877
878 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000879 public void testElemSequence() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000880 // <np><vp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000881 String seq1 = "{@type=korap:group, operation=operation:sequence, operands=[" +
882 "{@type=korap:span, key=np}," +
883 "{@type=korap:span, key=vp}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000884 "]}";
885 assertTrue(equalsQueryContent(seq1, "<np><vp>"));
886
887 // <np><vp><pp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000888 String seq2 = "{@type=korap:group, operation=operation:sequence, operands=[" +
889 "{@type=korap:span, key=np}," +
890 "{@type=korap:span, key=vp}," +
891 "{@type=korap:span, key=pp}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000892 "]}";
893 assertTrue(equalsQueryContent(seq2, "<np><vp><pp>"));
894 }
895
896 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000897 public void testClasses() throws QueryException {
Joachim Bingel0900a892014-06-30 16:26:21 +0000898 String query;
Joachim Bingel53333e62013-12-09 19:25:52 +0000899 // {[base=Mann]}
Joachim Bingel4c0c2012014-10-22 09:35:22 +0000900 String cls1 = "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000901 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000902 "]}";
Joachim Bingel8c640e42014-02-07 16:20:47 +0000903 ppt = new PoliqarpPlusTree("{[base=Mann]}");
904 map = ppt.getRequestMap().get("query").toString();
905 assertEquals(cls1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000906
907 // {[base=Mann][orth=Frau]}
Joachim Bingel0900a892014-06-30 16:26:21 +0000908 query = "{[base=Mann][orth=Frau]}";
Joachim Bingel4c0c2012014-10-22 09:35:22 +0000909 String cls2 = "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000910 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000911 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}," +
912 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000913 "]}" +
914 "]}";
Joachim Bingel0900a892014-06-30 16:26:21 +0000915 ppt = new PoliqarpPlusTree(query);
916 map = ppt.getRequestMap().get("query").toString();
917 assertEquals(cls2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000918
919 // [p=NN]{[base=Mann][orth=Frau]}
Joachim Bingel2daf9862014-02-12 10:18:54 +0000920 String cls3 = "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000921 "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}," +
Joachim Bingel4c0c2012014-10-22 09:35:22 +0000922 "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000923 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000924 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}," +
925 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000926 "]}" +
927 "]}" +
928 "]}";
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000929 ppt = new PoliqarpPlusTree("[p=NN]{[base=Mann][orth=Frau]}");
930 map = ppt.getRequestMap().get("query").toString();
931 assertEquals(cls3.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000932
933 // {[base=Mann][orth=Frau]}[p=NN]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000934 String cls4 = "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel4c0c2012014-10-22 09:35:22 +0000935 "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000936 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000937 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}," +
938 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000939 "]}" +
940 "]}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000941 "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000942 "]}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000943 ppt = new PoliqarpPlusTree("{[base=Mann][orth=Frau]}[p=NN]");
944 map = ppt.getRequestMap().get("query").toString();
945 assertEquals(cls4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000946
947 // {2:{1:[tt/p=ADJA]}[mate/p=NN]}"
Joachim Bingel832800e2014-10-17 14:46:39 +0000948 String cls5 = "{@type=korap:group, operation=operation:class, class=2, classOut=2, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000949 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel832800e2014-10-17 14:46:39 +0000950 "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000951 "{@type=korap:token, wrap={@type=korap:term, foundry=tt, layer=p, key=ADJA, match=match:eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000952 "]}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000953 "{@type=korap:token, wrap={@type=korap:term, foundry=mate, layer=p, key=NN, match=match:eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000954 "]}" +
955 "]}";
956 ppt = new PoliqarpPlusTree("{2: {1:[tt/p=ADJA]}[mate/p=NN]}");
957 map = ppt.getRequestMap().get("query").toString();
958 assertEquals(cls5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000959 }
960
961 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000962 public void testPositions() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000963 // contains(<s>,<np>)
Joachim Bingel832800e2014-10-17 14:46:39 +0000964 String pos1 = "{@type=korap:group, operation=operation:position, frames=[frames:contains], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000965 "{@type=korap:span, key=s}," +
966 "{@type=korap:span, key=np}" +
Joachim Bingel6b52d762014-09-30 15:29:11 +0000967 "], frame=frame:contains}";
Joachim Bingel53333e62013-12-09 19:25:52 +0000968 assertTrue(equalsQueryContent(pos1, "contains(<s>,<np>)"));
969
970 // contains(<s>,[base=Mann])
Joachim Bingel832800e2014-10-17 14:46:39 +0000971 String pos2 = "{@type=korap:group, operation=operation:position, frames=[frames:contains], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000972 "{@type=korap:span, key=s}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000973 "{@type=korap:token, wrap= {@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
Joachim Bingel6b52d762014-09-30 15:29:11 +0000974 "], frame=frame:contains}";
Joachim Bingel53333e62013-12-09 19:25:52 +0000975 assertTrue(equalsQueryContent(pos2, "contains(<s>,[base=Mann])"));
976
977 // contains(<s>,[orth=der][orth=Mann])
Joachim Bingel832800e2014-10-17 14:46:39 +0000978 String pos3 = "{@type=korap:group, operation=operation:position, frames=[frames:contains], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000979 "{@type=korap:span, key=s}," +
980 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000981 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
982 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000983 "]}" +
Joachim Bingel6b52d762014-09-30 15:29:11 +0000984 "], frame=frame:contains}";
Joachim Bingel53333e62013-12-09 19:25:52 +0000985 ppt = new PoliqarpPlusTree("contains(<s>,[orth=der][orth=Mann])");
986 map = ppt.getRequestMap().get("query").toString();
987 assertEquals(pos3.replaceAll(" ", ""), map.replaceAll(" ", ""));
988
989 // [base=Auto]contains(<s>,[base=Mann])
990 String pos4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000991 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000992 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Auto, match=match:eq}}," +
Joachim Bingel832800e2014-10-17 14:46:39 +0000993 "{@type=korap:group, operation=operation:position, frames=[frames:contains], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000994 "{@type=korap:span, key=s}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000995 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
Joachim Bingel6b52d762014-09-30 15:29:11 +0000996 "], frame=frame:contains}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000997 "]}";
998 ppt = new PoliqarpPlusTree("[base=Auto]contains(<s>,[base=Mann])");
999 map = ppt.getRequestMap().get("query").toString();
1000 assertEquals(pos4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelef7059b2014-04-22 13:44:19 +00001001
1002 // contains(<s>,[pos=N]*)
1003 String pos5 =
Joachim Bingel832800e2014-10-17 14:46:39 +00001004 "{@type=korap:group, operation=operation:position, frames=[frames:contains], operands=[" +
Joachim Bingelef7059b2014-04-22 13:44:19 +00001005 "{@type=korap:span, key=s}," +
Joachim Bingel33bd45f2014-06-25 15:00:54 +00001006 "{@type=korap:group, operation=operation:repetition, " +
Joachim Bingel0900a892014-06-30 16:26:21 +00001007 "operands=[{@type=korap:token, wrap={@type=korap:term, layer=pos, key=N, match=match:eq}}" +
Joachim Bingel687e4d42014-07-30 09:34:18 +00001008 "], boundary={@type=korap:boundary, min=0}, min=0" +
Joachim Bingelef7059b2014-04-22 13:44:19 +00001009 "}" +
Joachim Bingel6b52d762014-09-30 15:29:11 +00001010 "], frame=frame:contains}";
Joachim Bingelef7059b2014-04-22 13:44:19 +00001011 ppt = new PoliqarpPlusTree("contains(<s>,[pos=N]*)");
1012 map = ppt.getRequestMap().get("query").toString();
1013 assertEquals(pos5.replaceAll(" ", ""), map.replaceAll(" ", ""));
1014
1015 // [base=Auto]contains(<s>,[pos=N]*)
1016 String pos6 =
1017 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001018 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Auto, match=match:eq}}," +
Joachim Bingel832800e2014-10-17 14:46:39 +00001019 "{@type=korap:group, operation=operation:position, frames=[frames:contains], operands=[" +
Joachim Bingelef7059b2014-04-22 13:44:19 +00001020 "{@type=korap:span, key=s}," +
Joachim Bingel33bd45f2014-06-25 15:00:54 +00001021 "{@type=korap:group, operation=operation:repetition, " +
Joachim Bingel0900a892014-06-30 16:26:21 +00001022 "operands=[{@type=korap:token, wrap={@type=korap:term, layer=pos, key=N, match=match:eq}}" +
Joachim Bingel687e4d42014-07-30 09:34:18 +00001023 "], boundary={@type=korap:boundary, min=0}, min=0" +
Joachim Bingelef7059b2014-04-22 13:44:19 +00001024 "}" +
Joachim Bingel6b52d762014-09-30 15:29:11 +00001025 "], frame=frame:contains}" +
Joachim Bingelef7059b2014-04-22 13:44:19 +00001026 "]}";
1027 ppt = new PoliqarpPlusTree("[base=Auto]contains(<s>,[pos=N]*)");
1028 map = ppt.getRequestMap().get("query").toString();
1029 assertEquals(pos6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +00001030 }
1031
1032 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +00001033 public void testNestedPositions() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +00001034 // contains(<s>,startswith(<np>,[orth=Der]))
1035 String npos1 =
Joachim Bingel832800e2014-10-17 14:46:39 +00001036 "{@type=korap:group, operation=operation:position, frames=[frames:contains], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001037 "{@type=korap:span, key=s}," +
Joachim Bingel832800e2014-10-17 14:46:39 +00001038 "{@type=korap:group, operation=operation:position, frames=[frames:startswith], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001039 "{@type=korap:span, key=np}," +
Joachim Bingel0900a892014-06-30 16:26:21 +00001040 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}" +
Joachim Bingel6b52d762014-09-30 15:29:11 +00001041 "], frame=frame:startswith}" +
1042 "], frame=frame:contains}";
Joachim Bingelcd9ed332013-12-09 21:01:35 +00001043 ppt = new PoliqarpPlusTree("contains(<s>, startswith(<np>,[orth=Der]))");
Joachim Bingel53333e62013-12-09 19:25:52 +00001044 map = ppt.getRequestMap().get("query").toString();
1045 assertEquals(npos1.replaceAll(" ", ""), map.replaceAll(" ", ""));
1046 }
1047
1048 @Test
Joachim Bingel23c31ad2014-08-11 09:44:46 +00001049 public void testFocusSplit() throws QueryException {
Joachim Bingel0900a892014-06-30 16:26:21 +00001050 // focus([orth=Der]{[orth=Mann]})
Joachim Bingel53333e62013-12-09 19:25:52 +00001051 String shr1 =
Joachim Bingel4c0c2012014-10-22 09:35:22 +00001052 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001053 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001054 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}," +
Joachim Bingel4c0c2012014-10-22 09:35:22 +00001055 "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001056 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +00001057 "]}" +
1058 "]}" +
1059 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +00001060 ppt = new PoliqarpPlusTree("focus([orth=Der]{[orth=Mann]})");
Joachim Bingel53333e62013-12-09 19:25:52 +00001061 map = ppt.getRequestMap().get("query").toString();
1062 assertEquals(shr1.replaceAll(" ", ""), map.replaceAll(" ", ""));
1063
Joachim Bingel0900a892014-06-30 16:26:21 +00001064 // focus([orth=Der]{[orth=Mann][orth=geht]})
Joachim Bingel53333e62013-12-09 19:25:52 +00001065 String shr2 =
Joachim Bingel4c0c2012014-10-22 09:35:22 +00001066 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001067 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001068 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}," +
Joachim Bingel4c0c2012014-10-22 09:35:22 +00001069 "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001070 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001071 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}," +
1072 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=geht, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +00001073 "]}" +
1074 "]}" +
1075 "]}" +
1076 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +00001077 ppt = new PoliqarpPlusTree("focus([orth=Der]{[orth=Mann][orth=geht]})");
Joachim Bingel53333e62013-12-09 19:25:52 +00001078 map = ppt.getRequestMap().get("query").toString();
1079 assertEquals(shr2.replaceAll(" ", ""), map.replaceAll(" ", ""));
1080
Joachim Bingel0900a892014-06-30 16:26:21 +00001081 // focus(1:[orth=Der]{1:[orth=Mann][orth=geht]})
Joachim Bingel53333e62013-12-09 19:25:52 +00001082 String shr3 =
Joachim Bingeld1a3e712014-07-16 08:02:05 +00001083 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001084 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001085 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}," +
Joachim Bingel832800e2014-10-17 14:46:39 +00001086 "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001087 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001088 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}," +
1089 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=geht, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +00001090 "]}" +
1091 "]}" +
1092 "]}" +
1093 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +00001094 ppt = new PoliqarpPlusTree("focus(1:[orth=Der]{1:[orth=Mann][orth=geht]})");
Joachim Bingel53333e62013-12-09 19:25:52 +00001095 map = ppt.getRequestMap().get("query").toString();
1096 assertEquals(shr3.replaceAll(" ", ""), map.replaceAll(" ", ""));
1097
Joachim Bingel0900a892014-06-30 16:26:21 +00001098 // focus(1:startswith(<s>,{1:<np>}))
Joachim Bingel53333e62013-12-09 19:25:52 +00001099 String shr4 =
Joachim Bingeld1a3e712014-07-16 08:02:05 +00001100 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingel832800e2014-10-17 14:46:39 +00001101 "{@type=korap:group, operation=operation:position, frames=[frames:startswith], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001102 "{@type=korap:span, key=s}," +
Joachim Bingel832800e2014-10-17 14:46:39 +00001103 "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001104 "{@type=korap:span, key=np}" +
Joachim Bingel53333e62013-12-09 19:25:52 +00001105 "]}" +
Joachim Bingel6b52d762014-09-30 15:29:11 +00001106 "], frame=frame:startswith}" +
Joachim Bingel53333e62013-12-09 19:25:52 +00001107 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +00001108 ppt = new PoliqarpPlusTree("focus(1:startswith(<s>,{1:<np>}))");
Joachim Bingel53333e62013-12-09 19:25:52 +00001109 map = ppt.getRequestMap().get("query").toString();
1110 assertEquals(shr4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelcd9ed332013-12-09 21:01:35 +00001111
Joachim Bingel0900a892014-06-30 16:26:21 +00001112 // focus(3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))
Joachim Bingelcd9ed332013-12-09 21:01:35 +00001113 String shr5 =
Joachim Bingeld1a3e712014-07-16 08:02:05 +00001114 "{@type=korap:reference, operation=operation:focus, classRef=[3], operands=[" +
Joachim Bingel832800e2014-10-17 14:46:39 +00001115 "{@type=korap:group, operation=operation:position, frames=[frames:startswith], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001116 "{@type=korap:span, key=s}," +
Joachim Bingel832800e2014-10-17 14:46:39 +00001117 "{@type=korap:group, operation=operation:class, class=3, classOut=3, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001118 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001119 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
Joachim Bingel832800e2014-10-17 14:46:39 +00001120 "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001121 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001122 "{@type=korap:token, wrap={@type=korap:term, foundry=mate, layer=p, key=ADJA, match=match:eq}}," +
Joachim Bingel832800e2014-10-17 14:46:39 +00001123 "{@type=korap:group, operation=operation:class, class=2, classOut=2, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001124 "{@type=korap:token, wrap={@type=korap:term, foundry=tt, layer=p, key=NN, match=match:eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +00001125 "]}" +
1126 "]}" +
1127 "]}" +
1128 "]}" +
1129 "]}" +
Joachim Bingel6b52d762014-09-30 15:29:11 +00001130 "], frame=frame:startswith}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +00001131 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +00001132 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 +00001133 map = ppt.getRequestMap().get("query").toString();
1134 assertEquals(shr5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelba9a0ab2014-01-29 10:12:25 +00001135
1136 // split(3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))
1137 String shr6 =
Joachim Bingeld1a3e712014-07-16 08:02:05 +00001138 "{@type=korap:reference, operation=operation:split, classRef=[3], operands=[" +
Joachim Bingel832800e2014-10-17 14:46:39 +00001139 "{@type=korap:group, operation=operation:position, frames=[frames:startswith], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001140 "{@type=korap:span, key=s}," +
Joachim Bingel832800e2014-10-17 14:46:39 +00001141 "{@type=korap:group, operation=operation:class, class=3, classOut=3, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001142 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001143 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
Joachim Bingel832800e2014-10-17 14:46:39 +00001144 "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001145 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001146 "{@type=korap:token, wrap={@type=korap:term, foundry=mate, layer=p, key=ADJA, match=match:eq}}," +
Joachim Bingel832800e2014-10-17 14:46:39 +00001147 "{@type=korap:group, operation=operation:class, class=2, classOut=2, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001148 "{@type=korap:token, wrap={@type=korap:term, foundry=tt, layer=p, key=NN, match=match:eq}}" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +00001149 "]}" +
1150 "]}" +
1151 "]}" +
1152 "]}" +
1153 "]}" +
Joachim Bingel6b52d762014-09-30 15:29:11 +00001154 "], frame=frame:startswith}" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +00001155 "]}";
1156 ppt = new PoliqarpPlusTree("split(3:startswith(<s>,{3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) ");
1157 map = ppt.getRequestMap().get("query").toString();
1158 assertEquals(shr6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel8c640e42014-02-07 16:20:47 +00001159
1160 // split(2|3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))
1161 String shr7 =
Joachim Bingeld1a3e712014-07-16 08:02:05 +00001162 "{@type=korap:reference, operation=operation:split, classRef=[2, 3], classRefOp=classRefOp:intersection, operands=[" +
Joachim Bingel832800e2014-10-17 14:46:39 +00001163 "{@type=korap:group, operation=operation:position, frames=[frames:startswith], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001164 "{@type=korap:span, key=s}," +
Joachim Bingel832800e2014-10-17 14:46:39 +00001165 "{@type=korap:group, operation=operation:class, class=3, classOut=3, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001166 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001167 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
Joachim Bingel832800e2014-10-17 14:46:39 +00001168 "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001169 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001170 "{@type=korap:token, wrap={@type=korap:term, foundry=mate, layer=p, key=ADJA, match=match:eq}}," +
Joachim Bingel832800e2014-10-17 14:46:39 +00001171 "{@type=korap:group, operation=operation:class, class=2, classOut=2, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001172 "{@type=korap:token, wrap={@type=korap:term, foundry=tt, layer=p, key=NN, match=match:eq}}" +
Joachim Bingel8c640e42014-02-07 16:20:47 +00001173 "]}" +
1174 "]}" +
1175 "]}" +
1176 "]}" +
1177 "]}" +
Joachim Bingel6b52d762014-09-30 15:29:11 +00001178 "], frame=frame:startswith}" +
Joachim Bingel8c640e42014-02-07 16:20:47 +00001179 "]}";
1180 ppt = new PoliqarpPlusTree("split(2|3:startswith(<s>,{3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) ");
1181 map = ppt.getRequestMap().get("query").toString();
1182 assertEquals(shr7.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel5146ebe2014-06-12 08:49:21 +00001183
1184
1185 String shr8 =
Joachim Bingeld1a3e712014-07-16 08:02:05 +00001186 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingeladd0fb12014-06-24 08:54:14 +00001187 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel4c0c2012014-10-22 09:35:22 +00001188 "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001189 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}" +
Joachim Bingeladd0fb12014-06-24 08:54:14 +00001190 "]}," +
Joachim Bingel832800e2014-10-17 14:46:39 +00001191 "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001192 "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=ADJA, match=match:eq}}" +
Joachim Bingel5146ebe2014-06-12 08:49:21 +00001193 "]}" +
Joachim Bingeladd0fb12014-06-24 08:54:14 +00001194 "]}" +
1195 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +00001196 ppt = new PoliqarpPlusTree("focus(1:{[base=der]}{1:[pos=ADJA]})");
Joachim Bingeladd0fb12014-06-24 08:54:14 +00001197 map = ppt.getRequestMap().get("query").toString();
1198 assertEquals(shr8.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel5146ebe2014-06-12 08:49:21 +00001199
Joachim Bingel53333e62013-12-09 19:25:52 +00001200 }
1201
Joachim Bingel23c31ad2014-08-11 09:44:46 +00001202 @Test
1203 public void testSubspan() throws QueryException {
Joachim Bingel9bbd4fc2014-08-11 14:56:48 +00001204 query = "submatch(1,:<s>)";
Joachim Bingel23c31ad2014-08-11 09:44:46 +00001205 expected =
1206 "{@type=korap:reference, operation=operation:focus, operands=[" +
1207 "{@type=korap:span, key=s}" +
1208 "], spanRef=[1]" +
1209 "}";
1210 ppt = new PoliqarpPlusTree(query);
1211 map = ppt.getRequestMap().get("query").toString();
1212 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1213
Joachim Bingel9bbd4fc2014-08-11 14:56:48 +00001214 query = "submatch(1,4:<s>)";
Joachim Bingel23c31ad2014-08-11 09:44:46 +00001215 expected =
1216 "{@type=korap:reference, operation=operation:focus, operands=[" +
1217 "{@type=korap:span, key=s}" +
1218 "], spanRef=[1,4]" +
1219 "}";
1220 ppt = new PoliqarpPlusTree(query);
1221 map = ppt.getRequestMap().get("query").toString();
1222 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1223
Joachim Bingel9bbd4fc2014-08-11 14:56:48 +00001224 query = "submatch(1,4:contains(<s>,[base=Haus]))";
Joachim Bingel23c31ad2014-08-11 09:44:46 +00001225 expected =
1226 "{@type=korap:reference, operation=operation:focus, operands=[" +
Joachim Bingel832800e2014-10-17 14:46:39 +00001227 "{@type=korap:group, operation=operation:position, frames=[frames:contains], operands=[" +
Joachim Bingel23c31ad2014-08-11 09:44:46 +00001228 "{@type=korap:span, key=s}," +
1229 "{@type=korap:token, wrap= {@type=korap:term, layer=lemma, key=Haus, match=match:eq}}" +
Joachim Bingel6b52d762014-09-30 15:29:11 +00001230 "], frame=frame:contains}" +
Joachim Bingel23c31ad2014-08-11 09:44:46 +00001231 "], spanRef=[1,4]" +
1232 "}";
1233 ppt = new PoliqarpPlusTree(query);
1234 map = ppt.getRequestMap().get("query").toString();
1235 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1236 }
1237
1238 @Test
1239 public void testRelations() throws QueryException {
1240 query = "relatesTo(<s>,<np>)";
1241 expected =
1242 "{@type=korap:group, operation=operation:relation, operands=[" +
1243 "{@type=korap:span, key=s}," +
1244 "{@type=korap:span, key=np}" +
1245 "], relation={@type=korap:relation}" +
1246 "}";
1247 ppt = new PoliqarpPlusTree(query);
1248 map = ppt.getRequestMap().get("query").toString();
1249 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1250
1251 query = "relatesTo([base=Baum],<np>)";
1252 expected =
1253 "{@type=korap:group, operation=operation:relation, operands=[" +
1254 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Baum, match=match:eq}}," +
1255 "{@type=korap:span, key=np}" +
1256 "], relation={@type=korap:relation}" +
1257 "}";
1258 ppt = new PoliqarpPlusTree(query);
1259 map = ppt.getRequestMap().get("query").toString();
1260 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1261
1262 query = "dominates(<np>,[base=Baum])";
1263 expected =
1264 "{@type=korap:group, operation=operation:relation, operands=[" +
1265 "{@type=korap:span, key=np}," +
1266 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Baum, match=match:eq}}" +
1267 "], relation={@type=korap:relation, layer=c}" +
1268 "}";
1269 ppt = new PoliqarpPlusTree(query);
1270 map = ppt.getRequestMap().get("query").toString();
1271 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1272
1273 query = "dominates(cnx/c:<np>,[base=Baum])";
1274 expected =
1275 "{@type=korap:group, operation=operation:relation, operands=[" +
1276 "{@type=korap:span, key=np}," +
1277 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Baum, match=match:eq}}" +
1278 "], relation={@type=korap:relation, layer=c, foundry=cnx}" +
1279 "}";
1280 ppt = new PoliqarpPlusTree(query);
1281 map = ppt.getRequestMap().get("query").toString();
1282 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1283
1284 query = "dominates(cnx/c*:<np>,[base=Baum])";
1285 expected =
1286 "{@type=korap:group, operation=operation:relation, operands=[" +
1287 "{@type=korap:span, key=np}," +
1288 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Baum, match=match:eq}}" +
1289 "], relation={@type=korap:relation, layer=c, foundry=cnx, boundary={@type=korap:boundary, min=0}}" +
1290 "}";
1291 ppt = new PoliqarpPlusTree(query);
1292 map = ppt.getRequestMap().get("query").toString();
1293 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1294
1295 query = "dominates(cnx/c{1,5}:<np>,[base=Baum])";
1296 expected =
1297 "{@type=korap:group, operation=operation:relation, operands=[" +
1298 "{@type=korap:span, key=np}," +
1299 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Baum, match=match:eq}}" +
1300 "], relation={@type=korap:relation, layer=c, foundry=cnx, boundary={@type=korap:boundary, min=1, max=5}}" +
1301 "}";
1302 ppt = new PoliqarpPlusTree(query);
1303 map = ppt.getRequestMap().get("query").toString();
1304 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1305
1306 query = "relatesTo(mate/d=HEAD:<np>,[base=Baum])";
1307 expected =
1308 "{@type=korap:group, operation=operation:relation, operands=[" +
1309 "{@type=korap:span, key=np}," +
1310 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Baum, match=match:eq}}" +
1311 "], relation={@type=korap:relation, foundry=mate, layer=d, key=HEAD}" +
1312 "}";
1313 ppt = new PoliqarpPlusTree(query);
1314 map = ppt.getRequestMap().get("query").toString();
1315 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1316
1317 }
1318
1319
Joachim Bingel03882702013-12-31 19:53:05 +00001320
Joachim Bingel53333e62013-12-09 19:25:52 +00001321 @Test
Joachim Bingelba9a0ab2014-01-29 10:12:25 +00001322 public void testFoundries() throws QueryException {
1323 // [tt/base=Mann]
Joachim Bingel0900a892014-06-30 16:26:21 +00001324 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 +00001325 ppt = new PoliqarpPlusTree("[tt/base=Mann]");
1326 map = ppt.getRequestMap().get("query").toString();
1327 assertEquals(layer1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +00001328
1329 }
Joachim Bingel16da4e12013-12-17 09:48:12 +00001330
1331 @Test
Joachim Bingel8c640e42014-02-07 16:20:47 +00001332 public void testAlign() throws QueryException {
Joachim Bingel16da4e12013-12-17 09:48:12 +00001333 // [orth=der]^[orth=Mann]
Joachim Bingel832800e2014-10-17 14:46:39 +00001334 query = "[orth=der]^[orth=Mann]";
1335 expected =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001336 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001337 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
Joachim Bingel6b491c22014-10-21 08:35:18 +00001338 "{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001339 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" +
Joachim Bingel832800e2014-10-17 14:46:39 +00001340 "]}" +
Joachim Bingel16da4e12013-12-17 09:48:12 +00001341 "]}";
Joachim Bingel832800e2014-10-17 14:46:39 +00001342 metaExpected =
Joachim Bingel6b491c22014-10-21 08:35:18 +00001343 "{alignment=129}";
Joachim Bingel832800e2014-10-17 14:46:39 +00001344 ppt = new PoliqarpPlusTree(query);
Joachim Bingel16da4e12013-12-17 09:48:12 +00001345 map = ppt.getRequestMap().get("query").toString();
Joachim Bingel832800e2014-10-17 14:46:39 +00001346 metaMap = ppt.getRequestMap().get("meta").toString();
1347 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1348 assertEquals(metaExpected.replaceAll(" ", ""), metaMap.replaceAll(" ", ""));
Joachim Bingel16da4e12013-12-17 09:48:12 +00001349
Joachim Bingel84e33df2014-01-31 14:02:46 +00001350 // [orth=der]^[orth=große][orth=Mann]
Joachim Bingel832800e2014-10-17 14:46:39 +00001351 query = "[orth=der]^[orth=große][orth=Mann]";
1352 String expected =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001353 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001354 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
Joachim Bingel6b491c22014-10-21 08:35:18 +00001355 "{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001356 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001357 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=große, match=match:eq}}," +
1358 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +00001359 "]}" +
Joachim Bingel832800e2014-10-17 14:46:39 +00001360 "]}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +00001361 "]}";
Joachim Bingel832800e2014-10-17 14:46:39 +00001362 metaExpected =
Joachim Bingel6b491c22014-10-21 08:35:18 +00001363 "{alignment=129}";
Joachim Bingel84e33df2014-01-31 14:02:46 +00001364 ppt = new PoliqarpPlusTree(query);
1365 map = ppt.getRequestMap().get("query").toString();
Joachim Bingel832800e2014-10-17 14:46:39 +00001366 metaMap = ppt.getRequestMap().get("meta").toString();
1367 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1368 assertEquals(metaExpected.replaceAll(" ", ""), metaMap.replaceAll(" ", ""));
Joachim Bingel84e33df2014-01-31 14:02:46 +00001369
Joachim Bingel832800e2014-10-17 14:46:39 +00001370 query = "([base=a]^[base=b])|[base=c]";
1371 expected =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001372 "{@type=korap:group, operation=operation:or, operands=[" +
1373 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001374 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=a, match=match:eq}}," +
Joachim Bingel6b491c22014-10-21 08:35:18 +00001375 "{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001376 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=b, match=match:eq}}" +
Joachim Bingel832800e2014-10-17 14:46:39 +00001377 "]}" +
Joachim Bingel16da4e12013-12-17 09:48:12 +00001378 "]}," +
Joachim Bingel0900a892014-06-30 16:26:21 +00001379 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=c, match=match:eq}}" +
Joachim Bingel16da4e12013-12-17 09:48:12 +00001380 "]}";
Joachim Bingel832800e2014-10-17 14:46:39 +00001381 metaExpected =
Joachim Bingel6b491c22014-10-21 08:35:18 +00001382 "{alignment=129}";
Joachim Bingel832800e2014-10-17 14:46:39 +00001383 ppt = new PoliqarpPlusTree(query);
Joachim Bingel16da4e12013-12-17 09:48:12 +00001384 map = ppt.getRequestMap().get("query").toString();
Joachim Bingel832800e2014-10-17 14:46:39 +00001385 metaMap = ppt.getRequestMap().get("meta").toString();
1386 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1387 assertEquals(metaExpected.replaceAll(" ", ""), metaMap.replaceAll(" ", ""));
Joachim Bingela67e6a32014-01-02 18:35:24 +00001388
Joachim Bingel832800e2014-10-17 14:46:39 +00001389 query = "([base=a]^[base=b][base=c])|[base=d]";
1390 expected =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001391 "{@type=korap:group, operation=operation:or, operands=[" +
1392 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001393 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=a, match=match:eq}}," +
Joachim Bingel6b491c22014-10-21 08:35:18 +00001394 "{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001395 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001396 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=b, match=match:eq}}," +
1397 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=c, match=match:eq}}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +00001398 "]}" +
Joachim Bingel832800e2014-10-17 14:46:39 +00001399 "]}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +00001400 "]}," +
Joachim Bingel0900a892014-06-30 16:26:21 +00001401 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=d, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +00001402 "]}";
Joachim Bingel832800e2014-10-17 14:46:39 +00001403 metaExpected =
Joachim Bingel6b491c22014-10-21 08:35:18 +00001404 "{alignment=129}";
Joachim Bingel832800e2014-10-17 14:46:39 +00001405 ppt = new PoliqarpPlusTree(query);
Joachim Bingela67e6a32014-01-02 18:35:24 +00001406 map = ppt.getRequestMap().get("query").toString();
Joachim Bingel832800e2014-10-17 14:46:39 +00001407 metaMap = ppt.getRequestMap().get("meta").toString();
1408 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1409 assertEquals(metaExpected.replaceAll(" ", ""), metaMap.replaceAll(" ", ""));
Joachim Bingela67e6a32014-01-02 18:35:24 +00001410
Joachim Bingel832800e2014-10-17 14:46:39 +00001411 query = "([base=a]^[base=b]^[base=c])|[base=d]";
1412 expected =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001413 "{@type=korap:group, operation=operation:or, operands=[" +
1414 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001415 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=a, match=match:eq}}," +
Joachim Bingel6b491c22014-10-21 08:35:18 +00001416 "{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001417 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001418 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=b, match=match:eq}}," +
Joachim Bingel6b491c22014-10-21 08:35:18 +00001419 "{@type=korap:group, operation=operation:class, class=130, classOut=130, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001420 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=c, match=match:eq}}" +
Joachim Bingel832800e2014-10-17 14:46:39 +00001421 "]}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +00001422 "]}" +
Joachim Bingel832800e2014-10-17 14:46:39 +00001423 "]}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +00001424 "]}," +
Joachim Bingel0900a892014-06-30 16:26:21 +00001425 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=d, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +00001426 "]}";
Joachim Bingel832800e2014-10-17 14:46:39 +00001427 metaExpected =
Joachim Bingel6b491c22014-10-21 08:35:18 +00001428 "{alignment=[129,130]}";
Joachim Bingel832800e2014-10-17 14:46:39 +00001429 ppt = new PoliqarpPlusTree(query);
Joachim Bingela67e6a32014-01-02 18:35:24 +00001430 map = ppt.getRequestMap().get("query").toString();
Joachim Bingel832800e2014-10-17 14:46:39 +00001431 metaMap = ppt.getRequestMap().get("meta").toString();
1432 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1433 assertEquals(metaExpected.replaceAll(" ", ""), metaMap.replaceAll(" ", ""));
Joachim Bingela67e6a32014-01-02 18:35:24 +00001434
1435
Joachim Bingel16da4e12013-12-17 09:48:12 +00001436 }
1437
1438 @Test
Joachim Bingel8c640e42014-02-07 16:20:47 +00001439 public void testSimpleQueries() throws QueryException {
Joachim Bingela67e6a32014-01-02 18:35:24 +00001440 // Baum
1441 String simple1 =
Joachim Bingel0900a892014-06-30 16:26:21 +00001442 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq}}";
Joachim Bingela67e6a32014-01-02 18:35:24 +00001443 ppt = new PoliqarpPlusTree("Baum");
1444 map = ppt.getRequestMap().get("query").toString();
1445 assertEquals(simple1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel0900a892014-06-30 16:26:21 +00001446
1447 // Baum/i
1448 String simple1b =
1449 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq, caseInsensitive=true}}";
1450 ppt = new PoliqarpPlusTree("Baum/i");
1451 map = ppt.getRequestMap().get("query").toString();
1452 assertEquals(simple1b.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel16da4e12013-12-17 09:48:12 +00001453
Joachim Bingela67e6a32014-01-02 18:35:24 +00001454 // Der Baum
1455 String simple2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001456 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001457 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}, " +
1458 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +00001459 "]}";
1460 ppt = new PoliqarpPlusTree("Der Baum");
1461 map = ppt.getRequestMap().get("query").toString();
1462 assertEquals(simple2.replaceAll(" ", ""), map.replaceAll(" ", ""));
1463
Joachim Bingel0900a892014-06-30 16:26:21 +00001464 // Der Baum/i
1465 String simple2b =
1466 "{@type=korap:group, operation=operation:sequence, operands=[" +
1467 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}, " +
1468 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq, caseInsensitive=true}}" +
1469 "]}";
1470 ppt = new PoliqarpPlusTree("Der Baum/i");
1471 map = ppt.getRequestMap().get("query").toString();
1472 assertEquals(simple2b.replaceAll(" ", ""), map.replaceAll(" ", ""));
1473
Joachim Bingela67e6a32014-01-02 18:35:24 +00001474 // Der große Baum
1475 String simple3 =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001476 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001477 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}, " +
1478 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=große, match=match:eq}}, " +
1479 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +00001480 "]}";
1481 ppt = new PoliqarpPlusTree("Der große Baum");
1482 map = ppt.getRequestMap().get("query").toString();
1483 assertEquals(simple3.replaceAll(" ", ""), map.replaceAll(" ", ""));
1484
1485 // Baum | Stein
1486 String simple4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001487 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001488 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq}}, " +
1489 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Stein, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +00001490 "]}";
1491 ppt = new PoliqarpPlusTree("Baum | Stein");
1492 map = ppt.getRequestMap().get("query").toString();
1493 assertEquals(simple4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel84e33df2014-01-31 14:02:46 +00001494
1495 // Baum | Stein Haus
1496 String query = "(Baum | Stein) Haus";
1497 String simple5 =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001498 "{@type=korap:group, operation=operation:sequence, operands=[" +
1499 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001500 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq}}, " +
1501 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Stein, match=match:eq}}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +00001502 "]}," +
Joachim Bingel0900a892014-06-30 16:26:21 +00001503 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Haus, match=match:eq}} " +
Joachim Bingel84e33df2014-01-31 14:02:46 +00001504 "]}";
1505 ppt = new PoliqarpPlusTree(query);
1506 map = ppt.getRequestMap().get("query").toString();
1507 assertEquals(simple5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel16da4e12013-12-17 09:48:12 +00001508 }
Joachim Bingelb68361c2014-10-22 14:15:09 +00001509
1510 @Test
1511 public void testUnnecessaryParantheses() throws QueryException {
1512 String query1, query2;
1513 PoliqarpPlusTree tree1, tree2;
1514
1515 query1 = "Test";
1516 query2 = "(Test)";
1517 tree1 = new PoliqarpPlusTree(query1);
1518 tree2 = new PoliqarpPlusTree(query2);
1519 assertEquals(tree1.getRequestMap(), tree2.getRequestMap());
1520
1521 query1 = "pass|fail";
1522 query2 = "(pass|fail)";
1523 tree1 = new PoliqarpPlusTree(query1);
1524 tree2 = new PoliqarpPlusTree(query2);
1525 assertEquals(tree1.getRequestMap(), tree2.getRequestMap());
1526
1527 query1 = "pass|fail";
1528 query2 = "pass|(fail)";
1529 tree1 = new PoliqarpPlusTree(query1);
1530 tree2 = new PoliqarpPlusTree(query2);
1531 assertEquals(tree1.getRequestMap(), tree2.getRequestMap());
1532
1533 query1 = "pass|fail";
1534 query2 = "(pass|(fail))";
1535 tree1 = new PoliqarpPlusTree(query1);
1536 tree2 = new PoliqarpPlusTree(query2);
1537 assertEquals(tree1.getRequestMap(), tree2.getRequestMap());
1538
1539 query1 = "contains(<s>,Mann)";
1540 query2 = "contains((<s>),Mann)";
1541 tree1 = new PoliqarpPlusTree(query1);
1542 tree2 = new PoliqarpPlusTree(query2);
1543 assertEquals(tree1.getRequestMap(), tree2.getRequestMap());
1544 }
Joachim Bingel53333e62013-12-09 19:25:52 +00001545}
1546