blob: ad293eb6a4c7ba49116ba2365b017ee2b33b2d6c [file] [log] [blame]
Joachim Bingel53333e62013-12-09 19:25:52 +00001import static org.junit.Assert.*;
2
3import org.junit.Test;
4
Joachim Bingel2daf9862014-02-12 10:18:54 +00005import de.ids_mannheim.korap.query.serialize.CosmasTree;
Joachim Bingel53333e62013-12-09 19:25:52 +00006import de.ids_mannheim.korap.query.serialize.PoliqarpPlusTree;
Joachim Bingel16da4e12013-12-17 09:48:12 +00007import de.ids_mannheim.korap.util.QueryException;
Joachim Bingel53333e62013-12-09 19:25:52 +00008
9public class PoliqarpPlusTreeTest {
10
11 PoliqarpPlusTree ppt;
12 String map;
13
14 private boolean equalsContent(String str, Object map) {
15 str = str.replaceAll(" ", "");
16 String mapStr = map.toString().replaceAll(" ", "");
17 return str.equals(mapStr);
18 }
19
Joachim Bingel16da4e12013-12-17 09:48:12 +000020 private boolean equalsQueryContent(String res, String query) throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +000021 res = res.replaceAll(" ", "");
22 ppt = new PoliqarpPlusTree(query);
23 String queryMap = ppt.getRequestMap().get("query").toString().replaceAll(" ", "");
24 return res.equals(queryMap);
25 }
26
Joachim Bingel81812632014-02-18 08:55:22 +000027 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +000028 public void testContext() throws QueryException {
Joachim Bingel81812632014-02-18 08:55:22 +000029 String contextString = "http://ids-mannheim.de/ns/KorAP/json-ld/v0.1/context.jsonld";
Joachim Bingel2daf9862014-02-12 10:18:54 +000030 ppt = new PoliqarpPlusTree("Test");
31 assertEquals(contextString.replaceAll(" ", ""), ppt.getRequestMap().get("@context").toString().replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +000032 }
33
34 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +000035 public void testSingleTokens() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +000036 // [base=Mann]
Joachim Bingelee3b21d2014-02-12 12:34:59 +000037 String token1 = "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}";
Joachim Bingel53333e62013-12-09 19:25:52 +000038 assertTrue(equalsQueryContent(token1, "[base=Mann]"));
39
40 // [orth!=Frau]
Joachim Bingelee3b21d2014-02-12 12:34:59 +000041 String token2 = "{@type=korap:token, wrap={@type=korap:term, key=Frau, layer=orth, match=match:ne}}";
Joachim Bingel53333e62013-12-09 19:25:52 +000042 assertTrue(equalsQueryContent(token2, "[orth!=Frau]"));
43
44 // [!p=NN]
Joachim Bingelee3b21d2014-02-12 12:34:59 +000045 String token3 = "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, match=match:ne}}";
Joachim Bingel53333e62013-12-09 19:25:52 +000046 assertTrue(equalsQueryContent(token3, "[!p=NN]"));
47
48 // [!p!=NN]
Joachim Bingelee3b21d2014-02-12 12:34:59 +000049 String token4 = "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, match=match:eq}}";
Joachim Bingel53333e62013-12-09 19:25:52 +000050 assertTrue(equalsQueryContent(token4, "[!p!=NN]"));
51 }
52
53 @Test
Joachim Bingel41e112e2014-02-12 10:46:18 +000054 public void testRegex() throws QueryException {
55 String query = "[orth=\"M(a|ä)nn(er)?\"]";
Joachim Bingelbc537b62014-02-12 12:47:45 +000056 String re1 = "{@type=korap:token, wrap={@type=korap:term, type=type:regex, key=M(a|ä)nn(er)?, layer=orth, match=match:eq}}";
Joachim Bingel41e112e2014-02-12 10:46:18 +000057 ppt = new PoliqarpPlusTree(query);
58 map = ppt.getRequestMap().get("query").toString();
59 assertEquals(re1.replaceAll(" ", ""), map.replaceAll(" ", ""));
60 }
61
62 @Test
Joachim Bingel0207d5e2014-02-12 14:18:41 +000063 public void testCaseSensitivityFlag() throws QueryException {
64 String query="[orth=deutscher/i]";
65 String cs1 =
66 "{@type=korap:token, wrap={@type=korap:term, key=deutscher, layer=orth, match=match:eq, caseInsensitive=true}}";
67 ppt = new PoliqarpPlusTree(query);
68 map = ppt.getRequestMap().get("query").toString();
69 assertEquals(cs1.replaceAll(" ", ""), map.replaceAll(" ", ""));
70
71 query="[orth=deutscher/i][orth=Bundestag]";
72 String cs2 =
73 "{@type=korap:group, operation=operation:sequence, operands=[" +
74 "{@type=korap:token, wrap={@type=korap:term, key=deutscher, layer=orth, match=match:eq, caseInsensitive=true}}," +
75 "{@type=korap:token, wrap={@type=korap:term, key=Bundestag, layer=orth, match=match:eq}}" +
76 "]}";
77 ppt = new PoliqarpPlusTree(query);
78 map = ppt.getRequestMap().get("query").toString();
79 assertEquals(cs2.replaceAll(" ", ""), map.replaceAll(" ", ""));
80 }
81
82 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +000083 public void testElements() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +000084 // <s>
Joachim Bingel2daf9862014-02-12 10:18:54 +000085 String elem1 = "{@type=korap:span, key=s}";
Joachim Bingel53333e62013-12-09 19:25:52 +000086 assertTrue(equalsQueryContent(elem1, "<s>"));
87
88 // <vp>
Joachim Bingel2daf9862014-02-12 10:18:54 +000089 String elem2 = "{@type=korap:span, key=vp}";
Joachim Bingel53333e62013-12-09 19:25:52 +000090 assertTrue(equalsQueryContent(elem2, "<vp>"));
91 }
Joachim Bingel87480d02014-01-17 14:07:46 +000092
93 @Test
94 public void testEmptyTokens() throws QueryException {
95 // [base=der][][base=Mann]
96 String et1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +000097 "{@type=korap:group, operation=operation:sequence, inOrder=true, distances=[" +
98 "{@type=korap:distance, key=w, min=1, max=1}" +
Joachim Bingel87480d02014-01-17 14:07:46 +000099 "], " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000100 "operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000101 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=match:eq}}," +
102 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000103 "]}";
104 ppt = new PoliqarpPlusTree("[base=der][][base=Mann]");
105 map = ppt.getRequestMap().get("query").toString();
106 assertEquals(et1.replaceAll(" ", ""), map.replaceAll(" ", ""));
107
108 // [base=der][][][base=Mann]
109 String et2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000110 "{@type=korap:group, operation=operation:sequence, inOrder=true, distances=[" +
111 "{@type=korap:distance, key=w, min=2, max=2}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000112 "], " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000113 "operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000114 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=match:eq}}," +
115 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000116 "]}";
Joachim Bingelffd65e32014-01-22 14:22:57 +0000117 ppt = new PoliqarpPlusTree("[base=der][][][base=Mann]");
Joachim Bingel87480d02014-01-17 14:07:46 +0000118 map = ppt.getRequestMap().get("query").toString();
119 assertEquals(et2.replaceAll(" ", ""), map.replaceAll(" ", ""));
120
121 // [base=der][][]?[base=Mann]
122 String et3 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000123 "{@type=korap:group, operation=operation:sequence, inOrder=true, distances=[" +
124 "{@type=korap:distance, key=w, min=1, max=2}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000125 "], " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000126 "operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000127 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=match:eq}}," +
128 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000129 "]}";
130 ppt = new PoliqarpPlusTree("[base=der][][]?[base=Mann]");
131 map = ppt.getRequestMap().get("query").toString();
132 assertEquals(et3.replaceAll(" ", ""), map.replaceAll(" ", ""));
133
Joachim Bingel87480d02014-01-17 14:07:46 +0000134
135 // startswith(<s>, [][base=Mann]
Joachim Bingelffd65e32014-01-22 14:22:57 +0000136 String et4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000137 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
138 "{@type=korap:span, key=s}," +
139 "{@type=korap:group, operation=operation:sequence, offset-min=1, offset-max=1, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000140 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000141 "]}" +
142 "]}";
Joachim Bingelffd65e32014-01-22 14:22:57 +0000143 ppt = new PoliqarpPlusTree("startswith(<s>, [][base=Mann])");
144 map = ppt.getRequestMap().get("query").toString();
145 assertEquals(et4.replaceAll(" ", ""), map.replaceAll(" ", ""));
146
Joachim Bingel11d5b152014-02-11 21:33:47 +0000147 // [base=der][]{2,5}[base=Mann][]?[][base=Frau] nested distances=
Joachim Bingelffd65e32014-01-22 14:22:57 +0000148 String et5 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000149 "{@type=korap:group, operation=operation:sequence, inOrder=true, distances=[" +
150 "{@type=korap:distance, key=w, min=2, max=5}" +
Joachim Bingelffd65e32014-01-22 14:22:57 +0000151 "], " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000152 "operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000153 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000154 "{@type=korap:group, operation=operation:sequence, inOrder=true, distances=[" +
155 "{@type=korap:distance, key=w, min=1, max=2}" +
Joachim Bingelffd65e32014-01-22 14:22:57 +0000156 "], " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000157 "operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000158 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}," +
159 "{@type=korap:token, wrap={@type=korap:term, key=Frau, layer=lemma, match=match:eq}}" +
Joachim Bingelffd65e32014-01-22 14:22:57 +0000160 "]}" +
161 "]}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000162 ppt = new PoliqarpPlusTree("[base=der][]{2,5}[base=Mann][]?[][base=Frau]");
Joachim Bingel87480d02014-01-17 14:07:46 +0000163 map = ppt.getRequestMap().get("query").toString();
164 assertEquals(et5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel87480d02014-01-17 14:07:46 +0000165
166 }
Joachim Bingel53333e62013-12-09 19:25:52 +0000167
168 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000169 public void testCoordinatedFields() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000170 // [base=Mann&(cas=N|cas=A)]
171 String cof1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000172 "{@type=korap:token, wrap=" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000173 "{@type=korap:termGroup, relation=and, operands=[" +
174 "{@type=korap:term, key=Mann, layer=lemma, match=match:eq}," +
175 "{@type=korap:termGroup, relation=or, operands=[" +
176 "{@type=korap:term, key=N, layer=cas, match=match:eq}," +
177 "{@type=korap:term, key=A, layer=cas, match=match:eq}" +
178 "]}" +
179 "]}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000180 "}";
181 ppt = new PoliqarpPlusTree("[base=Mann&(cas=N|cas=A)]");
182 map = ppt.getRequestMap().get("query").toString();
183 assertEquals(cof1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Nils Diewald7d486c22013-12-13 16:32:18 +0000184
185
186 assertEquals(
187 new PoliqarpPlusTree(" [ base=Mann & ( cas=N | cas=A)] ").getRequestMap().get("query").toString(),
188 new PoliqarpPlusTree("[base=Mann &(cas=N|cas=A)]").getRequestMap().get("query").toString()
189 );
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000190
191 // [base=Mann&cas=N&gen=m]
192 String cof2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000193 "{@type=korap:token, wrap=" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000194 "{@type=korap:termGroup, relation=and, operands=[" +
195 "{@type=korap:term, key=Mann, layer=lemma, match=match:eq}," +
196 "{@type=korap:term, key=N, layer=cas, match=match:eq}," +
197 "{@type=korap:term, key=m, layer=gen, match=match:eq}" +
198 "]}" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000199 "}";
200 ppt = new PoliqarpPlusTree("[base=Mann&cas=N&gen=m]");
201 map = ppt.getRequestMap().get("query").toString();
202 assertEquals(cof2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000203 }
204
205 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000206 public void testOccurrence() throws QueryException {
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000207 // [base=foo]*
Joachim Bingel2daf9862014-02-12 10:18:54 +0000208 String occ1 = "{@type=korap:group, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000209 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000210 "], operation=operation:repetition, min=0, max=100}";
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000211 ppt = new PoliqarpPlusTree("[base=foo]*");
212 map = ppt.getRequestMap().get("query").toString();
213 assertEquals(occ1.replaceAll(" ", ""), map.replaceAll(" ", ""));
214
215 // [base=foo]*[base=bar]
216 String occ2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000217 "{@type=korap:group, operation=operation:sequence, operands=[" +
218 "{@type=korap:group, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000219 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000220 "], operation=operation:repetition, min=0, max=100 }," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000221 "{@type=korap:token, wrap={@type=korap:term, key=bar, layer=lemma, match=match:eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000222 "]}";
223 ppt = new PoliqarpPlusTree("[base=foo]*[base=bar]");
224 map = ppt.getRequestMap().get("query").toString();
225 assertEquals(occ2.replaceAll(" ", ""), map.replaceAll(" ", ""));
226
227 // [base=bar][base=foo]*
228 String occ3 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000229 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000230 "{@type=korap:token, wrap={@type=korap:term, key=bar, layer=lemma, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000231 "{@type=korap:group, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000232 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000233 "], operation=operation:repetition, min=0, max=100 }" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000234 "]}";
235 ppt = new PoliqarpPlusTree("[base=bar][base=foo]*");
236 map = ppt.getRequestMap().get("query").toString();
237 assertEquals(occ3.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb4da7022013-12-09 23:17:24 +0000238
239 // ([base=bar][base=foo])*
240 String occ4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000241 "{@type=korap:group, operands=[" +
242 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000243 "{@type=korap:token, wrap={@type=korap:term, key=bar, layer=lemma, match=match:eq}}," +
244 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000245 "]}" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000246 "], operation=operation:repetition, min=0, max=100 }" ;
Joachim Bingelb4da7022013-12-09 23:17:24 +0000247 ppt = new PoliqarpPlusTree("([base=bar][base=foo])*");
248 map = ppt.getRequestMap().get("query").toString();
249 assertEquals(occ4.replaceAll(" ", ""), map.replaceAll(" ", ""));
250
251 // <s>([base=bar][base=foo])*
252 String occ5 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000253 "{@type=korap:group, operation=operation:sequence, operands=[" +
254 "{@type=korap:span, key=s}," +
255 "{@type=korap:group, operands=[" +
256 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000257 "{@type=korap:token, wrap={@type=korap:term, key=bar, layer=lemma, match=match:eq}}," +
258 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000259 "]}" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000260 "], operation=operation:repetition, min=0, max=100 }" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000261 "]}" ;
262 ppt = new PoliqarpPlusTree("<s>([base=bar][base=foo])*");
263 map = ppt.getRequestMap().get("query").toString();
264 assertEquals(occ5.replaceAll(" ", ""), map.replaceAll(" ", ""));
265
266 // <s><np>([base=bar][base=foo])*
Joachim Bingelb4da7022013-12-09 23:17:24 +0000267 String occ6 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000268 "{@type=korap:group, operation=operation:sequence, operands=[" +
269 "{@type=korap:span, key=s}," +
270 "{@type=korap:span, key=np}," +
271 "{@type=korap:group, operands=[" +
272 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000273 "{@type=korap:token, wrap={@type=korap:term, key=bar, layer=lemma, match=match:eq}}," +
274 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000275 "]}" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000276 "], operation=operation:repetition, min=0, max=100 }" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000277 "]}" ;
278 ppt = new PoliqarpPlusTree("<s><np>([base=bar][base=foo])*");
279 map = ppt.getRequestMap().get("query").toString();
280 assertEquals(occ6.replaceAll(" ", ""), map.replaceAll(" ", ""));
281
282 // <s><np>([base=bar][base=foo])*[p=NN]
283 // comment: embedded sequence shouldn't really be here, but does not really hurt, either. (?)
284 // really hard to get this behaviour out of the PQPlus grammar...
285 String occ7 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000286 "{@type=korap:group, operation=operation:sequence, operands=[" +
287 "{@type=korap:span, key=s}," +
288 "{@type=korap:span, key=np}," +
289 "{@type=korap:group, operands=[" +
290 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000291 "{@type=korap:token, wrap={@type=korap:term, key=bar, layer=lemma, match=match:eq}}," +
292 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000293 "]}" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000294 "], operation=operation:repetition, min=0, max=100 }," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000295 "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000296 "]}" ;
297 ppt = new PoliqarpPlusTree("<s><np>([base=bar][base=foo])*[p=NN]");
298 map = ppt.getRequestMap().get("query").toString();
299 assertEquals(occ7.replaceAll(" ", ""), map.replaceAll(" ", ""));
300
301 // ([base=bar][base=foo])*[p=NN]
Joachim Bingelb4da7022013-12-09 23:17:24 +0000302 String occ8 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000303 "{@type=korap:group, operation=operation:sequence, operands=[" +
304 "{@type=korap:group, operands=[" +
305 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000306 "{@type=korap:token, wrap={@type=korap:term, key=bar, layer=lemma, match=match:eq}}," +
307 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000308 "]}" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000309 "], operation=operation:repetition, min=0, max=100 }," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000310 "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000311 "]}" ;
312 ppt = new PoliqarpPlusTree("([base=bar][base=foo])*[p=NN]");
313 map = ppt.getRequestMap().get("query").toString();
314 assertEquals(occ8.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000315
316 // [base=foo]+
Joachim Bingel2daf9862014-02-12 10:18:54 +0000317 String occ9 = "{@type=korap:group, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000318 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000319 "], operation=operation:repetition, min=1, max=100}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000320 ppt = new PoliqarpPlusTree("[base=foo]+");
321 map = ppt.getRequestMap().get("query").toString();
322 assertEquals(occ9.replaceAll(" ", ""), map.replaceAll(" ", ""));
323
324 // [base=foo]?
Joachim Bingel2daf9862014-02-12 10:18:54 +0000325 String occ10 = "{@type=korap:group, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000326 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000327 "], operation=operation:repetition, min=0, max=1}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000328 ppt = new PoliqarpPlusTree("[base=foo]?");
329 map = ppt.getRequestMap().get("query").toString();
330 assertEquals(occ10.replaceAll(" ", ""), map.replaceAll(" ", ""));
331
332 // [base=foo]{2,5}
Joachim Bingel2daf9862014-02-12 10:18:54 +0000333 String occ11 = "{@type=korap:group, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000334 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000335 "], operation=operation:repetition, min=2, max=5}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000336 ppt = new PoliqarpPlusTree("[base=foo]{2,5}");
337 map = ppt.getRequestMap().get("query").toString();
338 assertEquals(occ11.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000339 }
340
341 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000342 public void testTokenSequence() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000343 // [base=Mann][orth=Frau]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000344 String seq1 = "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000345 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}, " +
346 "{@type=korap:token, wrap={@type=korap:term, key=Frau, layer=orth, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000347 "]}";
348 assertTrue(equalsQueryContent(seq1, "[base=Mann][orth=Frau]"));
349
350 // [base=Mann][orth=Frau][p=NN]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000351 String seq2 = "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000352 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}, " +
353 "{@type=korap:token, wrap={@type=korap:term, key=Frau, layer=orth, match=match:eq}}, " +
354 "{@type=korap:token, wrap={@type=korap:term, key=NN,layer=p, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000355 "]}";
356 assertTrue(equalsQueryContent(seq2, "[base=Mann][orth=Frau][p=NN]"));
357 }
358
359 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000360 public void testDisjSegments() throws QueryException {
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000361 // ([base=der]|[base=das])[base=Schild]
362 String disj1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000363 "{@type=korap:group, operation=operation:sequence, operands=[" +
364 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000365 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=match:eq}}," +
366 "{@type=korap:token, wrap={@type=korap:term, key=das, layer=lemma, match=match:eq}}" +
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000367 "]}," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000368 "{@type=korap:token, wrap={@type=korap:term, key=Schild, layer=lemma, match=match:eq}}" +
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000369 "]}";
370 ppt = new PoliqarpPlusTree("([base=der]|[base=das])[base=Schild]");
371 map = ppt.getRequestMap().get("query").toString();
372 assertEquals(disj1.replaceAll(" ", ""), map.replaceAll(" ", ""));
373
374 // [base=Schild]([base=der]|[base=das])
375 String disj2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000376 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000377 "{@type=korap:token, wrap={@type=korap:term, key=Schild, layer=lemma, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000378 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000379 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=match:eq}}," +
380 "{@type=korap:token, wrap={@type=korap:term, key=das, layer=lemma, match=match:eq}}" +
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000381 "]}" +
382 "]}";
383 ppt = new PoliqarpPlusTree("[base=Schild]([base=der]|[base=das])");
384 map = ppt.getRequestMap().get("query").toString();
385 assertEquals(disj2.replaceAll(" ", ""), map.replaceAll(" ", ""));
386 }
387
388 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000389 public void testTokenElemSequence() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000390 // [base=Mann]<vp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000391 String seq1 = "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000392 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}, " +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000393 "{@type=korap:span, key=vp}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000394 "]}";
395 assertTrue(equalsQueryContent(seq1, "[base=Mann]<vp>"));
396
397 // <vp>[base=Mann]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000398 String seq2 = "{@type=korap:group, operation=operation:sequence, operands=[" +
399 "{@type=korap:span, key=vp}, "+
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000400 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}} " +
Joachim Bingel53333e62013-12-09 19:25:52 +0000401 "]}";
402 assertTrue(equalsQueryContent(seq2, "<vp>[base=Mann]"));
403
404 // <vp>[base=Mann]<pp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000405 String seq3 = "{@type=korap:group, operation=operation:sequence, operands=[" +
406 "{@type=korap:span, key=vp}, "+
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000407 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}, " +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000408 "{@type=korap:span, key=pp} "+
Joachim Bingel53333e62013-12-09 19:25:52 +0000409 "]}";
410 assertTrue(equalsQueryContent(seq3, "<vp>[base=Mann]<pp>"));
411 }
412
413 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000414 public void testElemSequence() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000415 // <np><vp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000416 String seq1 = "{@type=korap:group, operation=operation:sequence, operands=[" +
417 "{@type=korap:span, key=np}," +
418 "{@type=korap:span, key=vp}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000419 "]}";
420 assertTrue(equalsQueryContent(seq1, "<np><vp>"));
421
422 // <np><vp><pp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000423 String seq2 = "{@type=korap:group, operation=operation:sequence, operands=[" +
424 "{@type=korap:span, key=np}," +
425 "{@type=korap:span, key=vp}," +
426 "{@type=korap:span, key=pp}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000427 "]}";
428 assertTrue(equalsQueryContent(seq2, "<np><vp><pp>"));
429 }
430
431 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000432 public void testClasses() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000433 // {[base=Mann]}
Joachim Bingel2daf9862014-02-12 10:18:54 +0000434 String cls1 = "{@type=korap:group, operation=operation:class, class=0, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000435 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000436 "]}";
Joachim Bingel8c640e42014-02-07 16:20:47 +0000437 ppt = new PoliqarpPlusTree("{[base=Mann]}");
438 map = ppt.getRequestMap().get("query").toString();
439 assertEquals(cls1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000440
441 // {[base=Mann][orth=Frau]}
Joachim Bingel2daf9862014-02-12 10:18:54 +0000442 String cls2 = "{@type=korap:group, operation=operation:class, class=0, operands=[" +
443 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000444 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}," +
445 "{@type=korap:token, wrap={@type=korap:term, key=Frau, layer=orth, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000446 "]}" +
447 "]}";
448 assertTrue(equalsQueryContent(cls2, "{[base=Mann][orth=Frau]}"));
449
450 // [p=NN]{[base=Mann][orth=Frau]}
Joachim Bingel2daf9862014-02-12 10:18:54 +0000451 String cls3 = "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000452 "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000453 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
454 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000455 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}," +
456 "{@type=korap:token, wrap={@type=korap:term, key=Frau, layer=orth, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000457 "]}" +
458 "]}" +
459 "]}";
460 assertTrue(equalsQueryContent(cls3, "[p=NN]{[base=Mann][orth=Frau]}"));
461
462 // {[base=Mann][orth=Frau]}[p=NN]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000463 String cls4 = "{@type=korap:group, operation=operation:sequence, operands=[" +
464 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
465 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000466 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}," +
467 "{@type=korap:token, wrap={@type=korap:term, key=Frau, layer=orth, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000468 "]}" +
469 "]}," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000470 "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000471 "]}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000472 ppt = new PoliqarpPlusTree("{[base=Mann][orth=Frau]}[p=NN]");
473 map = ppt.getRequestMap().get("query").toString();
474 assertEquals(cls4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000475
476 // {2:{1:[tt/p=ADJA]}[mate/p=NN]}"
Joachim Bingel2daf9862014-02-12 10:18:54 +0000477 String cls5 = "{@type=korap:group, operation=operation:class, class=2, operands=[" +
478 "{@type=korap:group, operation=operation:sequence, operands=[" +
479 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000480 "{@type=korap:token, wrap={@type=korap:term, key=ADJA, layer=p, foundry=tt, match=match:eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000481 "]}," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000482 "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, foundry=mate, match=match:eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000483 "]}" +
484 "]}";
485 ppt = new PoliqarpPlusTree("{2: {1:[tt/p=ADJA]}[mate/p=NN]}");
486 map = ppt.getRequestMap().get("query").toString();
487 assertEquals(cls5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000488 }
489
490 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000491 public void testPositions() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000492 // contains(<s>,<np>)
Joachim Bingel2daf9862014-02-12 10:18:54 +0000493 String pos1 = "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
494 "{@type=korap:span, key=s}," +
495 "{@type=korap:span, key=np}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000496 "]}";
497 assertTrue(equalsQueryContent(pos1, "contains(<s>,<np>)"));
498
499 // contains(<s>,[base=Mann])
Joachim Bingel2daf9862014-02-12 10:18:54 +0000500 String pos2 = "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
501 "{@type=korap:span, key=s}," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000502 "{@type=korap:token, wrap= {@type=korap:term, key=Mann, layer=lemma, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000503 "]}";
504 assertTrue(equalsQueryContent(pos2, "contains(<s>,[base=Mann])"));
505
506 // contains(<s>,[orth=der][orth=Mann])
Joachim Bingel2daf9862014-02-12 10:18:54 +0000507 String pos3 = "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
508 "{@type=korap:span, key=s}," +
509 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000510 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
511 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000512 "]}" +
513 "]}";
514 ppt = new PoliqarpPlusTree("contains(<s>,[orth=der][orth=Mann])");
515 map = ppt.getRequestMap().get("query").toString();
516 assertEquals(pos3.replaceAll(" ", ""), map.replaceAll(" ", ""));
517
518 // [base=Auto]contains(<s>,[base=Mann])
519 String pos4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000520 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000521 "{@type=korap:token, wrap={@type=korap:term, key=Auto, layer=lemma, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000522 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
523 "{@type=korap:span, key=s}," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000524 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000525 "]}" +
526 "]}";
527 ppt = new PoliqarpPlusTree("[base=Auto]contains(<s>,[base=Mann])");
528 map = ppt.getRequestMap().get("query").toString();
529 assertEquals(pos4.replaceAll(" ", ""), map.replaceAll(" ", ""));
530 }
531
532 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000533 public void testNestedPositions() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000534 // contains(<s>,startswith(<np>,[orth=Der]))
535 String npos1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000536 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
537 "{@type=korap:span, key=s}," +
538 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
539 "{@type=korap:span, key=np}," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000540 "{@type=korap:token, wrap={@type=korap:term, key=Der, layer=orth, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000541 "]}" +
542 "]}";
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000543 ppt = new PoliqarpPlusTree("contains(<s>, startswith(<np>,[orth=Der]))");
Joachim Bingel53333e62013-12-09 19:25:52 +0000544 map = ppt.getRequestMap().get("query").toString();
545 assertEquals(npos1.replaceAll(" ", ""), map.replaceAll(" ", ""));
546 }
547
548 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000549 public void testShrinkSplit() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000550 // shrink([orth=Der]{[orth=Mann]})
551 String shr1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000552 "{@type=korap:group, operation=operation:submatch, classRef=[0], operands=[" +
553 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000554 "{@type=korap:token, wrap={@type=korap:term, key=Der, layer=orth, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000555 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000556 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000557 "]}" +
558 "]}" +
559 "]}";
560 ppt = new PoliqarpPlusTree("shrink([orth=Der]{[orth=Mann]})");
561 map = ppt.getRequestMap().get("query").toString();
562 assertEquals(shr1.replaceAll(" ", ""), map.replaceAll(" ", ""));
563
564 // shrink([orth=Der]{[orth=Mann][orth=geht]})
565 String shr2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000566 "{@type=korap:group, operation=operation:submatch, classRef=[0], operands=[" +
567 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000568 "{@type=korap:token, wrap={@type=korap:term, key=Der, layer=orth, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000569 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
570 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000571 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}," +
572 "{@type=korap:token, wrap={@type=korap:term, key=geht, layer=orth, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000573 "]}" +
574 "]}" +
575 "]}" +
576 "]}";
577 ppt = new PoliqarpPlusTree("shrink([orth=Der]{[orth=Mann][orth=geht]})");
578 map = ppt.getRequestMap().get("query").toString();
579 assertEquals(shr2.replaceAll(" ", ""), map.replaceAll(" ", ""));
580
581 // shrink(1:[orth=Der]{1:[orth=Mann][orth=geht]})
582 String shr3 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000583 "{@type=korap:group, operation=operation:submatch, classRef=[1], operands=[" +
584 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000585 "{@type=korap:token, wrap={@type=korap:term, key=Der, layer=orth, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000586 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
587 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000588 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}," +
589 "{@type=korap:token, wrap={@type=korap:term, key=geht, layer=orth, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000590 "]}" +
591 "]}" +
592 "]}" +
593 "]}";
594 ppt = new PoliqarpPlusTree("shrink(1:[orth=Der]{1:[orth=Mann][orth=geht]})");
595 map = ppt.getRequestMap().get("query").toString();
596 assertEquals(shr3.replaceAll(" ", ""), map.replaceAll(" ", ""));
597
598 // shrink(1:startswith(<s>,{1:<np>}))
599 String shr4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000600 "{@type=korap:group, operation=operation:submatch, classRef=[1], operands=[" +
601 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
602 "{@type=korap:span, key=s}," +
603 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
604 "{@type=korap:span, key=np}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000605 "]}" +
606 "]}" +
607 "]}";
Joachim Bingeladefa622013-12-13 10:51:48 +0000608 ppt = new PoliqarpPlusTree("shrink(1:startswith(<s>,{1:<np>}))");
Joachim Bingel53333e62013-12-09 19:25:52 +0000609 map = ppt.getRequestMap().get("query").toString();
610 assertEquals(shr4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000611
612 // shrink(3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))
613 String shr5 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000614 "{@type=korap:group, operation=operation:submatch, classRef=[3], operands=[" +
615 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
616 "{@type=korap:span, key=s}," +
617 "{@type=korap:group, operation=operation:class, class=3, operands=[" +
618 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000619 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000620 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
621 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000622 "{@type=korap:token, wrap={@type=korap:term, key=ADJA, layer=p, foundry=mate, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000623 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000624 "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, foundry=tt, match=match:eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000625 "]}" +
626 "]}" +
627 "]}" +
628 "]}" +
629 "]}" +
630 "]}" +
631 "]}";
Joachim Bingeladefa622013-12-13 10:51:48 +0000632 ppt = new PoliqarpPlusTree("shrink(3:startswith(<s>,{3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) ");
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000633 map = ppt.getRequestMap().get("query").toString();
634 assertEquals(shr5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000635
636 // split(3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))
637 String shr6 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000638 "{@type=korap:group, operation=operation:split, classRef=[3], operands=[" +
639 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
640 "{@type=korap:span, key=s}," +
641 "{@type=korap:group, operation=operation:class, class=3, operands=[" +
642 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000643 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000644 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
645 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000646 "{@type=korap:token, wrap={@type=korap:term, key=ADJA, layer=p, foundry=mate, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000647 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000648 "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, foundry=tt, match=match:eq}}" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000649 "]}" +
650 "]}" +
651 "]}" +
652 "]}" +
653 "]}" +
654 "]}" +
655 "]}";
656 ppt = new PoliqarpPlusTree("split(3:startswith(<s>,{3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) ");
657 map = ppt.getRequestMap().get("query").toString();
658 assertEquals(shr6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel8c640e42014-02-07 16:20:47 +0000659
660 // split(2|3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))
661 String shr7 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000662 "{@type=korap:group, operation=operation:split, classRef=[2, 3], classRefOp=classRefOp:intersection, operands=[" +
663 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
664 "{@type=korap:span, key=s}," +
665 "{@type=korap:group, operation=operation:class, class=3, operands=[" +
666 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000667 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000668 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
669 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000670 "{@type=korap:token, wrap={@type=korap:term, key=ADJA, layer=p, foundry=mate, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000671 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000672 "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, foundry=tt, match=match:eq}}" +
Joachim Bingel8c640e42014-02-07 16:20:47 +0000673 "]}" +
674 "]}" +
675 "]}" +
676 "]}" +
677 "]}" +
678 "]}" +
679 "]}";
680 ppt = new PoliqarpPlusTree("split(2|3:startswith(<s>,{3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) ");
681 map = ppt.getRequestMap().get("query").toString();
682 assertEquals(shr7.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000683 }
684
Joachim Bingel03882702013-12-31 19:53:05 +0000685
Joachim Bingel53333e62013-12-09 19:25:52 +0000686 @Test
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000687 public void testFoundries() throws QueryException {
688 // [tt/base=Mann]
Joachim Bingelac13a472014-02-14 21:18:52 +0000689 String layer1 = "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, foundry=tt, match=match:eq}}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000690 ppt = new PoliqarpPlusTree("[tt/base=Mann]");
691 map = ppt.getRequestMap().get("query").toString();
692 assertEquals(layer1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000693
694 }
Joachim Bingel16da4e12013-12-17 09:48:12 +0000695
696 @Test
Joachim Bingel8c640e42014-02-07 16:20:47 +0000697 public void testAlign() throws QueryException {
Joachim Bingel16da4e12013-12-17 09:48:12 +0000698 // [orth=der]^[orth=Mann]
699 String align1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000700 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000701 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000702 "{@type=korap:group, alignment=left, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000703 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
Joachim Bingel03882702013-12-31 19:53:05 +0000704 "]}" +
Joachim Bingel16da4e12013-12-17 09:48:12 +0000705 "]}";
706 ppt = new PoliqarpPlusTree("[orth=der]^[orth=Mann]");
707 map = ppt.getRequestMap().get("query").toString();
708 assertEquals(align1.replaceAll(" ", ""), map.replaceAll(" ", ""));
709
Joachim Bingel84e33df2014-01-31 14:02:46 +0000710 // [orth=der]^[orth=große][orth=Mann]
711 String query = "[orth=der]^[orth=große][orth=Mann]";
712 String align1b =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000713 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000714 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000715 "{@type=korap:group, alignment=left, operands=[" +
716 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000717 "{@type=korap:token, wrap={@type=korap:term, key=große, layer=orth, match=match:eq}}," +
718 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +0000719 "]}" +
720 "]}" +
721 "]}";
722 ppt = new PoliqarpPlusTree(query);
723 map = ppt.getRequestMap().get("query").toString();
724 assertEquals(align1b.replaceAll(" ", ""), map.replaceAll(" ", ""));
725
Joachim Bingel16da4e12013-12-17 09:48:12 +0000726 // "([base=a]^[base=b])|[base=c]",
727 String align2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000728 "{@type=korap:group, operation=operation:or, operands=[" +
729 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000730 "{@type=korap:token, wrap={@type=korap:term, key=a, layer=lemma, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000731 "{@type=korap:group, alignment=left, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000732 "{@type=korap:token, wrap={@type=korap:term, key=b, layer=lemma, match=match:eq}}" +
Joachim Bingel03882702013-12-31 19:53:05 +0000733 "]}" +
Joachim Bingel16da4e12013-12-17 09:48:12 +0000734 "]}," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000735 "{@type=korap:token, wrap={@type=korap:term, key=c, layer=lemma, match=match:eq}}" +
Joachim Bingel16da4e12013-12-17 09:48:12 +0000736 "]}";
737 ppt = new PoliqarpPlusTree("([base=a]^[base=b])|[base=c]");
738 map = ppt.getRequestMap().get("query").toString();
739 assertEquals(align2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingela67e6a32014-01-02 18:35:24 +0000740
741 // "([base=a]^[base=b][base=c])|[base=d]",
742 String align3 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000743 "{@type=korap:group, operation=operation:or, operands=[" +
744 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000745 "{@type=korap:token, wrap={@type=korap:term, key=a, layer=lemma, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000746 "{@type=korap:group, alignment=left, operands=[" +
747 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000748 "{@type=korap:token, wrap={@type=korap:term, key=b, layer=lemma, match=match:eq}}," +
749 "{@type=korap:token, wrap={@type=korap:term, key=c, layer=lemma, match=match:eq}}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +0000750 "]}" +
751 "]}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000752 "]}," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000753 "{@type=korap:token, wrap={@type=korap:term, key=d, layer=lemma, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000754 "]}";
755 ppt = new PoliqarpPlusTree("([base=a]^[base=b][base=c])|[base=d]");
756 map = ppt.getRequestMap().get("query").toString();
757 assertEquals(align3.replaceAll(" ", ""), map.replaceAll(" ", ""));
758
759 // "([base=a]^[base=b]^[base=c])|[base=d]",
760 String align4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000761 "{@type=korap:group, operation=operation:or, operands=[" +
762 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000763 "{@type=korap:token, wrap={@type=korap:term, key=a, layer=lemma, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000764 "{@type=korap:group, alignment=left, operands=[" +
765 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000766 "{@type=korap:token, wrap={@type=korap:term, key=b, layer=lemma, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000767 "{@type=korap:group, alignment=left, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000768 "{@type=korap:token, wrap={@type=korap:term, key=c, layer=lemma, match=match:eq}}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +0000769 "]}" +
770 "]}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000771 "]}" +
772 "]}," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000773 "{@type=korap:token, wrap={@type=korap:term, key=d, layer=lemma, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000774 "]}";
775 ppt = new PoliqarpPlusTree("([base=a]^[base=b]^[base=c])|[base=d]");
776 map = ppt.getRequestMap().get("query").toString();
777 assertEquals(align4.replaceAll(" ", ""), map.replaceAll(" ", ""));
778
779
Joachim Bingel16da4e12013-12-17 09:48:12 +0000780 }
781
782 @Test
Joachim Bingel8c640e42014-02-07 16:20:47 +0000783 public void testSimpleQueries() throws QueryException {
Joachim Bingela67e6a32014-01-02 18:35:24 +0000784 // Baum
785 String simple1 =
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000786 "{@type=korap:token, wrap={@type=korap:term, key=Baum, layer=orth, match=match:eq}}";
Joachim Bingela67e6a32014-01-02 18:35:24 +0000787 ppt = new PoliqarpPlusTree("Baum");
788 map = ppt.getRequestMap().get("query").toString();
789 assertEquals(simple1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel16da4e12013-12-17 09:48:12 +0000790
Joachim Bingela67e6a32014-01-02 18:35:24 +0000791 // Der Baum
792 String simple2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000793 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000794 "{@type=korap:token, wrap={@type=korap:term, key=Der, layer=orth, match=match:eq}}, " +
795 "{@type=korap:token, wrap={@type=korap:term, key=Baum, layer=orth, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000796 "]}";
797 ppt = new PoliqarpPlusTree("Der Baum");
798 map = ppt.getRequestMap().get("query").toString();
799 assertEquals(simple2.replaceAll(" ", ""), map.replaceAll(" ", ""));
800
801 // Der große Baum
802 String simple3 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000803 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000804 "{@type=korap:token, wrap={@type=korap:term, key=Der, layer=orth, match=match:eq}}, " +
805 "{@type=korap:token, wrap={@type=korap:term, key=große, layer=orth, match=match:eq}}, " +
806 "{@type=korap:token, wrap={@type=korap:term, key=Baum, layer=orth, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000807 "]}";
808 ppt = new PoliqarpPlusTree("Der große Baum");
809 map = ppt.getRequestMap().get("query").toString();
810 assertEquals(simple3.replaceAll(" ", ""), map.replaceAll(" ", ""));
811
812 // Baum | Stein
813 String simple4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000814 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000815 "{@type=korap:token, wrap={@type=korap:term, key=Baum, layer=orth, match=match:eq}}, " +
816 "{@type=korap:token, wrap={@type=korap:term, key=Stein, layer=orth, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000817 "]}";
818 ppt = new PoliqarpPlusTree("Baum | Stein");
819 map = ppt.getRequestMap().get("query").toString();
820 assertEquals(simple4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel84e33df2014-01-31 14:02:46 +0000821
822 // Baum | Stein Haus
823 String query = "(Baum | Stein) Haus";
824 String simple5 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000825 "{@type=korap:group, operation=operation:sequence, operands=[" +
826 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000827 "{@type=korap:token, wrap={@type=korap:term, key=Baum, layer=orth, match=match:eq}}, " +
828 "{@type=korap:token, wrap={@type=korap:term, key=Stein, layer=orth, match=match:eq}}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +0000829 "]}," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000830 "{@type=korap:token, wrap={@type=korap:term, key=Haus, layer=orth, match=match:eq}} " +
Joachim Bingel84e33df2014-01-31 14:02:46 +0000831 "]}";
832 ppt = new PoliqarpPlusTree(query);
833 map = ppt.getRequestMap().get("query").toString();
834 assertEquals(simple5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel16da4e12013-12-17 09:48:12 +0000835 }
Joachim Bingel53333e62013-12-09 19:25:52 +0000836}
837