blob: 28dd0cf7eb29650d520433c7fc4ae3cdf77e8461 [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 Bingelf8dfcf82014-06-25 09:57:44 +000091
92 query="deutscher Bundestag/i";
93 String cs5 =
94 "{@type=korap:group, operation=operation:sequence, operands=[" +
95 "{@type=korap:token, wrap={@type=korap:term, key=deutscher, layer=orth, match=match:eq}}," +
96 "{@type=korap:token, wrap={@type=korap:term, key=Bundestag, layer=orth, match=match:eq, caseInsensitive=true}}" +
97 "]}";
98 ppt = new PoliqarpPlusTree(query);
99 map = ppt.getRequestMap().get("query").toString();
100 assertEquals(cs5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel0207d5e2014-02-12 14:18:41 +0000101 }
102
103 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000104 public void testElements() throws QueryException {
Joachim Bingelfc1fb352014-02-26 14:40:27 +0000105 String query;
Joachim Bingel53333e62013-12-09 19:25:52 +0000106 // <s>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000107 String elem1 = "{@type=korap:span, key=s}";
Joachim Bingel53333e62013-12-09 19:25:52 +0000108 assertTrue(equalsQueryContent(elem1, "<s>"));
109
110 // <vp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000111 String elem2 = "{@type=korap:span, key=vp}";
Joachim Bingel53333e62013-12-09 19:25:52 +0000112 assertTrue(equalsQueryContent(elem2, "<vp>"));
Joachim Bingelfc1fb352014-02-26 14:40:27 +0000113
114 // <cnx/c=vp>
115 query = "<c=vp>";
116 String span3 = "{@type=korap:span, layer=c, key=vp}";
117 ppt = new PoliqarpPlusTree(query);
118 map = ppt.getRequestMap().get("query").toString();
119 assertEquals(span3.replaceAll(" ", ""), map.replaceAll(" ", ""));
120
121 // <cnx/c=vp>
122 query = "<cnx/c=vp>";
123 String span4 = "{@type=korap:span, foundry=cnx, layer=c, key=vp}";
124 ppt = new PoliqarpPlusTree(query);
125 map = ppt.getRequestMap().get("query").toString();
126 assertEquals(span4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000127 }
Joachim Bingel87480d02014-01-17 14:07:46 +0000128
129 @Test
130 public void testEmptyTokens() throws QueryException {
131 // [base=der][][base=Mann]
132 String et1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000133 "{@type=korap:group, operation=operation:sequence, inOrder=true, distances=[" +
Joachim Bingelb8a44a12014-04-17 09:35:30 +0000134 "{@type=korap:distance, key=w, min=2, max=2}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000135 "], " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000136 "operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000137 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=match:eq}}," +
138 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000139 "]}";
140 ppt = new PoliqarpPlusTree("[base=der][][base=Mann]");
141 map = ppt.getRequestMap().get("query").toString();
142 assertEquals(et1.replaceAll(" ", ""), map.replaceAll(" ", ""));
143
144 // [base=der][][][base=Mann]
145 String et2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000146 "{@type=korap:group, operation=operation:sequence, inOrder=true, distances=[" +
Joachim Bingelb8a44a12014-04-17 09:35:30 +0000147 "{@type=korap:distance, key=w, min=3, max=3}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000148 "], " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000149 "operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000150 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=match:eq}}," +
151 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000152 "]}";
Joachim Bingelffd65e32014-01-22 14:22:57 +0000153 ppt = new PoliqarpPlusTree("[base=der][][][base=Mann]");
Joachim Bingel87480d02014-01-17 14:07:46 +0000154 map = ppt.getRequestMap().get("query").toString();
155 assertEquals(et2.replaceAll(" ", ""), map.replaceAll(" ", ""));
156
157 // [base=der][][]?[base=Mann]
158 String et3 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000159 "{@type=korap:group, operation=operation:sequence, inOrder=true, distances=[" +
Joachim Bingelb8a44a12014-04-17 09:35:30 +0000160 "{@type=korap:distance, key=w, min=2, max=3}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000161 "], " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000162 "operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000163 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=match:eq}}," +
164 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000165 "]}";
166 ppt = new PoliqarpPlusTree("[base=der][][]?[base=Mann]");
167 map = ppt.getRequestMap().get("query").toString();
168 assertEquals(et3.replaceAll(" ", ""), map.replaceAll(" ", ""));
169
Joachim Bingel87480d02014-01-17 14:07:46 +0000170
171 // startswith(<s>, [][base=Mann]
Joachim Bingelffd65e32014-01-22 14:22:57 +0000172 String et4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000173 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
174 "{@type=korap:span, key=s}," +
175 "{@type=korap:group, operation=operation:sequence, offset-min=1, offset-max=1, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000176 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000177 "]}" +
178 "]}";
Joachim Bingelffd65e32014-01-22 14:22:57 +0000179 ppt = new PoliqarpPlusTree("startswith(<s>, [][base=Mann])");
180 map = ppt.getRequestMap().get("query").toString();
181 assertEquals(et4.replaceAll(" ", ""), map.replaceAll(" ", ""));
182
Joachim Bingel11d5b152014-02-11 21:33:47 +0000183 // [base=der][]{2,5}[base=Mann][]?[][base=Frau] nested distances=
Joachim Bingelffd65e32014-01-22 14:22:57 +0000184 String et5 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000185 "{@type=korap:group, operation=operation:sequence, inOrder=true, distances=[" +
Joachim Bingelb8a44a12014-04-17 09:35:30 +0000186 "{@type=korap:distance, key=w, min=3, max=6}" +
Joachim Bingelffd65e32014-01-22 14:22:57 +0000187 "], " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000188 "operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000189 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000190 "{@type=korap:group, operation=operation:sequence, inOrder=true, distances=[" +
Joachim Bingelb8a44a12014-04-17 09:35:30 +0000191 "{@type=korap:distance, key=w, min=2, max=3}" +
Joachim Bingelffd65e32014-01-22 14:22:57 +0000192 "], " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000193 "operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000194 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}," +
195 "{@type=korap:token, wrap={@type=korap:term, key=Frau, layer=lemma, match=match:eq}}" +
Joachim Bingelffd65e32014-01-22 14:22:57 +0000196 "]}" +
197 "]}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000198 ppt = new PoliqarpPlusTree("[base=der][]{2,5}[base=Mann][]?[][base=Frau]");
Joachim Bingel87480d02014-01-17 14:07:46 +0000199 map = ppt.getRequestMap().get("query").toString();
200 assertEquals(et5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel87480d02014-01-17 14:07:46 +0000201
Joachim Bingelc15720f2014-05-07 14:37:23 +0000202 // [base=der][]*[base=Mann]
203 String et6 =
204 "{@type=korap:group, operation=operation:sequence, inOrder=true, distances=[" +
205 "{@type=korap:distance, key=w, min=1, max=100}" +
206 "], " +
207 "operands=[" +
208 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=match:eq}}," +
209 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}" +
210 "]}";
211 ppt = new PoliqarpPlusTree("[base=der][]*[base=Mann]");
212 map = ppt.getRequestMap().get("query").toString();
213 assertEquals(et6.replaceAll(" ", ""), map.replaceAll(" ", ""));
214
215 // [base=der][]*[base=Mann]
216 String et7 =
217 "{@type=korap:group, operation=operation:sequence, inOrder=true, distances=[" +
218 "{@type=korap:distance, key=w, min=2, max=100}" +
219 "], " +
220 "operands=[" +
221 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=match:eq}}," +
222 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}" +
223 "]}";
224 ppt = new PoliqarpPlusTree("[base=der][]+[base=Mann]");
225 map = ppt.getRequestMap().get("query").toString();
226 assertEquals(et7.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel87480d02014-01-17 14:07:46 +0000227 }
Joachim Bingel53333e62013-12-09 19:25:52 +0000228
229 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000230 public void testCoordinatedFields() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000231 // [base=Mann&(cas=N|cas=A)]
232 String cof1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000233 "{@type=korap:token, wrap=" +
Joachim Bingel2980bda2014-04-04 12:09:46 +0000234 "{@type=korap:termGroup, relation=relation:and, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000235 "{@type=korap:term, key=Mann, layer=lemma, match=match:eq}," +
Joachim Bingel2980bda2014-04-04 12:09:46 +0000236 "{@type=korap:termGroup, relation=relation:or, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000237 "{@type=korap:term, key=N, layer=cas, match=match:eq}," +
238 "{@type=korap:term, key=A, layer=cas, match=match:eq}" +
239 "]}" +
240 "]}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000241 "}";
242 ppt = new PoliqarpPlusTree("[base=Mann&(cas=N|cas=A)]");
243 map = ppt.getRequestMap().get("query").toString();
244 assertEquals(cof1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Nils Diewald7d486c22013-12-13 16:32:18 +0000245
246
247 assertEquals(
248 new PoliqarpPlusTree(" [ base=Mann & ( cas=N | cas=A)] ").getRequestMap().get("query").toString(),
249 new PoliqarpPlusTree("[base=Mann &(cas=N|cas=A)]").getRequestMap().get("query").toString()
250 );
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000251
252 // [base=Mann&cas=N&gen=m]
253 String cof2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000254 "{@type=korap:token, wrap=" +
Joachim Bingel2980bda2014-04-04 12:09:46 +0000255 "{@type=korap:termGroup, relation=relation:and, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000256 "{@type=korap:term, key=Mann, layer=lemma, match=match:eq}," +
257 "{@type=korap:term, key=N, layer=cas, match=match:eq}," +
258 "{@type=korap:term, key=m, layer=gen, match=match:eq}" +
259 "]}" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000260 "}";
261 ppt = new PoliqarpPlusTree("[base=Mann&cas=N&gen=m]");
262 map = ppt.getRequestMap().get("query").toString();
263 assertEquals(cof2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000264 }
265
266 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000267 public void testOccurrence() throws QueryException {
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000268 // [base=foo]*
Joachim Bingel2daf9862014-02-12 10:18:54 +0000269 String occ1 = "{@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 Bingelcd9ed332013-12-09 21:01:35 +0000272 ppt = new PoliqarpPlusTree("[base=foo]*");
273 map = ppt.getRequestMap().get("query").toString();
274 assertEquals(occ1.replaceAll(" ", ""), map.replaceAll(" ", ""));
275
276 // [base=foo]*[base=bar]
277 String occ2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000278 "{@type=korap:group, operation=operation:sequence, operands=[" +
279 "{@type=korap:group, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000280 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000281 "], operation=operation:repetition, min=0, max=100 }," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000282 "{@type=korap:token, wrap={@type=korap:term, key=bar, layer=lemma, match=match:eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000283 "]}";
284 ppt = new PoliqarpPlusTree("[base=foo]*[base=bar]");
285 map = ppt.getRequestMap().get("query").toString();
286 assertEquals(occ2.replaceAll(" ", ""), map.replaceAll(" ", ""));
287
288 // [base=bar][base=foo]*
289 String occ3 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000290 "{@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}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000292 "{@type=korap:group, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000293 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000294 "], operation=operation:repetition, min=0, max=100 }" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000295 "]}";
296 ppt = new PoliqarpPlusTree("[base=bar][base=foo]*");
297 map = ppt.getRequestMap().get("query").toString();
298 assertEquals(occ3.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb4da7022013-12-09 23:17:24 +0000299
300 // ([base=bar][base=foo])*
301 String occ4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000302 "{@type=korap:group, operands=[" +
303 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000304 "{@type=korap:token, wrap={@type=korap:term, key=bar, layer=lemma, match=match:eq}}," +
305 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000306 "]}" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000307 "], operation=operation:repetition, min=0, max=100 }" ;
Joachim Bingelb4da7022013-12-09 23:17:24 +0000308 ppt = new PoliqarpPlusTree("([base=bar][base=foo])*");
309 map = ppt.getRequestMap().get("query").toString();
310 assertEquals(occ4.replaceAll(" ", ""), map.replaceAll(" ", ""));
311
312 // <s>([base=bar][base=foo])*
313 String occ5 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000314 "{@type=korap:group, operation=operation:sequence, operands=[" +
315 "{@type=korap:span, key=s}," +
316 "{@type=korap:group, operands=[" +
317 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000318 "{@type=korap:token, wrap={@type=korap:term, key=bar, layer=lemma, match=match:eq}}," +
319 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000320 "]}" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000321 "], operation=operation:repetition, min=0, max=100 }" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000322 "]}" ;
323 ppt = new PoliqarpPlusTree("<s>([base=bar][base=foo])*");
324 map = ppt.getRequestMap().get("query").toString();
325 assertEquals(occ5.replaceAll(" ", ""), map.replaceAll(" ", ""));
326
327 // <s><np>([base=bar][base=foo])*
Joachim Bingelb4da7022013-12-09 23:17:24 +0000328 String occ6 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000329 "{@type=korap:group, operation=operation:sequence, operands=[" +
330 "{@type=korap:span, key=s}," +
331 "{@type=korap:span, key=np}," +
332 "{@type=korap:group, operands=[" +
333 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000334 "{@type=korap:token, wrap={@type=korap:term, key=bar, layer=lemma, match=match:eq}}," +
335 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000336 "]}" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000337 "], operation=operation:repetition, min=0, max=100 }" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000338 "]}" ;
339 ppt = new PoliqarpPlusTree("<s><np>([base=bar][base=foo])*");
340 map = ppt.getRequestMap().get("query").toString();
341 assertEquals(occ6.replaceAll(" ", ""), map.replaceAll(" ", ""));
342
343 // <s><np>([base=bar][base=foo])*[p=NN]
344 // comment: embedded sequence shouldn't really be here, but does not really hurt, either. (?)
345 // really hard to get this behaviour out of the PQPlus grammar...
346 String occ7 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000347 "{@type=korap:group, operation=operation:sequence, operands=[" +
348 "{@type=korap:span, key=s}," +
349 "{@type=korap:span, key=np}," +
350 "{@type=korap:group, operands=[" +
351 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000352 "{@type=korap:token, wrap={@type=korap:term, key=bar, layer=lemma, match=match:eq}}," +
353 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000354 "]}" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000355 "], operation=operation:repetition, min=0, max=100 }," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000356 "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000357 "]}" ;
358 ppt = new PoliqarpPlusTree("<s><np>([base=bar][base=foo])*[p=NN]");
359 map = ppt.getRequestMap().get("query").toString();
360 assertEquals(occ7.replaceAll(" ", ""), map.replaceAll(" ", ""));
361
362 // ([base=bar][base=foo])*[p=NN]
Joachim Bingelb4da7022013-12-09 23:17:24 +0000363 String occ8 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000364 "{@type=korap:group, operation=operation:sequence, operands=[" +
365 "{@type=korap:group, operands=[" +
366 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000367 "{@type=korap:token, wrap={@type=korap:term, key=bar, layer=lemma, match=match:eq}}," +
368 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000369 "]}" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000370 "], operation=operation:repetition, min=0, max=100 }," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000371 "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000372 "]}" ;
373 ppt = new PoliqarpPlusTree("([base=bar][base=foo])*[p=NN]");
374 map = ppt.getRequestMap().get("query").toString();
375 assertEquals(occ8.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000376
377 // [base=foo]+
Joachim Bingel2daf9862014-02-12 10:18:54 +0000378 String occ9 = "{@type=korap:group, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000379 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000380 "], operation=operation:repetition, min=1, max=100}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000381 ppt = new PoliqarpPlusTree("[base=foo]+");
382 map = ppt.getRequestMap().get("query").toString();
383 assertEquals(occ9.replaceAll(" ", ""), map.replaceAll(" ", ""));
384
385 // [base=foo]?
Joachim Bingel2daf9862014-02-12 10:18:54 +0000386 String occ10 = "{@type=korap:group, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000387 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000388 "], operation=operation:repetition, min=0, max=1}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000389 ppt = new PoliqarpPlusTree("[base=foo]?");
390 map = ppt.getRequestMap().get("query").toString();
391 assertEquals(occ10.replaceAll(" ", ""), map.replaceAll(" ", ""));
392
393 // [base=foo]{2,5}
Joachim Bingel2daf9862014-02-12 10:18:54 +0000394 String occ11 = "{@type=korap:group, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000395 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000396 "], operation=operation:repetition, min=2, max=5}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000397 ppt = new PoliqarpPlusTree("[base=foo]{2,5}");
398 map = ppt.getRequestMap().get("query").toString();
399 assertEquals(occ11.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel2980bda2014-04-04 12:09:46 +0000400
401 // [base=foo]{2}
402 String occ12 = "{@type=korap:group, operands=[" +
403 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
404 "], operation=operation:repetition, min=2, max=2}";
405 ppt = new PoliqarpPlusTree("[base=foo]{2}");
406 map = ppt.getRequestMap().get("query").toString();
407 assertEquals(occ12.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000408 }
409
410 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000411 public void testTokenSequence() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000412 // [base=Mann][orth=Frau]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000413 String seq1 = "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000414 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}, " +
415 "{@type=korap:token, wrap={@type=korap:term, key=Frau, layer=orth, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000416 "]}";
417 assertTrue(equalsQueryContent(seq1, "[base=Mann][orth=Frau]"));
418
419 // [base=Mann][orth=Frau][p=NN]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000420 String seq2 = "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000421 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}, " +
422 "{@type=korap:token, wrap={@type=korap:term, key=Frau, layer=orth, match=match:eq}}, " +
423 "{@type=korap:token, wrap={@type=korap:term, key=NN,layer=p, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000424 "]}";
425 assertTrue(equalsQueryContent(seq2, "[base=Mann][orth=Frau][p=NN]"));
426 }
427
428 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000429 public void testDisjSegments() throws QueryException {
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000430 // ([base=der]|[base=das])[base=Schild]
431 String disj1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000432 "{@type=korap:group, operation=operation:sequence, operands=[" +
433 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000434 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=match:eq}}," +
435 "{@type=korap:token, wrap={@type=korap:term, key=das, layer=lemma, match=match:eq}}" +
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000436 "]}," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000437 "{@type=korap:token, wrap={@type=korap:term, key=Schild, layer=lemma, match=match:eq}}" +
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000438 "]}";
439 ppt = new PoliqarpPlusTree("([base=der]|[base=das])[base=Schild]");
440 map = ppt.getRequestMap().get("query").toString();
441 assertEquals(disj1.replaceAll(" ", ""), map.replaceAll(" ", ""));
442
443 // [base=Schild]([base=der]|[base=das])
444 String disj2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000445 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000446 "{@type=korap:token, wrap={@type=korap:term, key=Schild, layer=lemma, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000447 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000448 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=match:eq}}," +
449 "{@type=korap:token, wrap={@type=korap:term, key=das, layer=lemma, match=match:eq}}" +
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000450 "]}" +
451 "]}";
452 ppt = new PoliqarpPlusTree("[base=Schild]([base=der]|[base=das])");
453 map = ppt.getRequestMap().get("query").toString();
454 assertEquals(disj2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel76b498d2014-06-06 12:06:46 +0000455
456 // "([orth=der][base=katze])|([orth=eine][base=baum])"
457 String disj3 =
458 "{@type=korap:group, operation=operation:or, operands=[" +
459 "{@type=korap:group, operation=operation:sequence, operands=[" +
460 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
461 "{@type=korap:token, wrap={@type=korap:term, key=katze, layer=lemma, match=match:eq}}" +
462 "]}," +
463 "{@type=korap:group, operation=operation:sequence, operands=[" +
464 "{@type=korap:token, wrap={@type=korap:term, key=eine, layer=orth, match=match:eq}}," +
465 "{@type=korap:token, wrap={@type=korap:term, key=baum, layer=lemma, match=match:eq}}" +
466 "]}" +
467 "]}";
468 ppt = new PoliqarpPlusTree("([orth=der][base=katze])|([orth=eine][base=baum])");
469 map = ppt.getRequestMap().get("query").toString();
470 assertEquals(disj3.replaceAll(" ", ""), map.replaceAll(" ", ""));
471
472 // "[orth=der][base=katze]|[orth=eine][base=baum]"
473 String disj4 =
474 "{@type=korap:group, operation=operation:or, operands=[" +
475 "{@type=korap:group, operation=operation:sequence, operands=[" +
476 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
477 "{@type=korap:token, wrap={@type=korap:term, key=katze, layer=lemma, match=match:eq}}" +
478 "]}," +
479 "{@type=korap:group, operation=operation:sequence, operands=[" +
480 "{@type=korap:token, wrap={@type=korap:term, key=eine, layer=orth, match=match:eq}}," +
481 "{@type=korap:token, wrap={@type=korap:term, key=baum, layer=lemma, match=match:eq}}" +
482 "]}" +
483 "]}";
484 ppt = new PoliqarpPlusTree("[orth=der][base=katze]|[orth=eine][base=baum]");
485 map = ppt.getRequestMap().get("query").toString();
486 assertEquals(disj4.replaceAll(" ", ""), map.replaceAll(" ", ""));
487
488 PoliqarpPlusTree ppt1 = new PoliqarpPlusTree("[orth=der][base=katze]|[orth=eine][base=baum]");
489 PoliqarpPlusTree ppt2 = new PoliqarpPlusTree("([orth=der][base=katze])|([orth=eine][base=baum])");
490 assertEquals(ppt1.getRequestMap().toString(), ppt2.getRequestMap().toString());
491
492 // "[orth=der][base=katze]|[orth=der][base=hund]|[orth=der][base=baum]"
493 String disj5 =
494 "{@type=korap:group, operation=operation:or, operands=[" +
495 "{@type=korap:group, operation=operation:sequence, operands=[" +
496 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
497 "{@type=korap:token, wrap={@type=korap:term, key=katze, layer=lemma, match=match:eq}}" +
498 "]}," +
499 "{@type=korap:group, operation=operation:sequence, operands=[" +
500 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
501 "{@type=korap:token, wrap={@type=korap:term, key=hund, layer=lemma, match=match:eq}}" +
502 "]}," +
503 "{@type=korap:group, operation=operation:sequence, operands=[" +
504 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
505 "{@type=korap:token, wrap={@type=korap:term, key=baum, layer=lemma, match=match:eq}}" +
506 "]}" +
507 "]}";
508 ppt = new PoliqarpPlusTree("[orth=der][base=katze]|[orth=der][base=hund]|[orth=der][base=baum]");
509 map = ppt.getRequestMap().get("query").toString();
510 assertEquals(disj5.replaceAll(" ", ""), map.replaceAll(" ", ""));
511
512 // [orth=der]([base=katze]|[base=hund]|[base=baum])
513 String disj6 =
514 "{@type=korap:group, operation=operation:sequence, operands=[" +
515 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
516 "{@type=korap:group, operation=operation:or, operands=[" +
517 "{@type=korap:token, wrap={@type=korap:term, key=katze, layer=lemma, match=match:eq}}," +
518 "{@type=korap:token, wrap={@type=korap:term, key=hund, layer=lemma, match=match:eq}}," +
519 "{@type=korap:token, wrap={@type=korap:term, key=baum, layer=lemma, match=match:eq}}" +
520 "]}" +
521 "]}";
522 ppt = new PoliqarpPlusTree("[orth=der]([base=katze]|[base=hund]|[base=baum])");
523 map = ppt.getRequestMap().get("query").toString();
524 assertEquals(disj6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000525 }
526
527 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000528 public void testTokenElemSequence() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000529 // [base=Mann]<vp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000530 String seq1 = "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000531 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}, " +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000532 "{@type=korap:span, key=vp}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000533 "]}";
534 assertTrue(equalsQueryContent(seq1, "[base=Mann]<vp>"));
535
536 // <vp>[base=Mann]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000537 String seq2 = "{@type=korap:group, operation=operation:sequence, operands=[" +
538 "{@type=korap:span, key=vp}, "+
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000539 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}} " +
Joachim Bingel53333e62013-12-09 19:25:52 +0000540 "]}";
541 assertTrue(equalsQueryContent(seq2, "<vp>[base=Mann]"));
542
543 // <vp>[base=Mann]<pp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000544 String seq3 = "{@type=korap:group, operation=operation:sequence, operands=[" +
545 "{@type=korap:span, key=vp}, "+
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000546 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}, " +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000547 "{@type=korap:span, key=pp} "+
Joachim Bingel53333e62013-12-09 19:25:52 +0000548 "]}";
549 assertTrue(equalsQueryContent(seq3, "<vp>[base=Mann]<pp>"));
550 }
551
552 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000553 public void testElemSequence() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000554 // <np><vp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000555 String seq1 = "{@type=korap:group, operation=operation:sequence, operands=[" +
556 "{@type=korap:span, key=np}," +
557 "{@type=korap:span, key=vp}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000558 "]}";
559 assertTrue(equalsQueryContent(seq1, "<np><vp>"));
560
561 // <np><vp><pp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000562 String seq2 = "{@type=korap:group, operation=operation:sequence, operands=[" +
563 "{@type=korap:span, key=np}," +
564 "{@type=korap:span, key=vp}," +
565 "{@type=korap:span, key=pp}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000566 "]}";
567 assertTrue(equalsQueryContent(seq2, "<np><vp><pp>"));
568 }
569
570 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000571 public void testClasses() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000572 // {[base=Mann]}
Joachim Bingel2daf9862014-02-12 10:18:54 +0000573 String cls1 = "{@type=korap:group, operation=operation:class, class=0, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000574 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000575 "]}";
Joachim Bingel8c640e42014-02-07 16:20:47 +0000576 ppt = new PoliqarpPlusTree("{[base=Mann]}");
577 map = ppt.getRequestMap().get("query").toString();
578 assertEquals(cls1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000579
580 // {[base=Mann][orth=Frau]}
Joachim Bingel2daf9862014-02-12 10:18:54 +0000581 String cls2 = "{@type=korap:group, operation=operation:class, class=0, operands=[" +
582 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000583 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}," +
584 "{@type=korap:token, wrap={@type=korap:term, key=Frau, layer=orth, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000585 "]}" +
586 "]}";
587 assertTrue(equalsQueryContent(cls2, "{[base=Mann][orth=Frau]}"));
588
589 // [p=NN]{[base=Mann][orth=Frau]}
Joachim Bingel2daf9862014-02-12 10:18:54 +0000590 String cls3 = "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000591 "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000592 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
593 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000594 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}," +
595 "{@type=korap:token, wrap={@type=korap:term, key=Frau, layer=orth, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000596 "]}" +
597 "]}" +
598 "]}";
599 assertTrue(equalsQueryContent(cls3, "[p=NN]{[base=Mann][orth=Frau]}"));
600
601 // {[base=Mann][orth=Frau]}[p=NN]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000602 String cls4 = "{@type=korap:group, operation=operation:sequence, operands=[" +
603 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
604 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000605 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}," +
606 "{@type=korap:token, wrap={@type=korap:term, key=Frau, layer=orth, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000607 "]}" +
608 "]}," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000609 "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000610 "]}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000611 ppt = new PoliqarpPlusTree("{[base=Mann][orth=Frau]}[p=NN]");
612 map = ppt.getRequestMap().get("query").toString();
613 assertEquals(cls4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000614
615 // {2:{1:[tt/p=ADJA]}[mate/p=NN]}"
Joachim Bingel2daf9862014-02-12 10:18:54 +0000616 String cls5 = "{@type=korap:group, operation=operation:class, class=2, operands=[" +
617 "{@type=korap:group, operation=operation:sequence, operands=[" +
618 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000619 "{@type=korap:token, wrap={@type=korap:term, key=ADJA, layer=p, foundry=tt, match=match:eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000620 "]}," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000621 "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, foundry=mate, match=match:eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000622 "]}" +
623 "]}";
624 ppt = new PoliqarpPlusTree("{2: {1:[tt/p=ADJA]}[mate/p=NN]}");
625 map = ppt.getRequestMap().get("query").toString();
626 assertEquals(cls5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000627 }
628
629 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000630 public void testPositions() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000631 // contains(<s>,<np>)
Joachim Bingel2daf9862014-02-12 10:18:54 +0000632 String pos1 = "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
633 "{@type=korap:span, key=s}," +
634 "{@type=korap:span, key=np}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000635 "]}";
636 assertTrue(equalsQueryContent(pos1, "contains(<s>,<np>)"));
637
638 // contains(<s>,[base=Mann])
Joachim Bingel2daf9862014-02-12 10:18:54 +0000639 String pos2 = "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
640 "{@type=korap:span, key=s}," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000641 "{@type=korap:token, wrap= {@type=korap:term, key=Mann, layer=lemma, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000642 "]}";
643 assertTrue(equalsQueryContent(pos2, "contains(<s>,[base=Mann])"));
644
645 // contains(<s>,[orth=der][orth=Mann])
Joachim Bingel2daf9862014-02-12 10:18:54 +0000646 String pos3 = "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
647 "{@type=korap:span, key=s}," +
648 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000649 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
650 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000651 "]}" +
652 "]}";
653 ppt = new PoliqarpPlusTree("contains(<s>,[orth=der][orth=Mann])");
654 map = ppt.getRequestMap().get("query").toString();
655 assertEquals(pos3.replaceAll(" ", ""), map.replaceAll(" ", ""));
656
657 // [base=Auto]contains(<s>,[base=Mann])
658 String pos4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000659 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000660 "{@type=korap:token, wrap={@type=korap:term, key=Auto, layer=lemma, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000661 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
662 "{@type=korap:span, key=s}," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000663 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000664 "]}" +
665 "]}";
666 ppt = new PoliqarpPlusTree("[base=Auto]contains(<s>,[base=Mann])");
667 map = ppt.getRequestMap().get("query").toString();
668 assertEquals(pos4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelef7059b2014-04-22 13:44:19 +0000669
670 // contains(<s>,[pos=N]*)
671 String pos5 =
672 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
673 "{@type=korap:span, key=s}," +
674 "{@type=korap:group, " +
675 "operands=[{@type=korap:token, wrap={@type=korap:term, key=N, layer=pos, match=match:eq}}" +
676 "], operation=operation:repetition, min=0, max=100" +
677 "}" +
678 "]}";
679 ppt = new PoliqarpPlusTree("contains(<s>,[pos=N]*)");
680 map = ppt.getRequestMap().get("query").toString();
681 assertEquals(pos5.replaceAll(" ", ""), map.replaceAll(" ", ""));
682
683 // [base=Auto]contains(<s>,[pos=N]*)
684 String pos6 =
685 "{@type=korap:group, operation=operation:sequence, operands=[" +
686 "{@type=korap:token, wrap={@type=korap:term, key=Auto, layer=lemma, match=match:eq}}," +
687 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
688 "{@type=korap:span, key=s}," +
689 "{@type=korap:group, " +
690 "operands=[{@type=korap:token, wrap={@type=korap:term, key=N, layer=pos, match=match:eq}}" +
691 "], operation=operation:repetition, min=0, max=100" +
692 "}" +
693 "]}" +
694 "]}";
695 ppt = new PoliqarpPlusTree("[base=Auto]contains(<s>,[pos=N]*)");
696 map = ppt.getRequestMap().get("query").toString();
697 assertEquals(pos6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000698 }
699
700 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000701 public void testNestedPositions() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000702 // contains(<s>,startswith(<np>,[orth=Der]))
703 String npos1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000704 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
705 "{@type=korap:span, key=s}," +
706 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
707 "{@type=korap:span, key=np}," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000708 "{@type=korap:token, wrap={@type=korap:term, key=Der, layer=orth, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000709 "]}" +
710 "]}";
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000711 ppt = new PoliqarpPlusTree("contains(<s>, startswith(<np>,[orth=Der]))");
Joachim Bingel53333e62013-12-09 19:25:52 +0000712 map = ppt.getRequestMap().get("query").toString();
713 assertEquals(npos1.replaceAll(" ", ""), map.replaceAll(" ", ""));
714 }
715
716 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000717 public void testShrinkSplit() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000718 // shrink([orth=Der]{[orth=Mann]})
719 String shr1 =
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000720 "{@type=korap:reference, classRef=[0], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000721 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000722 "{@type=korap:token, wrap={@type=korap:term, key=Der, layer=orth, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000723 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000724 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000725 "]}" +
726 "]}" +
727 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000728 ppt = new PoliqarpPlusTree("focus([orth=Der]{[orth=Mann]})");
Joachim Bingel53333e62013-12-09 19:25:52 +0000729 map = ppt.getRequestMap().get("query").toString();
730 assertEquals(shr1.replaceAll(" ", ""), map.replaceAll(" ", ""));
731
732 // shrink([orth=Der]{[orth=Mann][orth=geht]})
733 String shr2 =
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000734 "{@type=korap:reference, classRef=[0], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000735 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000736 "{@type=korap:token, wrap={@type=korap:term, key=Der, layer=orth, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000737 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
738 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000739 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}," +
740 "{@type=korap:token, wrap={@type=korap:term, key=geht, layer=orth, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000741 "]}" +
742 "]}" +
743 "]}" +
744 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000745 ppt = new PoliqarpPlusTree("focus([orth=Der]{[orth=Mann][orth=geht]})");
Joachim Bingel53333e62013-12-09 19:25:52 +0000746 map = ppt.getRequestMap().get("query").toString();
747 assertEquals(shr2.replaceAll(" ", ""), map.replaceAll(" ", ""));
748
749 // shrink(1:[orth=Der]{1:[orth=Mann][orth=geht]})
750 String shr3 =
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000751 "{@type=korap:reference, classRef=[1], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000752 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000753 "{@type=korap:token, wrap={@type=korap:term, key=Der, layer=orth, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000754 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
755 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000756 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}," +
757 "{@type=korap:token, wrap={@type=korap:term, key=geht, layer=orth, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000758 "]}" +
759 "]}" +
760 "]}" +
761 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000762 ppt = new PoliqarpPlusTree("focus(1:[orth=Der]{1:[orth=Mann][orth=geht]})");
Joachim Bingel53333e62013-12-09 19:25:52 +0000763 map = ppt.getRequestMap().get("query").toString();
764 assertEquals(shr3.replaceAll(" ", ""), map.replaceAll(" ", ""));
765
766 // shrink(1:startswith(<s>,{1:<np>}))
767 String shr4 =
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000768 "{@type=korap:reference, classRef=[1], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000769 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
770 "{@type=korap:span, key=s}," +
771 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
772 "{@type=korap:span, key=np}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000773 "]}" +
774 "]}" +
775 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000776 ppt = new PoliqarpPlusTree("focus(1:startswith(<s>,{1:<np>}))");
Joachim Bingel53333e62013-12-09 19:25:52 +0000777 map = ppt.getRequestMap().get("query").toString();
778 assertEquals(shr4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000779
780 // shrink(3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))
781 String shr5 =
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000782 "{@type=korap:reference, classRef=[3], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000783 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
784 "{@type=korap:span, key=s}," +
785 "{@type=korap:group, operation=operation:class, class=3, operands=[" +
786 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000787 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000788 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
789 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000790 "{@type=korap:token, wrap={@type=korap:term, key=ADJA, layer=p, foundry=mate, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000791 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000792 "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, foundry=tt, match=match:eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000793 "]}" +
794 "]}" +
795 "]}" +
796 "]}" +
797 "]}" +
798 "]}" +
799 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000800 ppt = new PoliqarpPlusTree("focus(3:startswith(<s>,{3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) ");
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000801 map = ppt.getRequestMap().get("query").toString();
802 assertEquals(shr5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000803
804 // split(3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))
805 String shr6 =
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000806 "{@type=korap:reference, classRef=[3], operation=operation:split, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000807 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
808 "{@type=korap:span, key=s}," +
809 "{@type=korap:group, operation=operation:class, class=3, operands=[" +
810 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000811 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000812 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
813 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000814 "{@type=korap:token, wrap={@type=korap:term, key=ADJA, layer=p, foundry=mate, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000815 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000816 "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, foundry=tt, match=match:eq}}" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000817 "]}" +
818 "]}" +
819 "]}" +
820 "]}" +
821 "]}" +
822 "]}" +
823 "]}";
824 ppt = new PoliqarpPlusTree("split(3:startswith(<s>,{3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) ");
825 map = ppt.getRequestMap().get("query").toString();
826 assertEquals(shr6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel8c640e42014-02-07 16:20:47 +0000827
828 // split(2|3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))
829 String shr7 =
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000830 "{@type=korap:reference, classRef=[2, 3], operation=operation:split, classRefOp=classRefOp:intersection, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000831 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
832 "{@type=korap:span, key=s}," +
833 "{@type=korap:group, operation=operation:class, class=3, operands=[" +
834 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000835 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000836 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
837 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000838 "{@type=korap:token, wrap={@type=korap:term, key=ADJA, layer=p, foundry=mate, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000839 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000840 "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, foundry=tt, match=match:eq}}" +
Joachim Bingel8c640e42014-02-07 16:20:47 +0000841 "]}" +
842 "]}" +
843 "]}" +
844 "]}" +
845 "]}" +
846 "]}" +
847 "]}";
848 ppt = new PoliqarpPlusTree("split(2|3:startswith(<s>,{3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) ");
849 map = ppt.getRequestMap().get("query").toString();
850 assertEquals(shr7.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel5146ebe2014-06-12 08:49:21 +0000851
852
853 String shr8 =
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000854 "{@type=korap:reference, classRef=[1], operands=[" +
Joachim Bingeladd0fb12014-06-24 08:54:14 +0000855 "{@type=korap:group, operation=operation:sequence, operands=[" +
856 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
857 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=match:eq}}" +
858 "]}," +
859 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
860 "{@type=korap:token, wrap={@type=korap:term, key=ADJA, layer=pos, match=match:eq}}" +
Joachim Bingel5146ebe2014-06-12 08:49:21 +0000861 "]}" +
Joachim Bingeladd0fb12014-06-24 08:54:14 +0000862 "]}" +
863 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000864 ppt = new PoliqarpPlusTree("focus(1:{[base=der]}{1:[pos=ADJA]})");
Joachim Bingeladd0fb12014-06-24 08:54:14 +0000865 map = ppt.getRequestMap().get("query").toString();
866 assertEquals(shr8.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel5146ebe2014-06-12 08:49:21 +0000867
Joachim Bingel53333e62013-12-09 19:25:52 +0000868 }
869
Joachim Bingel03882702013-12-31 19:53:05 +0000870
Joachim Bingel53333e62013-12-09 19:25:52 +0000871 @Test
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000872 public void testFoundries() throws QueryException {
873 // [tt/base=Mann]
Joachim Bingelac13a472014-02-14 21:18:52 +0000874 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 +0000875 ppt = new PoliqarpPlusTree("[tt/base=Mann]");
876 map = ppt.getRequestMap().get("query").toString();
877 assertEquals(layer1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000878
879 }
Joachim Bingel16da4e12013-12-17 09:48:12 +0000880
881 @Test
Joachim Bingel8c640e42014-02-07 16:20:47 +0000882 public void testAlign() throws QueryException {
Joachim Bingel16da4e12013-12-17 09:48:12 +0000883 // [orth=der]^[orth=Mann]
884 String align1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000885 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000886 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000887 "{@type=korap:group, alignment=left, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000888 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
Joachim Bingel03882702013-12-31 19:53:05 +0000889 "]}" +
Joachim Bingel16da4e12013-12-17 09:48:12 +0000890 "]}";
891 ppt = new PoliqarpPlusTree("[orth=der]^[orth=Mann]");
892 map = ppt.getRequestMap().get("query").toString();
893 assertEquals(align1.replaceAll(" ", ""), map.replaceAll(" ", ""));
894
Joachim Bingel84e33df2014-01-31 14:02:46 +0000895 // [orth=der]^[orth=große][orth=Mann]
896 String query = "[orth=der]^[orth=große][orth=Mann]";
897 String align1b =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000898 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000899 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000900 "{@type=korap:group, alignment=left, operands=[" +
901 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000902 "{@type=korap:token, wrap={@type=korap:term, key=große, layer=orth, match=match:eq}}," +
903 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +0000904 "]}" +
905 "]}" +
906 "]}";
907 ppt = new PoliqarpPlusTree(query);
908 map = ppt.getRequestMap().get("query").toString();
909 assertEquals(align1b.replaceAll(" ", ""), map.replaceAll(" ", ""));
910
Joachim Bingel16da4e12013-12-17 09:48:12 +0000911 // "([base=a]^[base=b])|[base=c]",
912 String align2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000913 "{@type=korap:group, operation=operation:or, operands=[" +
914 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000915 "{@type=korap:token, wrap={@type=korap:term, key=a, layer=lemma, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000916 "{@type=korap:group, alignment=left, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000917 "{@type=korap:token, wrap={@type=korap:term, key=b, layer=lemma, match=match:eq}}" +
Joachim Bingel03882702013-12-31 19:53:05 +0000918 "]}" +
Joachim Bingel16da4e12013-12-17 09:48:12 +0000919 "]}," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000920 "{@type=korap:token, wrap={@type=korap:term, key=c, layer=lemma, match=match:eq}}" +
Joachim Bingel16da4e12013-12-17 09:48:12 +0000921 "]}";
922 ppt = new PoliqarpPlusTree("([base=a]^[base=b])|[base=c]");
923 map = ppt.getRequestMap().get("query").toString();
924 assertEquals(align2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingela67e6a32014-01-02 18:35:24 +0000925
926 // "([base=a]^[base=b][base=c])|[base=d]",
927 String align3 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000928 "{@type=korap:group, operation=operation:or, operands=[" +
929 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000930 "{@type=korap:token, wrap={@type=korap:term, key=a, layer=lemma, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000931 "{@type=korap:group, alignment=left, operands=[" +
932 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000933 "{@type=korap:token, wrap={@type=korap:term, key=b, layer=lemma, match=match:eq}}," +
934 "{@type=korap:token, wrap={@type=korap:term, key=c, layer=lemma, match=match:eq}}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +0000935 "]}" +
936 "]}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000937 "]}," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000938 "{@type=korap:token, wrap={@type=korap:term, key=d, layer=lemma, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000939 "]}";
940 ppt = new PoliqarpPlusTree("([base=a]^[base=b][base=c])|[base=d]");
941 map = ppt.getRequestMap().get("query").toString();
942 assertEquals(align3.replaceAll(" ", ""), map.replaceAll(" ", ""));
943
944 // "([base=a]^[base=b]^[base=c])|[base=d]",
945 String align4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000946 "{@type=korap:group, operation=operation:or, operands=[" +
947 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000948 "{@type=korap:token, wrap={@type=korap:term, key=a, layer=lemma, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000949 "{@type=korap:group, alignment=left, operands=[" +
950 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000951 "{@type=korap:token, wrap={@type=korap:term, key=b, layer=lemma, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000952 "{@type=korap:group, alignment=left, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000953 "{@type=korap:token, wrap={@type=korap:term, key=c, layer=lemma, match=match:eq}}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +0000954 "]}" +
955 "]}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000956 "]}" +
957 "]}," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000958 "{@type=korap:token, wrap={@type=korap:term, key=d, layer=lemma, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000959 "]}";
960 ppt = new PoliqarpPlusTree("([base=a]^[base=b]^[base=c])|[base=d]");
961 map = ppt.getRequestMap().get("query").toString();
962 assertEquals(align4.replaceAll(" ", ""), map.replaceAll(" ", ""));
963
964
Joachim Bingel16da4e12013-12-17 09:48:12 +0000965 }
966
967 @Test
Joachim Bingel8c640e42014-02-07 16:20:47 +0000968 public void testSimpleQueries() throws QueryException {
Joachim Bingela67e6a32014-01-02 18:35:24 +0000969 // Baum
970 String simple1 =
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000971 "{@type=korap:token, wrap={@type=korap:term, key=Baum, layer=orth, match=match:eq}}";
Joachim Bingela67e6a32014-01-02 18:35:24 +0000972 ppt = new PoliqarpPlusTree("Baum");
973 map = ppt.getRequestMap().get("query").toString();
974 assertEquals(simple1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel16da4e12013-12-17 09:48:12 +0000975
Joachim Bingela67e6a32014-01-02 18:35:24 +0000976 // Der Baum
977 String simple2 =
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=Baum, layer=orth, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000981 "]}";
982 ppt = new PoliqarpPlusTree("Der Baum");
983 map = ppt.getRequestMap().get("query").toString();
984 assertEquals(simple2.replaceAll(" ", ""), map.replaceAll(" ", ""));
985
986 // Der große Baum
987 String simple3 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000988 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000989 "{@type=korap:token, wrap={@type=korap:term, key=Der, layer=orth, match=match:eq}}, " +
990 "{@type=korap:token, wrap={@type=korap:term, key=große, layer=orth, match=match:eq}}, " +
991 "{@type=korap:token, wrap={@type=korap:term, key=Baum, layer=orth, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000992 "]}";
993 ppt = new PoliqarpPlusTree("Der große Baum");
994 map = ppt.getRequestMap().get("query").toString();
995 assertEquals(simple3.replaceAll(" ", ""), map.replaceAll(" ", ""));
996
997 // Baum | Stein
998 String simple4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000999 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +00001000 "{@type=korap:token, wrap={@type=korap:term, key=Baum, layer=orth, match=match:eq}}, " +
1001 "{@type=korap:token, wrap={@type=korap:term, key=Stein, layer=orth, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +00001002 "]}";
1003 ppt = new PoliqarpPlusTree("Baum | Stein");
1004 map = ppt.getRequestMap().get("query").toString();
1005 assertEquals(simple4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel84e33df2014-01-31 14:02:46 +00001006
1007 // Baum | Stein Haus
1008 String query = "(Baum | Stein) Haus";
1009 String simple5 =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001010 "{@type=korap:group, operation=operation:sequence, operands=[" +
1011 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +00001012 "{@type=korap:token, wrap={@type=korap:term, key=Baum, layer=orth, match=match:eq}}, " +
1013 "{@type=korap:token, wrap={@type=korap:term, key=Stein, layer=orth, match=match:eq}}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +00001014 "]}," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +00001015 "{@type=korap:token, wrap={@type=korap:term, key=Haus, layer=orth, match=match:eq}} " +
Joachim Bingel84e33df2014-01-31 14:02:46 +00001016 "]}";
1017 ppt = new PoliqarpPlusTree(query);
1018 map = ppt.getRequestMap().get("query").toString();
1019 assertEquals(simple5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel16da4e12013-12-17 09:48:12 +00001020 }
Joachim Bingel53333e62013-12-09 19:25:52 +00001021}
1022