blob: 07df5c3b360bfeda6e2debdce8a6a79b198bb409 [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(" ", ""));
523 }
524
525 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000526 public void testCoordinatedFields() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000527 // [base=Mann&(cas=N|cas=A)]
528 String cof1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000529 "{@type=korap:token, wrap=" +
Joachim Bingel2980bda2014-04-04 12:09:46 +0000530 "{@type=korap:termGroup, relation=relation:and, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000531 "{@type=korap:term, layer=lemma, key=Mann, match=match:eq}," +
Joachim Bingel2980bda2014-04-04 12:09:46 +0000532 "{@type=korap:termGroup, relation=relation:or, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000533 "{@type=korap:term, layer=cas, key=N, match=match:eq}," +
534 "{@type=korap:term, layer=cas, key=A, match=match:eq}" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000535 "]}" +
536 "]}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000537 "}";
538 ppt = new PoliqarpPlusTree("[base=Mann&(cas=N|cas=A)]");
539 map = ppt.getRequestMap().get("query").toString();
540 assertEquals(cof1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Nils Diewald7d486c22013-12-13 16:32:18 +0000541
542
543 assertEquals(
544 new PoliqarpPlusTree(" [ base=Mann & ( cas=N | cas=A)] ").getRequestMap().get("query").toString(),
545 new PoliqarpPlusTree("[base=Mann &(cas=N|cas=A)]").getRequestMap().get("query").toString()
546 );
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000547
548 // [base=Mann&cas=N&gen=m]
549 String cof2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000550 "{@type=korap:token, wrap=" +
Joachim Bingel2980bda2014-04-04 12:09:46 +0000551 "{@type=korap:termGroup, relation=relation:and, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000552 "{@type=korap:term, layer=lemma, key=Mann, match=match:eq}," +
553 "{@type=korap:termGroup, relation=relation:and, operands=[" +
554 "{@type=korap:term, layer=cas, key=N, match=match:eq}," +
555 "{@type=korap:term, layer=gen, key=m, match=match:eq}" +
556 "]}" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000557 "]}" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000558 "}";
559 ppt = new PoliqarpPlusTree("[base=Mann&cas=N&gen=m]");
560 map = ppt.getRequestMap().get("query").toString();
561 assertEquals(cof2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000562 }
563
564 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000565 public void testOccurrence() throws QueryException {
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000566 // [base=foo]*
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000567 String occ1 = "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000568 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingel687e4d42014-07-30 09:34:18 +0000569 "], boundary={@type=korap:boundary, min=0}, min=0}";
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000570 ppt = new PoliqarpPlusTree("[base=foo]*");
571 map = ppt.getRequestMap().get("query").toString();
572 assertEquals(occ1.replaceAll(" ", ""), map.replaceAll(" ", ""));
573
574 // [base=foo]*[base=bar]
575 String occ2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000576 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000577 "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000578 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingel687e4d42014-07-30 09:34:18 +0000579 "], boundary={@type=korap:boundary, min=0}, min=0 }," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000580 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000581 "]}";
582 ppt = new PoliqarpPlusTree("[base=foo]*[base=bar]");
583 map = ppt.getRequestMap().get("query").toString();
584 assertEquals(occ2.replaceAll(" ", ""), map.replaceAll(" ", ""));
585
586 // [base=bar][base=foo]*
587 String occ3 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000588 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000589 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000590 "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000591 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingel687e4d42014-07-30 09:34:18 +0000592 "], boundary={@type=korap:boundary, min=0}, min=0 }" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000593 "]}";
594 ppt = new PoliqarpPlusTree("[base=bar][base=foo]*");
595 map = ppt.getRequestMap().get("query").toString();
596 assertEquals(occ3.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb4da7022013-12-09 23:17:24 +0000597
598 // ([base=bar][base=foo])*
599 String occ4 =
Joachim Bingel0900a892014-06-30 16:26:21 +0000600 "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000601 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000602 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," +
603 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000604 "]}" +
Joachim Bingel687e4d42014-07-30 09:34:18 +0000605 "], boundary={@type=korap:boundary, min=0}, min=0}" ;
Joachim Bingelb4da7022013-12-09 23:17:24 +0000606 ppt = new PoliqarpPlusTree("([base=bar][base=foo])*");
607 map = ppt.getRequestMap().get("query").toString();
608 assertEquals(occ4.replaceAll(" ", ""), map.replaceAll(" ", ""));
609
610 // <s>([base=bar][base=foo])*
611 String occ5 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000612 "{@type=korap:group, operation=operation:sequence, operands=[" +
613 "{@type=korap:span, key=s}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000614 "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000615 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000616 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," +
617 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000618 "]}" +
Joachim Bingel687e4d42014-07-30 09:34:18 +0000619 "], boundary={@type=korap:boundary, min=0}, min=0 }" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000620 "]}" ;
621 ppt = new PoliqarpPlusTree("<s>([base=bar][base=foo])*");
622 map = ppt.getRequestMap().get("query").toString();
623 assertEquals(occ5.replaceAll(" ", ""), map.replaceAll(" ", ""));
624
625 // <s><np>([base=bar][base=foo])*
Joachim Bingelb4da7022013-12-09 23:17:24 +0000626 String occ6 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000627 "{@type=korap:group, operation=operation:sequence, operands=[" +
628 "{@type=korap:span, key=s}," +
629 "{@type=korap:span, key=np}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000630 "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000631 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000632 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," +
633 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000634 "]}" +
Joachim Bingel687e4d42014-07-30 09:34:18 +0000635 "], boundary={@type=korap:boundary, min=0}, min=0 }" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000636 "]}" ;
637 ppt = new PoliqarpPlusTree("<s><np>([base=bar][base=foo])*");
638 map = ppt.getRequestMap().get("query").toString();
639 assertEquals(occ6.replaceAll(" ", ""), map.replaceAll(" ", ""));
640
641 // <s><np>([base=bar][base=foo])*[p=NN]
642 // comment: embedded sequence shouldn't really be here, but does not really hurt, either. (?)
643 // really hard to get this behaviour out of the PQPlus grammar...
644 String occ7 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000645 "{@type=korap:group, operation=operation:sequence, operands=[" +
646 "{@type=korap:span, key=s}," +
647 "{@type=korap:span, key=np}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000648 "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000649 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000650 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," +
651 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000652 "]}" +
Joachim Bingel687e4d42014-07-30 09:34:18 +0000653 "], boundary={@type=korap:boundary, min=0}, min=0 }," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000654 "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000655 "]}" ;
656 ppt = new PoliqarpPlusTree("<s><np>([base=bar][base=foo])*[p=NN]");
657 map = ppt.getRequestMap().get("query").toString();
658 assertEquals(occ7.replaceAll(" ", ""), map.replaceAll(" ", ""));
659
660 // ([base=bar][base=foo])*[p=NN]
Joachim Bingelb4da7022013-12-09 23:17:24 +0000661 String occ8 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000662 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000663 "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000664 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000665 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," +
666 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000667 "]}" +
Joachim Bingel687e4d42014-07-30 09:34:18 +0000668 "], boundary={@type=korap:boundary, min=0}, min=0 }," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000669 "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000670 "]}" ;
671 ppt = new PoliqarpPlusTree("([base=bar][base=foo])*[p=NN]");
672 map = ppt.getRequestMap().get("query").toString();
673 assertEquals(occ8.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000674
675 // [base=foo]+
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000676 String occ9 = "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000677 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingel687e4d42014-07-30 09:34:18 +0000678 "], boundary={@type=korap:boundary, min=1}, min=1}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000679 ppt = new PoliqarpPlusTree("[base=foo]+");
680 map = ppt.getRequestMap().get("query").toString();
681 assertEquals(occ9.replaceAll(" ", ""), map.replaceAll(" ", ""));
682
683 // [base=foo]?
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000684 String occ10 = "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000685 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingel61631562014-07-24 14:26:02 +0000686 "], boundary={@type=korap:boundary, min=0, max=1}, min=0, max=1}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000687 ppt = new PoliqarpPlusTree("[base=foo]?");
688 map = ppt.getRequestMap().get("query").toString();
689 assertEquals(occ10.replaceAll(" ", ""), map.replaceAll(" ", ""));
690
691 // [base=foo]{2,5}
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000692 String occ11 = "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000693 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingel61631562014-07-24 14:26:02 +0000694 "], boundary={@type=korap:boundary, min=2, max=5}, min=2, max=5}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000695 ppt = new PoliqarpPlusTree("[base=foo]{2,5}");
696 map = ppt.getRequestMap().get("query").toString();
697 assertEquals(occ11.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel2980bda2014-04-04 12:09:46 +0000698
699 // [base=foo]{2}
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000700 String occ12 = "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000701 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingel61631562014-07-24 14:26:02 +0000702 "], boundary={@type=korap:boundary, min=2, max=2}, min=2, max=2}";
Joachim Bingel2980bda2014-04-04 12:09:46 +0000703 ppt = new PoliqarpPlusTree("[base=foo]{2}");
704 map = ppt.getRequestMap().get("query").toString();
705 assertEquals(occ12.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb2aa1c72014-07-01 12:48:46 +0000706
707 // [base=foo]{2}
708 String occ13 = "{@type=korap:group, operation=operation:repetition, operands=[" +
709 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingel687e4d42014-07-30 09:34:18 +0000710 "], boundary={@type=korap:boundary, min=2}, min=2}";
Joachim Bingelb2aa1c72014-07-01 12:48:46 +0000711 ppt = new PoliqarpPlusTree("[base=foo]{2,}");
712 map = ppt.getRequestMap().get("query").toString();
713 assertEquals(occ13.replaceAll(" ", ""), map.replaceAll(" ", ""));
714
715 // [base=foo]{2}
716 String occ14 = "{@type=korap:group, operation=operation:repetition, operands=[" +
717 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingel61631562014-07-24 14:26:02 +0000718 "], boundary={@type=korap:boundary, min=0, max=2}, min=0, max=2}";
Joachim Bingelb2aa1c72014-07-01 12:48:46 +0000719 ppt = new PoliqarpPlusTree("[base=foo]{,2}");
720 map = ppt.getRequestMap().get("query").toString();
721 assertEquals(occ14.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000722 }
723
724 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000725 public void testTokenSequence() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000726 // [base=Mann][orth=Frau]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000727 String seq1 = "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000728 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}, " +
729 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000730 "]}";
731 assertTrue(equalsQueryContent(seq1, "[base=Mann][orth=Frau]"));
732
733 // [base=Mann][orth=Frau][p=NN]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000734 String seq2 = "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000735 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}, " +
736 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}, " +
737 "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000738 "]}";
739 assertTrue(equalsQueryContent(seq2, "[base=Mann][orth=Frau][p=NN]"));
740 }
741
742 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000743 public void testDisjSegments() throws QueryException {
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000744 // ([base=der]|[base=das])[base=Schild]
745 String disj1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000746 "{@type=korap:group, operation=operation:sequence, operands=[" +
747 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000748 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
749 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=das, match=match:eq}}" +
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000750 "]}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000751 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Schild, match=match:eq}}" +
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000752 "]}";
753 ppt = new PoliqarpPlusTree("([base=der]|[base=das])[base=Schild]");
754 map = ppt.getRequestMap().get("query").toString();
755 assertEquals(disj1.replaceAll(" ", ""), map.replaceAll(" ", ""));
756
757 // [base=Schild]([base=der]|[base=das])
758 String disj2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000759 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000760 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Schild, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000761 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000762 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
763 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=das, match=match:eq}}" +
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000764 "]}" +
765 "]}";
766 ppt = new PoliqarpPlusTree("[base=Schild]([base=der]|[base=das])");
767 map = ppt.getRequestMap().get("query").toString();
768 assertEquals(disj2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel76b498d2014-06-06 12:06:46 +0000769
770 // "([orth=der][base=katze])|([orth=eine][base=baum])"
771 String disj3 =
772 "{@type=korap:group, operation=operation:or, operands=[" +
773 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000774 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
775 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=katze, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000776 "]}," +
777 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000778 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=eine, match=match:eq}}," +
779 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=baum, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000780 "]}" +
781 "]}";
782 ppt = new PoliqarpPlusTree("([orth=der][base=katze])|([orth=eine][base=baum])");
783 map = ppt.getRequestMap().get("query").toString();
784 assertEquals(disj3.replaceAll(" ", ""), map.replaceAll(" ", ""));
785
786 // "[orth=der][base=katze]|[orth=eine][base=baum]"
787 String disj4 =
788 "{@type=korap:group, operation=operation:or, operands=[" +
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=der, match=match:eq}}," +
791 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=katze, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000792 "]}," +
793 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000794 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=eine, match=match:eq}}," +
795 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=baum, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000796 "]}" +
797 "]}";
798 ppt = new PoliqarpPlusTree("[orth=der][base=katze]|[orth=eine][base=baum]");
799 map = ppt.getRequestMap().get("query").toString();
800 assertEquals(disj4.replaceAll(" ", ""), map.replaceAll(" ", ""));
801
802 PoliqarpPlusTree ppt1 = new PoliqarpPlusTree("[orth=der][base=katze]|[orth=eine][base=baum]");
803 PoliqarpPlusTree ppt2 = new PoliqarpPlusTree("([orth=der][base=katze])|([orth=eine][base=baum])");
804 assertEquals(ppt1.getRequestMap().toString(), ppt2.getRequestMap().toString());
805
806 // "[orth=der][base=katze]|[orth=der][base=hund]|[orth=der][base=baum]"
807 String disj5 =
808 "{@type=korap:group, operation=operation:or, operands=[" +
809 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000810 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
811 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=katze, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000812 "]}," +
813 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000814 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
815 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=hund, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000816 "]}," +
817 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000818 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
819 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=baum, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000820 "]}" +
821 "]}";
822 ppt = new PoliqarpPlusTree("[orth=der][base=katze]|[orth=der][base=hund]|[orth=der][base=baum]");
823 map = ppt.getRequestMap().get("query").toString();
824 assertEquals(disj5.replaceAll(" ", ""), map.replaceAll(" ", ""));
825
826 // [orth=der]([base=katze]|[base=hund]|[base=baum])
827 String disj6 =
828 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000829 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000830 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000831 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=katze, match=match:eq}}," +
832 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=hund, match=match:eq}}," +
833 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=baum, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000834 "]}" +
835 "]}";
836 ppt = new PoliqarpPlusTree("[orth=der]([base=katze]|[base=hund]|[base=baum])");
837 map = ppt.getRequestMap().get("query").toString();
838 assertEquals(disj6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000839 }
840
841 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000842 public void testTokenElemSequence() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000843 // [base=Mann]<vp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000844 String seq1 = "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000845 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}, " +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000846 "{@type=korap:span, key=vp}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000847 "]}";
848 assertTrue(equalsQueryContent(seq1, "[base=Mann]<vp>"));
849
850 // <vp>[base=Mann]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000851 String seq2 = "{@type=korap:group, operation=operation:sequence, operands=[" +
852 "{@type=korap:span, key=vp}, "+
Joachim Bingel0900a892014-06-30 16:26:21 +0000853 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}} " +
Joachim Bingel53333e62013-12-09 19:25:52 +0000854 "]}";
855 assertTrue(equalsQueryContent(seq2, "<vp>[base=Mann]"));
856
857 // <vp>[base=Mann]<pp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000858 String seq3 = "{@type=korap:group, operation=operation:sequence, operands=[" +
859 "{@type=korap:span, key=vp}, "+
Joachim Bingel0900a892014-06-30 16:26:21 +0000860 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}, " +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000861 "{@type=korap:span, key=pp} "+
Joachim Bingel53333e62013-12-09 19:25:52 +0000862 "]}";
863 assertTrue(equalsQueryContent(seq3, "<vp>[base=Mann]<pp>"));
864 }
865
866 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000867 public void testElemSequence() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000868 // <np><vp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000869 String seq1 = "{@type=korap:group, operation=operation:sequence, operands=[" +
870 "{@type=korap:span, key=np}," +
871 "{@type=korap:span, key=vp}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000872 "]}";
873 assertTrue(equalsQueryContent(seq1, "<np><vp>"));
874
875 // <np><vp><pp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000876 String seq2 = "{@type=korap:group, operation=operation:sequence, operands=[" +
877 "{@type=korap:span, key=np}," +
878 "{@type=korap:span, key=vp}," +
879 "{@type=korap:span, key=pp}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000880 "]}";
881 assertTrue(equalsQueryContent(seq2, "<np><vp><pp>"));
882 }
883
884 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000885 public void testClasses() throws QueryException {
Joachim Bingel0900a892014-06-30 16:26:21 +0000886 String query;
Joachim Bingel53333e62013-12-09 19:25:52 +0000887 // {[base=Mann]}
Joachim Bingel4c0c2012014-10-22 09:35:22 +0000888 String cls1 = "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000889 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000890 "]}";
Joachim Bingel8c640e42014-02-07 16:20:47 +0000891 ppt = new PoliqarpPlusTree("{[base=Mann]}");
892 map = ppt.getRequestMap().get("query").toString();
893 assertEquals(cls1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000894
895 // {[base=Mann][orth=Frau]}
Joachim Bingel0900a892014-06-30 16:26:21 +0000896 query = "{[base=Mann][orth=Frau]}";
Joachim Bingel4c0c2012014-10-22 09:35:22 +0000897 String cls2 = "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000898 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000899 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}," +
900 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000901 "]}" +
902 "]}";
Joachim Bingel0900a892014-06-30 16:26:21 +0000903 ppt = new PoliqarpPlusTree(query);
904 map = ppt.getRequestMap().get("query").toString();
905 assertEquals(cls2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000906
907 // [p=NN]{[base=Mann][orth=Frau]}
Joachim Bingel2daf9862014-02-12 10:18:54 +0000908 String cls3 = "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000909 "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}," +
Joachim Bingel4c0c2012014-10-22 09:35:22 +0000910 "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000911 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000912 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}," +
913 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000914 "]}" +
915 "]}" +
916 "]}";
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000917 ppt = new PoliqarpPlusTree("[p=NN]{[base=Mann][orth=Frau]}");
918 map = ppt.getRequestMap().get("query").toString();
919 assertEquals(cls3.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000920
921 // {[base=Mann][orth=Frau]}[p=NN]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000922 String cls4 = "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel4c0c2012014-10-22 09:35:22 +0000923 "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000924 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000925 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}," +
926 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000927 "]}" +
928 "]}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000929 "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000930 "]}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000931 ppt = new PoliqarpPlusTree("{[base=Mann][orth=Frau]}[p=NN]");
932 map = ppt.getRequestMap().get("query").toString();
933 assertEquals(cls4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000934
935 // {2:{1:[tt/p=ADJA]}[mate/p=NN]}"
Joachim Bingel832800e2014-10-17 14:46:39 +0000936 String cls5 = "{@type=korap:group, operation=operation:class, class=2, classOut=2, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000937 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel832800e2014-10-17 14:46:39 +0000938 "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000939 "{@type=korap:token, wrap={@type=korap:term, foundry=tt, layer=p, key=ADJA, match=match:eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000940 "]}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000941 "{@type=korap:token, wrap={@type=korap:term, foundry=mate, layer=p, key=NN, match=match:eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000942 "]}" +
943 "]}";
944 ppt = new PoliqarpPlusTree("{2: {1:[tt/p=ADJA]}[mate/p=NN]}");
945 map = ppt.getRequestMap().get("query").toString();
946 assertEquals(cls5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000947 }
948
949 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000950 public void testPositions() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000951 // contains(<s>,<np>)
Joachim Bingel832800e2014-10-17 14:46:39 +0000952 String pos1 = "{@type=korap:group, operation=operation:position, frames=[frames:contains], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000953 "{@type=korap:span, key=s}," +
954 "{@type=korap:span, key=np}" +
Joachim Bingel6b52d762014-09-30 15:29:11 +0000955 "], frame=frame:contains}";
Joachim Bingel53333e62013-12-09 19:25:52 +0000956 assertTrue(equalsQueryContent(pos1, "contains(<s>,<np>)"));
957
958 // contains(<s>,[base=Mann])
Joachim Bingel832800e2014-10-17 14:46:39 +0000959 String pos2 = "{@type=korap:group, operation=operation:position, frames=[frames:contains], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000960 "{@type=korap:span, key=s}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000961 "{@type=korap:token, wrap= {@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
Joachim Bingel6b52d762014-09-30 15:29:11 +0000962 "], frame=frame:contains}";
Joachim Bingel53333e62013-12-09 19:25:52 +0000963 assertTrue(equalsQueryContent(pos2, "contains(<s>,[base=Mann])"));
964
965 // contains(<s>,[orth=der][orth=Mann])
Joachim Bingel832800e2014-10-17 14:46:39 +0000966 String pos3 = "{@type=korap:group, operation=operation:position, frames=[frames:contains], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000967 "{@type=korap:span, key=s}," +
968 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000969 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
970 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000971 "]}" +
Joachim Bingel6b52d762014-09-30 15:29:11 +0000972 "], frame=frame:contains}";
Joachim Bingel53333e62013-12-09 19:25:52 +0000973 ppt = new PoliqarpPlusTree("contains(<s>,[orth=der][orth=Mann])");
974 map = ppt.getRequestMap().get("query").toString();
975 assertEquals(pos3.replaceAll(" ", ""), map.replaceAll(" ", ""));
976
977 // [base=Auto]contains(<s>,[base=Mann])
978 String pos4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000979 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000980 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Auto, match=match:eq}}," +
Joachim Bingel832800e2014-10-17 14:46:39 +0000981 "{@type=korap:group, operation=operation:position, frames=[frames:contains], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000982 "{@type=korap:span, key=s}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000983 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
Joachim Bingel6b52d762014-09-30 15:29:11 +0000984 "], frame=frame:contains}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000985 "]}";
986 ppt = new PoliqarpPlusTree("[base=Auto]contains(<s>,[base=Mann])");
987 map = ppt.getRequestMap().get("query").toString();
988 assertEquals(pos4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelef7059b2014-04-22 13:44:19 +0000989
990 // contains(<s>,[pos=N]*)
991 String pos5 =
Joachim Bingel832800e2014-10-17 14:46:39 +0000992 "{@type=korap:group, operation=operation:position, frames=[frames:contains], operands=[" +
Joachim Bingelef7059b2014-04-22 13:44:19 +0000993 "{@type=korap:span, key=s}," +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000994 "{@type=korap:group, operation=operation:repetition, " +
Joachim Bingel0900a892014-06-30 16:26:21 +0000995 "operands=[{@type=korap:token, wrap={@type=korap:term, layer=pos, key=N, match=match:eq}}" +
Joachim Bingel687e4d42014-07-30 09:34:18 +0000996 "], boundary={@type=korap:boundary, min=0}, min=0" +
Joachim Bingelef7059b2014-04-22 13:44:19 +0000997 "}" +
Joachim Bingel6b52d762014-09-30 15:29:11 +0000998 "], frame=frame:contains}";
Joachim Bingelef7059b2014-04-22 13:44:19 +0000999 ppt = new PoliqarpPlusTree("contains(<s>,[pos=N]*)");
1000 map = ppt.getRequestMap().get("query").toString();
1001 assertEquals(pos5.replaceAll(" ", ""), map.replaceAll(" ", ""));
1002
1003 // [base=Auto]contains(<s>,[pos=N]*)
1004 String pos6 =
1005 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001006 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Auto, match=match:eq}}," +
Joachim Bingel832800e2014-10-17 14:46:39 +00001007 "{@type=korap:group, operation=operation:position, frames=[frames:contains], operands=[" +
Joachim Bingelef7059b2014-04-22 13:44:19 +00001008 "{@type=korap:span, key=s}," +
Joachim Bingel33bd45f2014-06-25 15:00:54 +00001009 "{@type=korap:group, operation=operation:repetition, " +
Joachim Bingel0900a892014-06-30 16:26:21 +00001010 "operands=[{@type=korap:token, wrap={@type=korap:term, layer=pos, key=N, match=match:eq}}" +
Joachim Bingel687e4d42014-07-30 09:34:18 +00001011 "], boundary={@type=korap:boundary, min=0}, min=0" +
Joachim Bingelef7059b2014-04-22 13:44:19 +00001012 "}" +
Joachim Bingel6b52d762014-09-30 15:29:11 +00001013 "], frame=frame:contains}" +
Joachim Bingelef7059b2014-04-22 13:44:19 +00001014 "]}";
1015 ppt = new PoliqarpPlusTree("[base=Auto]contains(<s>,[pos=N]*)");
1016 map = ppt.getRequestMap().get("query").toString();
1017 assertEquals(pos6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +00001018 }
1019
1020 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +00001021 public void testNestedPositions() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +00001022 // contains(<s>,startswith(<np>,[orth=Der]))
1023 String npos1 =
Joachim Bingel832800e2014-10-17 14:46:39 +00001024 "{@type=korap:group, operation=operation:position, frames=[frames:contains], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001025 "{@type=korap:span, key=s}," +
Joachim Bingel832800e2014-10-17 14:46:39 +00001026 "{@type=korap:group, operation=operation:position, frames=[frames:startswith], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001027 "{@type=korap:span, key=np}," +
Joachim Bingel0900a892014-06-30 16:26:21 +00001028 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}" +
Joachim Bingel6b52d762014-09-30 15:29:11 +00001029 "], frame=frame:startswith}" +
1030 "], frame=frame:contains}";
Joachim Bingelcd9ed332013-12-09 21:01:35 +00001031 ppt = new PoliqarpPlusTree("contains(<s>, startswith(<np>,[orth=Der]))");
Joachim Bingel53333e62013-12-09 19:25:52 +00001032 map = ppt.getRequestMap().get("query").toString();
1033 assertEquals(npos1.replaceAll(" ", ""), map.replaceAll(" ", ""));
1034 }
1035
1036 @Test
Joachim Bingel23c31ad2014-08-11 09:44:46 +00001037 public void testFocusSplit() throws QueryException {
Joachim Bingel0900a892014-06-30 16:26:21 +00001038 // focus([orth=Der]{[orth=Mann]})
Joachim Bingel53333e62013-12-09 19:25:52 +00001039 String shr1 =
Joachim Bingel4c0c2012014-10-22 09:35:22 +00001040 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001041 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001042 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}," +
Joachim Bingel4c0c2012014-10-22 09:35:22 +00001043 "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001044 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +00001045 "]}" +
1046 "]}" +
1047 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +00001048 ppt = new PoliqarpPlusTree("focus([orth=Der]{[orth=Mann]})");
Joachim Bingel53333e62013-12-09 19:25:52 +00001049 map = ppt.getRequestMap().get("query").toString();
1050 assertEquals(shr1.replaceAll(" ", ""), map.replaceAll(" ", ""));
1051
Joachim Bingel0900a892014-06-30 16:26:21 +00001052 // focus([orth=Der]{[orth=Mann][orth=geht]})
Joachim Bingel53333e62013-12-09 19:25:52 +00001053 String shr2 =
Joachim Bingel4c0c2012014-10-22 09:35:22 +00001054 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001055 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001056 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}," +
Joachim Bingel4c0c2012014-10-22 09:35:22 +00001057 "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001058 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001059 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}," +
1060 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=geht, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +00001061 "]}" +
1062 "]}" +
1063 "]}" +
1064 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +00001065 ppt = new PoliqarpPlusTree("focus([orth=Der]{[orth=Mann][orth=geht]})");
Joachim Bingel53333e62013-12-09 19:25:52 +00001066 map = ppt.getRequestMap().get("query").toString();
1067 assertEquals(shr2.replaceAll(" ", ""), map.replaceAll(" ", ""));
1068
Joachim Bingel0900a892014-06-30 16:26:21 +00001069 // focus(1:[orth=Der]{1:[orth=Mann][orth=geht]})
Joachim Bingel53333e62013-12-09 19:25:52 +00001070 String shr3 =
Joachim Bingeld1a3e712014-07-16 08:02:05 +00001071 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001072 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001073 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}," +
Joachim Bingel832800e2014-10-17 14:46:39 +00001074 "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001075 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001076 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}," +
1077 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=geht, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +00001078 "]}" +
1079 "]}" +
1080 "]}" +
1081 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +00001082 ppt = new PoliqarpPlusTree("focus(1:[orth=Der]{1:[orth=Mann][orth=geht]})");
Joachim Bingel53333e62013-12-09 19:25:52 +00001083 map = ppt.getRequestMap().get("query").toString();
1084 assertEquals(shr3.replaceAll(" ", ""), map.replaceAll(" ", ""));
1085
Joachim Bingel0900a892014-06-30 16:26:21 +00001086 // focus(1:startswith(<s>,{1:<np>}))
Joachim Bingel53333e62013-12-09 19:25:52 +00001087 String shr4 =
Joachim Bingeld1a3e712014-07-16 08:02:05 +00001088 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingel832800e2014-10-17 14:46:39 +00001089 "{@type=korap:group, operation=operation:position, frames=[frames:startswith], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001090 "{@type=korap:span, key=s}," +
Joachim Bingel832800e2014-10-17 14:46:39 +00001091 "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001092 "{@type=korap:span, key=np}" +
Joachim Bingel53333e62013-12-09 19:25:52 +00001093 "]}" +
Joachim Bingel6b52d762014-09-30 15:29:11 +00001094 "], frame=frame:startswith}" +
Joachim Bingel53333e62013-12-09 19:25:52 +00001095 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +00001096 ppt = new PoliqarpPlusTree("focus(1:startswith(<s>,{1:<np>}))");
Joachim Bingel53333e62013-12-09 19:25:52 +00001097 map = ppt.getRequestMap().get("query").toString();
1098 assertEquals(shr4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelcd9ed332013-12-09 21:01:35 +00001099
Joachim Bingel0900a892014-06-30 16:26:21 +00001100 // focus(3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))
Joachim Bingelcd9ed332013-12-09 21:01:35 +00001101 String shr5 =
Joachim Bingeld1a3e712014-07-16 08:02:05 +00001102 "{@type=korap:reference, operation=operation:focus, classRef=[3], operands=[" +
Joachim Bingel832800e2014-10-17 14:46:39 +00001103 "{@type=korap:group, operation=operation:position, frames=[frames:startswith], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001104 "{@type=korap:span, key=s}," +
Joachim Bingel832800e2014-10-17 14:46:39 +00001105 "{@type=korap:group, operation=operation:class, class=3, classOut=3, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001106 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001107 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
Joachim Bingel832800e2014-10-17 14:46:39 +00001108 "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001109 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001110 "{@type=korap:token, wrap={@type=korap:term, foundry=mate, layer=p, key=ADJA, match=match:eq}}," +
Joachim Bingel832800e2014-10-17 14:46:39 +00001111 "{@type=korap:group, operation=operation:class, class=2, classOut=2, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001112 "{@type=korap:token, wrap={@type=korap:term, foundry=tt, layer=p, key=NN, match=match:eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +00001113 "]}" +
1114 "]}" +
1115 "]}" +
1116 "]}" +
1117 "]}" +
Joachim Bingel6b52d762014-09-30 15:29:11 +00001118 "], frame=frame:startswith}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +00001119 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +00001120 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 +00001121 map = ppt.getRequestMap().get("query").toString();
1122 assertEquals(shr5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelba9a0ab2014-01-29 10:12:25 +00001123
1124 // split(3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))
1125 String shr6 =
Joachim Bingeld1a3e712014-07-16 08:02:05 +00001126 "{@type=korap:reference, operation=operation:split, classRef=[3], operands=[" +
Joachim Bingel832800e2014-10-17 14:46:39 +00001127 "{@type=korap:group, operation=operation:position, frames=[frames:startswith], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001128 "{@type=korap:span, key=s}," +
Joachim Bingel832800e2014-10-17 14:46:39 +00001129 "{@type=korap:group, operation=operation:class, class=3, classOut=3, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001130 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001131 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
Joachim Bingel832800e2014-10-17 14:46:39 +00001132 "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001133 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001134 "{@type=korap:token, wrap={@type=korap:term, foundry=mate, layer=p, key=ADJA, match=match:eq}}," +
Joachim Bingel832800e2014-10-17 14:46:39 +00001135 "{@type=korap:group, operation=operation:class, class=2, classOut=2, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001136 "{@type=korap:token, wrap={@type=korap:term, foundry=tt, layer=p, key=NN, match=match:eq}}" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +00001137 "]}" +
1138 "]}" +
1139 "]}" +
1140 "]}" +
1141 "]}" +
Joachim Bingel6b52d762014-09-30 15:29:11 +00001142 "], frame=frame:startswith}" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +00001143 "]}";
1144 ppt = new PoliqarpPlusTree("split(3:startswith(<s>,{3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) ");
1145 map = ppt.getRequestMap().get("query").toString();
1146 assertEquals(shr6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel8c640e42014-02-07 16:20:47 +00001147
1148 // split(2|3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))
1149 String shr7 =
Joachim Bingeld1a3e712014-07-16 08:02:05 +00001150 "{@type=korap:reference, operation=operation:split, classRef=[2, 3], classRefOp=classRefOp:intersection, operands=[" +
Joachim Bingel832800e2014-10-17 14:46:39 +00001151 "{@type=korap:group, operation=operation:position, frames=[frames:startswith], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001152 "{@type=korap:span, key=s}," +
Joachim Bingel832800e2014-10-17 14:46:39 +00001153 "{@type=korap:group, operation=operation:class, class=3, classOut=3, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001154 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001155 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
Joachim Bingel832800e2014-10-17 14:46:39 +00001156 "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001157 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001158 "{@type=korap:token, wrap={@type=korap:term, foundry=mate, layer=p, key=ADJA, match=match:eq}}," +
Joachim Bingel832800e2014-10-17 14:46:39 +00001159 "{@type=korap:group, operation=operation:class, class=2, classOut=2, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001160 "{@type=korap:token, wrap={@type=korap:term, foundry=tt, layer=p, key=NN, match=match:eq}}" +
Joachim Bingel8c640e42014-02-07 16:20:47 +00001161 "]}" +
1162 "]}" +
1163 "]}" +
1164 "]}" +
1165 "]}" +
Joachim Bingel6b52d762014-09-30 15:29:11 +00001166 "], frame=frame:startswith}" +
Joachim Bingel8c640e42014-02-07 16:20:47 +00001167 "]}";
1168 ppt = new PoliqarpPlusTree("split(2|3:startswith(<s>,{3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) ");
1169 map = ppt.getRequestMap().get("query").toString();
1170 assertEquals(shr7.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel5146ebe2014-06-12 08:49:21 +00001171
1172
1173 String shr8 =
Joachim Bingeld1a3e712014-07-16 08:02:05 +00001174 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingeladd0fb12014-06-24 08:54:14 +00001175 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel4c0c2012014-10-22 09:35:22 +00001176 "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001177 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}" +
Joachim Bingeladd0fb12014-06-24 08:54:14 +00001178 "]}," +
Joachim Bingel832800e2014-10-17 14:46:39 +00001179 "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001180 "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=ADJA, match=match:eq}}" +
Joachim Bingel5146ebe2014-06-12 08:49:21 +00001181 "]}" +
Joachim Bingeladd0fb12014-06-24 08:54:14 +00001182 "]}" +
1183 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +00001184 ppt = new PoliqarpPlusTree("focus(1:{[base=der]}{1:[pos=ADJA]})");
Joachim Bingeladd0fb12014-06-24 08:54:14 +00001185 map = ppt.getRequestMap().get("query").toString();
1186 assertEquals(shr8.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel5146ebe2014-06-12 08:49:21 +00001187
Joachim Bingel53333e62013-12-09 19:25:52 +00001188 }
1189
Joachim Bingel23c31ad2014-08-11 09:44:46 +00001190 @Test
1191 public void testSubspan() throws QueryException {
Joachim Bingel9bbd4fc2014-08-11 14:56:48 +00001192 query = "submatch(1,:<s>)";
Joachim Bingel23c31ad2014-08-11 09:44:46 +00001193 expected =
1194 "{@type=korap:reference, operation=operation:focus, operands=[" +
1195 "{@type=korap:span, key=s}" +
1196 "], spanRef=[1]" +
1197 "}";
1198 ppt = new PoliqarpPlusTree(query);
1199 map = ppt.getRequestMap().get("query").toString();
1200 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1201
Joachim Bingel9bbd4fc2014-08-11 14:56:48 +00001202 query = "submatch(1,4:<s>)";
Joachim Bingel23c31ad2014-08-11 09:44:46 +00001203 expected =
1204 "{@type=korap:reference, operation=operation:focus, operands=[" +
1205 "{@type=korap:span, key=s}" +
1206 "], spanRef=[1,4]" +
1207 "}";
1208 ppt = new PoliqarpPlusTree(query);
1209 map = ppt.getRequestMap().get("query").toString();
1210 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1211
Joachim Bingel9bbd4fc2014-08-11 14:56:48 +00001212 query = "submatch(1,4:contains(<s>,[base=Haus]))";
Joachim Bingel23c31ad2014-08-11 09:44:46 +00001213 expected =
1214 "{@type=korap:reference, operation=operation:focus, operands=[" +
Joachim Bingel832800e2014-10-17 14:46:39 +00001215 "{@type=korap:group, operation=operation:position, frames=[frames:contains], operands=[" +
Joachim Bingel23c31ad2014-08-11 09:44:46 +00001216 "{@type=korap:span, key=s}," +
1217 "{@type=korap:token, wrap= {@type=korap:term, layer=lemma, key=Haus, match=match:eq}}" +
Joachim Bingel6b52d762014-09-30 15:29:11 +00001218 "], frame=frame:contains}" +
Joachim Bingel23c31ad2014-08-11 09:44:46 +00001219 "], spanRef=[1,4]" +
1220 "}";
1221 ppt = new PoliqarpPlusTree(query);
1222 map = ppt.getRequestMap().get("query").toString();
1223 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1224 }
1225
1226 @Test
1227 public void testRelations() throws QueryException {
1228 query = "relatesTo(<s>,<np>)";
1229 expected =
1230 "{@type=korap:group, operation=operation:relation, operands=[" +
1231 "{@type=korap:span, key=s}," +
1232 "{@type=korap:span, key=np}" +
1233 "], relation={@type=korap:relation}" +
1234 "}";
1235 ppt = new PoliqarpPlusTree(query);
1236 map = ppt.getRequestMap().get("query").toString();
1237 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1238
1239 query = "relatesTo([base=Baum],<np>)";
1240 expected =
1241 "{@type=korap:group, operation=operation:relation, operands=[" +
1242 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Baum, match=match:eq}}," +
1243 "{@type=korap:span, key=np}" +
1244 "], relation={@type=korap:relation}" +
1245 "}";
1246 ppt = new PoliqarpPlusTree(query);
1247 map = ppt.getRequestMap().get("query").toString();
1248 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1249
1250 query = "dominates(<np>,[base=Baum])";
1251 expected =
1252 "{@type=korap:group, operation=operation:relation, operands=[" +
1253 "{@type=korap:span, key=np}," +
1254 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Baum, match=match:eq}}" +
1255 "], relation={@type=korap:relation, layer=c}" +
1256 "}";
1257 ppt = new PoliqarpPlusTree(query);
1258 map = ppt.getRequestMap().get("query").toString();
1259 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1260
1261 query = "dominates(cnx/c:<np>,[base=Baum])";
1262 expected =
1263 "{@type=korap:group, operation=operation:relation, operands=[" +
1264 "{@type=korap:span, key=np}," +
1265 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Baum, match=match:eq}}" +
1266 "], relation={@type=korap:relation, layer=c, foundry=cnx}" +
1267 "}";
1268 ppt = new PoliqarpPlusTree(query);
1269 map = ppt.getRequestMap().get("query").toString();
1270 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1271
1272 query = "dominates(cnx/c*:<np>,[base=Baum])";
1273 expected =
1274 "{@type=korap:group, operation=operation:relation, operands=[" +
1275 "{@type=korap:span, key=np}," +
1276 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Baum, match=match:eq}}" +
1277 "], relation={@type=korap:relation, layer=c, foundry=cnx, boundary={@type=korap:boundary, min=0}}" +
1278 "}";
1279 ppt = new PoliqarpPlusTree(query);
1280 map = ppt.getRequestMap().get("query").toString();
1281 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1282
1283 query = "dominates(cnx/c{1,5}:<np>,[base=Baum])";
1284 expected =
1285 "{@type=korap:group, operation=operation:relation, operands=[" +
1286 "{@type=korap:span, key=np}," +
1287 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Baum, match=match:eq}}" +
1288 "], relation={@type=korap:relation, layer=c, foundry=cnx, boundary={@type=korap:boundary, min=1, max=5}}" +
1289 "}";
1290 ppt = new PoliqarpPlusTree(query);
1291 map = ppt.getRequestMap().get("query").toString();
1292 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1293
1294 query = "relatesTo(mate/d=HEAD:<np>,[base=Baum])";
1295 expected =
1296 "{@type=korap:group, operation=operation:relation, operands=[" +
1297 "{@type=korap:span, key=np}," +
1298 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Baum, match=match:eq}}" +
1299 "], relation={@type=korap:relation, foundry=mate, layer=d, key=HEAD}" +
1300 "}";
1301 ppt = new PoliqarpPlusTree(query);
1302 map = ppt.getRequestMap().get("query").toString();
1303 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1304
1305 }
1306
1307
Joachim Bingel03882702013-12-31 19:53:05 +00001308
Joachim Bingel53333e62013-12-09 19:25:52 +00001309 @Test
Joachim Bingelba9a0ab2014-01-29 10:12:25 +00001310 public void testFoundries() throws QueryException {
1311 // [tt/base=Mann]
Joachim Bingel0900a892014-06-30 16:26:21 +00001312 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 +00001313 ppt = new PoliqarpPlusTree("[tt/base=Mann]");
1314 map = ppt.getRequestMap().get("query").toString();
1315 assertEquals(layer1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +00001316
1317 }
Joachim Bingel16da4e12013-12-17 09:48:12 +00001318
1319 @Test
Joachim Bingel8c640e42014-02-07 16:20:47 +00001320 public void testAlign() throws QueryException {
Joachim Bingel16da4e12013-12-17 09:48:12 +00001321 // [orth=der]^[orth=Mann]
Joachim Bingel832800e2014-10-17 14:46:39 +00001322 query = "[orth=der]^[orth=Mann]";
1323 expected =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001324 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001325 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
Joachim Bingel6b491c22014-10-21 08:35:18 +00001326 "{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001327 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" +
Joachim Bingel832800e2014-10-17 14:46:39 +00001328 "]}" +
Joachim Bingel16da4e12013-12-17 09:48:12 +00001329 "]}";
Joachim Bingel832800e2014-10-17 14:46:39 +00001330 metaExpected =
Joachim Bingel6b491c22014-10-21 08:35:18 +00001331 "{alignment=129}";
Joachim Bingel832800e2014-10-17 14:46:39 +00001332 ppt = new PoliqarpPlusTree(query);
Joachim Bingel16da4e12013-12-17 09:48:12 +00001333 map = ppt.getRequestMap().get("query").toString();
Joachim Bingel832800e2014-10-17 14:46:39 +00001334 metaMap = ppt.getRequestMap().get("meta").toString();
1335 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1336 assertEquals(metaExpected.replaceAll(" ", ""), metaMap.replaceAll(" ", ""));
Joachim Bingel16da4e12013-12-17 09:48:12 +00001337
Joachim Bingel84e33df2014-01-31 14:02:46 +00001338 // [orth=der]^[orth=große][orth=Mann]
Joachim Bingel832800e2014-10-17 14:46:39 +00001339 query = "[orth=der]^[orth=große][orth=Mann]";
1340 String expected =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001341 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001342 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
Joachim Bingel6b491c22014-10-21 08:35:18 +00001343 "{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001344 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001345 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=große, match=match:eq}}," +
1346 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +00001347 "]}" +
Joachim Bingel832800e2014-10-17 14:46:39 +00001348 "]}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +00001349 "]}";
Joachim Bingel832800e2014-10-17 14:46:39 +00001350 metaExpected =
Joachim Bingel6b491c22014-10-21 08:35:18 +00001351 "{alignment=129}";
Joachim Bingel84e33df2014-01-31 14:02:46 +00001352 ppt = new PoliqarpPlusTree(query);
1353 map = ppt.getRequestMap().get("query").toString();
Joachim Bingel832800e2014-10-17 14:46:39 +00001354 metaMap = ppt.getRequestMap().get("meta").toString();
1355 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1356 assertEquals(metaExpected.replaceAll(" ", ""), metaMap.replaceAll(" ", ""));
Joachim Bingel84e33df2014-01-31 14:02:46 +00001357
Joachim Bingel832800e2014-10-17 14:46:39 +00001358 query = "([base=a]^[base=b])|[base=c]";
1359 expected =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001360 "{@type=korap:group, operation=operation:or, operands=[" +
1361 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001362 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=a, match=match:eq}}," +
Joachim Bingel6b491c22014-10-21 08:35:18 +00001363 "{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001364 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=b, match=match:eq}}" +
Joachim Bingel832800e2014-10-17 14:46:39 +00001365 "]}" +
Joachim Bingel16da4e12013-12-17 09:48:12 +00001366 "]}," +
Joachim Bingel0900a892014-06-30 16:26:21 +00001367 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=c, match=match:eq}}" +
Joachim Bingel16da4e12013-12-17 09:48:12 +00001368 "]}";
Joachim Bingel832800e2014-10-17 14:46:39 +00001369 metaExpected =
Joachim Bingel6b491c22014-10-21 08:35:18 +00001370 "{alignment=129}";
Joachim Bingel832800e2014-10-17 14:46:39 +00001371 ppt = new PoliqarpPlusTree(query);
Joachim Bingel16da4e12013-12-17 09:48:12 +00001372 map = ppt.getRequestMap().get("query").toString();
Joachim Bingel832800e2014-10-17 14:46:39 +00001373 metaMap = ppt.getRequestMap().get("meta").toString();
1374 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1375 assertEquals(metaExpected.replaceAll(" ", ""), metaMap.replaceAll(" ", ""));
Joachim Bingela67e6a32014-01-02 18:35:24 +00001376
Joachim Bingel832800e2014-10-17 14:46:39 +00001377 query = "([base=a]^[base=b][base=c])|[base=d]";
1378 expected =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001379 "{@type=korap:group, operation=operation:or, operands=[" +
1380 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001381 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=a, match=match:eq}}," +
Joachim Bingel6b491c22014-10-21 08:35:18 +00001382 "{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001383 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001384 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=b, match=match:eq}}," +
1385 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=c, match=match:eq}}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +00001386 "]}" +
Joachim Bingel832800e2014-10-17 14:46:39 +00001387 "]}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +00001388 "]}," +
Joachim Bingel0900a892014-06-30 16:26:21 +00001389 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=d, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +00001390 "]}";
Joachim Bingel832800e2014-10-17 14:46:39 +00001391 metaExpected =
Joachim Bingel6b491c22014-10-21 08:35:18 +00001392 "{alignment=129}";
Joachim Bingel832800e2014-10-17 14:46:39 +00001393 ppt = new PoliqarpPlusTree(query);
Joachim Bingela67e6a32014-01-02 18:35:24 +00001394 map = ppt.getRequestMap().get("query").toString();
Joachim Bingel832800e2014-10-17 14:46:39 +00001395 metaMap = ppt.getRequestMap().get("meta").toString();
1396 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1397 assertEquals(metaExpected.replaceAll(" ", ""), metaMap.replaceAll(" ", ""));
Joachim Bingela67e6a32014-01-02 18:35:24 +00001398
Joachim Bingel832800e2014-10-17 14:46:39 +00001399 query = "([base=a]^[base=b]^[base=c])|[base=d]";
1400 expected =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001401 "{@type=korap:group, operation=operation:or, operands=[" +
1402 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001403 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=a, match=match:eq}}," +
Joachim Bingel6b491c22014-10-21 08:35:18 +00001404 "{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001405 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001406 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=b, match=match:eq}}," +
Joachim Bingel6b491c22014-10-21 08:35:18 +00001407 "{@type=korap:group, operation=operation:class, class=130, classOut=130, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001408 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=c, match=match:eq}}" +
Joachim Bingel832800e2014-10-17 14:46:39 +00001409 "]}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +00001410 "]}" +
Joachim Bingel832800e2014-10-17 14:46:39 +00001411 "]}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +00001412 "]}," +
Joachim Bingel0900a892014-06-30 16:26:21 +00001413 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=d, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +00001414 "]}";
Joachim Bingel832800e2014-10-17 14:46:39 +00001415 metaExpected =
Joachim Bingel6b491c22014-10-21 08:35:18 +00001416 "{alignment=[129,130]}";
Joachim Bingel832800e2014-10-17 14:46:39 +00001417 ppt = new PoliqarpPlusTree(query);
Joachim Bingela67e6a32014-01-02 18:35:24 +00001418 map = ppt.getRequestMap().get("query").toString();
Joachim Bingel832800e2014-10-17 14:46:39 +00001419 metaMap = ppt.getRequestMap().get("meta").toString();
1420 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1421 assertEquals(metaExpected.replaceAll(" ", ""), metaMap.replaceAll(" ", ""));
Joachim Bingela67e6a32014-01-02 18:35:24 +00001422
1423
Joachim Bingel16da4e12013-12-17 09:48:12 +00001424 }
1425
1426 @Test
Joachim Bingel8c640e42014-02-07 16:20:47 +00001427 public void testSimpleQueries() throws QueryException {
Joachim Bingela67e6a32014-01-02 18:35:24 +00001428 // Baum
1429 String simple1 =
Joachim Bingel0900a892014-06-30 16:26:21 +00001430 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq}}";
Joachim Bingela67e6a32014-01-02 18:35:24 +00001431 ppt = new PoliqarpPlusTree("Baum");
1432 map = ppt.getRequestMap().get("query").toString();
1433 assertEquals(simple1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel0900a892014-06-30 16:26:21 +00001434
1435 // Baum/i
1436 String simple1b =
1437 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq, caseInsensitive=true}}";
1438 ppt = new PoliqarpPlusTree("Baum/i");
1439 map = ppt.getRequestMap().get("query").toString();
1440 assertEquals(simple1b.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel16da4e12013-12-17 09:48:12 +00001441
Joachim Bingela67e6a32014-01-02 18:35:24 +00001442 // Der Baum
1443 String simple2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001444 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001445 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}, " +
1446 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +00001447 "]}";
1448 ppt = new PoliqarpPlusTree("Der Baum");
1449 map = ppt.getRequestMap().get("query").toString();
1450 assertEquals(simple2.replaceAll(" ", ""), map.replaceAll(" ", ""));
1451
Joachim Bingel0900a892014-06-30 16:26:21 +00001452 // Der Baum/i
1453 String simple2b =
1454 "{@type=korap:group, operation=operation:sequence, operands=[" +
1455 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}, " +
1456 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq, caseInsensitive=true}}" +
1457 "]}";
1458 ppt = new PoliqarpPlusTree("Der Baum/i");
1459 map = ppt.getRequestMap().get("query").toString();
1460 assertEquals(simple2b.replaceAll(" ", ""), map.replaceAll(" ", ""));
1461
Joachim Bingela67e6a32014-01-02 18:35:24 +00001462 // Der große Baum
1463 String simple3 =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001464 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001465 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}, " +
1466 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=große, match=match:eq}}, " +
1467 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +00001468 "]}";
1469 ppt = new PoliqarpPlusTree("Der große Baum");
1470 map = ppt.getRequestMap().get("query").toString();
1471 assertEquals(simple3.replaceAll(" ", ""), map.replaceAll(" ", ""));
1472
1473 // Baum | Stein
1474 String simple4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001475 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001476 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq}}, " +
1477 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Stein, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +00001478 "]}";
1479 ppt = new PoliqarpPlusTree("Baum | Stein");
1480 map = ppt.getRequestMap().get("query").toString();
1481 assertEquals(simple4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel84e33df2014-01-31 14:02:46 +00001482
1483 // Baum | Stein Haus
1484 String query = "(Baum | Stein) Haus";
1485 String simple5 =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001486 "{@type=korap:group, operation=operation:sequence, operands=[" +
1487 "{@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 Bingel84e33df2014-01-31 14:02:46 +00001490 "]}," +
Joachim Bingel0900a892014-06-30 16:26:21 +00001491 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Haus, match=match:eq}} " +
Joachim Bingel84e33df2014-01-31 14:02:46 +00001492 "]}";
1493 ppt = new PoliqarpPlusTree(query);
1494 map = ppt.getRequestMap().get("query").toString();
1495 assertEquals(simple5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel16da4e12013-12-17 09:48:12 +00001496 }
Joachim Bingelb68361c2014-10-22 14:15:09 +00001497
1498 @Test
1499 public void testUnnecessaryParantheses() throws QueryException {
1500 String query1, query2;
1501 PoliqarpPlusTree tree1, tree2;
1502
1503 query1 = "Test";
1504 query2 = "(Test)";
1505 tree1 = new PoliqarpPlusTree(query1);
1506 tree2 = new PoliqarpPlusTree(query2);
1507 assertEquals(tree1.getRequestMap(), tree2.getRequestMap());
1508
1509 query1 = "pass|fail";
1510 query2 = "(pass|fail)";
1511 tree1 = new PoliqarpPlusTree(query1);
1512 tree2 = new PoliqarpPlusTree(query2);
1513 assertEquals(tree1.getRequestMap(), tree2.getRequestMap());
1514
1515 query1 = "pass|fail";
1516 query2 = "pass|(fail)";
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 = "contains(<s>,Mann)";
1528 query2 = "contains((<s>),Mann)";
1529 tree1 = new PoliqarpPlusTree(query1);
1530 tree2 = new PoliqarpPlusTree(query2);
1531 assertEquals(tree1.getRequestMap(), tree2.getRequestMap());
1532 }
Joachim Bingel53333e62013-12-09 19:25:52 +00001533}
1534