blob: 183679299088d0362fc14452274f37c9979870c6 [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 Bingel53333e62013-12-09 19:25:52 +000053 }
54
55 @Test
Joachim Bingel41e112e2014-02-12 10:46:18 +000056 public void testRegex() throws QueryException {
57 String query = "[orth=\"M(a|ä)nn(er)?\"]";
Joachim Bingel0900a892014-06-30 16:26:21 +000058 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 +000059 ppt = new PoliqarpPlusTree(query);
60 map = ppt.getRequestMap().get("query").toString();
61 assertEquals(re1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel0900a892014-06-30 16:26:21 +000062
63 query = "[orth=\"M(a|ä)nn(er)?\"/x]";
64 String re2 = "{@type=korap:token, wrap={@type=korap:term, layer=orth, type=type:regex, key=.*?M(a|ä)nn(er)?.*?, match=match:eq}}";
65 ppt = new PoliqarpPlusTree(query);
66 map = ppt.getRequestMap().get("query").toString();
67 assertEquals(re2.replaceAll(" ", ""), map.replaceAll(" ", ""));
68
69 query = "\"M(a|ä)nn(er)?\"/x";
70 String re3 = "{@type=korap:token, wrap={@type=korap:term, type=type:regex, layer=orth, key=.*?M(a|ä)nn(er)?.*?, match=match:eq}}";
71 ppt = new PoliqarpPlusTree(query);
72 map = ppt.getRequestMap().get("query").toString();
73 assertEquals(re3.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel41e112e2014-02-12 10:46:18 +000074 }
75
76 @Test
Joachim Bingel0207d5e2014-02-12 14:18:41 +000077 public void testCaseSensitivityFlag() throws QueryException {
78 String query="[orth=deutscher/i]";
79 String cs1 =
Joachim Bingel0900a892014-06-30 16:26:21 +000080 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=deutscher, match=match:eq, caseInsensitive=true}}";
Joachim Bingel0207d5e2014-02-12 14:18:41 +000081 ppt = new PoliqarpPlusTree(query);
82 map = ppt.getRequestMap().get("query").toString();
83 assertEquals(cs1.replaceAll(" ", ""), map.replaceAll(" ", ""));
84
85 query="[orth=deutscher/i][orth=Bundestag]";
86 String cs2 =
87 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +000088 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=deutscher, match=match:eq, caseInsensitive=true}}," +
89 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Bundestag, match=match:eq}}" +
Joachim Bingel0207d5e2014-02-12 14:18:41 +000090 "]}";
91 ppt = new PoliqarpPlusTree(query);
92 map = ppt.getRequestMap().get("query").toString();
93 assertEquals(cs2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeladd0fb12014-06-24 08:54:14 +000094
95 query="deutscher/i";
96 String cs3 =
Joachim Bingel0900a892014-06-30 16:26:21 +000097 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=deutscher, match=match:eq, caseInsensitive=true}}";
Joachim Bingeladd0fb12014-06-24 08:54:14 +000098 ppt = new PoliqarpPlusTree(query);
99 map = ppt.getRequestMap().get("query").toString();
100 assertEquals(cs3.replaceAll(" ", ""), map.replaceAll(" ", ""));
101
102 query="deutscher/i Bundestag";
103 String cs4 =
104 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000105 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=deutscher, match=match:eq, caseInsensitive=true}}," +
106 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Bundestag, match=match:eq}}" +
Joachim Bingeladd0fb12014-06-24 08:54:14 +0000107 "]}";
108 ppt = new PoliqarpPlusTree(query);
109 map = ppt.getRequestMap().get("query").toString();
110 assertEquals(cs4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000111
112 query="deutscher Bundestag/i";
113 String cs5 =
114 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000115 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=deutscher, match=match:eq}}," +
116 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Bundestag, match=match:eq, caseInsensitive=true}}" +
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000117 "]}";
118 ppt = new PoliqarpPlusTree(query);
119 map = ppt.getRequestMap().get("query").toString();
120 assertEquals(cs5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel0207d5e2014-02-12 14:18:41 +0000121 }
122
123 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000124 public void testElements() throws QueryException {
Joachim Bingelfc1fb352014-02-26 14:40:27 +0000125 String query;
Joachim Bingel53333e62013-12-09 19:25:52 +0000126 // <s>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000127 String elem1 = "{@type=korap:span, key=s}";
Joachim Bingel53333e62013-12-09 19:25:52 +0000128 assertTrue(equalsQueryContent(elem1, "<s>"));
129
130 // <vp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000131 String elem2 = "{@type=korap:span, key=vp}";
Joachim Bingel53333e62013-12-09 19:25:52 +0000132 assertTrue(equalsQueryContent(elem2, "<vp>"));
Joachim Bingelfc1fb352014-02-26 14:40:27 +0000133
134 // <cnx/c=vp>
135 query = "<c=vp>";
136 String span3 = "{@type=korap:span, layer=c, key=vp}";
137 ppt = new PoliqarpPlusTree(query);
138 map = ppt.getRequestMap().get("query").toString();
139 assertEquals(span3.replaceAll(" ", ""), map.replaceAll(" ", ""));
140
141 // <cnx/c=vp>
142 query = "<cnx/c=vp>";
143 String span4 = "{@type=korap:span, foundry=cnx, layer=c, key=vp}";
144 ppt = new PoliqarpPlusTree(query);
145 map = ppt.getRequestMap().get("query").toString();
146 assertEquals(span4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000147 }
Joachim Bingel87480d02014-01-17 14:07:46 +0000148
149 @Test
150 public void testEmptyTokens() throws QueryException {
151 // [base=der][][base=Mann]
152 String et1 =
Joachim Bingel0900a892014-06-30 16:26:21 +0000153 "{@type=korap:group, operation=operation:sequence, " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000154 "operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000155 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
156 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
157 "], inOrder=true, distances=[" +
158 "{@type=korap:distance, key=w, min=2, max=2}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000159 "]}";
160 ppt = new PoliqarpPlusTree("[base=der][][base=Mann]");
161 map = ppt.getRequestMap().get("query").toString();
162 assertEquals(et1.replaceAll(" ", ""), map.replaceAll(" ", ""));
163
164 // [base=der][][][base=Mann]
165 String et2 =
Joachim Bingel0900a892014-06-30 16:26:21 +0000166 "{@type=korap:group, operation=operation:sequence, " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000167 "operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000168 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
169 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
170 "], inOrder=true, distances=[" +
171 "{@type=korap:distance, key=w, min=3, max=3}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000172 "]}";
Joachim Bingelffd65e32014-01-22 14:22:57 +0000173 ppt = new PoliqarpPlusTree("[base=der][][][base=Mann]");
Joachim Bingel87480d02014-01-17 14:07:46 +0000174 map = ppt.getRequestMap().get("query").toString();
175 assertEquals(et2.replaceAll(" ", ""), map.replaceAll(" ", ""));
176
177 // [base=der][][]?[base=Mann]
178 String et3 =
Joachim Bingel0900a892014-06-30 16:26:21 +0000179 "{@type=korap:group, operation=operation:sequence, " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000180 "operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000181 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
182 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
183 "], inOrder=true, distances=[" +
184 "{@type=korap:distance, key=w, min=2, max=3}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000185 "]}";
186 ppt = new PoliqarpPlusTree("[base=der][][]?[base=Mann]");
187 map = ppt.getRequestMap().get("query").toString();
188 assertEquals(et3.replaceAll(" ", ""), map.replaceAll(" ", ""));
189
Joachim Bingel87480d02014-01-17 14:07:46 +0000190
191 // startswith(<s>, [][base=Mann]
Joachim Bingelffd65e32014-01-22 14:22:57 +0000192 String et4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000193 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
194 "{@type=korap:span, key=s}," +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000195 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000196 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
Joachim Bingelbea1ec62014-07-11 15:00:14 +0000197 "], leftOffset={@type=korap:boundary, min=1, max=1}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000198 "]}";
Joachim Bingelffd65e32014-01-22 14:22:57 +0000199 ppt = new PoliqarpPlusTree("startswith(<s>, [][base=Mann])");
200 map = ppt.getRequestMap().get("query").toString();
201 assertEquals(et4.replaceAll(" ", ""), map.replaceAll(" ", ""));
202
Joachim Bingel11d5b152014-02-11 21:33:47 +0000203 // [base=der][]{2,5}[base=Mann][]?[][base=Frau] nested distances=
Joachim Bingelffd65e32014-01-22 14:22:57 +0000204 String et5 =
Joachim Bingel0900a892014-06-30 16:26:21 +0000205 "{@type=korap:group, operation=operation:sequence," +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000206 "operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000207 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
208 "{@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=Mann, match=match:eq}}," +
211 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Frau, match=match:eq}}" +
212 "], inOrder=true, distances=[" +
213 "{@type=korap:distance, key=w, min=2, max=3}" +
Joachim Bingelffd65e32014-01-22 14:22:57 +0000214 "]}" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000215 "], inOrder=true, distances=[" +
216 "{@type=korap:distance, key=w, min=3, max=6}" +
Joachim Bingelffd65e32014-01-22 14:22:57 +0000217 "]}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000218 ppt = new PoliqarpPlusTree("[base=der][]{2,5}[base=Mann][]?[][base=Frau]");
Joachim Bingel87480d02014-01-17 14:07:46 +0000219 map = ppt.getRequestMap().get("query").toString();
220 assertEquals(et5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel87480d02014-01-17 14:07:46 +0000221
Joachim Bingelc15720f2014-05-07 14:37:23 +0000222 // [base=der][]*[base=Mann]
223 String et6 =
Joachim Bingel0900a892014-06-30 16:26:21 +0000224 "{@type=korap:group, operation=operation:sequence, " +
Joachim Bingelc15720f2014-05-07 14:37:23 +0000225 "operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000226 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
227 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
228 "], inOrder=true, distances=[" +
229 "{@type=korap:distance, key=w, min=1, max=100}" +
Joachim Bingelc15720f2014-05-07 14:37:23 +0000230 "]}";
231 ppt = new PoliqarpPlusTree("[base=der][]*[base=Mann]");
232 map = ppt.getRequestMap().get("query").toString();
233 assertEquals(et6.replaceAll(" ", ""), map.replaceAll(" ", ""));
234
Joachim Bingel0900a892014-06-30 16:26:21 +0000235 // [base=der][]+[base=Mann]
Joachim Bingelc15720f2014-05-07 14:37:23 +0000236 String et7 =
Joachim Bingel0900a892014-06-30 16:26:21 +0000237 "{@type=korap:group, operation=operation:sequence, " +
Joachim Bingelc15720f2014-05-07 14:37:23 +0000238 "operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000239 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
240 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
241 "], inOrder=true, distances=[" +
242 "{@type=korap:distance, key=w, min=2, max=100}" +
Joachim Bingelc15720f2014-05-07 14:37:23 +0000243 "]}";
244 ppt = new PoliqarpPlusTree("[base=der][]+[base=Mann]");
245 map = ppt.getRequestMap().get("query").toString();
246 assertEquals(et7.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel87480d02014-01-17 14:07:46 +0000247 }
Joachim Bingel53333e62013-12-09 19:25:52 +0000248
249 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000250 public void testCoordinatedFields() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000251 // [base=Mann&(cas=N|cas=A)]
252 String cof1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000253 "{@type=korap:token, wrap=" +
Joachim Bingel2980bda2014-04-04 12:09:46 +0000254 "{@type=korap:termGroup, relation=relation:and, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000255 "{@type=korap:term, layer=lemma, key=Mann, match=match:eq}," +
Joachim Bingel2980bda2014-04-04 12:09:46 +0000256 "{@type=korap:termGroup, relation=relation:or, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000257 "{@type=korap:term, layer=cas, key=N, match=match:eq}," +
258 "{@type=korap:term, layer=cas, key=A, match=match:eq}" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000259 "]}" +
260 "]}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000261 "}";
262 ppt = new PoliqarpPlusTree("[base=Mann&(cas=N|cas=A)]");
263 map = ppt.getRequestMap().get("query").toString();
264 assertEquals(cof1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Nils Diewald7d486c22013-12-13 16:32:18 +0000265
266
267 assertEquals(
268 new PoliqarpPlusTree(" [ base=Mann & ( cas=N | cas=A)] ").getRequestMap().get("query").toString(),
269 new PoliqarpPlusTree("[base=Mann &(cas=N|cas=A)]").getRequestMap().get("query").toString()
270 );
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000271
272 // [base=Mann&cas=N&gen=m]
273 String cof2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000274 "{@type=korap:token, wrap=" +
Joachim Bingel2980bda2014-04-04 12:09:46 +0000275 "{@type=korap:termGroup, relation=relation:and, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000276 "{@type=korap:term, layer=lemma, key=Mann, match=match:eq}," +
277 "{@type=korap:termGroup, relation=relation:and, operands=[" +
278 "{@type=korap:term, layer=cas, key=N, match=match:eq}," +
279 "{@type=korap:term, layer=gen, key=m, match=match:eq}" +
280 "]}" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000281 "]}" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000282 "}";
283 ppt = new PoliqarpPlusTree("[base=Mann&cas=N&gen=m]");
284 map = ppt.getRequestMap().get("query").toString();
285 assertEquals(cof2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000286 }
287
288 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000289 public void testOccurrence() throws QueryException {
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000290 // [base=foo]*
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000291 String occ1 = "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000292 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000293 "], min=0, max=100}";
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000294 ppt = new PoliqarpPlusTree("[base=foo]*");
295 map = ppt.getRequestMap().get("query").toString();
296 assertEquals(occ1.replaceAll(" ", ""), map.replaceAll(" ", ""));
297
298 // [base=foo]*[base=bar]
299 String occ2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000300 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000301 "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000302 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000303 "], min=0, max=100 }," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000304 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000305 "]}";
306 ppt = new PoliqarpPlusTree("[base=foo]*[base=bar]");
307 map = ppt.getRequestMap().get("query").toString();
308 assertEquals(occ2.replaceAll(" ", ""), map.replaceAll(" ", ""));
309
310 // [base=bar][base=foo]*
311 String occ3 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000312 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000313 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000314 "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000315 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000316 "], min=0, max=100 }" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000317 "]}";
318 ppt = new PoliqarpPlusTree("[base=bar][base=foo]*");
319 map = ppt.getRequestMap().get("query").toString();
320 assertEquals(occ3.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb4da7022013-12-09 23:17:24 +0000321
322 // ([base=bar][base=foo])*
323 String occ4 =
Joachim Bingel0900a892014-06-30 16:26:21 +0000324 "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000325 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000326 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," +
327 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000328 "]}" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000329 "], min=0, max=100}" ;
Joachim Bingelb4da7022013-12-09 23:17:24 +0000330 ppt = new PoliqarpPlusTree("([base=bar][base=foo])*");
331 map = ppt.getRequestMap().get("query").toString();
332 assertEquals(occ4.replaceAll(" ", ""), map.replaceAll(" ", ""));
333
334 // <s>([base=bar][base=foo])*
335 String occ5 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000336 "{@type=korap:group, operation=operation:sequence, operands=[" +
337 "{@type=korap:span, key=s}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000338 "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000339 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000340 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," +
341 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000342 "]}" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000343 "], min=0, max=100 }" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000344 "]}" ;
345 ppt = new PoliqarpPlusTree("<s>([base=bar][base=foo])*");
346 map = ppt.getRequestMap().get("query").toString();
347 assertEquals(occ5.replaceAll(" ", ""), map.replaceAll(" ", ""));
348
349 // <s><np>([base=bar][base=foo])*
Joachim Bingelb4da7022013-12-09 23:17:24 +0000350 String occ6 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000351 "{@type=korap:group, operation=operation:sequence, operands=[" +
352 "{@type=korap:span, key=s}," +
353 "{@type=korap:span, key=np}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000354 "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000355 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000356 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," +
357 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000358 "]}" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000359 "], min=0, max=100 }" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000360 "]}" ;
361 ppt = new PoliqarpPlusTree("<s><np>([base=bar][base=foo])*");
362 map = ppt.getRequestMap().get("query").toString();
363 assertEquals(occ6.replaceAll(" ", ""), map.replaceAll(" ", ""));
364
365 // <s><np>([base=bar][base=foo])*[p=NN]
366 // comment: embedded sequence shouldn't really be here, but does not really hurt, either. (?)
367 // really hard to get this behaviour out of the PQPlus grammar...
368 String occ7 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000369 "{@type=korap:group, operation=operation:sequence, operands=[" +
370 "{@type=korap:span, key=s}," +
371 "{@type=korap:span, key=np}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000372 "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000373 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000374 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," +
375 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000376 "]}" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000377 "], min=0, max=100 }," +
378 "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000379 "]}" ;
380 ppt = new PoliqarpPlusTree("<s><np>([base=bar][base=foo])*[p=NN]");
381 map = ppt.getRequestMap().get("query").toString();
382 assertEquals(occ7.replaceAll(" ", ""), map.replaceAll(" ", ""));
383
384 // ([base=bar][base=foo])*[p=NN]
Joachim Bingelb4da7022013-12-09 23:17:24 +0000385 String occ8 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000386 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000387 "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000388 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000389 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," +
390 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000391 "]}" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000392 "], min=0, max=100 }," +
393 "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000394 "]}" ;
395 ppt = new PoliqarpPlusTree("([base=bar][base=foo])*[p=NN]");
396 map = ppt.getRequestMap().get("query").toString();
397 assertEquals(occ8.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000398
399 // [base=foo]+
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000400 String occ9 = "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000401 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000402 "], min=1, max=100}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000403 ppt = new PoliqarpPlusTree("[base=foo]+");
404 map = ppt.getRequestMap().get("query").toString();
405 assertEquals(occ9.replaceAll(" ", ""), map.replaceAll(" ", ""));
406
407 // [base=foo]?
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000408 String occ10 = "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000409 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000410 "], min=0, max=1}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000411 ppt = new PoliqarpPlusTree("[base=foo]?");
412 map = ppt.getRequestMap().get("query").toString();
413 assertEquals(occ10.replaceAll(" ", ""), map.replaceAll(" ", ""));
414
415 // [base=foo]{2,5}
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000416 String occ11 = "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000417 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000418 "], min=2, max=5}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000419 ppt = new PoliqarpPlusTree("[base=foo]{2,5}");
420 map = ppt.getRequestMap().get("query").toString();
421 assertEquals(occ11.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel2980bda2014-04-04 12:09:46 +0000422
423 // [base=foo]{2}
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000424 String occ12 = "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000425 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000426 "], min=2, max=2}";
Joachim Bingel2980bda2014-04-04 12:09:46 +0000427 ppt = new PoliqarpPlusTree("[base=foo]{2}");
428 map = ppt.getRequestMap().get("query").toString();
429 assertEquals(occ12.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb2aa1c72014-07-01 12:48:46 +0000430
431 // [base=foo]{2}
432 String occ13 = "{@type=korap:group, operation=operation:repetition, operands=[" +
433 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
434 "], min=2, max=100}";
435 ppt = new PoliqarpPlusTree("[base=foo]{2,}");
436 map = ppt.getRequestMap().get("query").toString();
437 assertEquals(occ13.replaceAll(" ", ""), map.replaceAll(" ", ""));
438
439 // [base=foo]{2}
440 String occ14 = "{@type=korap:group, operation=operation:repetition, operands=[" +
441 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" +
442 "], min=0, max=2}";
443 ppt = new PoliqarpPlusTree("[base=foo]{,2}");
444 map = ppt.getRequestMap().get("query").toString();
445 assertEquals(occ14.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000446 }
447
448 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000449 public void testTokenSequence() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000450 // [base=Mann][orth=Frau]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000451 String seq1 = "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000452 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}, " +
453 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000454 "]}";
455 assertTrue(equalsQueryContent(seq1, "[base=Mann][orth=Frau]"));
456
457 // [base=Mann][orth=Frau][p=NN]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000458 String seq2 = "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000459 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}, " +
460 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}, " +
461 "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000462 "]}";
463 assertTrue(equalsQueryContent(seq2, "[base=Mann][orth=Frau][p=NN]"));
464 }
465
466 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000467 public void testDisjSegments() throws QueryException {
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000468 // ([base=der]|[base=das])[base=Schild]
469 String disj1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000470 "{@type=korap:group, operation=operation:sequence, operands=[" +
471 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000472 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
473 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=das, match=match:eq}}" +
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000474 "]}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000475 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Schild, match=match:eq}}" +
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000476 "]}";
477 ppt = new PoliqarpPlusTree("([base=der]|[base=das])[base=Schild]");
478 map = ppt.getRequestMap().get("query").toString();
479 assertEquals(disj1.replaceAll(" ", ""), map.replaceAll(" ", ""));
480
481 // [base=Schild]([base=der]|[base=das])
482 String disj2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000483 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000484 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Schild, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000485 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000486 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
487 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=das, match=match:eq}}" +
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000488 "]}" +
489 "]}";
490 ppt = new PoliqarpPlusTree("[base=Schild]([base=der]|[base=das])");
491 map = ppt.getRequestMap().get("query").toString();
492 assertEquals(disj2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel76b498d2014-06-06 12:06:46 +0000493
494 // "([orth=der][base=katze])|([orth=eine][base=baum])"
495 String disj3 =
496 "{@type=korap:group, operation=operation:or, operands=[" +
497 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000498 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
499 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=katze, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000500 "]}," +
501 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000502 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=eine, match=match:eq}}," +
503 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=baum, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000504 "]}" +
505 "]}";
506 ppt = new PoliqarpPlusTree("([orth=der][base=katze])|([orth=eine][base=baum])");
507 map = ppt.getRequestMap().get("query").toString();
508 assertEquals(disj3.replaceAll(" ", ""), map.replaceAll(" ", ""));
509
510 // "[orth=der][base=katze]|[orth=eine][base=baum]"
511 String disj4 =
512 "{@type=korap:group, operation=operation:or, operands=[" +
513 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000514 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
515 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=katze, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000516 "]}," +
517 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000518 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=eine, match=match:eq}}," +
519 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=baum, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000520 "]}" +
521 "]}";
522 ppt = new PoliqarpPlusTree("[orth=der][base=katze]|[orth=eine][base=baum]");
523 map = ppt.getRequestMap().get("query").toString();
524 assertEquals(disj4.replaceAll(" ", ""), map.replaceAll(" ", ""));
525
526 PoliqarpPlusTree ppt1 = new PoliqarpPlusTree("[orth=der][base=katze]|[orth=eine][base=baum]");
527 PoliqarpPlusTree ppt2 = new PoliqarpPlusTree("([orth=der][base=katze])|([orth=eine][base=baum])");
528 assertEquals(ppt1.getRequestMap().toString(), ppt2.getRequestMap().toString());
529
530 // "[orth=der][base=katze]|[orth=der][base=hund]|[orth=der][base=baum]"
531 String disj5 =
532 "{@type=korap:group, operation=operation:or, operands=[" +
533 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000534 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
535 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=katze, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000536 "]}," +
537 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000538 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
539 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=hund, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000540 "]}," +
541 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000542 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
543 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=baum, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000544 "]}" +
545 "]}";
546 ppt = new PoliqarpPlusTree("[orth=der][base=katze]|[orth=der][base=hund]|[orth=der][base=baum]");
547 map = ppt.getRequestMap().get("query").toString();
548 assertEquals(disj5.replaceAll(" ", ""), map.replaceAll(" ", ""));
549
550 // [orth=der]([base=katze]|[base=hund]|[base=baum])
551 String disj6 =
552 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000553 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000554 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000555 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=katze, match=match:eq}}," +
556 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=hund, match=match:eq}}," +
557 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=baum, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000558 "]}" +
559 "]}";
560 ppt = new PoliqarpPlusTree("[orth=der]([base=katze]|[base=hund]|[base=baum])");
561 map = ppt.getRequestMap().get("query").toString();
562 assertEquals(disj6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000563 }
564
565 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000566 public void testTokenElemSequence() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000567 // [base=Mann]<vp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000568 String seq1 = "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000569 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}, " +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000570 "{@type=korap:span, key=vp}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000571 "]}";
572 assertTrue(equalsQueryContent(seq1, "[base=Mann]<vp>"));
573
574 // <vp>[base=Mann]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000575 String seq2 = "{@type=korap:group, operation=operation:sequence, operands=[" +
576 "{@type=korap:span, key=vp}, "+
Joachim Bingel0900a892014-06-30 16:26:21 +0000577 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}} " +
Joachim Bingel53333e62013-12-09 19:25:52 +0000578 "]}";
579 assertTrue(equalsQueryContent(seq2, "<vp>[base=Mann]"));
580
581 // <vp>[base=Mann]<pp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000582 String seq3 = "{@type=korap:group, operation=operation:sequence, operands=[" +
583 "{@type=korap:span, key=vp}, "+
Joachim Bingel0900a892014-06-30 16:26:21 +0000584 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}, " +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000585 "{@type=korap:span, key=pp} "+
Joachim Bingel53333e62013-12-09 19:25:52 +0000586 "]}";
587 assertTrue(equalsQueryContent(seq3, "<vp>[base=Mann]<pp>"));
588 }
589
590 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000591 public void testElemSequence() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000592 // <np><vp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000593 String seq1 = "{@type=korap:group, operation=operation:sequence, operands=[" +
594 "{@type=korap:span, key=np}," +
595 "{@type=korap:span, key=vp}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000596 "]}";
597 assertTrue(equalsQueryContent(seq1, "<np><vp>"));
598
599 // <np><vp><pp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000600 String seq2 = "{@type=korap:group, operation=operation:sequence, operands=[" +
601 "{@type=korap:span, key=np}," +
602 "{@type=korap:span, key=vp}," +
603 "{@type=korap:span, key=pp}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000604 "]}";
605 assertTrue(equalsQueryContent(seq2, "<np><vp><pp>"));
606 }
607
608 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000609 public void testClasses() throws QueryException {
Joachim Bingel0900a892014-06-30 16:26:21 +0000610 String query;
Joachim Bingel53333e62013-12-09 19:25:52 +0000611 // {[base=Mann]}
Joachim Bingel2daf9862014-02-12 10:18:54 +0000612 String cls1 = "{@type=korap:group, operation=operation:class, class=0, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000613 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000614 "]}";
Joachim Bingel8c640e42014-02-07 16:20:47 +0000615 ppt = new PoliqarpPlusTree("{[base=Mann]}");
616 map = ppt.getRequestMap().get("query").toString();
617 assertEquals(cls1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000618
619 // {[base=Mann][orth=Frau]}
Joachim Bingel0900a892014-06-30 16:26:21 +0000620 query = "{[base=Mann][orth=Frau]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000621 String cls2 = "{@type=korap:group, operation=operation:class, class=0, operands=[" +
622 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000623 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}," +
624 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000625 "]}" +
626 "]}";
Joachim Bingel0900a892014-06-30 16:26:21 +0000627 ppt = new PoliqarpPlusTree(query);
628 map = ppt.getRequestMap().get("query").toString();
629 assertEquals(cls2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000630
631 // [p=NN]{[base=Mann][orth=Frau]}
Joachim Bingel2daf9862014-02-12 10:18:54 +0000632 String cls3 = "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000633 "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000634 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
635 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000636 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}," +
637 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000638 "]}" +
639 "]}" +
640 "]}";
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000641 ppt = new PoliqarpPlusTree("[p=NN]{[base=Mann][orth=Frau]}");
642 map = ppt.getRequestMap().get("query").toString();
643 assertEquals(cls3.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000644
645 // {[base=Mann][orth=Frau]}[p=NN]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000646 String cls4 = "{@type=korap:group, operation=operation:sequence, operands=[" +
647 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
648 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000649 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}," +
650 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000651 "]}" +
652 "]}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000653 "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000654 "]}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000655 ppt = new PoliqarpPlusTree("{[base=Mann][orth=Frau]}[p=NN]");
656 map = ppt.getRequestMap().get("query").toString();
657 assertEquals(cls4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000658
659 // {2:{1:[tt/p=ADJA]}[mate/p=NN]}"
Joachim Bingel2daf9862014-02-12 10:18:54 +0000660 String cls5 = "{@type=korap:group, operation=operation:class, class=2, operands=[" +
661 "{@type=korap:group, operation=operation:sequence, operands=[" +
662 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000663 "{@type=korap:token, wrap={@type=korap:term, foundry=tt, layer=p, key=ADJA, match=match:eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000664 "]}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000665 "{@type=korap:token, wrap={@type=korap:term, foundry=mate, layer=p, key=NN, match=match:eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000666 "]}" +
667 "]}";
668 ppt = new PoliqarpPlusTree("{2: {1:[tt/p=ADJA]}[mate/p=NN]}");
669 map = ppt.getRequestMap().get("query").toString();
670 assertEquals(cls5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000671 }
672
673 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000674 public void testPositions() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000675 // contains(<s>,<np>)
Joachim Bingel2daf9862014-02-12 10:18:54 +0000676 String pos1 = "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
677 "{@type=korap:span, key=s}," +
678 "{@type=korap:span, key=np}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000679 "]}";
680 assertTrue(equalsQueryContent(pos1, "contains(<s>,<np>)"));
681
682 // contains(<s>,[base=Mann])
Joachim Bingel2daf9862014-02-12 10:18:54 +0000683 String pos2 = "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
684 "{@type=korap:span, key=s}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000685 "{@type=korap:token, wrap= {@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000686 "]}";
687 assertTrue(equalsQueryContent(pos2, "contains(<s>,[base=Mann])"));
688
689 // contains(<s>,[orth=der][orth=Mann])
Joachim Bingel2daf9862014-02-12 10:18:54 +0000690 String pos3 = "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
691 "{@type=korap:span, key=s}," +
692 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000693 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
694 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000695 "]}" +
696 "]}";
697 ppt = new PoliqarpPlusTree("contains(<s>,[orth=der][orth=Mann])");
698 map = ppt.getRequestMap().get("query").toString();
699 assertEquals(pos3.replaceAll(" ", ""), map.replaceAll(" ", ""));
700
701 // [base=Auto]contains(<s>,[base=Mann])
702 String pos4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000703 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000704 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Auto, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000705 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
706 "{@type=korap:span, key=s}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000707 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000708 "]}" +
709 "]}";
710 ppt = new PoliqarpPlusTree("[base=Auto]contains(<s>,[base=Mann])");
711 map = ppt.getRequestMap().get("query").toString();
712 assertEquals(pos4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelef7059b2014-04-22 13:44:19 +0000713
714 // contains(<s>,[pos=N]*)
715 String pos5 =
716 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
717 "{@type=korap:span, key=s}," +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000718 "{@type=korap:group, operation=operation:repetition, " +
Joachim Bingel0900a892014-06-30 16:26:21 +0000719 "operands=[{@type=korap:token, wrap={@type=korap:term, layer=pos, key=N, match=match:eq}}" +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000720 "], min=0, max=100" +
Joachim Bingelef7059b2014-04-22 13:44:19 +0000721 "}" +
722 "]}";
723 ppt = new PoliqarpPlusTree("contains(<s>,[pos=N]*)");
724 map = ppt.getRequestMap().get("query").toString();
725 assertEquals(pos5.replaceAll(" ", ""), map.replaceAll(" ", ""));
726
727 // [base=Auto]contains(<s>,[pos=N]*)
728 String pos6 =
729 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000730 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Auto, match=match:eq}}," +
Joachim Bingelef7059b2014-04-22 13:44:19 +0000731 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
732 "{@type=korap:span, key=s}," +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000733 "{@type=korap:group, operation=operation:repetition, " +
Joachim Bingel0900a892014-06-30 16:26:21 +0000734 "operands=[{@type=korap:token, wrap={@type=korap:term, layer=pos, key=N, match=match:eq}}" +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000735 "], min=0, max=100" +
Joachim Bingelef7059b2014-04-22 13:44:19 +0000736 "}" +
737 "]}" +
738 "]}";
739 ppt = new PoliqarpPlusTree("[base=Auto]contains(<s>,[pos=N]*)");
740 map = ppt.getRequestMap().get("query").toString();
741 assertEquals(pos6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000742 }
743
744 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000745 public void testNestedPositions() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000746 // contains(<s>,startswith(<np>,[orth=Der]))
747 String npos1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000748 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
749 "{@type=korap:span, key=s}," +
750 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
751 "{@type=korap:span, key=np}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000752 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000753 "]}" +
754 "]}";
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000755 ppt = new PoliqarpPlusTree("contains(<s>, startswith(<np>,[orth=Der]))");
Joachim Bingel53333e62013-12-09 19:25:52 +0000756 map = ppt.getRequestMap().get("query").toString();
757 assertEquals(npos1.replaceAll(" ", ""), map.replaceAll(" ", ""));
758 }
759
760 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000761 public void testShrinkSplit() throws QueryException {
Joachim Bingel0900a892014-06-30 16:26:21 +0000762 // focus([orth=Der]{[orth=Mann]})
Joachim Bingel53333e62013-12-09 19:25:52 +0000763 String shr1 =
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000764 "{@type=korap:reference, classRef=[0], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000765 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000766 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000767 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000768 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000769 "]}" +
770 "]}" +
771 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000772 ppt = new PoliqarpPlusTree("focus([orth=Der]{[orth=Mann]})");
Joachim Bingel53333e62013-12-09 19:25:52 +0000773 map = ppt.getRequestMap().get("query").toString();
774 assertEquals(shr1.replaceAll(" ", ""), map.replaceAll(" ", ""));
775
Joachim Bingel0900a892014-06-30 16:26:21 +0000776 // focus([orth=Der]{[orth=Mann][orth=geht]})
Joachim Bingel53333e62013-12-09 19:25:52 +0000777 String shr2 =
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000778 "{@type=korap:reference, classRef=[0], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000779 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000780 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000781 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
782 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000783 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}," +
784 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=geht, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000785 "]}" +
786 "]}" +
787 "]}" +
788 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000789 ppt = new PoliqarpPlusTree("focus([orth=Der]{[orth=Mann][orth=geht]})");
Joachim Bingel53333e62013-12-09 19:25:52 +0000790 map = ppt.getRequestMap().get("query").toString();
791 assertEquals(shr2.replaceAll(" ", ""), map.replaceAll(" ", ""));
792
Joachim Bingel0900a892014-06-30 16:26:21 +0000793 // focus(1:[orth=Der]{1:[orth=Mann][orth=geht]})
Joachim Bingel53333e62013-12-09 19:25:52 +0000794 String shr3 =
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000795 "{@type=korap:reference, classRef=[1], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000796 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000797 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000798 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
799 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000800 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}," +
801 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=geht, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000802 "]}" +
803 "]}" +
804 "]}" +
805 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000806 ppt = new PoliqarpPlusTree("focus(1:[orth=Der]{1:[orth=Mann][orth=geht]})");
Joachim Bingel53333e62013-12-09 19:25:52 +0000807 map = ppt.getRequestMap().get("query").toString();
808 assertEquals(shr3.replaceAll(" ", ""), map.replaceAll(" ", ""));
809
Joachim Bingel0900a892014-06-30 16:26:21 +0000810 // focus(1:startswith(<s>,{1:<np>}))
Joachim Bingel53333e62013-12-09 19:25:52 +0000811 String shr4 =
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000812 "{@type=korap:reference, classRef=[1], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000813 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
814 "{@type=korap:span, key=s}," +
815 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
816 "{@type=korap:span, key=np}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000817 "]}" +
818 "]}" +
819 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000820 ppt = new PoliqarpPlusTree("focus(1:startswith(<s>,{1:<np>}))");
Joachim Bingel53333e62013-12-09 19:25:52 +0000821 map = ppt.getRequestMap().get("query").toString();
822 assertEquals(shr4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000823
Joachim Bingel0900a892014-06-30 16:26:21 +0000824 // focus(3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000825 String shr5 =
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000826 "{@type=korap:reference, classRef=[3], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000827 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
828 "{@type=korap:span, key=s}," +
829 "{@type=korap:group, operation=operation:class, class=3, operands=[" +
830 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000831 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000832 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
833 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000834 "{@type=korap:token, wrap={@type=korap:term, foundry=mate, layer=p, key=ADJA, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000835 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000836 "{@type=korap:token, wrap={@type=korap:term, foundry=tt, layer=p, key=NN, match=match:eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000837 "]}" +
838 "]}" +
839 "]}" +
840 "]}" +
841 "]}" +
842 "]}" +
843 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000844 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 +0000845 map = ppt.getRequestMap().get("query").toString();
846 assertEquals(shr5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000847
848 // split(3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))
849 String shr6 =
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000850 "{@type=korap:reference, classRef=[3], operation=operation:split, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000851 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
852 "{@type=korap:span, key=s}," +
853 "{@type=korap:group, operation=operation:class, class=3, operands=[" +
854 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000855 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000856 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
857 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000858 "{@type=korap:token, wrap={@type=korap:term, foundry=mate, layer=p, key=ADJA, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000859 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000860 "{@type=korap:token, wrap={@type=korap:term, foundry=tt, layer=p, key=NN, match=match:eq}}" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000861 "]}" +
862 "]}" +
863 "]}" +
864 "]}" +
865 "]}" +
866 "]}" +
867 "]}";
868 ppt = new PoliqarpPlusTree("split(3:startswith(<s>,{3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) ");
869 map = ppt.getRequestMap().get("query").toString();
870 assertEquals(shr6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel8c640e42014-02-07 16:20:47 +0000871
872 // split(2|3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))
873 String shr7 =
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000874 "{@type=korap:reference, classRef=[2, 3], operation=operation:split, classRefOp=classRefOp:intersection, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000875 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
876 "{@type=korap:span, key=s}," +
877 "{@type=korap:group, operation=operation:class, class=3, operands=[" +
878 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000879 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000880 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
881 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000882 "{@type=korap:token, wrap={@type=korap:term, foundry=mate, layer=p, key=ADJA, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000883 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000884 "{@type=korap:token, wrap={@type=korap:term, foundry=tt, layer=p, key=NN, match=match:eq}}" +
Joachim Bingel8c640e42014-02-07 16:20:47 +0000885 "]}" +
886 "]}" +
887 "]}" +
888 "]}" +
889 "]}" +
890 "]}" +
891 "]}";
892 ppt = new PoliqarpPlusTree("split(2|3:startswith(<s>,{3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) ");
893 map = ppt.getRequestMap().get("query").toString();
894 assertEquals(shr7.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel5146ebe2014-06-12 08:49:21 +0000895
896
897 String shr8 =
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000898 "{@type=korap:reference, classRef=[1], operands=[" +
Joachim Bingeladd0fb12014-06-24 08:54:14 +0000899 "{@type=korap:group, operation=operation:sequence, operands=[" +
900 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000901 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}" +
Joachim Bingeladd0fb12014-06-24 08:54:14 +0000902 "]}," +
903 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000904 "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=ADJA, match=match:eq}}" +
Joachim Bingel5146ebe2014-06-12 08:49:21 +0000905 "]}" +
Joachim Bingeladd0fb12014-06-24 08:54:14 +0000906 "]}" +
907 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000908 ppt = new PoliqarpPlusTree("focus(1:{[base=der]}{1:[pos=ADJA]})");
Joachim Bingeladd0fb12014-06-24 08:54:14 +0000909 map = ppt.getRequestMap().get("query").toString();
910 assertEquals(shr8.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel5146ebe2014-06-12 08:49:21 +0000911
Joachim Bingel53333e62013-12-09 19:25:52 +0000912 }
913
Joachim Bingel03882702013-12-31 19:53:05 +0000914
Joachim Bingel53333e62013-12-09 19:25:52 +0000915 @Test
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000916 public void testFoundries() throws QueryException {
917 // [tt/base=Mann]
Joachim Bingel0900a892014-06-30 16:26:21 +0000918 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 +0000919 ppt = new PoliqarpPlusTree("[tt/base=Mann]");
920 map = ppt.getRequestMap().get("query").toString();
921 assertEquals(layer1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000922
923 }
Joachim Bingel16da4e12013-12-17 09:48:12 +0000924
925 @Test
Joachim Bingel8c640e42014-02-07 16:20:47 +0000926 public void testAlign() throws QueryException {
Joachim Bingel16da4e12013-12-17 09:48:12 +0000927 // [orth=der]^[orth=Mann]
928 String align1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000929 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000930 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
931 "{@type=korap:group, operation=operation:alignment, operands=[" +
932 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" +
933 "], align=align:left}" +
Joachim Bingel16da4e12013-12-17 09:48:12 +0000934 "]}";
935 ppt = new PoliqarpPlusTree("[orth=der]^[orth=Mann]");
936 map = ppt.getRequestMap().get("query").toString();
937 assertEquals(align1.replaceAll(" ", ""), map.replaceAll(" ", ""));
938
Joachim Bingel84e33df2014-01-31 14:02:46 +0000939 // [orth=der]^[orth=große][orth=Mann]
940 String query = "[orth=der]^[orth=große][orth=Mann]";
941 String align1b =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000942 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000943 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
944 "{@type=korap:group, operation=operation:alignment, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000945 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000946 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=große, match=match:eq}}," +
947 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +0000948 "]}" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000949 "], align=align:left}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +0000950 "]}";
951 ppt = new PoliqarpPlusTree(query);
952 map = ppt.getRequestMap().get("query").toString();
953 assertEquals(align1b.replaceAll(" ", ""), map.replaceAll(" ", ""));
954
Joachim Bingel16da4e12013-12-17 09:48:12 +0000955 // "([base=a]^[base=b])|[base=c]",
956 String align2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000957 "{@type=korap:group, operation=operation:or, operands=[" +
958 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000959 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=a, match=match:eq}}," +
960 "{@type=korap:group, operation=operation:alignment, operands=[" +
961 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=b, match=match:eq}}" +
962 "], align=align:left}" +
Joachim Bingel16da4e12013-12-17 09:48:12 +0000963 "]}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000964 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=c, match=match:eq}}" +
Joachim Bingel16da4e12013-12-17 09:48:12 +0000965 "]}";
966 ppt = new PoliqarpPlusTree("([base=a]^[base=b])|[base=c]");
967 map = ppt.getRequestMap().get("query").toString();
968 assertEquals(align2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingela67e6a32014-01-02 18:35:24 +0000969
970 // "([base=a]^[base=b][base=c])|[base=d]",
971 String align3 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000972 "{@type=korap:group, operation=operation:or, operands=[" +
973 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000974 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=a, match=match:eq}}," +
975 "{@type=korap:group, operation=operation:alignment, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000976 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000977 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=b, match=match:eq}}," +
978 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=c, match=match:eq}}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +0000979 "]}" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000980 "], align=align:left}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000981 "]}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000982 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=d, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000983 "]}";
984 ppt = new PoliqarpPlusTree("([base=a]^[base=b][base=c])|[base=d]");
985 map = ppt.getRequestMap().get("query").toString();
986 assertEquals(align3.replaceAll(" ", ""), map.replaceAll(" ", ""));
987
988 // "([base=a]^[base=b]^[base=c])|[base=d]",
989 String align4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000990 "{@type=korap:group, operation=operation:or, operands=[" +
991 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000992 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=a, match=match:eq}}," +
993 "{@type=korap:group, operation=operation:alignment, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000994 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000995 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=b, match=match:eq}}," +
996 "{@type=korap:group, operation=operation:alignment, operands=[" +
997 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=c, match=match:eq}}" +
998 "], align=align:left}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +0000999 "]}" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001000 "], align=align:left}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +00001001 "]}," +
Joachim Bingel0900a892014-06-30 16:26:21 +00001002 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=d, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +00001003 "]}";
1004 ppt = new PoliqarpPlusTree("([base=a]^[base=b]^[base=c])|[base=d]");
1005 map = ppt.getRequestMap().get("query").toString();
1006 assertEquals(align4.replaceAll(" ", ""), map.replaceAll(" ", ""));
1007
1008
Joachim Bingel16da4e12013-12-17 09:48:12 +00001009 }
1010
1011 @Test
Joachim Bingel8c640e42014-02-07 16:20:47 +00001012 public void testSimpleQueries() throws QueryException {
Joachim Bingela67e6a32014-01-02 18:35:24 +00001013 // Baum
1014 String simple1 =
Joachim Bingel0900a892014-06-30 16:26:21 +00001015 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq}}";
Joachim Bingela67e6a32014-01-02 18:35:24 +00001016 ppt = new PoliqarpPlusTree("Baum");
1017 map = ppt.getRequestMap().get("query").toString();
1018 assertEquals(simple1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel0900a892014-06-30 16:26:21 +00001019
1020 // Baum/i
1021 String simple1b =
1022 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq, caseInsensitive=true}}";
1023 ppt = new PoliqarpPlusTree("Baum/i");
1024 map = ppt.getRequestMap().get("query").toString();
1025 assertEquals(simple1b.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel16da4e12013-12-17 09:48:12 +00001026
Joachim Bingela67e6a32014-01-02 18:35:24 +00001027 // Der Baum
1028 String simple2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001029 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001030 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}, " +
1031 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +00001032 "]}";
1033 ppt = new PoliqarpPlusTree("Der Baum");
1034 map = ppt.getRequestMap().get("query").toString();
1035 assertEquals(simple2.replaceAll(" ", ""), map.replaceAll(" ", ""));
1036
Joachim Bingel0900a892014-06-30 16:26:21 +00001037 // Der Baum/i
1038 String simple2b =
1039 "{@type=korap:group, operation=operation:sequence, operands=[" +
1040 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}, " +
1041 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq, caseInsensitive=true}}" +
1042 "]}";
1043 ppt = new PoliqarpPlusTree("Der Baum/i");
1044 map = ppt.getRequestMap().get("query").toString();
1045 assertEquals(simple2b.replaceAll(" ", ""), map.replaceAll(" ", ""));
1046
Joachim Bingela67e6a32014-01-02 18:35:24 +00001047 // Der große Baum
1048 String simple3 =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001049 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001050 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}, " +
1051 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=große, match=match:eq}}, " +
1052 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +00001053 "]}";
1054 ppt = new PoliqarpPlusTree("Der große Baum");
1055 map = ppt.getRequestMap().get("query").toString();
1056 assertEquals(simple3.replaceAll(" ", ""), map.replaceAll(" ", ""));
1057
1058 // Baum | Stein
1059 String simple4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001060 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001061 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq}}, " +
1062 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Stein, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +00001063 "]}";
1064 ppt = new PoliqarpPlusTree("Baum | Stein");
1065 map = ppt.getRequestMap().get("query").toString();
1066 assertEquals(simple4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel84e33df2014-01-31 14:02:46 +00001067
1068 // Baum | Stein Haus
1069 String query = "(Baum | Stein) Haus";
1070 String simple5 =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001071 "{@type=korap:group, operation=operation:sequence, operands=[" +
1072 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001073 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq}}, " +
1074 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Stein, match=match:eq}}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +00001075 "]}," +
Joachim Bingel0900a892014-06-30 16:26:21 +00001076 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Haus, match=match:eq}} " +
Joachim Bingel84e33df2014-01-31 14:02:46 +00001077 "]}";
1078 ppt = new PoliqarpPlusTree(query);
1079 map = ppt.getRequestMap().get("query").toString();
1080 assertEquals(simple5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel16da4e12013-12-17 09:48:12 +00001081 }
Joachim Bingel53333e62013-12-09 19:25:52 +00001082}
1083