blob: 4f835fb5e4d7aa5e47ac23c5a117bfcd9361c50c [file] [log] [blame]
Joachim Bingel53333e62013-12-09 19:25:52 +00001import static org.junit.Assert.*;
2
3import org.junit.Test;
4
5import de.ids_mannheim.korap.query.serialize.PoliqarpPlusTree;
Joachim Bingel16da4e12013-12-17 09:48:12 +00006import de.ids_mannheim.korap.util.QueryException;
Joachim Bingel53333e62013-12-09 19:25:52 +00007
8public class PoliqarpPlusTreeTest {
9
10 PoliqarpPlusTree ppt;
11 String map;
Joachim Bingel14239d82014-07-22 09:55:04 +000012 String expected;
13 String query;
Joachim Bingel53333e62013-12-09 19:25:52 +000014
Joachim Bingel16da4e12013-12-17 09:48:12 +000015 private boolean equalsQueryContent(String res, String query) throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +000016 res = res.replaceAll(" ", "");
17 ppt = new PoliqarpPlusTree(query);
18 String queryMap = ppt.getRequestMap().get("query").toString().replaceAll(" ", "");
19 return res.equals(queryMap);
20 }
21
Joachim Bingel81812632014-02-18 08:55:22 +000022 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +000023 public void testContext() throws QueryException {
Joachim Bingel81812632014-02-18 08:55:22 +000024 String contextString = "http://ids-mannheim.de/ns/KorAP/json-ld/v0.1/context.jsonld";
Joachim Bingel2daf9862014-02-12 10:18:54 +000025 ppt = new PoliqarpPlusTree("Test");
26 assertEquals(contextString.replaceAll(" ", ""), ppt.getRequestMap().get("@context").toString().replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +000027 }
28
29 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +000030 public void testSingleTokens() throws QueryException {
Joachim Bingel0900a892014-06-30 16:26:21 +000031 String query;
Joachim Bingel53333e62013-12-09 19:25:52 +000032 // [base=Mann]
Joachim Bingel0900a892014-06-30 16:26:21 +000033 String token1 = "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}";
Joachim Bingel53333e62013-12-09 19:25:52 +000034 assertTrue(equalsQueryContent(token1, "[base=Mann]"));
35
36 // [orth!=Frau]
Joachim Bingel0900a892014-06-30 16:26:21 +000037 String token2 = "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:ne}}";
Joachim Bingel53333e62013-12-09 19:25:52 +000038 assertTrue(equalsQueryContent(token2, "[orth!=Frau]"));
39
40 // [!p=NN]
Joachim Bingel0900a892014-06-30 16:26:21 +000041 query = "[!p=NN]";
42 String token3 = "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:ne}}";
43 ppt = new PoliqarpPlusTree(query);
44 map = ppt.getRequestMap().get("query").toString();
45 assertEquals(token3.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +000046
47 // [!p!=NN]
Joachim Bingel0900a892014-06-30 16:26:21 +000048 query = "[!p!=NN]";
49 String token4 = "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}";
50 ppt = new PoliqarpPlusTree(query);
51 map = ppt.getRequestMap().get("query").toString();
52 assertEquals(token4.replaceAll(" ", ""), map.replaceAll(" ", ""));
53
Joachim Bingeld1a3e712014-07-16 08:02:05 +000054 query = "[base=schland/x]";
Joachim Bingela83f8cc2014-08-05 14:12:59 +000055 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 +000056 ppt = new PoliqarpPlusTree(query);
57 map = ppt.getRequestMap().get("query").toString();
58 assertEquals(token5.replaceAll(" ", ""), map.replaceAll(" ", ""));
59 }
60
61 @Test
62 public void testValue() throws QueryException {
63 String query;
64
65 query = "[mate/m=temp:pres]";
66 String value1 = "{@type=korap:token, wrap={@type=korap:term, foundry=mate, layer=m, key=temp, value=pres, match=match:eq}}";
67 ppt = new PoliqarpPlusTree(query);
68 map = ppt.getRequestMap().get("query").toString();
69 assertEquals(value1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +000070 }
71
72 @Test
Joachim Bingel41e112e2014-02-12 10:46:18 +000073 public void testRegex() throws QueryException {
74 String query = "[orth=\"M(a|ä)nn(er)?\"]";
Joachim Bingel0900a892014-06-30 16:26:21 +000075 String re1 = "{@type=korap:token, wrap={@type=korap:term, layer=orth, type=type:regex, key=M(a|ä)nn(er)?, match=match:eq}}";
Joachim Bingel41e112e2014-02-12 10:46:18 +000076 ppt = new PoliqarpPlusTree(query);
77 map = ppt.getRequestMap().get("query").toString();
78 assertEquals(re1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel0900a892014-06-30 16:26:21 +000079
80 query = "[orth=\"M(a|ä)nn(er)?\"/x]";
81 String re2 = "{@type=korap:token, wrap={@type=korap:term, layer=orth, type=type:regex, key=.*?M(a|ä)nn(er)?.*?, match=match:eq}}";
82 ppt = new PoliqarpPlusTree(query);
83 map = ppt.getRequestMap().get("query").toString();
84 assertEquals(re2.replaceAll(" ", ""), map.replaceAll(" ", ""));
85
86 query = "\"M(a|ä)nn(er)?\"/x";
87 String re3 = "{@type=korap:token, wrap={@type=korap:term, type=type:regex, layer=orth, key=.*?M(a|ä)nn(er)?.*?, match=match:eq}}";
88 ppt = new PoliqarpPlusTree(query);
89 map = ppt.getRequestMap().get("query").toString();
90 assertEquals(re3.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeld1a3e712014-07-16 08:02:05 +000091
92 query = "schland/x";
Joachim Bingela83f8cc2014-08-05 14:12:59 +000093 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 +000094 ppt = new PoliqarpPlusTree(query);
95 map = ppt.getRequestMap().get("query").toString();
96 assertEquals(re4.replaceAll(" ", ""), map.replaceAll(" ", ""));
97
98 query = "\".*?Mann.*?\"";
99 String re5 = "{@type=korap:token, wrap={@type=korap:term, type=type:regex, layer=orth, key=.*?Mann.*?, match=match:eq}}";
100 ppt = new PoliqarpPlusTree(query);
101 map = ppt.getRequestMap().get("query").toString();
102 assertEquals(re5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingela83f8cc2014-08-05 14:12:59 +0000103
104 query = "z.B./x";
105 String re6 = "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=.*?z\\.B\\..*?, match=match:eq, type=type:regex}}";
106 ppt = new PoliqarpPlusTree(query);
107 map = ppt.getRequestMap().get("query").toString();
108 assertEquals(re6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel41e112e2014-02-12 10:46:18 +0000109 }
110
111 @Test
Joachim Bingel0207d5e2014-02-12 14:18:41 +0000112 public void testCaseSensitivityFlag() throws QueryException {
113 String query="[orth=deutscher/i]";
114 String cs1 =
Joachim Bingel0900a892014-06-30 16:26:21 +0000115 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=deutscher, match=match:eq, caseInsensitive=true}}";
Joachim Bingel0207d5e2014-02-12 14:18:41 +0000116 ppt = new PoliqarpPlusTree(query);
117 map = ppt.getRequestMap().get("query").toString();
118 assertEquals(cs1.replaceAll(" ", ""), map.replaceAll(" ", ""));
119
120 query="[orth=deutscher/i][orth=Bundestag]";
121 String cs2 =
122 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000123 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=deutscher, match=match:eq, caseInsensitive=true}}," +
124 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Bundestag, match=match:eq}}" +
Joachim Bingel0207d5e2014-02-12 14:18:41 +0000125 "]}";
126 ppt = new PoliqarpPlusTree(query);
127 map = ppt.getRequestMap().get("query").toString();
128 assertEquals(cs2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeladd0fb12014-06-24 08:54:14 +0000129
130 query="deutscher/i";
131 String cs3 =
Joachim Bingel0900a892014-06-30 16:26:21 +0000132 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=deutscher, match=match:eq, caseInsensitive=true}}";
Joachim Bingeladd0fb12014-06-24 08:54:14 +0000133 ppt = new PoliqarpPlusTree(query);
134 map = ppt.getRequestMap().get("query").toString();
135 assertEquals(cs3.replaceAll(" ", ""), map.replaceAll(" ", ""));
136
137 query="deutscher/i Bundestag";
138 String cs4 =
139 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000140 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=deutscher, match=match:eq, caseInsensitive=true}}," +
141 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Bundestag, match=match:eq}}" +
Joachim Bingeladd0fb12014-06-24 08:54:14 +0000142 "]}";
143 ppt = new PoliqarpPlusTree(query);
144 map = ppt.getRequestMap().get("query").toString();
145 assertEquals(cs4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000146
147 query="deutscher Bundestag/i";
148 String cs5 =
149 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000150 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=deutscher, match=match:eq}}," +
151 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Bundestag, match=match:eq, caseInsensitive=true}}" +
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000152 "]}";
153 ppt = new PoliqarpPlusTree(query);
154 map = ppt.getRequestMap().get("query").toString();
155 assertEquals(cs5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel0207d5e2014-02-12 14:18:41 +0000156 }
157
158 @Test
Joachim Bingel3a41a442014-07-22 12:16:16 +0000159 public void testSpans() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000160 // <s>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000161 String elem1 = "{@type=korap:span, key=s}";
Joachim Bingel53333e62013-12-09 19:25:52 +0000162 assertTrue(equalsQueryContent(elem1, "<s>"));
163
164 // <vp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000165 String elem2 = "{@type=korap:span, key=vp}";
Joachim Bingel53333e62013-12-09 19:25:52 +0000166 assertTrue(equalsQueryContent(elem2, "<vp>"));
Joachim Bingelfc1fb352014-02-26 14:40:27 +0000167
168 // <cnx/c=vp>
169 query = "<c=vp>";
170 String span3 = "{@type=korap:span, layer=c, key=vp}";
171 ppt = new PoliqarpPlusTree(query);
172 map = ppt.getRequestMap().get("query").toString();
173 assertEquals(span3.replaceAll(" ", ""), map.replaceAll(" ", ""));
174
175 // <cnx/c=vp>
176 query = "<cnx/c=vp>";
177 String span4 = "{@type=korap:span, foundry=cnx, layer=c, key=vp}";
178 ppt = new PoliqarpPlusTree(query);
179 map = ppt.getRequestMap().get("query").toString();
180 assertEquals(span4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel3a41a442014-07-22 12:16:16 +0000181
182 // span negation
183 query = "<cnx/c!=vp>";
184 expected = "{@type=korap:span, foundry=cnx, layer=c, key=vp, match=match:ne}";
185 ppt = new PoliqarpPlusTree(query);
186 map = ppt.getRequestMap().get("query").toString();
187 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
188
189 // span negation
190 query = "<cnx/c!=vp>";
191 expected = "{@type=korap:span, foundry=cnx, layer=c, key=vp, match=match:ne}";
192 ppt = new PoliqarpPlusTree(query);
193 map = ppt.getRequestMap().get("query").toString();
194 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
195
196 query = "<cnx/c=vp class!=header>";
197 expected = "{@type=korap:span, foundry=cnx, layer=c, key=vp, attr={@type=korap:term, key=class, value=header, match=match:ne}}";
198 ppt = new PoliqarpPlusTree(query);
199 map = ppt.getRequestMap().get("query").toString();
200 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
201
202 query = "<cnx/c=vp !(class=header&id=7)>";
203 expected =
204 "{@type=korap:span, foundry=cnx, layer=c, key=vp, attr=" +
205 "{@type=korap:termGroup, relation=relation:and, operands=[" +
206 "{@type=korap:term, key=class, value=header, match=match:ne}," +
207 "{@type=korap:term, key=id, value=7, match=match:ne}" +
208 "]}" +
209 "}";
210 ppt = new PoliqarpPlusTree(query);
211 map = ppt.getRequestMap().get("query").toString();
212 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
213
214 query = "<cnx/c!=vp (class=header&id=7)>";
215 expected =
216 "{@type=korap:span, foundry=cnx, layer=c, key=vp, match=match:ne, attr=" +
217 "{@type=korap:termGroup, relation=relation:and, operands=[" +
218 "{@type=korap:term, key=class, value=header, match=match:eq}," +
219 "{@type=korap:term, key=id, value=7, match=match:eq}" +
220 "]}" +
221 "}";
222 ppt = new PoliqarpPlusTree(query);
223 map = ppt.getRequestMap().get("query").toString();
224 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
225
226 query = "<cnx/c=vp !!class=header>";
227 expected = "{@type=korap:span, foundry=cnx, layer=c, key=vp, attr={@type=korap:term, key=class, value=header, match=match:eq}}";
228 ppt = new PoliqarpPlusTree(query);
229 map = ppt.getRequestMap().get("query").toString();
230 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingela0ef08f2014-07-24 08:27:57 +0000231
232 query = "<cnx/c!=vp (foundry/class=header&id=7)>";
233 expected =
234 "{@type=korap:span, foundry=cnx, layer=c, key=vp, match=match:ne, attr=" +
235 "{@type=korap:termGroup, relation=relation:and, operands=[" +
236 "{@type=korap:term, foundry=foundry, key=class, value=header, match=match:eq}," +
237 "{@type=korap:term, key=id, value=7, match=match:eq}" +
238 "]}" +
239 "}";
240 ppt = new PoliqarpPlusTree(query);
241 map = ppt.getRequestMap().get("query").toString();
242 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000243 }
Joachim Bingel87480d02014-01-17 14:07:46 +0000244
245 @Test
Joachim Bingel14239d82014-07-22 09:55:04 +0000246 public void testDistances() throws QueryException {
Joachim Bingel87480d02014-01-17 14:07:46 +0000247 // [base=der][][base=Mann]
248 String et1 =
Joachim Bingel0900a892014-06-30 16:26:21 +0000249 "{@type=korap:group, operation=operation:sequence, " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000250 "operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000251 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
252 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
253 "], inOrder=true, distances=[" +
Joachim Bingel5a146cd2014-07-24 14:44:57 +0000254 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=2, max=2}, min=2, max=2}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000255 "]}";
256 ppt = new PoliqarpPlusTree("[base=der][][base=Mann]");
257 map = ppt.getRequestMap().get("query").toString();
258 assertEquals(et1.replaceAll(" ", ""), map.replaceAll(" ", ""));
259
260 // [base=der][][][base=Mann]
261 String et2 =
Joachim Bingel0900a892014-06-30 16:26:21 +0000262 "{@type=korap:group, operation=operation:sequence, " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000263 "operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000264 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
265 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
266 "], inOrder=true, distances=[" +
Joachim Bingel5a146cd2014-07-24 14:44:57 +0000267 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=3, max=3}, min=3, max=3}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000268 "]}";
Joachim Bingelffd65e32014-01-22 14:22:57 +0000269 ppt = new PoliqarpPlusTree("[base=der][][][base=Mann]");
Joachim Bingel87480d02014-01-17 14:07:46 +0000270 map = ppt.getRequestMap().get("query").toString();
271 assertEquals(et2.replaceAll(" ", ""), map.replaceAll(" ", ""));
272
273 // [base=der][][]?[base=Mann]
274 String et3 =
Joachim Bingel0900a892014-06-30 16:26:21 +0000275 "{@type=korap:group, operation=operation:sequence, " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000276 "operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000277 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
278 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
279 "], inOrder=true, distances=[" +
Joachim Bingel5a146cd2014-07-24 14:44:57 +0000280 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=2, max=3}, min=2, max=3}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000281 "]}";
282 ppt = new PoliqarpPlusTree("[base=der][][]?[base=Mann]");
283 map = ppt.getRequestMap().get("query").toString();
284 assertEquals(et3.replaceAll(" ", ""), map.replaceAll(" ", ""));
285
Joachim Bingel87480d02014-01-17 14:07:46 +0000286
Joachim Bingel14239d82014-07-22 09:55:04 +0000287
Joachim Bingelffd65e32014-01-22 14:22:57 +0000288
Joachim Bingel11d5b152014-02-11 21:33:47 +0000289 // [base=der][]{2,5}[base=Mann][]?[][base=Frau] nested distances=
Joachim Bingelffd65e32014-01-22 14:22:57 +0000290 String et5 =
Joachim Bingel0900a892014-06-30 16:26:21 +0000291 "{@type=korap:group, operation=operation:sequence," +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000292 "operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000293 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
294 "{@type=korap:group, operation=operation:sequence, " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000295 "operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000296 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}," +
297 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Frau, match=match:eq}}" +
298 "], inOrder=true, distances=[" +
Joachim Bingel5a146cd2014-07-24 14:44:57 +0000299 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=2, max=3}, min=2, max=3}" +
Joachim Bingelffd65e32014-01-22 14:22:57 +0000300 "]}" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000301 "], inOrder=true, distances=[" +
Joachim Bingel5a146cd2014-07-24 14:44:57 +0000302 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=3, max=6}, min=3, max=6}" +
Joachim Bingelffd65e32014-01-22 14:22:57 +0000303 "]}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000304 ppt = new PoliqarpPlusTree("[base=der][]{2,5}[base=Mann][]?[][base=Frau]");
Joachim Bingel87480d02014-01-17 14:07:46 +0000305 map = ppt.getRequestMap().get("query").toString();
306 assertEquals(et5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel87480d02014-01-17 14:07:46 +0000307
Joachim Bingelc15720f2014-05-07 14:37:23 +0000308 // [base=der][]*[base=Mann]
309 String et6 =
Joachim Bingel0900a892014-06-30 16:26:21 +0000310 "{@type=korap:group, operation=operation:sequence, " +
Joachim Bingelc15720f2014-05-07 14:37:23 +0000311 "operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000312 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
313 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
314 "], inOrder=true, distances=[" +
Joachim Bingel687e4d42014-07-30 09:34:18 +0000315 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1}, min=1}" +
Joachim Bingelc15720f2014-05-07 14:37:23 +0000316 "]}";
317 ppt = new PoliqarpPlusTree("[base=der][]*[base=Mann]");
318 map = ppt.getRequestMap().get("query").toString();
319 assertEquals(et6.replaceAll(" ", ""), map.replaceAll(" ", ""));
320
Joachim Bingel0900a892014-06-30 16:26:21 +0000321 // [base=der][]+[base=Mann]
Joachim Bingelc15720f2014-05-07 14:37:23 +0000322 String et7 =
Joachim Bingel0900a892014-06-30 16:26:21 +0000323 "{@type=korap:group, operation=operation:sequence, " +
Joachim Bingelc15720f2014-05-07 14:37:23 +0000324 "operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000325 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
326 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
327 "], inOrder=true, distances=[" +
Joachim Bingel687e4d42014-07-30 09:34:18 +0000328 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=2}, min=2}" +
Joachim Bingelc15720f2014-05-07 14:37:23 +0000329 "]}";
330 ppt = new PoliqarpPlusTree("[base=der][]+[base=Mann]");
331 map = ppt.getRequestMap().get("query").toString();
332 assertEquals(et7.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel14239d82014-07-22 09:55:04 +0000333
334 // [base=der][]+[base=Mann]
335 String et8 =
336 "{@type=korap:group, operation=operation:sequence, " +
337 "operands=[" +
338 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
339 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
340 "], inOrder=true, distances=[" +
Joachim Bingel687e4d42014-07-30 09:34:18 +0000341 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=2, max=103}, min=2, max=103}" +
Joachim Bingel14239d82014-07-22 09:55:04 +0000342 "]}";
343 ppt = new PoliqarpPlusTree("[base=der][]{1,102}[base=Mann]");
344 map = ppt.getRequestMap().get("query").toString();
345 assertEquals(et8.replaceAll(" ", ""), map.replaceAll(" ", ""));
346
347 // [base=geht][base=der][]*[base=Mann]
348 String et9 =
349 "{@type=korap:group, operation=operation:sequence, operands=[" +
350 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=geht, match=match:eq}}," +
351 "{@type=korap:group, operation=operation:sequence, " +
352 "operands=[" +
353 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
354 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
355 "], inOrder=true, distances=[" +
Joachim Bingel687e4d42014-07-30 09:34:18 +0000356 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1}, min=1}" +
Joachim Bingel14239d82014-07-22 09:55:04 +0000357 "]}" +
358 "]}";
359 ppt = new PoliqarpPlusTree("[base=geht][base=der][]*[base=Mann]");
360 map = ppt.getRequestMap().get("query").toString();
361 assertEquals(et9.replaceAll(" ", ""), map.replaceAll(" ", ""));
362
363 query = "[base=geht][base=der][]*[base=Mann][base=da]";
364 expected =
365 "{@type=korap:group, operation=operation:sequence, operands=[" +
366 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=geht, match=match:eq}}," +
367 "{@type=korap:group, operation=operation:sequence, " +
368 "operands=[" +
369 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
370 "{@type=korap:group, operation=operation:sequence, operands=[" +
371 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}," +
372 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=da, match=match:eq}}" +
373 "]}" +
374 "], inOrder=true, distances=[" +
Joachim Bingel687e4d42014-07-30 09:34:18 +0000375 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1}, min=1}" +
Joachim Bingel14239d82014-07-22 09:55:04 +0000376 "]}" +
377 "]}";
378 ppt = new PoliqarpPlusTree(query);
379 map = ppt.getRequestMap().get("query").toString();
380 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
381
382 query = "[base=geht][base=der][]*contains(<s>,<np>)";
383 expected =
384 "{@type=korap:group, operation=operation:sequence, operands=[" +
385 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=geht, match=match:eq}}," +
386 "{@type=korap:group, operation=operation:sequence, " +
387 "operands=[" +
388 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
389 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
390 "{@type=korap:span, key=s}," +
391 "{@type=korap:span, key=np}" +
392 "]}" +
393 "], inOrder=true, distances=[" +
Joachim Bingel687e4d42014-07-30 09:34:18 +0000394 "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1}, min=1}" +
Joachim Bingel14239d82014-07-22 09:55:04 +0000395 "]}" +
396 "]}";
397 ppt = new PoliqarpPlusTree(query);
398 map = ppt.getRequestMap().get("query").toString();
399 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel87480d02014-01-17 14:07:46 +0000400 }
Joachim Bingel53333e62013-12-09 19:25:52 +0000401
402 @Test
Joachim Bingel14239d82014-07-22 09:55:04 +0000403 public void testLeadingTrailingEmptyTokens() throws QueryException {
404 // startswith(<s>, [][base=Mann]
405 String et1 =
406 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
407 "{@type=korap:span, key=s}," +
408 "{@type=korap:group, operation=operation:sequence, operands=[" +
409 "{@type=korap:token}," +
410 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
411 "]}" +
412 "]}";
413 ppt = new PoliqarpPlusTree("startswith(<s>, [][base=Mann])");
414 map = ppt.getRequestMap().get("query").toString();
415 assertEquals(et1.replaceAll(" ", ""), map.replaceAll(" ", ""));
416
417 query = "[][base=Mann]";
418 expected =
419 "{@type=korap:group, operation=operation:sequence, operands=[" +
420 "{@type=korap:token}," +
421 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
422 "]}";
423 ppt = new PoliqarpPlusTree(query);
424 map = ppt.getRequestMap().get("query").toString();
425 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
426
427 query = "[][][base=Mann]";
428 expected =
429 "{@type=korap:group, operation=operation:sequence, operands=[" +
430 "{@type=korap:group, operation=operation:repetition, operands=[" +
431 "{@type=korap:token}" +
Joachim Bingel61631562014-07-24 14:26:02 +0000432 "], boundary={@type=korap:boundary, min=2, max=2}, min=2, max=2}," +
Joachim Bingel14239d82014-07-22 09:55:04 +0000433 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
434 "]}";
435 ppt = new PoliqarpPlusTree(query);
436 map = ppt.getRequestMap().get("query").toString();
437 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
438
439 query = "[][]*[base=Mann]";
440 expected =
441 "{@type=korap:group, operation=operation:sequence, operands=[" +
442 "{@type=korap:group, operation=operation:repetition, operands=[" +
443 "{@type=korap:token}" +
Joachim Bingel687e4d42014-07-30 09:34:18 +0000444 "], boundary={@type=korap:boundary, min=1}, min=1}," +
Joachim Bingel14239d82014-07-22 09:55:04 +0000445 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
446 "]}";
447 ppt = new PoliqarpPlusTree(query);
448 map = ppt.getRequestMap().get("query").toString();
449 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
450
451 query = "[][]*[base=Mann][][]";
452 expected =
453 "{@type=korap:group, operation=operation:sequence, operands=[" +
454 "{@type=korap:group, operation=operation:repetition, operands=[" +
455 "{@type=korap:token}" +
Joachim Bingel687e4d42014-07-30 09:34:18 +0000456 "], boundary={@type=korap:boundary, min=1}, min=1}," +
Joachim Bingel14239d82014-07-22 09:55:04 +0000457 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}," +
458 "{@type=korap:group, operation=operation:repetition, operands=[" +
459 "{@type=korap:token}" +
Joachim Bingel61631562014-07-24 14:26:02 +0000460 "], boundary={@type=korap:boundary, min=2, max=2}, min=2, max=2}" +
Joachim Bingel14239d82014-07-22 09:55:04 +0000461 "]}";
462 ppt = new PoliqarpPlusTree(query);
463 map = ppt.getRequestMap().get("query").toString();
464 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
465
466 query = "[][]*contains(<s>, <np>)[][]";
467 expected =
468 "{@type=korap:group, operation=operation:sequence, operands=[" +
469 "{@type=korap:group, operation=operation:repetition, operands=[" +
470 "{@type=korap:token}" +
Joachim Bingel687e4d42014-07-30 09:34:18 +0000471 "], boundary={@type=korap:boundary, min=1}, min=1}," +
Joachim Bingel14239d82014-07-22 09:55:04 +0000472 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
473 "{@type=korap:span, key=s}," +
474 "{@type=korap:span, key=np}" +
475 "]}," +
476 "{@type=korap:group, operation=operation:repetition, operands=[" +
477 "{@type=korap:token}" +
Joachim Bingel61631562014-07-24 14:26:02 +0000478 "], boundary={@type=korap:boundary, min=2, max=2}, min=2, max=2}" +
Joachim Bingel14239d82014-07-22 09:55:04 +0000479 "]}";
480 ppt = new PoliqarpPlusTree(query);
481 map = ppt.getRequestMap().get("query").toString();
482 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
483 }
484
485 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000486 public void testCoordinatedFields() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000487 // [base=Mann&(cas=N|cas=A)]
488 String cof1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000489 "{@type=korap:token, wrap=" +
Joachim Bingel2980bda2014-04-04 12:09:46 +0000490 "{@type=korap:termGroup, relation=relation:and, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000491 "{@type=korap:term, layer=lemma, key=Mann, match=match:eq}," +
Joachim Bingel2980bda2014-04-04 12:09:46 +0000492 "{@type=korap:termGroup, relation=relation:or, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000493 "{@type=korap:term, layer=cas, key=N, match=match:eq}," +
494 "{@type=korap:term, layer=cas, key=A, match=match:eq}" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000495 "]}" +
496 "]}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000497 "}";
498 ppt = new PoliqarpPlusTree("[base=Mann&(cas=N|cas=A)]");
499 map = ppt.getRequestMap().get("query").toString();
500 assertEquals(cof1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Nils Diewald7d486c22013-12-13 16:32:18 +0000501
502
503 assertEquals(
504 new PoliqarpPlusTree(" [ base=Mann & ( cas=N | cas=A)] ").getRequestMap().get("query").toString(),
505 new PoliqarpPlusTree("[base=Mann &(cas=N|cas=A)]").getRequestMap().get("query").toString()
506 );
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000507
508 // [base=Mann&cas=N&gen=m]
509 String cof2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000510 "{@type=korap:token, wrap=" +
Joachim Bingel2980bda2014-04-04 12:09:46 +0000511 "{@type=korap:termGroup, relation=relation:and, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000512 "{@type=korap:term, layer=lemma, key=Mann, match=match:eq}," +
513 "{@type=korap:termGroup, relation=relation:and, operands=[" +
514 "{@type=korap:term, layer=cas, key=N, match=match:eq}," +
515 "{@type=korap:term, layer=gen, key=m, match=match:eq}" +
516 "]}" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000517 "]}" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000518 "}";
519 ppt = new PoliqarpPlusTree("[base=Mann&cas=N&gen=m]");
520 map = ppt.getRequestMap().get("query").toString();
521 assertEquals(cof2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000522 }
523
524 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000525 public void testOccurrence() throws QueryException {
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000526 // [base=foo]*
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000527 String occ1 = "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000528 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingel687e4d42014-07-30 09:34:18 +0000529 "], boundary={@type=korap:boundary, min=0}, min=0}";
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000530 ppt = new PoliqarpPlusTree("[base=foo]*");
531 map = ppt.getRequestMap().get("query").toString();
532 assertEquals(occ1.replaceAll(" ", ""), map.replaceAll(" ", ""));
533
534 // [base=foo]*[base=bar]
535 String occ2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000536 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000537 "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000538 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingel687e4d42014-07-30 09:34:18 +0000539 "], boundary={@type=korap:boundary, min=0}, min=0 }," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000540 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000541 "]}";
542 ppt = new PoliqarpPlusTree("[base=foo]*[base=bar]");
543 map = ppt.getRequestMap().get("query").toString();
544 assertEquals(occ2.replaceAll(" ", ""), map.replaceAll(" ", ""));
545
546 // [base=bar][base=foo]*
547 String occ3 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000548 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000549 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000550 "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000551 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingel687e4d42014-07-30 09:34:18 +0000552 "], boundary={@type=korap:boundary, min=0}, min=0 }" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000553 "]}";
554 ppt = new PoliqarpPlusTree("[base=bar][base=foo]*");
555 map = ppt.getRequestMap().get("query").toString();
556 assertEquals(occ3.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb4da7022013-12-09 23:17:24 +0000557
558 // ([base=bar][base=foo])*
559 String occ4 =
Joachim Bingel0900a892014-06-30 16:26:21 +0000560 "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000561 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000562 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," +
563 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000564 "]}" +
Joachim Bingel687e4d42014-07-30 09:34:18 +0000565 "], boundary={@type=korap:boundary, min=0}, min=0}" ;
Joachim Bingelb4da7022013-12-09 23:17:24 +0000566 ppt = new PoliqarpPlusTree("([base=bar][base=foo])*");
567 map = ppt.getRequestMap().get("query").toString();
568 assertEquals(occ4.replaceAll(" ", ""), map.replaceAll(" ", ""));
569
570 // <s>([base=bar][base=foo])*
571 String occ5 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000572 "{@type=korap:group, operation=operation:sequence, operands=[" +
573 "{@type=korap:span, key=s}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000574 "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000575 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000576 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," +
577 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000578 "]}" +
Joachim Bingel687e4d42014-07-30 09:34:18 +0000579 "], boundary={@type=korap:boundary, min=0}, min=0 }" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000580 "]}" ;
581 ppt = new PoliqarpPlusTree("<s>([base=bar][base=foo])*");
582 map = ppt.getRequestMap().get("query").toString();
583 assertEquals(occ5.replaceAll(" ", ""), map.replaceAll(" ", ""));
584
585 // <s><np>([base=bar][base=foo])*
Joachim Bingelb4da7022013-12-09 23:17:24 +0000586 String occ6 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000587 "{@type=korap:group, operation=operation:sequence, operands=[" +
588 "{@type=korap:span, key=s}," +
589 "{@type=korap:span, key=np}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000590 "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000591 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000592 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," +
593 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000594 "]}" +
Joachim Bingel687e4d42014-07-30 09:34:18 +0000595 "], boundary={@type=korap:boundary, min=0}, min=0 }" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000596 "]}" ;
597 ppt = new PoliqarpPlusTree("<s><np>([base=bar][base=foo])*");
598 map = ppt.getRequestMap().get("query").toString();
599 assertEquals(occ6.replaceAll(" ", ""), map.replaceAll(" ", ""));
600
601 // <s><np>([base=bar][base=foo])*[p=NN]
602 // comment: embedded sequence shouldn't really be here, but does not really hurt, either. (?)
603 // really hard to get this behaviour out of the PQPlus grammar...
604 String occ7 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000605 "{@type=korap:group, operation=operation:sequence, operands=[" +
606 "{@type=korap:span, key=s}," +
607 "{@type=korap:span, key=np}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000608 "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000609 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000610 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," +
611 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000612 "]}" +
Joachim Bingel687e4d42014-07-30 09:34:18 +0000613 "], boundary={@type=korap:boundary, min=0}, min=0 }," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000614 "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000615 "]}" ;
616 ppt = new PoliqarpPlusTree("<s><np>([base=bar][base=foo])*[p=NN]");
617 map = ppt.getRequestMap().get("query").toString();
618 assertEquals(occ7.replaceAll(" ", ""), map.replaceAll(" ", ""));
619
620 // ([base=bar][base=foo])*[p=NN]
Joachim Bingelb4da7022013-12-09 23:17:24 +0000621 String occ8 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000622 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000623 "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000624 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000625 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," +
626 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000627 "]}" +
Joachim Bingel687e4d42014-07-30 09:34:18 +0000628 "], boundary={@type=korap:boundary, min=0}, min=0 }," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000629 "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000630 "]}" ;
631 ppt = new PoliqarpPlusTree("([base=bar][base=foo])*[p=NN]");
632 map = ppt.getRequestMap().get("query").toString();
633 assertEquals(occ8.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000634
635 // [base=foo]+
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000636 String occ9 = "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000637 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingel687e4d42014-07-30 09:34:18 +0000638 "], boundary={@type=korap:boundary, min=1}, min=1}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000639 ppt = new PoliqarpPlusTree("[base=foo]+");
640 map = ppt.getRequestMap().get("query").toString();
641 assertEquals(occ9.replaceAll(" ", ""), map.replaceAll(" ", ""));
642
643 // [base=foo]?
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000644 String occ10 = "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000645 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingel61631562014-07-24 14:26:02 +0000646 "], boundary={@type=korap:boundary, min=0, max=1}, min=0, max=1}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000647 ppt = new PoliqarpPlusTree("[base=foo]?");
648 map = ppt.getRequestMap().get("query").toString();
649 assertEquals(occ10.replaceAll(" ", ""), map.replaceAll(" ", ""));
650
651 // [base=foo]{2,5}
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000652 String occ11 = "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000653 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingel61631562014-07-24 14:26:02 +0000654 "], boundary={@type=korap:boundary, min=2, max=5}, min=2, max=5}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000655 ppt = new PoliqarpPlusTree("[base=foo]{2,5}");
656 map = ppt.getRequestMap().get("query").toString();
657 assertEquals(occ11.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel2980bda2014-04-04 12:09:46 +0000658
659 // [base=foo]{2}
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000660 String occ12 = "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000661 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingel61631562014-07-24 14:26:02 +0000662 "], boundary={@type=korap:boundary, min=2, max=2}, min=2, max=2}";
Joachim Bingel2980bda2014-04-04 12:09:46 +0000663 ppt = new PoliqarpPlusTree("[base=foo]{2}");
664 map = ppt.getRequestMap().get("query").toString();
665 assertEquals(occ12.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb2aa1c72014-07-01 12:48:46 +0000666
667 // [base=foo]{2}
668 String occ13 = "{@type=korap:group, operation=operation:repetition, operands=[" +
669 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingel687e4d42014-07-30 09:34:18 +0000670 "], boundary={@type=korap:boundary, min=2}, min=2}";
Joachim Bingelb2aa1c72014-07-01 12:48:46 +0000671 ppt = new PoliqarpPlusTree("[base=foo]{2,}");
672 map = ppt.getRequestMap().get("query").toString();
673 assertEquals(occ13.replaceAll(" ", ""), map.replaceAll(" ", ""));
674
675 // [base=foo]{2}
676 String occ14 = "{@type=korap:group, operation=operation:repetition, operands=[" +
677 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingel61631562014-07-24 14:26:02 +0000678 "], boundary={@type=korap:boundary, min=0, max=2}, min=0, max=2}";
Joachim Bingelb2aa1c72014-07-01 12:48:46 +0000679 ppt = new PoliqarpPlusTree("[base=foo]{,2}");
680 map = ppt.getRequestMap().get("query").toString();
681 assertEquals(occ14.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000682 }
683
684 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000685 public void testTokenSequence() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000686 // [base=Mann][orth=Frau]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000687 String seq1 = "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000688 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}, " +
689 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000690 "]}";
691 assertTrue(equalsQueryContent(seq1, "[base=Mann][orth=Frau]"));
692
693 // [base=Mann][orth=Frau][p=NN]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000694 String seq2 = "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000695 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}, " +
696 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}, " +
697 "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000698 "]}";
699 assertTrue(equalsQueryContent(seq2, "[base=Mann][orth=Frau][p=NN]"));
700 }
701
702 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000703 public void testDisjSegments() throws QueryException {
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000704 // ([base=der]|[base=das])[base=Schild]
705 String disj1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000706 "{@type=korap:group, operation=operation:sequence, operands=[" +
707 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000708 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
709 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=das, match=match:eq}}" +
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000710 "]}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000711 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Schild, match=match:eq}}" +
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000712 "]}";
713 ppt = new PoliqarpPlusTree("([base=der]|[base=das])[base=Schild]");
714 map = ppt.getRequestMap().get("query").toString();
715 assertEquals(disj1.replaceAll(" ", ""), map.replaceAll(" ", ""));
716
717 // [base=Schild]([base=der]|[base=das])
718 String disj2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000719 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000720 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Schild, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000721 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000722 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
723 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=das, match=match:eq}}" +
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000724 "]}" +
725 "]}";
726 ppt = new PoliqarpPlusTree("[base=Schild]([base=der]|[base=das])");
727 map = ppt.getRequestMap().get("query").toString();
728 assertEquals(disj2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel76b498d2014-06-06 12:06:46 +0000729
730 // "([orth=der][base=katze])|([orth=eine][base=baum])"
731 String disj3 =
732 "{@type=korap:group, operation=operation:or, operands=[" +
733 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000734 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
735 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=katze, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000736 "]}," +
737 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000738 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=eine, match=match:eq}}," +
739 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=baum, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000740 "]}" +
741 "]}";
742 ppt = new PoliqarpPlusTree("([orth=der][base=katze])|([orth=eine][base=baum])");
743 map = ppt.getRequestMap().get("query").toString();
744 assertEquals(disj3.replaceAll(" ", ""), map.replaceAll(" ", ""));
745
746 // "[orth=der][base=katze]|[orth=eine][base=baum]"
747 String disj4 =
748 "{@type=korap:group, operation=operation:or, operands=[" +
749 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000750 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
751 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=katze, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000752 "]}," +
753 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000754 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=eine, match=match:eq}}," +
755 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=baum, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000756 "]}" +
757 "]}";
758 ppt = new PoliqarpPlusTree("[orth=der][base=katze]|[orth=eine][base=baum]");
759 map = ppt.getRequestMap().get("query").toString();
760 assertEquals(disj4.replaceAll(" ", ""), map.replaceAll(" ", ""));
761
762 PoliqarpPlusTree ppt1 = new PoliqarpPlusTree("[orth=der][base=katze]|[orth=eine][base=baum]");
763 PoliqarpPlusTree ppt2 = new PoliqarpPlusTree("([orth=der][base=katze])|([orth=eine][base=baum])");
764 assertEquals(ppt1.getRequestMap().toString(), ppt2.getRequestMap().toString());
765
766 // "[orth=der][base=katze]|[orth=der][base=hund]|[orth=der][base=baum]"
767 String disj5 =
768 "{@type=korap:group, operation=operation:or, operands=[" +
769 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000770 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
771 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=katze, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000772 "]}," +
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=hund, 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=der, 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=der][base=hund]|[orth=der][base=baum]");
783 map = ppt.getRequestMap().get("query").toString();
784 assertEquals(disj5.replaceAll(" ", ""), map.replaceAll(" ", ""));
785
786 // [orth=der]([base=katze]|[base=hund]|[base=baum])
787 String disj6 =
788 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000789 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000790 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000791 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=katze, match=match:eq}}," +
792 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=hund, match=match:eq}}," +
793 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=baum, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000794 "]}" +
795 "]}";
796 ppt = new PoliqarpPlusTree("[orth=der]([base=katze]|[base=hund]|[base=baum])");
797 map = ppt.getRequestMap().get("query").toString();
798 assertEquals(disj6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000799 }
800
801 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000802 public void testTokenElemSequence() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000803 // [base=Mann]<vp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000804 String seq1 = "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000805 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}, " +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000806 "{@type=korap:span, key=vp}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000807 "]}";
808 assertTrue(equalsQueryContent(seq1, "[base=Mann]<vp>"));
809
810 // <vp>[base=Mann]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000811 String seq2 = "{@type=korap:group, operation=operation:sequence, operands=[" +
812 "{@type=korap:span, key=vp}, "+
Joachim Bingel0900a892014-06-30 16:26:21 +0000813 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}} " +
Joachim Bingel53333e62013-12-09 19:25:52 +0000814 "]}";
815 assertTrue(equalsQueryContent(seq2, "<vp>[base=Mann]"));
816
817 // <vp>[base=Mann]<pp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000818 String seq3 = "{@type=korap:group, operation=operation:sequence, operands=[" +
819 "{@type=korap:span, key=vp}, "+
Joachim Bingel0900a892014-06-30 16:26:21 +0000820 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}, " +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000821 "{@type=korap:span, key=pp} "+
Joachim Bingel53333e62013-12-09 19:25:52 +0000822 "]}";
823 assertTrue(equalsQueryContent(seq3, "<vp>[base=Mann]<pp>"));
824 }
825
826 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000827 public void testElemSequence() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000828 // <np><vp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000829 String seq1 = "{@type=korap:group, operation=operation:sequence, operands=[" +
830 "{@type=korap:span, key=np}," +
831 "{@type=korap:span, key=vp}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000832 "]}";
833 assertTrue(equalsQueryContent(seq1, "<np><vp>"));
834
835 // <np><vp><pp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000836 String seq2 = "{@type=korap:group, operation=operation:sequence, operands=[" +
837 "{@type=korap:span, key=np}," +
838 "{@type=korap:span, key=vp}," +
839 "{@type=korap:span, key=pp}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000840 "]}";
841 assertTrue(equalsQueryContent(seq2, "<np><vp><pp>"));
842 }
843
844 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000845 public void testClasses() throws QueryException {
Joachim Bingel0900a892014-06-30 16:26:21 +0000846 String query;
Joachim Bingel53333e62013-12-09 19:25:52 +0000847 // {[base=Mann]}
Joachim Bingel2daf9862014-02-12 10:18:54 +0000848 String cls1 = "{@type=korap:group, operation=operation:class, class=0, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000849 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000850 "]}";
Joachim Bingel8c640e42014-02-07 16:20:47 +0000851 ppt = new PoliqarpPlusTree("{[base=Mann]}");
852 map = ppt.getRequestMap().get("query").toString();
853 assertEquals(cls1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000854
855 // {[base=Mann][orth=Frau]}
Joachim Bingel0900a892014-06-30 16:26:21 +0000856 query = "{[base=Mann][orth=Frau]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000857 String cls2 = "{@type=korap:group, operation=operation:class, class=0, operands=[" +
858 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000859 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}," +
860 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000861 "]}" +
862 "]}";
Joachim Bingel0900a892014-06-30 16:26:21 +0000863 ppt = new PoliqarpPlusTree(query);
864 map = ppt.getRequestMap().get("query").toString();
865 assertEquals(cls2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000866
867 // [p=NN]{[base=Mann][orth=Frau]}
Joachim Bingel2daf9862014-02-12 10:18:54 +0000868 String cls3 = "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000869 "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000870 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
871 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000872 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}," +
873 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000874 "]}" +
875 "]}" +
876 "]}";
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000877 ppt = new PoliqarpPlusTree("[p=NN]{[base=Mann][orth=Frau]}");
878 map = ppt.getRequestMap().get("query").toString();
879 assertEquals(cls3.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000880
881 // {[base=Mann][orth=Frau]}[p=NN]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000882 String cls4 = "{@type=korap:group, operation=operation:sequence, operands=[" +
883 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
884 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000885 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}," +
886 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000887 "]}" +
888 "]}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000889 "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000890 "]}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000891 ppt = new PoliqarpPlusTree("{[base=Mann][orth=Frau]}[p=NN]");
892 map = ppt.getRequestMap().get("query").toString();
893 assertEquals(cls4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000894
895 // {2:{1:[tt/p=ADJA]}[mate/p=NN]}"
Joachim Bingel2daf9862014-02-12 10:18:54 +0000896 String cls5 = "{@type=korap:group, operation=operation:class, class=2, operands=[" +
897 "{@type=korap:group, operation=operation:sequence, operands=[" +
898 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000899 "{@type=korap:token, wrap={@type=korap:term, foundry=tt, layer=p, key=ADJA, match=match:eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000900 "]}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000901 "{@type=korap:token, wrap={@type=korap:term, foundry=mate, layer=p, key=NN, match=match:eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000902 "]}" +
903 "]}";
904 ppt = new PoliqarpPlusTree("{2: {1:[tt/p=ADJA]}[mate/p=NN]}");
905 map = ppt.getRequestMap().get("query").toString();
906 assertEquals(cls5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000907 }
908
909 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000910 public void testPositions() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000911 // contains(<s>,<np>)
Joachim Bingel2daf9862014-02-12 10:18:54 +0000912 String pos1 = "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
913 "{@type=korap:span, key=s}," +
914 "{@type=korap:span, key=np}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000915 "]}";
916 assertTrue(equalsQueryContent(pos1, "contains(<s>,<np>)"));
917
918 // contains(<s>,[base=Mann])
Joachim Bingel2daf9862014-02-12 10:18:54 +0000919 String pos2 = "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
920 "{@type=korap:span, key=s}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000921 "{@type=korap:token, wrap= {@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000922 "]}";
923 assertTrue(equalsQueryContent(pos2, "contains(<s>,[base=Mann])"));
924
925 // contains(<s>,[orth=der][orth=Mann])
Joachim Bingel2daf9862014-02-12 10:18:54 +0000926 String pos3 = "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
927 "{@type=korap:span, key=s}," +
928 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000929 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
930 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000931 "]}" +
932 "]}";
933 ppt = new PoliqarpPlusTree("contains(<s>,[orth=der][orth=Mann])");
934 map = ppt.getRequestMap().get("query").toString();
935 assertEquals(pos3.replaceAll(" ", ""), map.replaceAll(" ", ""));
936
937 // [base=Auto]contains(<s>,[base=Mann])
938 String pos4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000939 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000940 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Auto, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000941 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
942 "{@type=korap:span, key=s}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000943 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000944 "]}" +
945 "]}";
946 ppt = new PoliqarpPlusTree("[base=Auto]contains(<s>,[base=Mann])");
947 map = ppt.getRequestMap().get("query").toString();
948 assertEquals(pos4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelef7059b2014-04-22 13:44:19 +0000949
950 // contains(<s>,[pos=N]*)
951 String pos5 =
952 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
953 "{@type=korap:span, key=s}," +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000954 "{@type=korap:group, operation=operation:repetition, " +
Joachim Bingel0900a892014-06-30 16:26:21 +0000955 "operands=[{@type=korap:token, wrap={@type=korap:term, layer=pos, key=N, match=match:eq}}" +
Joachim Bingel687e4d42014-07-30 09:34:18 +0000956 "], boundary={@type=korap:boundary, min=0}, min=0" +
Joachim Bingelef7059b2014-04-22 13:44:19 +0000957 "}" +
958 "]}";
959 ppt = new PoliqarpPlusTree("contains(<s>,[pos=N]*)");
960 map = ppt.getRequestMap().get("query").toString();
961 assertEquals(pos5.replaceAll(" ", ""), map.replaceAll(" ", ""));
962
963 // [base=Auto]contains(<s>,[pos=N]*)
964 String pos6 =
965 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000966 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Auto, match=match:eq}}," +
Joachim Bingelef7059b2014-04-22 13:44:19 +0000967 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
968 "{@type=korap:span, key=s}," +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000969 "{@type=korap:group, operation=operation:repetition, " +
Joachim Bingel0900a892014-06-30 16:26:21 +0000970 "operands=[{@type=korap:token, wrap={@type=korap:term, layer=pos, key=N, match=match:eq}}" +
Joachim Bingel687e4d42014-07-30 09:34:18 +0000971 "], boundary={@type=korap:boundary, min=0}, min=0" +
Joachim Bingelef7059b2014-04-22 13:44:19 +0000972 "}" +
973 "]}" +
974 "]}";
975 ppt = new PoliqarpPlusTree("[base=Auto]contains(<s>,[pos=N]*)");
976 map = ppt.getRequestMap().get("query").toString();
977 assertEquals(pos6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000978 }
979
980 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000981 public void testNestedPositions() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000982 // contains(<s>,startswith(<np>,[orth=Der]))
983 String npos1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000984 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
985 "{@type=korap:span, key=s}," +
986 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
987 "{@type=korap:span, key=np}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000988 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000989 "]}" +
990 "]}";
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000991 ppt = new PoliqarpPlusTree("contains(<s>, startswith(<np>,[orth=Der]))");
Joachim Bingel53333e62013-12-09 19:25:52 +0000992 map = ppt.getRequestMap().get("query").toString();
993 assertEquals(npos1.replaceAll(" ", ""), map.replaceAll(" ", ""));
994 }
995
996 @Test
Joachim Bingel23c31ad2014-08-11 09:44:46 +0000997 public void testFocusSplit() throws QueryException {
Joachim Bingel0900a892014-06-30 16:26:21 +0000998 // focus([orth=Der]{[orth=Mann]})
Joachim Bingel53333e62013-12-09 19:25:52 +0000999 String shr1 =
Joachim Bingeld1a3e712014-07-16 08:02:05 +00001000 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001001 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001002 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001003 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001004 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +00001005 "]}" +
1006 "]}" +
1007 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +00001008 ppt = new PoliqarpPlusTree("focus([orth=Der]{[orth=Mann]})");
Joachim Bingel53333e62013-12-09 19:25:52 +00001009 map = ppt.getRequestMap().get("query").toString();
1010 assertEquals(shr1.replaceAll(" ", ""), map.replaceAll(" ", ""));
1011
Joachim Bingel0900a892014-06-30 16:26:21 +00001012 // focus([orth=Der]{[orth=Mann][orth=geht]})
Joachim Bingel53333e62013-12-09 19:25:52 +00001013 String shr2 =
Joachim Bingeld1a3e712014-07-16 08:02:05 +00001014 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001015 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001016 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001017 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
1018 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001019 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}," +
1020 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=geht, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +00001021 "]}" +
1022 "]}" +
1023 "]}" +
1024 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +00001025 ppt = new PoliqarpPlusTree("focus([orth=Der]{[orth=Mann][orth=geht]})");
Joachim Bingel53333e62013-12-09 19:25:52 +00001026 map = ppt.getRequestMap().get("query").toString();
1027 assertEquals(shr2.replaceAll(" ", ""), map.replaceAll(" ", ""));
1028
Joachim Bingel0900a892014-06-30 16:26:21 +00001029 // focus(1:[orth=Der]{1:[orth=Mann][orth=geht]})
Joachim Bingel53333e62013-12-09 19:25:52 +00001030 String shr3 =
Joachim Bingeld1a3e712014-07-16 08:02:05 +00001031 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001032 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001033 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001034 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
1035 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001036 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}," +
1037 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=geht, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +00001038 "]}" +
1039 "]}" +
1040 "]}" +
1041 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +00001042 ppt = new PoliqarpPlusTree("focus(1:[orth=Der]{1:[orth=Mann][orth=geht]})");
Joachim Bingel53333e62013-12-09 19:25:52 +00001043 map = ppt.getRequestMap().get("query").toString();
1044 assertEquals(shr3.replaceAll(" ", ""), map.replaceAll(" ", ""));
1045
Joachim Bingel0900a892014-06-30 16:26:21 +00001046 // focus(1:startswith(<s>,{1:<np>}))
Joachim Bingel53333e62013-12-09 19:25:52 +00001047 String shr4 =
Joachim Bingeld1a3e712014-07-16 08:02:05 +00001048 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001049 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
1050 "{@type=korap:span, key=s}," +
1051 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
1052 "{@type=korap:span, key=np}" +
Joachim Bingel53333e62013-12-09 19:25:52 +00001053 "]}" +
1054 "]}" +
1055 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +00001056 ppt = new PoliqarpPlusTree("focus(1:startswith(<s>,{1:<np>}))");
Joachim Bingel53333e62013-12-09 19:25:52 +00001057 map = ppt.getRequestMap().get("query").toString();
1058 assertEquals(shr4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelcd9ed332013-12-09 21:01:35 +00001059
Joachim Bingel0900a892014-06-30 16:26:21 +00001060 // focus(3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))
Joachim Bingelcd9ed332013-12-09 21:01:35 +00001061 String shr5 =
Joachim Bingeld1a3e712014-07-16 08:02:05 +00001062 "{@type=korap:reference, operation=operation:focus, classRef=[3], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001063 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
1064 "{@type=korap:span, key=s}," +
1065 "{@type=korap:group, operation=operation:class, class=3, operands=[" +
1066 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001067 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001068 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
1069 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001070 "{@type=korap:token, wrap={@type=korap:term, foundry=mate, layer=p, key=ADJA, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001071 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001072 "{@type=korap:token, wrap={@type=korap:term, foundry=tt, layer=p, key=NN, match=match:eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +00001073 "]}" +
1074 "]}" +
1075 "]}" +
1076 "]}" +
1077 "]}" +
1078 "]}" +
1079 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +00001080 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 +00001081 map = ppt.getRequestMap().get("query").toString();
1082 assertEquals(shr5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelba9a0ab2014-01-29 10:12:25 +00001083
1084 // split(3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))
1085 String shr6 =
Joachim Bingeld1a3e712014-07-16 08:02:05 +00001086 "{@type=korap:reference, operation=operation:split, classRef=[3], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001087 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
1088 "{@type=korap:span, key=s}," +
1089 "{@type=korap:group, operation=operation:class, class=3, operands=[" +
1090 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001091 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001092 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
1093 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001094 "{@type=korap:token, wrap={@type=korap:term, foundry=mate, layer=p, key=ADJA, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001095 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001096 "{@type=korap:token, wrap={@type=korap:term, foundry=tt, layer=p, key=NN, match=match:eq}}" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +00001097 "]}" +
1098 "]}" +
1099 "]}" +
1100 "]}" +
1101 "]}" +
1102 "]}" +
1103 "]}";
1104 ppt = new PoliqarpPlusTree("split(3:startswith(<s>,{3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) ");
1105 map = ppt.getRequestMap().get("query").toString();
1106 assertEquals(shr6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel8c640e42014-02-07 16:20:47 +00001107
1108 // split(2|3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))
1109 String shr7 =
Joachim Bingeld1a3e712014-07-16 08:02:05 +00001110 "{@type=korap:reference, operation=operation:split, classRef=[2, 3], classRefOp=classRefOp:intersection, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001111 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
1112 "{@type=korap:span, key=s}," +
1113 "{@type=korap:group, operation=operation:class, class=3, operands=[" +
1114 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001115 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001116 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
1117 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001118 "{@type=korap:token, wrap={@type=korap:term, foundry=mate, layer=p, key=ADJA, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001119 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001120 "{@type=korap:token, wrap={@type=korap:term, foundry=tt, layer=p, key=NN, match=match:eq}}" +
Joachim Bingel8c640e42014-02-07 16:20:47 +00001121 "]}" +
1122 "]}" +
1123 "]}" +
1124 "]}" +
1125 "]}" +
1126 "]}" +
1127 "]}";
1128 ppt = new PoliqarpPlusTree("split(2|3:startswith(<s>,{3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) ");
1129 map = ppt.getRequestMap().get("query").toString();
1130 assertEquals(shr7.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel5146ebe2014-06-12 08:49:21 +00001131
1132
1133 String shr8 =
Joachim Bingeld1a3e712014-07-16 08:02:05 +00001134 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingeladd0fb12014-06-24 08:54:14 +00001135 "{@type=korap:group, operation=operation:sequence, operands=[" +
1136 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001137 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}" +
Joachim Bingeladd0fb12014-06-24 08:54:14 +00001138 "]}," +
1139 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001140 "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=ADJA, match=match:eq}}" +
Joachim Bingel5146ebe2014-06-12 08:49:21 +00001141 "]}" +
Joachim Bingeladd0fb12014-06-24 08:54:14 +00001142 "]}" +
1143 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +00001144 ppt = new PoliqarpPlusTree("focus(1:{[base=der]}{1:[pos=ADJA]})");
Joachim Bingeladd0fb12014-06-24 08:54:14 +00001145 map = ppt.getRequestMap().get("query").toString();
1146 assertEquals(shr8.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel5146ebe2014-06-12 08:49:21 +00001147
Joachim Bingel53333e62013-12-09 19:25:52 +00001148 }
1149
Joachim Bingel23c31ad2014-08-11 09:44:46 +00001150 @Test
1151 public void testSubspan() throws QueryException {
1152 query = "subspan(1:<s>)";
1153 expected =
1154 "{@type=korap:reference, operation=operation:focus, operands=[" +
1155 "{@type=korap:span, key=s}" +
1156 "], spanRef=[1]" +
1157 "}";
1158 ppt = new PoliqarpPlusTree(query);
1159 map = ppt.getRequestMap().get("query").toString();
1160 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1161
1162 query = "subspan(1,4:<s>)";
1163 expected =
1164 "{@type=korap:reference, operation=operation:focus, operands=[" +
1165 "{@type=korap:span, key=s}" +
1166 "], spanRef=[1,4]" +
1167 "}";
1168 ppt = new PoliqarpPlusTree(query);
1169 map = ppt.getRequestMap().get("query").toString();
1170 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1171
1172 query = "subspan(1,4:contains(<s>,[base=Haus]))";
1173 expected =
1174 "{@type=korap:reference, operation=operation:focus, operands=[" +
1175 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
1176 "{@type=korap:span, key=s}," +
1177 "{@type=korap:token, wrap= {@type=korap:term, layer=lemma, key=Haus, match=match:eq}}" +
1178 "]}" +
1179 "], spanRef=[1,4]" +
1180 "}";
1181 ppt = new PoliqarpPlusTree(query);
1182 map = ppt.getRequestMap().get("query").toString();
1183 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1184 }
1185
1186 @Test
1187 public void testRelations() throws QueryException {
1188 query = "relatesTo(<s>,<np>)";
1189 expected =
1190 "{@type=korap:group, operation=operation:relation, operands=[" +
1191 "{@type=korap:span, key=s}," +
1192 "{@type=korap:span, key=np}" +
1193 "], relation={@type=korap:relation}" +
1194 "}";
1195 ppt = new PoliqarpPlusTree(query);
1196 map = ppt.getRequestMap().get("query").toString();
1197 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1198
1199 query = "relatesTo([base=Baum],<np>)";
1200 expected =
1201 "{@type=korap:group, operation=operation:relation, operands=[" +
1202 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Baum, match=match:eq}}," +
1203 "{@type=korap:span, key=np}" +
1204 "], relation={@type=korap:relation}" +
1205 "}";
1206 ppt = new PoliqarpPlusTree(query);
1207 map = ppt.getRequestMap().get("query").toString();
1208 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1209
1210 query = "dominates(<np>,[base=Baum])";
1211 expected =
1212 "{@type=korap:group, operation=operation:relation, operands=[" +
1213 "{@type=korap:span, key=np}," +
1214 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Baum, match=match:eq}}" +
1215 "], relation={@type=korap:relation, layer=c}" +
1216 "}";
1217 ppt = new PoliqarpPlusTree(query);
1218 map = ppt.getRequestMap().get("query").toString();
1219 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1220
1221 query = "dominates(cnx/c:<np>,[base=Baum])";
1222 expected =
1223 "{@type=korap:group, operation=operation:relation, operands=[" +
1224 "{@type=korap:span, key=np}," +
1225 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Baum, match=match:eq}}" +
1226 "], relation={@type=korap:relation, layer=c, foundry=cnx}" +
1227 "}";
1228 ppt = new PoliqarpPlusTree(query);
1229 map = ppt.getRequestMap().get("query").toString();
1230 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1231
1232 query = "dominates(cnx/c*:<np>,[base=Baum])";
1233 expected =
1234 "{@type=korap:group, operation=operation:relation, operands=[" +
1235 "{@type=korap:span, key=np}," +
1236 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Baum, match=match:eq}}" +
1237 "], relation={@type=korap:relation, layer=c, foundry=cnx, boundary={@type=korap:boundary, min=0}}" +
1238 "}";
1239 ppt = new PoliqarpPlusTree(query);
1240 map = ppt.getRequestMap().get("query").toString();
1241 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1242
1243 query = "dominates(cnx/c{1,5}:<np>,[base=Baum])";
1244 expected =
1245 "{@type=korap:group, operation=operation:relation, operands=[" +
1246 "{@type=korap:span, key=np}," +
1247 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Baum, match=match:eq}}" +
1248 "], relation={@type=korap:relation, layer=c, foundry=cnx, boundary={@type=korap:boundary, min=1, max=5}}" +
1249 "}";
1250 ppt = new PoliqarpPlusTree(query);
1251 map = ppt.getRequestMap().get("query").toString();
1252 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1253
1254 query = "relatesTo(mate/d=HEAD:<np>,[base=Baum])";
1255 expected =
1256 "{@type=korap:group, operation=operation:relation, operands=[" +
1257 "{@type=korap:span, key=np}," +
1258 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Baum, match=match:eq}}" +
1259 "], relation={@type=korap:relation, foundry=mate, layer=d, key=HEAD}" +
1260 "}";
1261 ppt = new PoliqarpPlusTree(query);
1262 map = ppt.getRequestMap().get("query").toString();
1263 assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", ""));
1264
1265 }
1266
1267
Joachim Bingel03882702013-12-31 19:53:05 +00001268
Joachim Bingel53333e62013-12-09 19:25:52 +00001269 @Test
Joachim Bingelba9a0ab2014-01-29 10:12:25 +00001270 public void testFoundries() throws QueryException {
1271 // [tt/base=Mann]
Joachim Bingel0900a892014-06-30 16:26:21 +00001272 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 +00001273 ppt = new PoliqarpPlusTree("[tt/base=Mann]");
1274 map = ppt.getRequestMap().get("query").toString();
1275 assertEquals(layer1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +00001276
1277 }
Joachim Bingel16da4e12013-12-17 09:48:12 +00001278
1279 @Test
Joachim Bingel8c640e42014-02-07 16:20:47 +00001280 public void testAlign() throws QueryException {
Joachim Bingel16da4e12013-12-17 09:48:12 +00001281 // [orth=der]^[orth=Mann]
1282 String align1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001283 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001284 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
1285 "{@type=korap:group, operation=operation:alignment, operands=[" +
1286 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" +
1287 "], align=align:left}" +
Joachim Bingel16da4e12013-12-17 09:48:12 +00001288 "]}";
1289 ppt = new PoliqarpPlusTree("[orth=der]^[orth=Mann]");
1290 map = ppt.getRequestMap().get("query").toString();
1291 assertEquals(align1.replaceAll(" ", ""), map.replaceAll(" ", ""));
1292
Joachim Bingel84e33df2014-01-31 14:02:46 +00001293 // [orth=der]^[orth=große][orth=Mann]
1294 String query = "[orth=der]^[orth=große][orth=Mann]";
1295 String align1b =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001296 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001297 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
1298 "{@type=korap:group, operation=operation:alignment, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001299 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001300 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=große, match=match:eq}}," +
1301 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +00001302 "]}" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001303 "], align=align:left}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +00001304 "]}";
1305 ppt = new PoliqarpPlusTree(query);
1306 map = ppt.getRequestMap().get("query").toString();
1307 assertEquals(align1b.replaceAll(" ", ""), map.replaceAll(" ", ""));
1308
Joachim Bingel16da4e12013-12-17 09:48:12 +00001309 // "([base=a]^[base=b])|[base=c]",
1310 String align2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001311 "{@type=korap:group, operation=operation:or, operands=[" +
1312 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001313 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=a, match=match:eq}}," +
1314 "{@type=korap:group, operation=operation:alignment, operands=[" +
1315 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=b, match=match:eq}}" +
1316 "], align=align:left}" +
Joachim Bingel16da4e12013-12-17 09:48:12 +00001317 "]}," +
Joachim Bingel0900a892014-06-30 16:26:21 +00001318 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=c, match=match:eq}}" +
Joachim Bingel16da4e12013-12-17 09:48:12 +00001319 "]}";
1320 ppt = new PoliqarpPlusTree("([base=a]^[base=b])|[base=c]");
1321 map = ppt.getRequestMap().get("query").toString();
1322 assertEquals(align2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingela67e6a32014-01-02 18:35:24 +00001323
1324 // "([base=a]^[base=b][base=c])|[base=d]",
1325 String align3 =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001326 "{@type=korap:group, operation=operation:or, operands=[" +
1327 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001328 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=a, match=match:eq}}," +
1329 "{@type=korap:group, operation=operation:alignment, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001330 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001331 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=b, match=match:eq}}," +
1332 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=c, match=match:eq}}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +00001333 "]}" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001334 "], align=align:left}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +00001335 "]}," +
Joachim Bingel0900a892014-06-30 16:26:21 +00001336 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=d, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +00001337 "]}";
1338 ppt = new PoliqarpPlusTree("([base=a]^[base=b][base=c])|[base=d]");
1339 map = ppt.getRequestMap().get("query").toString();
1340 assertEquals(align3.replaceAll(" ", ""), map.replaceAll(" ", ""));
1341
1342 // "([base=a]^[base=b]^[base=c])|[base=d]",
1343 String align4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001344 "{@type=korap:group, operation=operation:or, operands=[" +
1345 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001346 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=a, match=match:eq}}," +
1347 "{@type=korap:group, operation=operation:alignment, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001348 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001349 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=b, match=match:eq}}," +
1350 "{@type=korap:group, operation=operation:alignment, operands=[" +
1351 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=c, match=match:eq}}" +
1352 "], align=align:left}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +00001353 "]}" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001354 "], align=align:left}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +00001355 "]}," +
Joachim Bingel0900a892014-06-30 16:26:21 +00001356 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=d, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +00001357 "]}";
1358 ppt = new PoliqarpPlusTree("([base=a]^[base=b]^[base=c])|[base=d]");
1359 map = ppt.getRequestMap().get("query").toString();
1360 assertEquals(align4.replaceAll(" ", ""), map.replaceAll(" ", ""));
1361
1362
Joachim Bingel16da4e12013-12-17 09:48:12 +00001363 }
1364
1365 @Test
Joachim Bingel8c640e42014-02-07 16:20:47 +00001366 public void testSimpleQueries() throws QueryException {
Joachim Bingela67e6a32014-01-02 18:35:24 +00001367 // Baum
1368 String simple1 =
Joachim Bingel0900a892014-06-30 16:26:21 +00001369 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq}}";
Joachim Bingela67e6a32014-01-02 18:35:24 +00001370 ppt = new PoliqarpPlusTree("Baum");
1371 map = ppt.getRequestMap().get("query").toString();
1372 assertEquals(simple1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel0900a892014-06-30 16:26:21 +00001373
1374 // Baum/i
1375 String simple1b =
1376 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq, caseInsensitive=true}}";
1377 ppt = new PoliqarpPlusTree("Baum/i");
1378 map = ppt.getRequestMap().get("query").toString();
1379 assertEquals(simple1b.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel16da4e12013-12-17 09:48:12 +00001380
Joachim Bingela67e6a32014-01-02 18:35:24 +00001381 // Der Baum
1382 String simple2 =
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=orth, key=Der, match=match:eq}}, " +
1385 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +00001386 "]}";
1387 ppt = new PoliqarpPlusTree("Der Baum");
1388 map = ppt.getRequestMap().get("query").toString();
1389 assertEquals(simple2.replaceAll(" ", ""), map.replaceAll(" ", ""));
1390
Joachim Bingel0900a892014-06-30 16:26:21 +00001391 // Der Baum/i
1392 String simple2b =
1393 "{@type=korap:group, operation=operation:sequence, operands=[" +
1394 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}, " +
1395 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq, caseInsensitive=true}}" +
1396 "]}";
1397 ppt = new PoliqarpPlusTree("Der Baum/i");
1398 map = ppt.getRequestMap().get("query").toString();
1399 assertEquals(simple2b.replaceAll(" ", ""), map.replaceAll(" ", ""));
1400
Joachim Bingela67e6a32014-01-02 18:35:24 +00001401 // Der große Baum
1402 String simple3 =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001403 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001404 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}, " +
1405 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=große, match=match:eq}}, " +
1406 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +00001407 "]}";
1408 ppt = new PoliqarpPlusTree("Der große Baum");
1409 map = ppt.getRequestMap().get("query").toString();
1410 assertEquals(simple3.replaceAll(" ", ""), map.replaceAll(" ", ""));
1411
1412 // Baum | Stein
1413 String simple4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001414 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001415 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq}}, " +
1416 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Stein, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +00001417 "]}";
1418 ppt = new PoliqarpPlusTree("Baum | Stein");
1419 map = ppt.getRequestMap().get("query").toString();
1420 assertEquals(simple4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel84e33df2014-01-31 14:02:46 +00001421
1422 // Baum | Stein Haus
1423 String query = "(Baum | Stein) Haus";
1424 String simple5 =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001425 "{@type=korap:group, operation=operation:sequence, operands=[" +
1426 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001427 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq}}, " +
1428 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Stein, match=match:eq}}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +00001429 "]}," +
Joachim Bingel0900a892014-06-30 16:26:21 +00001430 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Haus, match=match:eq}} " +
Joachim Bingel84e33df2014-01-31 14:02:46 +00001431 "]}";
1432 ppt = new PoliqarpPlusTree(query);
1433 map = ppt.getRequestMap().get("query").toString();
1434 assertEquals(simple5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel16da4e12013-12-17 09:48:12 +00001435 }
Joachim Bingel53333e62013-12-09 19:25:52 +00001436}
1437