blob: 9da4cfc25502d9e14eb8b4d323f79977bdb0034c [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;
12
Joachim Bingel53333e62013-12-09 19:25:52 +000013
Joachim Bingel16da4e12013-12-17 09:48:12 +000014 private boolean equalsQueryContent(String res, String query) throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +000015 res = res.replaceAll(" ", "");
16 ppt = new PoliqarpPlusTree(query);
17 String queryMap = ppt.getRequestMap().get("query").toString().replaceAll(" ", "");
18 return res.equals(queryMap);
19 }
20
Joachim Bingel81812632014-02-18 08:55:22 +000021 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +000022 public void testContext() throws QueryException {
Joachim Bingel81812632014-02-18 08:55:22 +000023 String contextString = "http://ids-mannheim.de/ns/KorAP/json-ld/v0.1/context.jsonld";
Joachim Bingel2daf9862014-02-12 10:18:54 +000024 ppt = new PoliqarpPlusTree("Test");
25 assertEquals(contextString.replaceAll(" ", ""), ppt.getRequestMap().get("@context").toString().replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +000026 }
27
28 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +000029 public void testSingleTokens() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +000030 // [base=Mann]
Joachim Bingelee3b21d2014-02-12 12:34:59 +000031 String token1 = "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}";
Joachim Bingel53333e62013-12-09 19:25:52 +000032 assertTrue(equalsQueryContent(token1, "[base=Mann]"));
33
34 // [orth!=Frau]
Joachim Bingelee3b21d2014-02-12 12:34:59 +000035 String token2 = "{@type=korap:token, wrap={@type=korap:term, key=Frau, layer=orth, match=match:ne}}";
Joachim Bingel53333e62013-12-09 19:25:52 +000036 assertTrue(equalsQueryContent(token2, "[orth!=Frau]"));
37
38 // [!p=NN]
Joachim Bingelee3b21d2014-02-12 12:34:59 +000039 String token3 = "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, match=match:ne}}";
Joachim Bingel53333e62013-12-09 19:25:52 +000040 assertTrue(equalsQueryContent(token3, "[!p=NN]"));
41
42 // [!p!=NN]
Joachim Bingelee3b21d2014-02-12 12:34:59 +000043 String token4 = "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, match=match:eq}}";
Joachim Bingel53333e62013-12-09 19:25:52 +000044 assertTrue(equalsQueryContent(token4, "[!p!=NN]"));
45 }
46
47 @Test
Joachim Bingel41e112e2014-02-12 10:46:18 +000048 public void testRegex() throws QueryException {
49 String query = "[orth=\"M(a|ä)nn(er)?\"]";
Joachim Bingelbc537b62014-02-12 12:47:45 +000050 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 +000051 ppt = new PoliqarpPlusTree(query);
52 map = ppt.getRequestMap().get("query").toString();
53 assertEquals(re1.replaceAll(" ", ""), map.replaceAll(" ", ""));
54 }
55
56 @Test
Joachim Bingel0207d5e2014-02-12 14:18:41 +000057 public void testCaseSensitivityFlag() throws QueryException {
58 String query="[orth=deutscher/i]";
59 String cs1 =
60 "{@type=korap:token, wrap={@type=korap:term, key=deutscher, layer=orth, match=match:eq, caseInsensitive=true}}";
61 ppt = new PoliqarpPlusTree(query);
62 map = ppt.getRequestMap().get("query").toString();
63 assertEquals(cs1.replaceAll(" ", ""), map.replaceAll(" ", ""));
64
65 query="[orth=deutscher/i][orth=Bundestag]";
66 String cs2 =
67 "{@type=korap:group, operation=operation:sequence, operands=[" +
68 "{@type=korap:token, wrap={@type=korap:term, key=deutscher, layer=orth, match=match:eq, caseInsensitive=true}}," +
69 "{@type=korap:token, wrap={@type=korap:term, key=Bundestag, layer=orth, match=match:eq}}" +
70 "]}";
71 ppt = new PoliqarpPlusTree(query);
72 map = ppt.getRequestMap().get("query").toString();
73 assertEquals(cs2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeladd0fb12014-06-24 08:54:14 +000074
75 query="deutscher/i";
76 String cs3 =
77 "{@type=korap:token, wrap={@type=korap:term, key=deutscher, layer=orth, match=match:eq, caseInsensitive=true}}";
78 ppt = new PoliqarpPlusTree(query);
79 map = ppt.getRequestMap().get("query").toString();
80 assertEquals(cs3.replaceAll(" ", ""), map.replaceAll(" ", ""));
81
82 query="deutscher/i Bundestag";
83 String cs4 =
84 "{@type=korap:group, operation=operation:sequence, operands=[" +
85 "{@type=korap:token, wrap={@type=korap:term, key=deutscher, layer=orth, match=match:eq, caseInsensitive=true}}," +
86 "{@type=korap:token, wrap={@type=korap:term, key=Bundestag, layer=orth, match=match:eq}}" +
87 "]}";
88 ppt = new PoliqarpPlusTree(query);
89 map = ppt.getRequestMap().get("query").toString();
90 assertEquals(cs4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel0207d5e2014-02-12 14:18:41 +000091 }
92
93 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +000094 public void testElements() throws QueryException {
Joachim Bingelfc1fb352014-02-26 14:40:27 +000095 String query;
Joachim Bingel53333e62013-12-09 19:25:52 +000096 // <s>
Joachim Bingel2daf9862014-02-12 10:18:54 +000097 String elem1 = "{@type=korap:span, key=s}";
Joachim Bingel53333e62013-12-09 19:25:52 +000098 assertTrue(equalsQueryContent(elem1, "<s>"));
99
100 // <vp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000101 String elem2 = "{@type=korap:span, key=vp}";
Joachim Bingel53333e62013-12-09 19:25:52 +0000102 assertTrue(equalsQueryContent(elem2, "<vp>"));
Joachim Bingelfc1fb352014-02-26 14:40:27 +0000103
104 // <cnx/c=vp>
105 query = "<c=vp>";
106 String span3 = "{@type=korap:span, layer=c, key=vp}";
107 ppt = new PoliqarpPlusTree(query);
108 map = ppt.getRequestMap().get("query").toString();
109 assertEquals(span3.replaceAll(" ", ""), map.replaceAll(" ", ""));
110
111 // <cnx/c=vp>
112 query = "<cnx/c=vp>";
113 String span4 = "{@type=korap:span, foundry=cnx, layer=c, key=vp}";
114 ppt = new PoliqarpPlusTree(query);
115 map = ppt.getRequestMap().get("query").toString();
116 assertEquals(span4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000117 }
Joachim Bingel87480d02014-01-17 14:07:46 +0000118
119 @Test
120 public void testEmptyTokens() throws QueryException {
121 // [base=der][][base=Mann]
122 String et1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000123 "{@type=korap:group, operation=operation:sequence, inOrder=true, distances=[" +
Joachim Bingelb8a44a12014-04-17 09:35:30 +0000124 "{@type=korap:distance, key=w, min=2, 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(et1.replaceAll(" ", ""), map.replaceAll(" ", ""));
133
134 // [base=der][][][base=Mann]
135 String et2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000136 "{@type=korap:group, operation=operation:sequence, inOrder=true, distances=[" +
Joachim Bingelb8a44a12014-04-17 09:35:30 +0000137 "{@type=korap:distance, key=w, min=3, max=3}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000138 "], " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000139 "operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000140 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=match:eq}}," +
141 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000142 "]}";
Joachim Bingelffd65e32014-01-22 14:22:57 +0000143 ppt = new PoliqarpPlusTree("[base=der][][][base=Mann]");
Joachim Bingel87480d02014-01-17 14:07:46 +0000144 map = ppt.getRequestMap().get("query").toString();
145 assertEquals(et2.replaceAll(" ", ""), map.replaceAll(" ", ""));
146
147 // [base=der][][]?[base=Mann]
148 String et3 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000149 "{@type=korap:group, operation=operation:sequence, inOrder=true, distances=[" +
Joachim Bingelb8a44a12014-04-17 09:35:30 +0000150 "{@type=korap:distance, key=w, min=2, max=3}" +
Joachim Bingel87480d02014-01-17 14:07:46 +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}}," +
154 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000155 "]}";
156 ppt = new PoliqarpPlusTree("[base=der][][]?[base=Mann]");
157 map = ppt.getRequestMap().get("query").toString();
158 assertEquals(et3.replaceAll(" ", ""), map.replaceAll(" ", ""));
159
Joachim Bingel87480d02014-01-17 14:07:46 +0000160
161 // startswith(<s>, [][base=Mann]
Joachim Bingelffd65e32014-01-22 14:22:57 +0000162 String et4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000163 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
164 "{@type=korap:span, key=s}," +
165 "{@type=korap:group, operation=operation:sequence, offset-min=1, offset-max=1, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000166 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000167 "]}" +
168 "]}";
Joachim Bingelffd65e32014-01-22 14:22:57 +0000169 ppt = new PoliqarpPlusTree("startswith(<s>, [][base=Mann])");
170 map = ppt.getRequestMap().get("query").toString();
171 assertEquals(et4.replaceAll(" ", ""), map.replaceAll(" ", ""));
172
Joachim Bingel11d5b152014-02-11 21:33:47 +0000173 // [base=der][]{2,5}[base=Mann][]?[][base=Frau] nested distances=
Joachim Bingelffd65e32014-01-22 14:22:57 +0000174 String et5 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000175 "{@type=korap:group, operation=operation:sequence, inOrder=true, distances=[" +
Joachim Bingelb8a44a12014-04-17 09:35:30 +0000176 "{@type=korap:distance, key=w, min=3, max=6}" +
Joachim Bingelffd65e32014-01-22 14:22:57 +0000177 "], " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000178 "operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000179 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000180 "{@type=korap:group, operation=operation:sequence, inOrder=true, distances=[" +
Joachim Bingelb8a44a12014-04-17 09:35:30 +0000181 "{@type=korap:distance, key=w, min=2, max=3}" +
Joachim Bingelffd65e32014-01-22 14:22:57 +0000182 "], " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000183 "operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000184 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}," +
185 "{@type=korap:token, wrap={@type=korap:term, key=Frau, layer=lemma, match=match:eq}}" +
Joachim Bingelffd65e32014-01-22 14:22:57 +0000186 "]}" +
187 "]}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000188 ppt = new PoliqarpPlusTree("[base=der][]{2,5}[base=Mann][]?[][base=Frau]");
Joachim Bingel87480d02014-01-17 14:07:46 +0000189 map = ppt.getRequestMap().get("query").toString();
190 assertEquals(et5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel87480d02014-01-17 14:07:46 +0000191
Joachim Bingelc15720f2014-05-07 14:37:23 +0000192 // [base=der][]*[base=Mann]
193 String et6 =
194 "{@type=korap:group, operation=operation:sequence, inOrder=true, distances=[" +
195 "{@type=korap:distance, key=w, min=1, max=100}" +
196 "], " +
197 "operands=[" +
198 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=match:eq}}," +
199 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}" +
200 "]}";
201 ppt = new PoliqarpPlusTree("[base=der][]*[base=Mann]");
202 map = ppt.getRequestMap().get("query").toString();
203 assertEquals(et6.replaceAll(" ", ""), map.replaceAll(" ", ""));
204
205 // [base=der][]*[base=Mann]
206 String et7 =
207 "{@type=korap:group, operation=operation:sequence, inOrder=true, distances=[" +
208 "{@type=korap:distance, key=w, min=2, max=100}" +
209 "], " +
210 "operands=[" +
211 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=match:eq}}," +
212 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}" +
213 "]}";
214 ppt = new PoliqarpPlusTree("[base=der][]+[base=Mann]");
215 map = ppt.getRequestMap().get("query").toString();
216 assertEquals(et7.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel87480d02014-01-17 14:07:46 +0000217 }
Joachim Bingel53333e62013-12-09 19:25:52 +0000218
219 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000220 public void testCoordinatedFields() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000221 // [base=Mann&(cas=N|cas=A)]
222 String cof1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000223 "{@type=korap:token, wrap=" +
Joachim Bingel2980bda2014-04-04 12:09:46 +0000224 "{@type=korap:termGroup, relation=relation:and, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000225 "{@type=korap:term, key=Mann, layer=lemma, match=match:eq}," +
Joachim Bingel2980bda2014-04-04 12:09:46 +0000226 "{@type=korap:termGroup, relation=relation:or, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000227 "{@type=korap:term, key=N, layer=cas, match=match:eq}," +
228 "{@type=korap:term, key=A, layer=cas, match=match:eq}" +
229 "]}" +
230 "]}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000231 "}";
232 ppt = new PoliqarpPlusTree("[base=Mann&(cas=N|cas=A)]");
233 map = ppt.getRequestMap().get("query").toString();
234 assertEquals(cof1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Nils Diewald7d486c22013-12-13 16:32:18 +0000235
236
237 assertEquals(
238 new PoliqarpPlusTree(" [ base=Mann & ( cas=N | cas=A)] ").getRequestMap().get("query").toString(),
239 new PoliqarpPlusTree("[base=Mann &(cas=N|cas=A)]").getRequestMap().get("query").toString()
240 );
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000241
242 // [base=Mann&cas=N&gen=m]
243 String cof2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000244 "{@type=korap:token, wrap=" +
Joachim Bingel2980bda2014-04-04 12:09:46 +0000245 "{@type=korap:termGroup, relation=relation:and, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000246 "{@type=korap:term, key=Mann, layer=lemma, match=match:eq}," +
247 "{@type=korap:term, key=N, layer=cas, match=match:eq}," +
248 "{@type=korap:term, key=m, layer=gen, match=match:eq}" +
249 "]}" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000250 "}";
251 ppt = new PoliqarpPlusTree("[base=Mann&cas=N&gen=m]");
252 map = ppt.getRequestMap().get("query").toString();
253 assertEquals(cof2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000254 }
255
256 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000257 public void testOccurrence() throws QueryException {
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000258 // [base=foo]*
Joachim Bingel2daf9862014-02-12 10:18:54 +0000259 String occ1 = "{@type=korap:group, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000260 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000261 "], operation=operation:repetition, min=0, max=100}";
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000262 ppt = new PoliqarpPlusTree("[base=foo]*");
263 map = ppt.getRequestMap().get("query").toString();
264 assertEquals(occ1.replaceAll(" ", ""), map.replaceAll(" ", ""));
265
266 // [base=foo]*[base=bar]
267 String occ2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000268 "{@type=korap:group, operation=operation:sequence, operands=[" +
269 "{@type=korap:group, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000270 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000271 "], operation=operation:repetition, min=0, max=100 }," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000272 "{@type=korap:token, wrap={@type=korap:term, key=bar, layer=lemma, match=match:eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000273 "]}";
274 ppt = new PoliqarpPlusTree("[base=foo]*[base=bar]");
275 map = ppt.getRequestMap().get("query").toString();
276 assertEquals(occ2.replaceAll(" ", ""), map.replaceAll(" ", ""));
277
278 // [base=bar][base=foo]*
279 String occ3 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000280 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000281 "{@type=korap:token, wrap={@type=korap:term, key=bar, layer=lemma, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000282 "{@type=korap:group, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000283 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000284 "], operation=operation:repetition, min=0, max=100 }" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000285 "]}";
286 ppt = new PoliqarpPlusTree("[base=bar][base=foo]*");
287 map = ppt.getRequestMap().get("query").toString();
288 assertEquals(occ3.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb4da7022013-12-09 23:17:24 +0000289
290 // ([base=bar][base=foo])*
291 String occ4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000292 "{@type=korap:group, operands=[" +
293 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000294 "{@type=korap:token, wrap={@type=korap:term, key=bar, layer=lemma, match=match:eq}}," +
295 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000296 "]}" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000297 "], operation=operation:repetition, min=0, max=100 }" ;
Joachim Bingelb4da7022013-12-09 23:17:24 +0000298 ppt = new PoliqarpPlusTree("([base=bar][base=foo])*");
299 map = ppt.getRequestMap().get("query").toString();
300 assertEquals(occ4.replaceAll(" ", ""), map.replaceAll(" ", ""));
301
302 // <s>([base=bar][base=foo])*
303 String occ5 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000304 "{@type=korap:group, operation=operation:sequence, operands=[" +
305 "{@type=korap:span, key=s}," +
306 "{@type=korap:group, operands=[" +
307 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000308 "{@type=korap:token, wrap={@type=korap:term, key=bar, layer=lemma, match=match:eq}}," +
309 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000310 "]}" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000311 "], operation=operation:repetition, min=0, max=100 }" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000312 "]}" ;
313 ppt = new PoliqarpPlusTree("<s>([base=bar][base=foo])*");
314 map = ppt.getRequestMap().get("query").toString();
315 assertEquals(occ5.replaceAll(" ", ""), map.replaceAll(" ", ""));
316
317 // <s><np>([base=bar][base=foo])*
Joachim Bingelb4da7022013-12-09 23:17:24 +0000318 String occ6 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000319 "{@type=korap:group, operation=operation:sequence, operands=[" +
320 "{@type=korap:span, key=s}," +
321 "{@type=korap:span, key=np}," +
322 "{@type=korap:group, operands=[" +
323 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000324 "{@type=korap:token, wrap={@type=korap:term, key=bar, layer=lemma, match=match:eq}}," +
325 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000326 "]}" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000327 "], operation=operation:repetition, min=0, max=100 }" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000328 "]}" ;
329 ppt = new PoliqarpPlusTree("<s><np>([base=bar][base=foo])*");
330 map = ppt.getRequestMap().get("query").toString();
331 assertEquals(occ6.replaceAll(" ", ""), map.replaceAll(" ", ""));
332
333 // <s><np>([base=bar][base=foo])*[p=NN]
334 // comment: embedded sequence shouldn't really be here, but does not really hurt, either. (?)
335 // really hard to get this behaviour out of the PQPlus grammar...
336 String occ7 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000337 "{@type=korap:group, operation=operation:sequence, operands=[" +
338 "{@type=korap:span, key=s}," +
339 "{@type=korap:span, key=np}," +
340 "{@type=korap:group, operands=[" +
341 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000342 "{@type=korap:token, wrap={@type=korap:term, key=bar, layer=lemma, match=match:eq}}," +
343 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000344 "]}" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000345 "], operation=operation:repetition, min=0, max=100 }," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000346 "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000347 "]}" ;
348 ppt = new PoliqarpPlusTree("<s><np>([base=bar][base=foo])*[p=NN]");
349 map = ppt.getRequestMap().get("query").toString();
350 assertEquals(occ7.replaceAll(" ", ""), map.replaceAll(" ", ""));
351
352 // ([base=bar][base=foo])*[p=NN]
Joachim Bingelb4da7022013-12-09 23:17:24 +0000353 String occ8 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000354 "{@type=korap:group, operation=operation:sequence, operands=[" +
355 "{@type=korap:group, operands=[" +
356 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000357 "{@type=korap:token, wrap={@type=korap:term, key=bar, layer=lemma, match=match:eq}}," +
358 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000359 "]}" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000360 "], operation=operation:repetition, min=0, max=100 }," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000361 "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000362 "]}" ;
363 ppt = new PoliqarpPlusTree("([base=bar][base=foo])*[p=NN]");
364 map = ppt.getRequestMap().get("query").toString();
365 assertEquals(occ8.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000366
367 // [base=foo]+
Joachim Bingel2daf9862014-02-12 10:18:54 +0000368 String occ9 = "{@type=korap:group, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000369 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000370 "], operation=operation:repetition, min=1, max=100}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000371 ppt = new PoliqarpPlusTree("[base=foo]+");
372 map = ppt.getRequestMap().get("query").toString();
373 assertEquals(occ9.replaceAll(" ", ""), map.replaceAll(" ", ""));
374
375 // [base=foo]?
Joachim Bingel2daf9862014-02-12 10:18:54 +0000376 String occ10 = "{@type=korap:group, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000377 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000378 "], operation=operation:repetition, min=0, max=1}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000379 ppt = new PoliqarpPlusTree("[base=foo]?");
380 map = ppt.getRequestMap().get("query").toString();
381 assertEquals(occ10.replaceAll(" ", ""), map.replaceAll(" ", ""));
382
383 // [base=foo]{2,5}
Joachim Bingel2daf9862014-02-12 10:18:54 +0000384 String occ11 = "{@type=korap:group, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000385 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000386 "], operation=operation:repetition, min=2, max=5}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000387 ppt = new PoliqarpPlusTree("[base=foo]{2,5}");
388 map = ppt.getRequestMap().get("query").toString();
389 assertEquals(occ11.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel2980bda2014-04-04 12:09:46 +0000390
391 // [base=foo]{2}
392 String occ12 = "{@type=korap:group, operands=[" +
393 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
394 "], operation=operation:repetition, min=2, max=2}";
395 ppt = new PoliqarpPlusTree("[base=foo]{2}");
396 map = ppt.getRequestMap().get("query").toString();
397 assertEquals(occ12.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000398 }
399
400 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000401 public void testTokenSequence() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000402 // [base=Mann][orth=Frau]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000403 String seq1 = "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000404 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}, " +
405 "{@type=korap:token, wrap={@type=korap:term, key=Frau, layer=orth, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000406 "]}";
407 assertTrue(equalsQueryContent(seq1, "[base=Mann][orth=Frau]"));
408
409 // [base=Mann][orth=Frau][p=NN]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000410 String seq2 = "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000411 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}, " +
412 "{@type=korap:token, wrap={@type=korap:term, key=Frau, layer=orth, match=match:eq}}, " +
413 "{@type=korap:token, wrap={@type=korap:term, key=NN,layer=p, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000414 "]}";
415 assertTrue(equalsQueryContent(seq2, "[base=Mann][orth=Frau][p=NN]"));
416 }
417
418 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000419 public void testDisjSegments() throws QueryException {
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000420 // ([base=der]|[base=das])[base=Schild]
421 String disj1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000422 "{@type=korap:group, operation=operation:sequence, operands=[" +
423 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000424 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=match:eq}}," +
425 "{@type=korap:token, wrap={@type=korap:term, key=das, layer=lemma, match=match:eq}}" +
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000426 "]}," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000427 "{@type=korap:token, wrap={@type=korap:term, key=Schild, layer=lemma, match=match:eq}}" +
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000428 "]}";
429 ppt = new PoliqarpPlusTree("([base=der]|[base=das])[base=Schild]");
430 map = ppt.getRequestMap().get("query").toString();
431 assertEquals(disj1.replaceAll(" ", ""), map.replaceAll(" ", ""));
432
433 // [base=Schild]([base=der]|[base=das])
434 String disj2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000435 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000436 "{@type=korap:token, wrap={@type=korap:term, key=Schild, layer=lemma, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000437 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000438 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=match:eq}}," +
439 "{@type=korap:token, wrap={@type=korap:term, key=das, layer=lemma, match=match:eq}}" +
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000440 "]}" +
441 "]}";
442 ppt = new PoliqarpPlusTree("[base=Schild]([base=der]|[base=das])");
443 map = ppt.getRequestMap().get("query").toString();
444 assertEquals(disj2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel76b498d2014-06-06 12:06:46 +0000445
446 // "([orth=der][base=katze])|([orth=eine][base=baum])"
447 String disj3 =
448 "{@type=korap:group, operation=operation:or, operands=[" +
449 "{@type=korap:group, operation=operation:sequence, operands=[" +
450 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
451 "{@type=korap:token, wrap={@type=korap:term, key=katze, layer=lemma, match=match:eq}}" +
452 "]}," +
453 "{@type=korap:group, operation=operation:sequence, operands=[" +
454 "{@type=korap:token, wrap={@type=korap:term, key=eine, layer=orth, match=match:eq}}," +
455 "{@type=korap:token, wrap={@type=korap:term, key=baum, layer=lemma, match=match:eq}}" +
456 "]}" +
457 "]}";
458 ppt = new PoliqarpPlusTree("([orth=der][base=katze])|([orth=eine][base=baum])");
459 map = ppt.getRequestMap().get("query").toString();
460 assertEquals(disj3.replaceAll(" ", ""), map.replaceAll(" ", ""));
461
462 // "[orth=der][base=katze]|[orth=eine][base=baum]"
463 String disj4 =
464 "{@type=korap:group, operation=operation:or, operands=[" +
465 "{@type=korap:group, operation=operation:sequence, operands=[" +
466 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
467 "{@type=korap:token, wrap={@type=korap:term, key=katze, layer=lemma, match=match:eq}}" +
468 "]}," +
469 "{@type=korap:group, operation=operation:sequence, operands=[" +
470 "{@type=korap:token, wrap={@type=korap:term, key=eine, layer=orth, match=match:eq}}," +
471 "{@type=korap:token, wrap={@type=korap:term, key=baum, layer=lemma, match=match:eq}}" +
472 "]}" +
473 "]}";
474 ppt = new PoliqarpPlusTree("[orth=der][base=katze]|[orth=eine][base=baum]");
475 map = ppt.getRequestMap().get("query").toString();
476 assertEquals(disj4.replaceAll(" ", ""), map.replaceAll(" ", ""));
477
478 PoliqarpPlusTree ppt1 = new PoliqarpPlusTree("[orth=der][base=katze]|[orth=eine][base=baum]");
479 PoliqarpPlusTree ppt2 = new PoliqarpPlusTree("([orth=der][base=katze])|([orth=eine][base=baum])");
480 assertEquals(ppt1.getRequestMap().toString(), ppt2.getRequestMap().toString());
481
482 // "[orth=der][base=katze]|[orth=der][base=hund]|[orth=der][base=baum]"
483 String disj5 =
484 "{@type=korap:group, operation=operation:or, operands=[" +
485 "{@type=korap:group, operation=operation:sequence, operands=[" +
486 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
487 "{@type=korap:token, wrap={@type=korap:term, key=katze, layer=lemma, match=match:eq}}" +
488 "]}," +
489 "{@type=korap:group, operation=operation:sequence, operands=[" +
490 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
491 "{@type=korap:token, wrap={@type=korap:term, key=hund, layer=lemma, match=match:eq}}" +
492 "]}," +
493 "{@type=korap:group, operation=operation:sequence, operands=[" +
494 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
495 "{@type=korap:token, wrap={@type=korap:term, key=baum, layer=lemma, match=match:eq}}" +
496 "]}" +
497 "]}";
498 ppt = new PoliqarpPlusTree("[orth=der][base=katze]|[orth=der][base=hund]|[orth=der][base=baum]");
499 map = ppt.getRequestMap().get("query").toString();
500 assertEquals(disj5.replaceAll(" ", ""), map.replaceAll(" ", ""));
501
502 // [orth=der]([base=katze]|[base=hund]|[base=baum])
503 String disj6 =
504 "{@type=korap:group, operation=operation:sequence, operands=[" +
505 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
506 "{@type=korap:group, operation=operation:or, operands=[" +
507 "{@type=korap:token, wrap={@type=korap:term, key=katze, layer=lemma, match=match:eq}}," +
508 "{@type=korap:token, wrap={@type=korap:term, key=hund, layer=lemma, match=match:eq}}," +
509 "{@type=korap:token, wrap={@type=korap:term, key=baum, layer=lemma, match=match:eq}}" +
510 "]}" +
511 "]}";
512 ppt = new PoliqarpPlusTree("[orth=der]([base=katze]|[base=hund]|[base=baum])");
513 map = ppt.getRequestMap().get("query").toString();
514 assertEquals(disj6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000515 }
516
517 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000518 public void testTokenElemSequence() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000519 // [base=Mann]<vp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000520 String seq1 = "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000521 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}, " +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000522 "{@type=korap:span, key=vp}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000523 "]}";
524 assertTrue(equalsQueryContent(seq1, "[base=Mann]<vp>"));
525
526 // <vp>[base=Mann]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000527 String seq2 = "{@type=korap:group, operation=operation:sequence, operands=[" +
528 "{@type=korap:span, key=vp}, "+
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000529 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}} " +
Joachim Bingel53333e62013-12-09 19:25:52 +0000530 "]}";
531 assertTrue(equalsQueryContent(seq2, "<vp>[base=Mann]"));
532
533 // <vp>[base=Mann]<pp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000534 String seq3 = "{@type=korap:group, operation=operation:sequence, operands=[" +
535 "{@type=korap:span, key=vp}, "+
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000536 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}, " +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000537 "{@type=korap:span, key=pp} "+
Joachim Bingel53333e62013-12-09 19:25:52 +0000538 "]}";
539 assertTrue(equalsQueryContent(seq3, "<vp>[base=Mann]<pp>"));
540 }
541
542 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000543 public void testElemSequence() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000544 // <np><vp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000545 String seq1 = "{@type=korap:group, operation=operation:sequence, operands=[" +
546 "{@type=korap:span, key=np}," +
547 "{@type=korap:span, key=vp}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000548 "]}";
549 assertTrue(equalsQueryContent(seq1, "<np><vp>"));
550
551 // <np><vp><pp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000552 String seq2 = "{@type=korap:group, operation=operation:sequence, operands=[" +
553 "{@type=korap:span, key=np}," +
554 "{@type=korap:span, key=vp}," +
555 "{@type=korap:span, key=pp}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000556 "]}";
557 assertTrue(equalsQueryContent(seq2, "<np><vp><pp>"));
558 }
559
560 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000561 public void testClasses() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000562 // {[base=Mann]}
Joachim Bingel2daf9862014-02-12 10:18:54 +0000563 String cls1 = "{@type=korap:group, operation=operation:class, class=0, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000564 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000565 "]}";
Joachim Bingel8c640e42014-02-07 16:20:47 +0000566 ppt = new PoliqarpPlusTree("{[base=Mann]}");
567 map = ppt.getRequestMap().get("query").toString();
568 assertEquals(cls1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000569
570 // {[base=Mann][orth=Frau]}
Joachim Bingel2daf9862014-02-12 10:18:54 +0000571 String cls2 = "{@type=korap:group, operation=operation:class, class=0, operands=[" +
572 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000573 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}," +
574 "{@type=korap:token, wrap={@type=korap:term, key=Frau, layer=orth, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000575 "]}" +
576 "]}";
577 assertTrue(equalsQueryContent(cls2, "{[base=Mann][orth=Frau]}"));
578
579 // [p=NN]{[base=Mann][orth=Frau]}
Joachim Bingel2daf9862014-02-12 10:18:54 +0000580 String cls3 = "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000581 "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000582 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
583 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000584 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}," +
585 "{@type=korap:token, wrap={@type=korap:term, key=Frau, layer=orth, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000586 "]}" +
587 "]}" +
588 "]}";
589 assertTrue(equalsQueryContent(cls3, "[p=NN]{[base=Mann][orth=Frau]}"));
590
591 // {[base=Mann][orth=Frau]}[p=NN]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000592 String cls4 = "{@type=korap:group, operation=operation:sequence, operands=[" +
593 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
594 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000595 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}," +
596 "{@type=korap:token, wrap={@type=korap:term, key=Frau, layer=orth, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000597 "]}" +
598 "]}," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000599 "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000600 "]}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000601 ppt = new PoliqarpPlusTree("{[base=Mann][orth=Frau]}[p=NN]");
602 map = ppt.getRequestMap().get("query").toString();
603 assertEquals(cls4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000604
605 // {2:{1:[tt/p=ADJA]}[mate/p=NN]}"
Joachim Bingel2daf9862014-02-12 10:18:54 +0000606 String cls5 = "{@type=korap:group, operation=operation:class, class=2, operands=[" +
607 "{@type=korap:group, operation=operation:sequence, operands=[" +
608 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000609 "{@type=korap:token, wrap={@type=korap:term, key=ADJA, layer=p, foundry=tt, match=match:eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000610 "]}," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000611 "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, foundry=mate, match=match:eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000612 "]}" +
613 "]}";
614 ppt = new PoliqarpPlusTree("{2: {1:[tt/p=ADJA]}[mate/p=NN]}");
615 map = ppt.getRequestMap().get("query").toString();
616 assertEquals(cls5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000617 }
618
619 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000620 public void testPositions() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000621 // contains(<s>,<np>)
Joachim Bingel2daf9862014-02-12 10:18:54 +0000622 String pos1 = "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
623 "{@type=korap:span, key=s}," +
624 "{@type=korap:span, key=np}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000625 "]}";
626 assertTrue(equalsQueryContent(pos1, "contains(<s>,<np>)"));
627
628 // contains(<s>,[base=Mann])
Joachim Bingel2daf9862014-02-12 10:18:54 +0000629 String pos2 = "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
630 "{@type=korap:span, key=s}," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000631 "{@type=korap:token, wrap= {@type=korap:term, key=Mann, layer=lemma, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000632 "]}";
633 assertTrue(equalsQueryContent(pos2, "contains(<s>,[base=Mann])"));
634
635 // contains(<s>,[orth=der][orth=Mann])
Joachim Bingel2daf9862014-02-12 10:18:54 +0000636 String pos3 = "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
637 "{@type=korap:span, key=s}," +
638 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000639 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
640 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000641 "]}" +
642 "]}";
643 ppt = new PoliqarpPlusTree("contains(<s>,[orth=der][orth=Mann])");
644 map = ppt.getRequestMap().get("query").toString();
645 assertEquals(pos3.replaceAll(" ", ""), map.replaceAll(" ", ""));
646
647 // [base=Auto]contains(<s>,[base=Mann])
648 String pos4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000649 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000650 "{@type=korap:token, wrap={@type=korap:term, key=Auto, layer=lemma, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000651 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
652 "{@type=korap:span, key=s}," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000653 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000654 "]}" +
655 "]}";
656 ppt = new PoliqarpPlusTree("[base=Auto]contains(<s>,[base=Mann])");
657 map = ppt.getRequestMap().get("query").toString();
658 assertEquals(pos4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelef7059b2014-04-22 13:44:19 +0000659
660 // contains(<s>,[pos=N]*)
661 String pos5 =
662 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
663 "{@type=korap:span, key=s}," +
664 "{@type=korap:group, " +
665 "operands=[{@type=korap:token, wrap={@type=korap:term, key=N, layer=pos, match=match:eq}}" +
666 "], operation=operation:repetition, min=0, max=100" +
667 "}" +
668 "]}";
669 ppt = new PoliqarpPlusTree("contains(<s>,[pos=N]*)");
670 map = ppt.getRequestMap().get("query").toString();
671 assertEquals(pos5.replaceAll(" ", ""), map.replaceAll(" ", ""));
672
673 // [base=Auto]contains(<s>,[pos=N]*)
674 String pos6 =
675 "{@type=korap:group, operation=operation:sequence, operands=[" +
676 "{@type=korap:token, wrap={@type=korap:term, key=Auto, layer=lemma, match=match:eq}}," +
677 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
678 "{@type=korap:span, key=s}," +
679 "{@type=korap:group, " +
680 "operands=[{@type=korap:token, wrap={@type=korap:term, key=N, layer=pos, match=match:eq}}" +
681 "], operation=operation:repetition, min=0, max=100" +
682 "}" +
683 "]}" +
684 "]}";
685 ppt = new PoliqarpPlusTree("[base=Auto]contains(<s>,[pos=N]*)");
686 map = ppt.getRequestMap().get("query").toString();
687 assertEquals(pos6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000688 }
689
690 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000691 public void testNestedPositions() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000692 // contains(<s>,startswith(<np>,[orth=Der]))
693 String npos1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000694 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
695 "{@type=korap:span, key=s}," +
696 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
697 "{@type=korap:span, key=np}," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000698 "{@type=korap:token, wrap={@type=korap:term, key=Der, layer=orth, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000699 "]}" +
700 "]}";
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000701 ppt = new PoliqarpPlusTree("contains(<s>, startswith(<np>,[orth=Der]))");
Joachim Bingel53333e62013-12-09 19:25:52 +0000702 map = ppt.getRequestMap().get("query").toString();
703 assertEquals(npos1.replaceAll(" ", ""), map.replaceAll(" ", ""));
704 }
705
706 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000707 public void testShrinkSplit() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000708 // shrink([orth=Der]{[orth=Mann]})
709 String shr1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000710 "{@type=korap:group, operation=operation:submatch, classRef=[0], operands=[" +
711 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000712 "{@type=korap:token, wrap={@type=korap:term, key=Der, layer=orth, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000713 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000714 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000715 "]}" +
716 "]}" +
717 "]}";
718 ppt = new PoliqarpPlusTree("shrink([orth=Der]{[orth=Mann]})");
719 map = ppt.getRequestMap().get("query").toString();
720 assertEquals(shr1.replaceAll(" ", ""), map.replaceAll(" ", ""));
721
722 // shrink([orth=Der]{[orth=Mann][orth=geht]})
723 String shr2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000724 "{@type=korap:group, operation=operation:submatch, classRef=[0], operands=[" +
725 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000726 "{@type=korap:token, wrap={@type=korap:term, key=Der, layer=orth, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000727 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
728 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000729 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}," +
730 "{@type=korap:token, wrap={@type=korap:term, key=geht, layer=orth, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000731 "]}" +
732 "]}" +
733 "]}" +
734 "]}";
735 ppt = new PoliqarpPlusTree("shrink([orth=Der]{[orth=Mann][orth=geht]})");
736 map = ppt.getRequestMap().get("query").toString();
737 assertEquals(shr2.replaceAll(" ", ""), map.replaceAll(" ", ""));
738
739 // shrink(1:[orth=Der]{1:[orth=Mann][orth=geht]})
740 String shr3 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000741 "{@type=korap:group, operation=operation:submatch, classRef=[1], operands=[" +
742 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000743 "{@type=korap:token, wrap={@type=korap:term, key=Der, layer=orth, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000744 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
745 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000746 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}," +
747 "{@type=korap:token, wrap={@type=korap:term, key=geht, layer=orth, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000748 "]}" +
749 "]}" +
750 "]}" +
751 "]}";
752 ppt = new PoliqarpPlusTree("shrink(1:[orth=Der]{1:[orth=Mann][orth=geht]})");
753 map = ppt.getRequestMap().get("query").toString();
754 assertEquals(shr3.replaceAll(" ", ""), map.replaceAll(" ", ""));
755
756 // shrink(1:startswith(<s>,{1:<np>}))
757 String shr4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000758 "{@type=korap:group, operation=operation:submatch, classRef=[1], operands=[" +
759 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
760 "{@type=korap:span, key=s}," +
761 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
762 "{@type=korap:span, key=np}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000763 "]}" +
764 "]}" +
765 "]}";
Joachim Bingeladefa622013-12-13 10:51:48 +0000766 ppt = new PoliqarpPlusTree("shrink(1:startswith(<s>,{1:<np>}))");
Joachim Bingel53333e62013-12-09 19:25:52 +0000767 map = ppt.getRequestMap().get("query").toString();
768 assertEquals(shr4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000769
770 // shrink(3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))
771 String shr5 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000772 "{@type=korap:group, operation=operation:submatch, classRef=[3], operands=[" +
773 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
774 "{@type=korap:span, key=s}," +
775 "{@type=korap:group, operation=operation:class, class=3, operands=[" +
776 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000777 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000778 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
779 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000780 "{@type=korap:token, wrap={@type=korap:term, key=ADJA, layer=p, foundry=mate, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000781 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000782 "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, foundry=tt, match=match:eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000783 "]}" +
784 "]}" +
785 "]}" +
786 "]}" +
787 "]}" +
788 "]}" +
789 "]}";
Joachim Bingeladefa622013-12-13 10:51:48 +0000790 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 +0000791 map = ppt.getRequestMap().get("query").toString();
792 assertEquals(shr5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000793
794 // split(3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))
795 String shr6 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000796 "{@type=korap:group, operation=operation:split, classRef=[3], operands=[" +
797 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
798 "{@type=korap:span, key=s}," +
799 "{@type=korap:group, operation=operation:class, class=3, operands=[" +
800 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000801 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000802 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
803 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000804 "{@type=korap:token, wrap={@type=korap:term, key=ADJA, layer=p, foundry=mate, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000805 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000806 "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, foundry=tt, match=match:eq}}" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000807 "]}" +
808 "]}" +
809 "]}" +
810 "]}" +
811 "]}" +
812 "]}" +
813 "]}";
814 ppt = new PoliqarpPlusTree("split(3:startswith(<s>,{3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) ");
815 map = ppt.getRequestMap().get("query").toString();
816 assertEquals(shr6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel8c640e42014-02-07 16:20:47 +0000817
818 // split(2|3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))
819 String shr7 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000820 "{@type=korap:group, operation=operation:split, classRef=[2, 3], classRefOp=classRefOp:intersection, operands=[" +
821 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
822 "{@type=korap:span, key=s}," +
823 "{@type=korap:group, operation=operation:class, class=3, operands=[" +
824 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000825 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000826 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
827 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000828 "{@type=korap:token, wrap={@type=korap:term, key=ADJA, layer=p, foundry=mate, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000829 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000830 "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, foundry=tt, match=match:eq}}" +
Joachim Bingel8c640e42014-02-07 16:20:47 +0000831 "]}" +
832 "]}" +
833 "]}" +
834 "]}" +
835 "]}" +
836 "]}" +
837 "]}";
838 ppt = new PoliqarpPlusTree("split(2|3:startswith(<s>,{3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) ");
839 map = ppt.getRequestMap().get("query").toString();
840 assertEquals(shr7.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel5146ebe2014-06-12 08:49:21 +0000841
842
843 String shr8 =
Joachim Bingeladd0fb12014-06-24 08:54:14 +0000844 "{@type=korap:group, operation=operation:submatch, classRef=[1], operands=[" +
845 "{@type=korap:group, operation=operation:sequence, operands=[" +
846 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
847 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=match:eq}}" +
848 "]}," +
849 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
850 "{@type=korap:token, wrap={@type=korap:term, key=ADJA, layer=pos, match=match:eq}}" +
Joachim Bingel5146ebe2014-06-12 08:49:21 +0000851 "]}" +
Joachim Bingeladd0fb12014-06-24 08:54:14 +0000852 "]}" +
853 "]}";
854 ppt = new PoliqarpPlusTree("shrink(1:{[base=der]}{1:[pos=ADJA]})");
855 map = ppt.getRequestMap().get("query").toString();
856 assertEquals(shr8.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel5146ebe2014-06-12 08:49:21 +0000857
Joachim Bingel53333e62013-12-09 19:25:52 +0000858 }
859
Joachim Bingel03882702013-12-31 19:53:05 +0000860
Joachim Bingel53333e62013-12-09 19:25:52 +0000861 @Test
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000862 public void testFoundries() throws QueryException {
863 // [tt/base=Mann]
Joachim Bingelac13a472014-02-14 21:18:52 +0000864 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 +0000865 ppt = new PoliqarpPlusTree("[tt/base=Mann]");
866 map = ppt.getRequestMap().get("query").toString();
867 assertEquals(layer1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000868
869 }
Joachim Bingel16da4e12013-12-17 09:48:12 +0000870
871 @Test
Joachim Bingel8c640e42014-02-07 16:20:47 +0000872 public void testAlign() throws QueryException {
Joachim Bingel16da4e12013-12-17 09:48:12 +0000873 // [orth=der]^[orth=Mann]
874 String align1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000875 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000876 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000877 "{@type=korap:group, alignment=left, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000878 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
Joachim Bingel03882702013-12-31 19:53:05 +0000879 "]}" +
Joachim Bingel16da4e12013-12-17 09:48:12 +0000880 "]}";
881 ppt = new PoliqarpPlusTree("[orth=der]^[orth=Mann]");
882 map = ppt.getRequestMap().get("query").toString();
883 assertEquals(align1.replaceAll(" ", ""), map.replaceAll(" ", ""));
884
Joachim Bingel84e33df2014-01-31 14:02:46 +0000885 // [orth=der]^[orth=große][orth=Mann]
886 String query = "[orth=der]^[orth=große][orth=Mann]";
887 String align1b =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000888 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000889 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000890 "{@type=korap:group, alignment=left, operands=[" +
891 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000892 "{@type=korap:token, wrap={@type=korap:term, key=große, layer=orth, match=match:eq}}," +
893 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +0000894 "]}" +
895 "]}" +
896 "]}";
897 ppt = new PoliqarpPlusTree(query);
898 map = ppt.getRequestMap().get("query").toString();
899 assertEquals(align1b.replaceAll(" ", ""), map.replaceAll(" ", ""));
900
Joachim Bingel16da4e12013-12-17 09:48:12 +0000901 // "([base=a]^[base=b])|[base=c]",
902 String align2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000903 "{@type=korap:group, operation=operation:or, operands=[" +
904 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000905 "{@type=korap:token, wrap={@type=korap:term, key=a, layer=lemma, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000906 "{@type=korap:group, alignment=left, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000907 "{@type=korap:token, wrap={@type=korap:term, key=b, layer=lemma, match=match:eq}}" +
Joachim Bingel03882702013-12-31 19:53:05 +0000908 "]}" +
Joachim Bingel16da4e12013-12-17 09:48:12 +0000909 "]}," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000910 "{@type=korap:token, wrap={@type=korap:term, key=c, layer=lemma, match=match:eq}}" +
Joachim Bingel16da4e12013-12-17 09:48:12 +0000911 "]}";
912 ppt = new PoliqarpPlusTree("([base=a]^[base=b])|[base=c]");
913 map = ppt.getRequestMap().get("query").toString();
914 assertEquals(align2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingela67e6a32014-01-02 18:35:24 +0000915
916 // "([base=a]^[base=b][base=c])|[base=d]",
917 String align3 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000918 "{@type=korap:group, operation=operation:or, operands=[" +
919 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000920 "{@type=korap:token, wrap={@type=korap:term, key=a, layer=lemma, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000921 "{@type=korap:group, alignment=left, operands=[" +
922 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000923 "{@type=korap:token, wrap={@type=korap:term, key=b, layer=lemma, match=match:eq}}," +
924 "{@type=korap:token, wrap={@type=korap:term, key=c, layer=lemma, match=match:eq}}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +0000925 "]}" +
926 "]}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000927 "]}," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000928 "{@type=korap:token, wrap={@type=korap:term, key=d, layer=lemma, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000929 "]}";
930 ppt = new PoliqarpPlusTree("([base=a]^[base=b][base=c])|[base=d]");
931 map = ppt.getRequestMap().get("query").toString();
932 assertEquals(align3.replaceAll(" ", ""), map.replaceAll(" ", ""));
933
934 // "([base=a]^[base=b]^[base=c])|[base=d]",
935 String align4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000936 "{@type=korap:group, operation=operation:or, operands=[" +
937 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000938 "{@type=korap:token, wrap={@type=korap:term, key=a, layer=lemma, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000939 "{@type=korap:group, alignment=left, operands=[" +
940 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000941 "{@type=korap:token, wrap={@type=korap:term, key=b, layer=lemma, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000942 "{@type=korap:group, alignment=left, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000943 "{@type=korap:token, wrap={@type=korap:term, key=c, layer=lemma, match=match:eq}}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +0000944 "]}" +
945 "]}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000946 "]}" +
947 "]}," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000948 "{@type=korap:token, wrap={@type=korap:term, key=d, layer=lemma, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000949 "]}";
950 ppt = new PoliqarpPlusTree("([base=a]^[base=b]^[base=c])|[base=d]");
951 map = ppt.getRequestMap().get("query").toString();
952 assertEquals(align4.replaceAll(" ", ""), map.replaceAll(" ", ""));
953
954
Joachim Bingel16da4e12013-12-17 09:48:12 +0000955 }
956
957 @Test
Joachim Bingel8c640e42014-02-07 16:20:47 +0000958 public void testSimpleQueries() throws QueryException {
Joachim Bingela67e6a32014-01-02 18:35:24 +0000959 // Baum
960 String simple1 =
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000961 "{@type=korap:token, wrap={@type=korap:term, key=Baum, layer=orth, match=match:eq}}";
Joachim Bingela67e6a32014-01-02 18:35:24 +0000962 ppt = new PoliqarpPlusTree("Baum");
963 map = ppt.getRequestMap().get("query").toString();
964 assertEquals(simple1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel16da4e12013-12-17 09:48:12 +0000965
Joachim Bingela67e6a32014-01-02 18:35:24 +0000966 // Der Baum
967 String simple2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000968 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000969 "{@type=korap:token, wrap={@type=korap:term, key=Der, layer=orth, match=match:eq}}, " +
970 "{@type=korap:token, wrap={@type=korap:term, key=Baum, layer=orth, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000971 "]}";
972 ppt = new PoliqarpPlusTree("Der Baum");
973 map = ppt.getRequestMap().get("query").toString();
974 assertEquals(simple2.replaceAll(" ", ""), map.replaceAll(" ", ""));
975
976 // Der große Baum
977 String simple3 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000978 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000979 "{@type=korap:token, wrap={@type=korap:term, key=Der, layer=orth, match=match:eq}}, " +
980 "{@type=korap:token, wrap={@type=korap:term, key=große, layer=orth, match=match:eq}}, " +
981 "{@type=korap:token, wrap={@type=korap:term, key=Baum, layer=orth, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000982 "]}";
983 ppt = new PoliqarpPlusTree("Der große Baum");
984 map = ppt.getRequestMap().get("query").toString();
985 assertEquals(simple3.replaceAll(" ", ""), map.replaceAll(" ", ""));
986
987 // Baum | Stein
988 String simple4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000989 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000990 "{@type=korap:token, wrap={@type=korap:term, key=Baum, layer=orth, match=match:eq}}, " +
991 "{@type=korap:token, wrap={@type=korap:term, key=Stein, layer=orth, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000992 "]}";
993 ppt = new PoliqarpPlusTree("Baum | Stein");
994 map = ppt.getRequestMap().get("query").toString();
995 assertEquals(simple4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel84e33df2014-01-31 14:02:46 +0000996
997 // Baum | Stein Haus
998 String query = "(Baum | Stein) Haus";
999 String simple5 =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001000 "{@type=korap:group, operation=operation:sequence, operands=[" +
1001 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +00001002 "{@type=korap:token, wrap={@type=korap:term, key=Baum, layer=orth, match=match:eq}}, " +
1003 "{@type=korap:token, wrap={@type=korap:term, key=Stein, layer=orth, match=match:eq}}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +00001004 "]}," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +00001005 "{@type=korap:token, wrap={@type=korap:term, key=Haus, layer=orth, match=match:eq}} " +
Joachim Bingel84e33df2014-01-31 14:02:46 +00001006 "]}";
1007 ppt = new PoliqarpPlusTree(query);
1008 map = ppt.getRequestMap().get("query").toString();
1009 assertEquals(simple5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel16da4e12013-12-17 09:48:12 +00001010 }
Joachim Bingel53333e62013-12-09 19:25:52 +00001011}
1012