blob: 72edd37931459000faff00f299d5a1dbe024d6f1 [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 Bingel0900a892014-06-30 16:26:21 +000030 String query;
Joachim Bingel53333e62013-12-09 19:25:52 +000031 // [base=Mann]
Joachim Bingel0900a892014-06-30 16:26:21 +000032 String token1 = "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}";
Joachim Bingel53333e62013-12-09 19:25:52 +000033 assertTrue(equalsQueryContent(token1, "[base=Mann]"));
34
35 // [orth!=Frau]
Joachim Bingel0900a892014-06-30 16:26:21 +000036 String token2 = "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:ne}}";
Joachim Bingel53333e62013-12-09 19:25:52 +000037 assertTrue(equalsQueryContent(token2, "[orth!=Frau]"));
38
39 // [!p=NN]
Joachim Bingel0900a892014-06-30 16:26:21 +000040 query = "[!p=NN]";
41 String token3 = "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:ne}}";
42 ppt = new PoliqarpPlusTree(query);
43 map = ppt.getRequestMap().get("query").toString();
44 assertEquals(token3.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +000045
46 // [!p!=NN]
Joachim Bingel0900a892014-06-30 16:26:21 +000047 query = "[!p!=NN]";
48 String token4 = "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}";
49 ppt = new PoliqarpPlusTree(query);
50 map = ppt.getRequestMap().get("query").toString();
51 assertEquals(token4.replaceAll(" ", ""), map.replaceAll(" ", ""));
52
Joachim Bingeld1a3e712014-07-16 08:02:05 +000053 query = "[base=schland/x]";
54 String token5 = "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=.*?\\Qschland\\E.*?, match=match:eq, type=type:regex}}";
55 ppt = new PoliqarpPlusTree(query);
56 map = ppt.getRequestMap().get("query").toString();
57 assertEquals(token5.replaceAll(" ", ""), map.replaceAll(" ", ""));
58 }
59
60 @Test
61 public void testValue() throws QueryException {
62 String query;
63
64 query = "[mate/m=temp:pres]";
65 String value1 = "{@type=korap:token, wrap={@type=korap:term, foundry=mate, layer=m, key=temp, value=pres, match=match:eq}}";
66 ppt = new PoliqarpPlusTree(query);
67 map = ppt.getRequestMap().get("query").toString();
68 assertEquals(value1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +000069 }
70
71 @Test
Joachim Bingel41e112e2014-02-12 10:46:18 +000072 public void testRegex() throws QueryException {
73 String query = "[orth=\"M(a|ä)nn(er)?\"]";
Joachim Bingel0900a892014-06-30 16:26:21 +000074 String re1 = "{@type=korap:token, wrap={@type=korap:term, layer=orth, type=type:regex, key=M(a|ä)nn(er)?, match=match:eq}}";
Joachim Bingel41e112e2014-02-12 10:46:18 +000075 ppt = new PoliqarpPlusTree(query);
76 map = ppt.getRequestMap().get("query").toString();
77 assertEquals(re1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel0900a892014-06-30 16:26:21 +000078
79 query = "[orth=\"M(a|ä)nn(er)?\"/x]";
80 String re2 = "{@type=korap:token, wrap={@type=korap:term, layer=orth, type=type:regex, key=.*?M(a|ä)nn(er)?.*?, match=match:eq}}";
81 ppt = new PoliqarpPlusTree(query);
82 map = ppt.getRequestMap().get("query").toString();
83 assertEquals(re2.replaceAll(" ", ""), map.replaceAll(" ", ""));
84
85 query = "\"M(a|ä)nn(er)?\"/x";
86 String re3 = "{@type=korap:token, wrap={@type=korap:term, type=type:regex, layer=orth, key=.*?M(a|ä)nn(er)?.*?, match=match:eq}}";
87 ppt = new PoliqarpPlusTree(query);
88 map = ppt.getRequestMap().get("query").toString();
89 assertEquals(re3.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeld1a3e712014-07-16 08:02:05 +000090
91 query = "schland/x";
92 String re4 = "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=.*?\\Qschland\\E.*?, match=match:eq, type=type:regex}}";
93 ppt = new PoliqarpPlusTree(query);
94 map = ppt.getRequestMap().get("query").toString();
95 assertEquals(re4.replaceAll(" ", ""), map.replaceAll(" ", ""));
96
97 query = "\".*?Mann.*?\"";
98 String re5 = "{@type=korap:token, wrap={@type=korap:term, type=type:regex, layer=orth, key=.*?Mann.*?, match=match:eq}}";
99 ppt = new PoliqarpPlusTree(query);
100 map = ppt.getRequestMap().get("query").toString();
101 assertEquals(re5.replaceAll(" ", ""), map.replaceAll(" ", ""));
102
Joachim Bingel41e112e2014-02-12 10:46:18 +0000103 }
104
105 @Test
Joachim Bingel0207d5e2014-02-12 14:18:41 +0000106 public void testCaseSensitivityFlag() throws QueryException {
107 String query="[orth=deutscher/i]";
108 String cs1 =
Joachim Bingel0900a892014-06-30 16:26:21 +0000109 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=deutscher, match=match:eq, caseInsensitive=true}}";
Joachim Bingel0207d5e2014-02-12 14:18:41 +0000110 ppt = new PoliqarpPlusTree(query);
111 map = ppt.getRequestMap().get("query").toString();
112 assertEquals(cs1.replaceAll(" ", ""), map.replaceAll(" ", ""));
113
114 query="[orth=deutscher/i][orth=Bundestag]";
115 String cs2 =
116 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000117 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=deutscher, match=match:eq, caseInsensitive=true}}," +
118 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Bundestag, match=match:eq}}" +
Joachim Bingel0207d5e2014-02-12 14:18:41 +0000119 "]}";
120 ppt = new PoliqarpPlusTree(query);
121 map = ppt.getRequestMap().get("query").toString();
122 assertEquals(cs2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeladd0fb12014-06-24 08:54:14 +0000123
124 query="deutscher/i";
125 String cs3 =
Joachim Bingel0900a892014-06-30 16:26:21 +0000126 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=deutscher, match=match:eq, caseInsensitive=true}}";
Joachim Bingeladd0fb12014-06-24 08:54:14 +0000127 ppt = new PoliqarpPlusTree(query);
128 map = ppt.getRequestMap().get("query").toString();
129 assertEquals(cs3.replaceAll(" ", ""), map.replaceAll(" ", ""));
130
131 query="deutscher/i Bundestag";
132 String cs4 =
133 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000134 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=deutscher, match=match:eq, caseInsensitive=true}}," +
135 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Bundestag, match=match:eq}}" +
Joachim Bingeladd0fb12014-06-24 08:54:14 +0000136 "]}";
137 ppt = new PoliqarpPlusTree(query);
138 map = ppt.getRequestMap().get("query").toString();
139 assertEquals(cs4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000140
141 query="deutscher Bundestag/i";
142 String cs5 =
143 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000144 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=deutscher, match=match:eq}}," +
145 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Bundestag, match=match:eq, caseInsensitive=true}}" +
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000146 "]}";
147 ppt = new PoliqarpPlusTree(query);
148 map = ppt.getRequestMap().get("query").toString();
149 assertEquals(cs5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel0207d5e2014-02-12 14:18:41 +0000150 }
151
152 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000153 public void testElements() throws QueryException {
Joachim Bingelfc1fb352014-02-26 14:40:27 +0000154 String query;
Joachim Bingel53333e62013-12-09 19:25:52 +0000155 // <s>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000156 String elem1 = "{@type=korap:span, key=s}";
Joachim Bingel53333e62013-12-09 19:25:52 +0000157 assertTrue(equalsQueryContent(elem1, "<s>"));
158
159 // <vp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000160 String elem2 = "{@type=korap:span, key=vp}";
Joachim Bingel53333e62013-12-09 19:25:52 +0000161 assertTrue(equalsQueryContent(elem2, "<vp>"));
Joachim Bingelfc1fb352014-02-26 14:40:27 +0000162
163 // <cnx/c=vp>
164 query = "<c=vp>";
165 String span3 = "{@type=korap:span, layer=c, key=vp}";
166 ppt = new PoliqarpPlusTree(query);
167 map = ppt.getRequestMap().get("query").toString();
168 assertEquals(span3.replaceAll(" ", ""), map.replaceAll(" ", ""));
169
170 // <cnx/c=vp>
171 query = "<cnx/c=vp>";
172 String span4 = "{@type=korap:span, foundry=cnx, layer=c, key=vp}";
173 ppt = new PoliqarpPlusTree(query);
174 map = ppt.getRequestMap().get("query").toString();
175 assertEquals(span4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000176 }
Joachim Bingel87480d02014-01-17 14:07:46 +0000177
178 @Test
179 public void testEmptyTokens() throws QueryException {
180 // [base=der][][base=Mann]
181 String et1 =
Joachim Bingel0900a892014-06-30 16:26:21 +0000182 "{@type=korap:group, operation=operation:sequence, " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000183 "operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000184 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
185 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
186 "], inOrder=true, distances=[" +
187 "{@type=korap:distance, key=w, min=2, max=2}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000188 "]}";
189 ppt = new PoliqarpPlusTree("[base=der][][base=Mann]");
190 map = ppt.getRequestMap().get("query").toString();
191 assertEquals(et1.replaceAll(" ", ""), map.replaceAll(" ", ""));
192
193 // [base=der][][][base=Mann]
194 String et2 =
Joachim Bingel0900a892014-06-30 16:26:21 +0000195 "{@type=korap:group, operation=operation:sequence, " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000196 "operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000197 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
198 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
199 "], inOrder=true, distances=[" +
200 "{@type=korap:distance, key=w, min=3, max=3}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000201 "]}";
Joachim Bingelffd65e32014-01-22 14:22:57 +0000202 ppt = new PoliqarpPlusTree("[base=der][][][base=Mann]");
Joachim Bingel87480d02014-01-17 14:07:46 +0000203 map = ppt.getRequestMap().get("query").toString();
204 assertEquals(et2.replaceAll(" ", ""), map.replaceAll(" ", ""));
205
206 // [base=der][][]?[base=Mann]
207 String et3 =
Joachim Bingel0900a892014-06-30 16:26:21 +0000208 "{@type=korap:group, operation=operation:sequence, " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000209 "operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000210 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
211 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
212 "], inOrder=true, distances=[" +
213 "{@type=korap:distance, key=w, min=2, max=3}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000214 "]}";
215 ppt = new PoliqarpPlusTree("[base=der][][]?[base=Mann]");
216 map = ppt.getRequestMap().get("query").toString();
217 assertEquals(et3.replaceAll(" ", ""), map.replaceAll(" ", ""));
218
Joachim Bingel87480d02014-01-17 14:07:46 +0000219
220 // startswith(<s>, [][base=Mann]
Joachim Bingelffd65e32014-01-22 14:22:57 +0000221 String et4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000222 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
223 "{@type=korap:span, key=s}," +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000224 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000225 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
Joachim Bingelbea1ec62014-07-11 15:00:14 +0000226 "], leftOffset={@type=korap:boundary, min=1, max=1}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000227 "]}";
Joachim Bingelffd65e32014-01-22 14:22:57 +0000228 ppt = new PoliqarpPlusTree("startswith(<s>, [][base=Mann])");
229 map = ppt.getRequestMap().get("query").toString();
230 assertEquals(et4.replaceAll(" ", ""), map.replaceAll(" ", ""));
231
Joachim Bingel11d5b152014-02-11 21:33:47 +0000232 // [base=der][]{2,5}[base=Mann][]?[][base=Frau] nested distances=
Joachim Bingelffd65e32014-01-22 14:22:57 +0000233 String et5 =
Joachim Bingel0900a892014-06-30 16:26:21 +0000234 "{@type=korap:group, operation=operation:sequence," +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000235 "operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000236 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
237 "{@type=korap:group, operation=operation:sequence, " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000238 "operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000239 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}," +
240 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Frau, match=match:eq}}" +
241 "], inOrder=true, distances=[" +
242 "{@type=korap:distance, key=w, min=2, max=3}" +
Joachim Bingelffd65e32014-01-22 14:22:57 +0000243 "]}" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000244 "], inOrder=true, distances=[" +
245 "{@type=korap:distance, key=w, min=3, max=6}" +
Joachim Bingelffd65e32014-01-22 14:22:57 +0000246 "]}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000247 ppt = new PoliqarpPlusTree("[base=der][]{2,5}[base=Mann][]?[][base=Frau]");
Joachim Bingel87480d02014-01-17 14:07:46 +0000248 map = ppt.getRequestMap().get("query").toString();
249 assertEquals(et5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel87480d02014-01-17 14:07:46 +0000250
Joachim Bingelc15720f2014-05-07 14:37:23 +0000251 // [base=der][]*[base=Mann]
252 String et6 =
Joachim Bingel0900a892014-06-30 16:26:21 +0000253 "{@type=korap:group, operation=operation:sequence, " +
Joachim Bingelc15720f2014-05-07 14:37:23 +0000254 "operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000255 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
256 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
257 "], inOrder=true, distances=[" +
258 "{@type=korap:distance, key=w, min=1, max=100}" +
Joachim Bingelc15720f2014-05-07 14:37:23 +0000259 "]}";
260 ppt = new PoliqarpPlusTree("[base=der][]*[base=Mann]");
261 map = ppt.getRequestMap().get("query").toString();
262 assertEquals(et6.replaceAll(" ", ""), map.replaceAll(" ", ""));
263
Joachim Bingel0900a892014-06-30 16:26:21 +0000264 // [base=der][]+[base=Mann]
Joachim Bingelc15720f2014-05-07 14:37:23 +0000265 String et7 =
Joachim Bingel0900a892014-06-30 16:26:21 +0000266 "{@type=korap:group, operation=operation:sequence, " +
Joachim Bingelc15720f2014-05-07 14:37:23 +0000267 "operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000268 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
269 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
270 "], inOrder=true, distances=[" +
271 "{@type=korap:distance, key=w, min=2, max=100}" +
Joachim Bingelc15720f2014-05-07 14:37:23 +0000272 "]}";
273 ppt = new PoliqarpPlusTree("[base=der][]+[base=Mann]");
274 map = ppt.getRequestMap().get("query").toString();
275 assertEquals(et7.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel87480d02014-01-17 14:07:46 +0000276 }
Joachim Bingel53333e62013-12-09 19:25:52 +0000277
278 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000279 public void testCoordinatedFields() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000280 // [base=Mann&(cas=N|cas=A)]
281 String cof1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000282 "{@type=korap:token, wrap=" +
Joachim Bingel2980bda2014-04-04 12:09:46 +0000283 "{@type=korap:termGroup, relation=relation:and, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000284 "{@type=korap:term, layer=lemma, key=Mann, match=match:eq}," +
Joachim Bingel2980bda2014-04-04 12:09:46 +0000285 "{@type=korap:termGroup, relation=relation:or, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000286 "{@type=korap:term, layer=cas, key=N, match=match:eq}," +
287 "{@type=korap:term, layer=cas, key=A, match=match:eq}" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000288 "]}" +
289 "]}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000290 "}";
291 ppt = new PoliqarpPlusTree("[base=Mann&(cas=N|cas=A)]");
292 map = ppt.getRequestMap().get("query").toString();
293 assertEquals(cof1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Nils Diewald7d486c22013-12-13 16:32:18 +0000294
295
296 assertEquals(
297 new PoliqarpPlusTree(" [ base=Mann & ( cas=N | cas=A)] ").getRequestMap().get("query").toString(),
298 new PoliqarpPlusTree("[base=Mann &(cas=N|cas=A)]").getRequestMap().get("query").toString()
299 );
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000300
301 // [base=Mann&cas=N&gen=m]
302 String cof2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000303 "{@type=korap:token, wrap=" +
Joachim Bingel2980bda2014-04-04 12:09:46 +0000304 "{@type=korap:termGroup, relation=relation:and, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000305 "{@type=korap:term, layer=lemma, key=Mann, match=match:eq}," +
306 "{@type=korap:termGroup, relation=relation:and, operands=[" +
307 "{@type=korap:term, layer=cas, key=N, match=match:eq}," +
308 "{@type=korap:term, layer=gen, key=m, match=match:eq}" +
309 "]}" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000310 "]}" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000311 "}";
312 ppt = new PoliqarpPlusTree("[base=Mann&cas=N&gen=m]");
313 map = ppt.getRequestMap().get("query").toString();
314 assertEquals(cof2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000315 }
316
317 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000318 public void testOccurrence() throws QueryException {
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000319 // [base=foo]*
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000320 String occ1 = "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000321 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000322 "], min=0, max=100}";
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000323 ppt = new PoliqarpPlusTree("[base=foo]*");
324 map = ppt.getRequestMap().get("query").toString();
325 assertEquals(occ1.replaceAll(" ", ""), map.replaceAll(" ", ""));
326
327 // [base=foo]*[base=bar]
328 String occ2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000329 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000330 "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000331 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000332 "], min=0, max=100 }," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000333 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000334 "]}";
335 ppt = new PoliqarpPlusTree("[base=foo]*[base=bar]");
336 map = ppt.getRequestMap().get("query").toString();
337 assertEquals(occ2.replaceAll(" ", ""), map.replaceAll(" ", ""));
338
339 // [base=bar][base=foo]*
340 String occ3 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000341 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000342 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000343 "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000344 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000345 "], min=0, max=100 }" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000346 "]}";
347 ppt = new PoliqarpPlusTree("[base=bar][base=foo]*");
348 map = ppt.getRequestMap().get("query").toString();
349 assertEquals(occ3.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb4da7022013-12-09 23:17:24 +0000350
351 // ([base=bar][base=foo])*
352 String occ4 =
Joachim Bingel0900a892014-06-30 16:26:21 +0000353 "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000354 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000355 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," +
356 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000357 "]}" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000358 "], min=0, max=100}" ;
Joachim Bingelb4da7022013-12-09 23:17:24 +0000359 ppt = new PoliqarpPlusTree("([base=bar][base=foo])*");
360 map = ppt.getRequestMap().get("query").toString();
361 assertEquals(occ4.replaceAll(" ", ""), map.replaceAll(" ", ""));
362
363 // <s>([base=bar][base=foo])*
364 String occ5 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000365 "{@type=korap:group, operation=operation:sequence, operands=[" +
366 "{@type=korap:span, key=s}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000367 "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000368 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000369 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," +
370 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000371 "]}" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000372 "], min=0, max=100 }" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000373 "]}" ;
374 ppt = new PoliqarpPlusTree("<s>([base=bar][base=foo])*");
375 map = ppt.getRequestMap().get("query").toString();
376 assertEquals(occ5.replaceAll(" ", ""), map.replaceAll(" ", ""));
377
378 // <s><np>([base=bar][base=foo])*
Joachim Bingelb4da7022013-12-09 23:17:24 +0000379 String occ6 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000380 "{@type=korap:group, operation=operation:sequence, operands=[" +
381 "{@type=korap:span, key=s}," +
382 "{@type=korap:span, key=np}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000383 "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000384 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000385 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," +
386 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000387 "]}" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000388 "], min=0, max=100 }" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000389 "]}" ;
390 ppt = new PoliqarpPlusTree("<s><np>([base=bar][base=foo])*");
391 map = ppt.getRequestMap().get("query").toString();
392 assertEquals(occ6.replaceAll(" ", ""), map.replaceAll(" ", ""));
393
394 // <s><np>([base=bar][base=foo])*[p=NN]
395 // comment: embedded sequence shouldn't really be here, but does not really hurt, either. (?)
396 // really hard to get this behaviour out of the PQPlus grammar...
397 String occ7 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000398 "{@type=korap:group, operation=operation:sequence, operands=[" +
399 "{@type=korap:span, key=s}," +
400 "{@type=korap:span, key=np}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000401 "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000402 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000403 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," +
404 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000405 "]}" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000406 "], min=0, max=100 }," +
407 "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000408 "]}" ;
409 ppt = new PoliqarpPlusTree("<s><np>([base=bar][base=foo])*[p=NN]");
410 map = ppt.getRequestMap().get("query").toString();
411 assertEquals(occ7.replaceAll(" ", ""), map.replaceAll(" ", ""));
412
413 // ([base=bar][base=foo])*[p=NN]
Joachim Bingelb4da7022013-12-09 23:17:24 +0000414 String occ8 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000415 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000416 "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000417 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000418 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," +
419 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000420 "]}" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000421 "], min=0, max=100 }," +
422 "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000423 "]}" ;
424 ppt = new PoliqarpPlusTree("([base=bar][base=foo])*[p=NN]");
425 map = ppt.getRequestMap().get("query").toString();
426 assertEquals(occ8.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000427
428 // [base=foo]+
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000429 String occ9 = "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000430 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000431 "], min=1, max=100}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000432 ppt = new PoliqarpPlusTree("[base=foo]+");
433 map = ppt.getRequestMap().get("query").toString();
434 assertEquals(occ9.replaceAll(" ", ""), map.replaceAll(" ", ""));
435
436 // [base=foo]?
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000437 String occ10 = "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000438 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000439 "], min=0, max=1}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000440 ppt = new PoliqarpPlusTree("[base=foo]?");
441 map = ppt.getRequestMap().get("query").toString();
442 assertEquals(occ10.replaceAll(" ", ""), map.replaceAll(" ", ""));
443
444 // [base=foo]{2,5}
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000445 String occ11 = "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000446 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000447 "], min=2, max=5}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000448 ppt = new PoliqarpPlusTree("[base=foo]{2,5}");
449 map = ppt.getRequestMap().get("query").toString();
450 assertEquals(occ11.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel2980bda2014-04-04 12:09:46 +0000451
452 // [base=foo]{2}
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000453 String occ12 = "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000454 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000455 "], min=2, max=2}";
Joachim Bingel2980bda2014-04-04 12:09:46 +0000456 ppt = new PoliqarpPlusTree("[base=foo]{2}");
457 map = ppt.getRequestMap().get("query").toString();
458 assertEquals(occ12.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb2aa1c72014-07-01 12:48:46 +0000459
460 // [base=foo]{2}
461 String occ13 = "{@type=korap:group, operation=operation:repetition, operands=[" +
462 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
463 "], min=2, max=100}";
464 ppt = new PoliqarpPlusTree("[base=foo]{2,}");
465 map = ppt.getRequestMap().get("query").toString();
466 assertEquals(occ13.replaceAll(" ", ""), map.replaceAll(" ", ""));
467
468 // [base=foo]{2}
469 String occ14 = "{@type=korap:group, operation=operation:repetition, operands=[" +
470 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
471 "], min=0, max=2}";
472 ppt = new PoliqarpPlusTree("[base=foo]{,2}");
473 map = ppt.getRequestMap().get("query").toString();
474 assertEquals(occ14.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000475 }
476
477 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000478 public void testTokenSequence() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000479 // [base=Mann][orth=Frau]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000480 String seq1 = "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000481 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}, " +
482 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000483 "]}";
484 assertTrue(equalsQueryContent(seq1, "[base=Mann][orth=Frau]"));
485
486 // [base=Mann][orth=Frau][p=NN]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000487 String seq2 = "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000488 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}, " +
489 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}, " +
490 "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000491 "]}";
492 assertTrue(equalsQueryContent(seq2, "[base=Mann][orth=Frau][p=NN]"));
493 }
494
495 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000496 public void testDisjSegments() throws QueryException {
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000497 // ([base=der]|[base=das])[base=Schild]
498 String disj1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000499 "{@type=korap:group, operation=operation:sequence, operands=[" +
500 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000501 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
502 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=das, match=match:eq}}" +
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000503 "]}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000504 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Schild, match=match:eq}}" +
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000505 "]}";
506 ppt = new PoliqarpPlusTree("([base=der]|[base=das])[base=Schild]");
507 map = ppt.getRequestMap().get("query").toString();
508 assertEquals(disj1.replaceAll(" ", ""), map.replaceAll(" ", ""));
509
510 // [base=Schild]([base=der]|[base=das])
511 String disj2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000512 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000513 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Schild, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000514 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000515 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
516 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=das, match=match:eq}}" +
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000517 "]}" +
518 "]}";
519 ppt = new PoliqarpPlusTree("[base=Schild]([base=der]|[base=das])");
520 map = ppt.getRequestMap().get("query").toString();
521 assertEquals(disj2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel76b498d2014-06-06 12:06:46 +0000522
523 // "([orth=der][base=katze])|([orth=eine][base=baum])"
524 String disj3 =
525 "{@type=korap:group, operation=operation:or, operands=[" +
526 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000527 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
528 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=katze, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000529 "]}," +
530 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000531 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=eine, match=match:eq}}," +
532 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=baum, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000533 "]}" +
534 "]}";
535 ppt = new PoliqarpPlusTree("([orth=der][base=katze])|([orth=eine][base=baum])");
536 map = ppt.getRequestMap().get("query").toString();
537 assertEquals(disj3.replaceAll(" ", ""), map.replaceAll(" ", ""));
538
539 // "[orth=der][base=katze]|[orth=eine][base=baum]"
540 String disj4 =
541 "{@type=korap:group, operation=operation:or, operands=[" +
542 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000543 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
544 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=katze, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000545 "]}," +
546 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000547 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=eine, match=match:eq}}," +
548 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=baum, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000549 "]}" +
550 "]}";
551 ppt = new PoliqarpPlusTree("[orth=der][base=katze]|[orth=eine][base=baum]");
552 map = ppt.getRequestMap().get("query").toString();
553 assertEquals(disj4.replaceAll(" ", ""), map.replaceAll(" ", ""));
554
555 PoliqarpPlusTree ppt1 = new PoliqarpPlusTree("[orth=der][base=katze]|[orth=eine][base=baum]");
556 PoliqarpPlusTree ppt2 = new PoliqarpPlusTree("([orth=der][base=katze])|([orth=eine][base=baum])");
557 assertEquals(ppt1.getRequestMap().toString(), ppt2.getRequestMap().toString());
558
559 // "[orth=der][base=katze]|[orth=der][base=hund]|[orth=der][base=baum]"
560 String disj5 =
561 "{@type=korap:group, operation=operation:or, operands=[" +
562 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000563 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
564 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=katze, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000565 "]}," +
566 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000567 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
568 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=hund, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000569 "]}," +
570 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000571 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
572 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=baum, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000573 "]}" +
574 "]}";
575 ppt = new PoliqarpPlusTree("[orth=der][base=katze]|[orth=der][base=hund]|[orth=der][base=baum]");
576 map = ppt.getRequestMap().get("query").toString();
577 assertEquals(disj5.replaceAll(" ", ""), map.replaceAll(" ", ""));
578
579 // [orth=der]([base=katze]|[base=hund]|[base=baum])
580 String disj6 =
581 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000582 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000583 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000584 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=katze, match=match:eq}}," +
585 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=hund, match=match:eq}}," +
586 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=baum, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000587 "]}" +
588 "]}";
589 ppt = new PoliqarpPlusTree("[orth=der]([base=katze]|[base=hund]|[base=baum])");
590 map = ppt.getRequestMap().get("query").toString();
591 assertEquals(disj6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000592 }
593
594 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000595 public void testTokenElemSequence() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000596 // [base=Mann]<vp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000597 String seq1 = "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000598 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}, " +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000599 "{@type=korap:span, key=vp}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000600 "]}";
601 assertTrue(equalsQueryContent(seq1, "[base=Mann]<vp>"));
602
603 // <vp>[base=Mann]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000604 String seq2 = "{@type=korap:group, operation=operation:sequence, operands=[" +
605 "{@type=korap:span, key=vp}, "+
Joachim Bingel0900a892014-06-30 16:26:21 +0000606 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}} " +
Joachim Bingel53333e62013-12-09 19:25:52 +0000607 "]}";
608 assertTrue(equalsQueryContent(seq2, "<vp>[base=Mann]"));
609
610 // <vp>[base=Mann]<pp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000611 String seq3 = "{@type=korap:group, operation=operation:sequence, operands=[" +
612 "{@type=korap:span, key=vp}, "+
Joachim Bingel0900a892014-06-30 16:26:21 +0000613 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}, " +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000614 "{@type=korap:span, key=pp} "+
Joachim Bingel53333e62013-12-09 19:25:52 +0000615 "]}";
616 assertTrue(equalsQueryContent(seq3, "<vp>[base=Mann]<pp>"));
617 }
618
619 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000620 public void testElemSequence() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000621 // <np><vp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000622 String seq1 = "{@type=korap:group, operation=operation:sequence, operands=[" +
623 "{@type=korap:span, key=np}," +
624 "{@type=korap:span, key=vp}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000625 "]}";
626 assertTrue(equalsQueryContent(seq1, "<np><vp>"));
627
628 // <np><vp><pp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000629 String seq2 = "{@type=korap:group, operation=operation:sequence, operands=[" +
630 "{@type=korap:span, key=np}," +
631 "{@type=korap:span, key=vp}," +
632 "{@type=korap:span, key=pp}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000633 "]}";
634 assertTrue(equalsQueryContent(seq2, "<np><vp><pp>"));
635 }
636
637 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000638 public void testClasses() throws QueryException {
Joachim Bingel0900a892014-06-30 16:26:21 +0000639 String query;
Joachim Bingel53333e62013-12-09 19:25:52 +0000640 // {[base=Mann]}
Joachim Bingel2daf9862014-02-12 10:18:54 +0000641 String cls1 = "{@type=korap:group, operation=operation:class, class=0, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000642 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000643 "]}";
Joachim Bingel8c640e42014-02-07 16:20:47 +0000644 ppt = new PoliqarpPlusTree("{[base=Mann]}");
645 map = ppt.getRequestMap().get("query").toString();
646 assertEquals(cls1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000647
648 // {[base=Mann][orth=Frau]}
Joachim Bingel0900a892014-06-30 16:26:21 +0000649 query = "{[base=Mann][orth=Frau]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000650 String cls2 = "{@type=korap:group, operation=operation:class, class=0, operands=[" +
651 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000652 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}," +
653 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000654 "]}" +
655 "]}";
Joachim Bingel0900a892014-06-30 16:26:21 +0000656 ppt = new PoliqarpPlusTree(query);
657 map = ppt.getRequestMap().get("query").toString();
658 assertEquals(cls2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000659
660 // [p=NN]{[base=Mann][orth=Frau]}
Joachim Bingel2daf9862014-02-12 10:18:54 +0000661 String cls3 = "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000662 "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000663 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
664 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000665 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}," +
666 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000667 "]}" +
668 "]}" +
669 "]}";
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000670 ppt = new PoliqarpPlusTree("[p=NN]{[base=Mann][orth=Frau]}");
671 map = ppt.getRequestMap().get("query").toString();
672 assertEquals(cls3.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000673
674 // {[base=Mann][orth=Frau]}[p=NN]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000675 String cls4 = "{@type=korap:group, operation=operation:sequence, operands=[" +
676 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
677 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000678 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}," +
679 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000680 "]}" +
681 "]}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000682 "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000683 "]}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000684 ppt = new PoliqarpPlusTree("{[base=Mann][orth=Frau]}[p=NN]");
685 map = ppt.getRequestMap().get("query").toString();
686 assertEquals(cls4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000687
688 // {2:{1:[tt/p=ADJA]}[mate/p=NN]}"
Joachim Bingel2daf9862014-02-12 10:18:54 +0000689 String cls5 = "{@type=korap:group, operation=operation:class, class=2, operands=[" +
690 "{@type=korap:group, operation=operation:sequence, operands=[" +
691 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000692 "{@type=korap:token, wrap={@type=korap:term, foundry=tt, layer=p, key=ADJA, match=match:eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000693 "]}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000694 "{@type=korap:token, wrap={@type=korap:term, foundry=mate, layer=p, key=NN, match=match:eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000695 "]}" +
696 "]}";
697 ppt = new PoliqarpPlusTree("{2: {1:[tt/p=ADJA]}[mate/p=NN]}");
698 map = ppt.getRequestMap().get("query").toString();
699 assertEquals(cls5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000700 }
701
702 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000703 public void testPositions() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000704 // contains(<s>,<np>)
Joachim Bingel2daf9862014-02-12 10:18:54 +0000705 String pos1 = "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
706 "{@type=korap:span, key=s}," +
707 "{@type=korap:span, key=np}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000708 "]}";
709 assertTrue(equalsQueryContent(pos1, "contains(<s>,<np>)"));
710
711 // contains(<s>,[base=Mann])
Joachim Bingel2daf9862014-02-12 10:18:54 +0000712 String pos2 = "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
713 "{@type=korap:span, key=s}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000714 "{@type=korap:token, wrap= {@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000715 "]}";
716 assertTrue(equalsQueryContent(pos2, "contains(<s>,[base=Mann])"));
717
718 // contains(<s>,[orth=der][orth=Mann])
Joachim Bingel2daf9862014-02-12 10:18:54 +0000719 String pos3 = "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
720 "{@type=korap:span, key=s}," +
721 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000722 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
723 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000724 "]}" +
725 "]}";
726 ppt = new PoliqarpPlusTree("contains(<s>,[orth=der][orth=Mann])");
727 map = ppt.getRequestMap().get("query").toString();
728 assertEquals(pos3.replaceAll(" ", ""), map.replaceAll(" ", ""));
729
730 // [base=Auto]contains(<s>,[base=Mann])
731 String pos4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000732 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000733 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Auto, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000734 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
735 "{@type=korap:span, key=s}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000736 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000737 "]}" +
738 "]}";
739 ppt = new PoliqarpPlusTree("[base=Auto]contains(<s>,[base=Mann])");
740 map = ppt.getRequestMap().get("query").toString();
741 assertEquals(pos4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelef7059b2014-04-22 13:44:19 +0000742
743 // contains(<s>,[pos=N]*)
744 String pos5 =
745 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
746 "{@type=korap:span, key=s}," +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000747 "{@type=korap:group, operation=operation:repetition, " +
Joachim Bingel0900a892014-06-30 16:26:21 +0000748 "operands=[{@type=korap:token, wrap={@type=korap:term, layer=pos, key=N, match=match:eq}}" +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000749 "], min=0, max=100" +
Joachim Bingelef7059b2014-04-22 13:44:19 +0000750 "}" +
751 "]}";
752 ppt = new PoliqarpPlusTree("contains(<s>,[pos=N]*)");
753 map = ppt.getRequestMap().get("query").toString();
754 assertEquals(pos5.replaceAll(" ", ""), map.replaceAll(" ", ""));
755
756 // [base=Auto]contains(<s>,[pos=N]*)
757 String pos6 =
758 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000759 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Auto, match=match:eq}}," +
Joachim Bingelef7059b2014-04-22 13:44:19 +0000760 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
761 "{@type=korap:span, key=s}," +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000762 "{@type=korap:group, operation=operation:repetition, " +
Joachim Bingel0900a892014-06-30 16:26:21 +0000763 "operands=[{@type=korap:token, wrap={@type=korap:term, layer=pos, key=N, match=match:eq}}" +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000764 "], min=0, max=100" +
Joachim Bingelef7059b2014-04-22 13:44:19 +0000765 "}" +
766 "]}" +
767 "]}";
768 ppt = new PoliqarpPlusTree("[base=Auto]contains(<s>,[pos=N]*)");
769 map = ppt.getRequestMap().get("query").toString();
770 assertEquals(pos6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000771 }
772
773 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000774 public void testNestedPositions() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000775 // contains(<s>,startswith(<np>,[orth=Der]))
776 String npos1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000777 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
778 "{@type=korap:span, key=s}," +
779 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
780 "{@type=korap:span, key=np}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000781 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000782 "]}" +
783 "]}";
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000784 ppt = new PoliqarpPlusTree("contains(<s>, startswith(<np>,[orth=Der]))");
Joachim Bingel53333e62013-12-09 19:25:52 +0000785 map = ppt.getRequestMap().get("query").toString();
786 assertEquals(npos1.replaceAll(" ", ""), map.replaceAll(" ", ""));
787 }
788
789 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000790 public void testShrinkSplit() throws QueryException {
Joachim Bingel0900a892014-06-30 16:26:21 +0000791 // focus([orth=Der]{[orth=Mann]})
Joachim Bingel53333e62013-12-09 19:25:52 +0000792 String shr1 =
Joachim Bingeld1a3e712014-07-16 08:02:05 +0000793 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000794 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000795 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000796 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000797 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000798 "]}" +
799 "]}" +
800 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000801 ppt = new PoliqarpPlusTree("focus([orth=Der]{[orth=Mann]})");
Joachim Bingel53333e62013-12-09 19:25:52 +0000802 map = ppt.getRequestMap().get("query").toString();
803 assertEquals(shr1.replaceAll(" ", ""), map.replaceAll(" ", ""));
804
Joachim Bingel0900a892014-06-30 16:26:21 +0000805 // focus([orth=Der]{[orth=Mann][orth=geht]})
Joachim Bingel53333e62013-12-09 19:25:52 +0000806 String shr2 =
Joachim Bingeld1a3e712014-07-16 08:02:05 +0000807 "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000808 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000809 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000810 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
811 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000812 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}," +
813 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=geht, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000814 "]}" +
815 "]}" +
816 "]}" +
817 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000818 ppt = new PoliqarpPlusTree("focus([orth=Der]{[orth=Mann][orth=geht]})");
Joachim Bingel53333e62013-12-09 19:25:52 +0000819 map = ppt.getRequestMap().get("query").toString();
820 assertEquals(shr2.replaceAll(" ", ""), map.replaceAll(" ", ""));
821
Joachim Bingel0900a892014-06-30 16:26:21 +0000822 // focus(1:[orth=Der]{1:[orth=Mann][orth=geht]})
Joachim Bingel53333e62013-12-09 19:25:52 +0000823 String shr3 =
Joachim Bingeld1a3e712014-07-16 08:02:05 +0000824 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000825 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000826 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000827 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
828 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000829 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}," +
830 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=geht, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000831 "]}" +
832 "]}" +
833 "]}" +
834 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000835 ppt = new PoliqarpPlusTree("focus(1:[orth=Der]{1:[orth=Mann][orth=geht]})");
Joachim Bingel53333e62013-12-09 19:25:52 +0000836 map = ppt.getRequestMap().get("query").toString();
837 assertEquals(shr3.replaceAll(" ", ""), map.replaceAll(" ", ""));
838
Joachim Bingel0900a892014-06-30 16:26:21 +0000839 // focus(1:startswith(<s>,{1:<np>}))
Joachim Bingel53333e62013-12-09 19:25:52 +0000840 String shr4 =
Joachim Bingeld1a3e712014-07-16 08:02:05 +0000841 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000842 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
843 "{@type=korap:span, key=s}," +
844 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
845 "{@type=korap:span, key=np}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000846 "]}" +
847 "]}" +
848 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000849 ppt = new PoliqarpPlusTree("focus(1:startswith(<s>,{1:<np>}))");
Joachim Bingel53333e62013-12-09 19:25:52 +0000850 map = ppt.getRequestMap().get("query").toString();
851 assertEquals(shr4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000852
Joachim Bingel0900a892014-06-30 16:26:21 +0000853 // focus(3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000854 String shr5 =
Joachim Bingeld1a3e712014-07-16 08:02:05 +0000855 "{@type=korap:reference, operation=operation:focus, classRef=[3], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000856 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
857 "{@type=korap:span, key=s}," +
858 "{@type=korap:group, operation=operation:class, class=3, operands=[" +
859 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000860 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000861 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
862 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000863 "{@type=korap:token, wrap={@type=korap:term, foundry=mate, layer=p, key=ADJA, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000864 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000865 "{@type=korap:token, wrap={@type=korap:term, foundry=tt, layer=p, key=NN, match=match:eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000866 "]}" +
867 "]}" +
868 "]}" +
869 "]}" +
870 "]}" +
871 "]}" +
872 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000873 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 +0000874 map = ppt.getRequestMap().get("query").toString();
875 assertEquals(shr5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000876
877 // split(3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))
878 String shr6 =
Joachim Bingeld1a3e712014-07-16 08:02:05 +0000879 "{@type=korap:reference, operation=operation:split, classRef=[3], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000880 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
881 "{@type=korap:span, key=s}," +
882 "{@type=korap:group, operation=operation:class, class=3, operands=[" +
883 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000884 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000885 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
886 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000887 "{@type=korap:token, wrap={@type=korap:term, foundry=mate, layer=p, key=ADJA, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000888 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000889 "{@type=korap:token, wrap={@type=korap:term, foundry=tt, layer=p, key=NN, match=match:eq}}" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000890 "]}" +
891 "]}" +
892 "]}" +
893 "]}" +
894 "]}" +
895 "]}" +
896 "]}";
897 ppt = new PoliqarpPlusTree("split(3:startswith(<s>,{3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) ");
898 map = ppt.getRequestMap().get("query").toString();
899 assertEquals(shr6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel8c640e42014-02-07 16:20:47 +0000900
901 // split(2|3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))
902 String shr7 =
Joachim Bingeld1a3e712014-07-16 08:02:05 +0000903 "{@type=korap:reference, operation=operation:split, classRef=[2, 3], classRefOp=classRefOp:intersection, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000904 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
905 "{@type=korap:span, key=s}," +
906 "{@type=korap:group, operation=operation:class, class=3, operands=[" +
907 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000908 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000909 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
910 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000911 "{@type=korap:token, wrap={@type=korap:term, foundry=mate, layer=p, key=ADJA, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000912 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000913 "{@type=korap:token, wrap={@type=korap:term, foundry=tt, layer=p, key=NN, match=match:eq}}" +
Joachim Bingel8c640e42014-02-07 16:20:47 +0000914 "]}" +
915 "]}" +
916 "]}" +
917 "]}" +
918 "]}" +
919 "]}" +
920 "]}";
921 ppt = new PoliqarpPlusTree("split(2|3:startswith(<s>,{3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) ");
922 map = ppt.getRequestMap().get("query").toString();
923 assertEquals(shr7.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel5146ebe2014-06-12 08:49:21 +0000924
925
926 String shr8 =
Joachim Bingeld1a3e712014-07-16 08:02:05 +0000927 "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" +
Joachim Bingeladd0fb12014-06-24 08:54:14 +0000928 "{@type=korap:group, operation=operation:sequence, operands=[" +
929 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000930 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}" +
Joachim Bingeladd0fb12014-06-24 08:54:14 +0000931 "]}," +
932 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000933 "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=ADJA, match=match:eq}}" +
Joachim Bingel5146ebe2014-06-12 08:49:21 +0000934 "]}" +
Joachim Bingeladd0fb12014-06-24 08:54:14 +0000935 "]}" +
936 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000937 ppt = new PoliqarpPlusTree("focus(1:{[base=der]}{1:[pos=ADJA]})");
Joachim Bingeladd0fb12014-06-24 08:54:14 +0000938 map = ppt.getRequestMap().get("query").toString();
939 assertEquals(shr8.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel5146ebe2014-06-12 08:49:21 +0000940
Joachim Bingel53333e62013-12-09 19:25:52 +0000941 }
942
Joachim Bingel03882702013-12-31 19:53:05 +0000943
Joachim Bingel53333e62013-12-09 19:25:52 +0000944 @Test
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000945 public void testFoundries() throws QueryException {
946 // [tt/base=Mann]
Joachim Bingel0900a892014-06-30 16:26:21 +0000947 String layer1 = "{@type=korap:token, wrap={@type=korap:term, foundry=tt, layer=lemma, key=Mann, match=match:eq}}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000948 ppt = new PoliqarpPlusTree("[tt/base=Mann]");
949 map = ppt.getRequestMap().get("query").toString();
950 assertEquals(layer1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000951
952 }
Joachim Bingel16da4e12013-12-17 09:48:12 +0000953
954 @Test
Joachim Bingel8c640e42014-02-07 16:20:47 +0000955 public void testAlign() throws QueryException {
Joachim Bingel16da4e12013-12-17 09:48:12 +0000956 // [orth=der]^[orth=Mann]
957 String align1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000958 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000959 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
960 "{@type=korap:group, operation=operation:alignment, operands=[" +
961 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" +
962 "], align=align:left}" +
Joachim Bingel16da4e12013-12-17 09:48:12 +0000963 "]}";
964 ppt = new PoliqarpPlusTree("[orth=der]^[orth=Mann]");
965 map = ppt.getRequestMap().get("query").toString();
966 assertEquals(align1.replaceAll(" ", ""), map.replaceAll(" ", ""));
967
Joachim Bingel84e33df2014-01-31 14:02:46 +0000968 // [orth=der]^[orth=große][orth=Mann]
969 String query = "[orth=der]^[orth=große][orth=Mann]";
970 String align1b =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000971 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000972 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
973 "{@type=korap:group, operation=operation:alignment, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000974 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000975 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=große, match=match:eq}}," +
976 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +0000977 "]}" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000978 "], align=align:left}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +0000979 "]}";
980 ppt = new PoliqarpPlusTree(query);
981 map = ppt.getRequestMap().get("query").toString();
982 assertEquals(align1b.replaceAll(" ", ""), map.replaceAll(" ", ""));
983
Joachim Bingel16da4e12013-12-17 09:48:12 +0000984 // "([base=a]^[base=b])|[base=c]",
985 String align2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000986 "{@type=korap:group, operation=operation:or, operands=[" +
987 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000988 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=a, match=match:eq}}," +
989 "{@type=korap:group, operation=operation:alignment, operands=[" +
990 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=b, match=match:eq}}" +
991 "], align=align:left}" +
Joachim Bingel16da4e12013-12-17 09:48:12 +0000992 "]}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000993 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=c, match=match:eq}}" +
Joachim Bingel16da4e12013-12-17 09:48:12 +0000994 "]}";
995 ppt = new PoliqarpPlusTree("([base=a]^[base=b])|[base=c]");
996 map = ppt.getRequestMap().get("query").toString();
997 assertEquals(align2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingela67e6a32014-01-02 18:35:24 +0000998
999 // "([base=a]^[base=b][base=c])|[base=d]",
1000 String align3 =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001001 "{@type=korap:group, operation=operation:or, operands=[" +
1002 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001003 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=a, match=match:eq}}," +
1004 "{@type=korap:group, operation=operation:alignment, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001005 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001006 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=b, match=match:eq}}," +
1007 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=c, match=match:eq}}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +00001008 "]}" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001009 "], align=align:left}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +00001010 "]}," +
Joachim Bingel0900a892014-06-30 16:26:21 +00001011 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=d, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +00001012 "]}";
1013 ppt = new PoliqarpPlusTree("([base=a]^[base=b][base=c])|[base=d]");
1014 map = ppt.getRequestMap().get("query").toString();
1015 assertEquals(align3.replaceAll(" ", ""), map.replaceAll(" ", ""));
1016
1017 // "([base=a]^[base=b]^[base=c])|[base=d]",
1018 String align4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001019 "{@type=korap:group, operation=operation:or, operands=[" +
1020 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001021 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=a, match=match:eq}}," +
1022 "{@type=korap:group, operation=operation:alignment, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +00001023 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001024 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=b, match=match:eq}}," +
1025 "{@type=korap:group, operation=operation:alignment, operands=[" +
1026 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=c, match=match:eq}}" +
1027 "], align=align:left}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +00001028 "]}" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001029 "], align=align:left}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +00001030 "]}," +
Joachim Bingel0900a892014-06-30 16:26:21 +00001031 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=d, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +00001032 "]}";
1033 ppt = new PoliqarpPlusTree("([base=a]^[base=b]^[base=c])|[base=d]");
1034 map = ppt.getRequestMap().get("query").toString();
1035 assertEquals(align4.replaceAll(" ", ""), map.replaceAll(" ", ""));
1036
1037
Joachim Bingel16da4e12013-12-17 09:48:12 +00001038 }
1039
1040 @Test
Joachim Bingel8c640e42014-02-07 16:20:47 +00001041 public void testSimpleQueries() throws QueryException {
Joachim Bingela67e6a32014-01-02 18:35:24 +00001042 // Baum
1043 String simple1 =
Joachim Bingel0900a892014-06-30 16:26:21 +00001044 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq}}";
Joachim Bingela67e6a32014-01-02 18:35:24 +00001045 ppt = new PoliqarpPlusTree("Baum");
1046 map = ppt.getRequestMap().get("query").toString();
1047 assertEquals(simple1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel0900a892014-06-30 16:26:21 +00001048
1049 // Baum/i
1050 String simple1b =
1051 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq, caseInsensitive=true}}";
1052 ppt = new PoliqarpPlusTree("Baum/i");
1053 map = ppt.getRequestMap().get("query").toString();
1054 assertEquals(simple1b.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel16da4e12013-12-17 09:48:12 +00001055
Joachim Bingela67e6a32014-01-02 18:35:24 +00001056 // Der Baum
1057 String simple2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001058 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001059 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}, " +
1060 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +00001061 "]}";
1062 ppt = new PoliqarpPlusTree("Der Baum");
1063 map = ppt.getRequestMap().get("query").toString();
1064 assertEquals(simple2.replaceAll(" ", ""), map.replaceAll(" ", ""));
1065
Joachim Bingel0900a892014-06-30 16:26:21 +00001066 // Der Baum/i
1067 String simple2b =
1068 "{@type=korap:group, operation=operation:sequence, operands=[" +
1069 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}, " +
1070 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq, caseInsensitive=true}}" +
1071 "]}";
1072 ppt = new PoliqarpPlusTree("Der Baum/i");
1073 map = ppt.getRequestMap().get("query").toString();
1074 assertEquals(simple2b.replaceAll(" ", ""), map.replaceAll(" ", ""));
1075
Joachim Bingela67e6a32014-01-02 18:35:24 +00001076 // Der große Baum
1077 String simple3 =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001078 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001079 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}, " +
1080 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=große, match=match:eq}}, " +
1081 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +00001082 "]}";
1083 ppt = new PoliqarpPlusTree("Der große Baum");
1084 map = ppt.getRequestMap().get("query").toString();
1085 assertEquals(simple3.replaceAll(" ", ""), map.replaceAll(" ", ""));
1086
1087 // Baum | Stein
1088 String simple4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001089 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001090 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq}}, " +
1091 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Stein, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +00001092 "]}";
1093 ppt = new PoliqarpPlusTree("Baum | Stein");
1094 map = ppt.getRequestMap().get("query").toString();
1095 assertEquals(simple4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel84e33df2014-01-31 14:02:46 +00001096
1097 // Baum | Stein Haus
1098 String query = "(Baum | Stein) Haus";
1099 String simple5 =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001100 "{@type=korap:group, operation=operation:sequence, operands=[" +
1101 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001102 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq}}, " +
1103 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Stein, match=match:eq}}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +00001104 "]}," +
Joachim Bingel0900a892014-06-30 16:26:21 +00001105 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Haus, match=match:eq}} " +
Joachim Bingel84e33df2014-01-31 14:02:46 +00001106 "]}";
1107 ppt = new PoliqarpPlusTree(query);
1108 map = ppt.getRequestMap().get("query").toString();
1109 assertEquals(simple5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel16da4e12013-12-17 09:48:12 +00001110 }
Joachim Bingel53333e62013-12-09 19:25:52 +00001111}
1112