blob: 7e2afc1c6fbaee770848ab005a25946348ef2da3 [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 Bingel33bd45f2014-06-25 15:00:54 +0000197 "], offset-min=1, offset-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 Bingel53333e62013-12-09 19:25:52 +0000430 }
431
432 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000433 public void testTokenSequence() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000434 // [base=Mann][orth=Frau]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000435 String seq1 = "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000436 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}, " +
437 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000438 "]}";
439 assertTrue(equalsQueryContent(seq1, "[base=Mann][orth=Frau]"));
440
441 // [base=Mann][orth=Frau][p=NN]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000442 String seq2 = "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000443 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}, " +
444 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}, " +
445 "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000446 "]}";
447 assertTrue(equalsQueryContent(seq2, "[base=Mann][orth=Frau][p=NN]"));
448 }
449
450 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000451 public void testDisjSegments() throws QueryException {
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000452 // ([base=der]|[base=das])[base=Schild]
453 String disj1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000454 "{@type=korap:group, operation=operation:sequence, operands=[" +
455 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000456 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
457 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=das, match=match:eq}}" +
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000458 "]}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000459 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Schild, match=match:eq}}" +
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000460 "]}";
461 ppt = new PoliqarpPlusTree("([base=der]|[base=das])[base=Schild]");
462 map = ppt.getRequestMap().get("query").toString();
463 assertEquals(disj1.replaceAll(" ", ""), map.replaceAll(" ", ""));
464
465 // [base=Schild]([base=der]|[base=das])
466 String disj2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000467 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000468 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Schild, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000469 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000470 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
471 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=das, match=match:eq}}" +
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000472 "]}" +
473 "]}";
474 ppt = new PoliqarpPlusTree("[base=Schild]([base=der]|[base=das])");
475 map = ppt.getRequestMap().get("query").toString();
476 assertEquals(disj2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel76b498d2014-06-06 12:06:46 +0000477
478 // "([orth=der][base=katze])|([orth=eine][base=baum])"
479 String disj3 =
480 "{@type=korap:group, operation=operation:or, operands=[" +
481 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000482 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
483 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=katze, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000484 "]}," +
485 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000486 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=eine, match=match:eq}}," +
487 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=baum, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000488 "]}" +
489 "]}";
490 ppt = new PoliqarpPlusTree("([orth=der][base=katze])|([orth=eine][base=baum])");
491 map = ppt.getRequestMap().get("query").toString();
492 assertEquals(disj3.replaceAll(" ", ""), map.replaceAll(" ", ""));
493
494 // "[orth=der][base=katze]|[orth=eine][base=baum]"
495 String disj4 =
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(disj4.replaceAll(" ", ""), map.replaceAll(" ", ""));
509
510 PoliqarpPlusTree ppt1 = new PoliqarpPlusTree("[orth=der][base=katze]|[orth=eine][base=baum]");
511 PoliqarpPlusTree ppt2 = new PoliqarpPlusTree("([orth=der][base=katze])|([orth=eine][base=baum])");
512 assertEquals(ppt1.getRequestMap().toString(), ppt2.getRequestMap().toString());
513
514 // "[orth=der][base=katze]|[orth=der][base=hund]|[orth=der][base=baum]"
515 String disj5 =
516 "{@type=korap:group, operation=operation:or, operands=[" +
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=der, match=match:eq}}," +
519 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=katze, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000520 "]}," +
521 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000522 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
523 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=hund, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000524 "]}," +
525 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000526 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
527 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=baum, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000528 "]}" +
529 "]}";
530 ppt = new PoliqarpPlusTree("[orth=der][base=katze]|[orth=der][base=hund]|[orth=der][base=baum]");
531 map = ppt.getRequestMap().get("query").toString();
532 assertEquals(disj5.replaceAll(" ", ""), map.replaceAll(" ", ""));
533
534 // [orth=der]([base=katze]|[base=hund]|[base=baum])
535 String disj6 =
536 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000537 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000538 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000539 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=katze, match=match:eq}}," +
540 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=hund, match=match:eq}}," +
541 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=baum, match=match:eq}}" +
Joachim Bingel76b498d2014-06-06 12:06:46 +0000542 "]}" +
543 "]}";
544 ppt = new PoliqarpPlusTree("[orth=der]([base=katze]|[base=hund]|[base=baum])");
545 map = ppt.getRequestMap().get("query").toString();
546 assertEquals(disj6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000547 }
548
549 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000550 public void testTokenElemSequence() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000551 // [base=Mann]<vp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000552 String seq1 = "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000553 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}, " +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000554 "{@type=korap:span, key=vp}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000555 "]}";
556 assertTrue(equalsQueryContent(seq1, "[base=Mann]<vp>"));
557
558 // <vp>[base=Mann]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000559 String seq2 = "{@type=korap:group, operation=operation:sequence, operands=[" +
560 "{@type=korap:span, key=vp}, "+
Joachim Bingel0900a892014-06-30 16:26:21 +0000561 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}} " +
Joachim Bingel53333e62013-12-09 19:25:52 +0000562 "]}";
563 assertTrue(equalsQueryContent(seq2, "<vp>[base=Mann]"));
564
565 // <vp>[base=Mann]<pp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000566 String seq3 = "{@type=korap:group, operation=operation:sequence, operands=[" +
567 "{@type=korap:span, key=vp}, "+
Joachim Bingel0900a892014-06-30 16:26:21 +0000568 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}, " +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000569 "{@type=korap:span, key=pp} "+
Joachim Bingel53333e62013-12-09 19:25:52 +0000570 "]}";
571 assertTrue(equalsQueryContent(seq3, "<vp>[base=Mann]<pp>"));
572 }
573
574 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000575 public void testElemSequence() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000576 // <np><vp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000577 String seq1 = "{@type=korap:group, operation=operation:sequence, operands=[" +
578 "{@type=korap:span, key=np}," +
579 "{@type=korap:span, key=vp}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000580 "]}";
581 assertTrue(equalsQueryContent(seq1, "<np><vp>"));
582
583 // <np><vp><pp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000584 String seq2 = "{@type=korap:group, operation=operation:sequence, operands=[" +
585 "{@type=korap:span, key=np}," +
586 "{@type=korap:span, key=vp}," +
587 "{@type=korap:span, key=pp}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000588 "]}";
589 assertTrue(equalsQueryContent(seq2, "<np><vp><pp>"));
590 }
591
592 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000593 public void testClasses() throws QueryException {
Joachim Bingel0900a892014-06-30 16:26:21 +0000594 String query;
Joachim Bingel53333e62013-12-09 19:25:52 +0000595 // {[base=Mann]}
Joachim Bingel2daf9862014-02-12 10:18:54 +0000596 String cls1 = "{@type=korap:group, operation=operation:class, class=0, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000597 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000598 "]}";
Joachim Bingel8c640e42014-02-07 16:20:47 +0000599 ppt = new PoliqarpPlusTree("{[base=Mann]}");
600 map = ppt.getRequestMap().get("query").toString();
601 assertEquals(cls1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000602
603 // {[base=Mann][orth=Frau]}
Joachim Bingel0900a892014-06-30 16:26:21 +0000604 query = "{[base=Mann][orth=Frau]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000605 String cls2 = "{@type=korap:group, operation=operation:class, class=0, operands=[" +
606 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000607 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}," +
608 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000609 "]}" +
610 "]}";
Joachim Bingel0900a892014-06-30 16:26:21 +0000611 ppt = new PoliqarpPlusTree(query);
612 map = ppt.getRequestMap().get("query").toString();
613 assertEquals(cls2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000614
615 // [p=NN]{[base=Mann][orth=Frau]}
Joachim Bingel2daf9862014-02-12 10:18:54 +0000616 String cls3 = "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000617 "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000618 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
619 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000620 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}," +
621 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000622 "]}" +
623 "]}" +
624 "]}";
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000625 ppt = new PoliqarpPlusTree("[p=NN]{[base=Mann][orth=Frau]}");
626 map = ppt.getRequestMap().get("query").toString();
627 assertEquals(cls3.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000628
629 // {[base=Mann][orth=Frau]}[p=NN]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000630 String cls4 = "{@type=korap:group, operation=operation:sequence, operands=[" +
631 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
632 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000633 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}," +
634 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000635 "]}" +
636 "]}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000637 "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000638 "]}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000639 ppt = new PoliqarpPlusTree("{[base=Mann][orth=Frau]}[p=NN]");
640 map = ppt.getRequestMap().get("query").toString();
641 assertEquals(cls4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000642
643 // {2:{1:[tt/p=ADJA]}[mate/p=NN]}"
Joachim Bingel2daf9862014-02-12 10:18:54 +0000644 String cls5 = "{@type=korap:group, operation=operation:class, class=2, operands=[" +
645 "{@type=korap:group, operation=operation:sequence, operands=[" +
646 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000647 "{@type=korap:token, wrap={@type=korap:term, foundry=tt, layer=p, key=ADJA, match=match:eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000648 "]}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000649 "{@type=korap:token, wrap={@type=korap:term, foundry=mate, layer=p, key=NN, match=match:eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000650 "]}" +
651 "]}";
652 ppt = new PoliqarpPlusTree("{2: {1:[tt/p=ADJA]}[mate/p=NN]}");
653 map = ppt.getRequestMap().get("query").toString();
654 assertEquals(cls5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000655 }
656
657 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000658 public void testPositions() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000659 // contains(<s>,<np>)
Joachim Bingel2daf9862014-02-12 10:18:54 +0000660 String pos1 = "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
661 "{@type=korap:span, key=s}," +
662 "{@type=korap:span, key=np}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000663 "]}";
664 assertTrue(equalsQueryContent(pos1, "contains(<s>,<np>)"));
665
666 // contains(<s>,[base=Mann])
Joachim Bingel2daf9862014-02-12 10:18:54 +0000667 String pos2 = "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
668 "{@type=korap:span, key=s}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000669 "{@type=korap:token, wrap= {@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000670 "]}";
671 assertTrue(equalsQueryContent(pos2, "contains(<s>,[base=Mann])"));
672
673 // contains(<s>,[orth=der][orth=Mann])
Joachim Bingel2daf9862014-02-12 10:18:54 +0000674 String pos3 = "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
675 "{@type=korap:span, key=s}," +
676 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000677 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
678 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000679 "]}" +
680 "]}";
681 ppt = new PoliqarpPlusTree("contains(<s>,[orth=der][orth=Mann])");
682 map = ppt.getRequestMap().get("query").toString();
683 assertEquals(pos3.replaceAll(" ", ""), map.replaceAll(" ", ""));
684
685 // [base=Auto]contains(<s>,[base=Mann])
686 String pos4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000687 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000688 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Auto, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000689 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
690 "{@type=korap:span, key=s}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000691 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000692 "]}" +
693 "]}";
694 ppt = new PoliqarpPlusTree("[base=Auto]contains(<s>,[base=Mann])");
695 map = ppt.getRequestMap().get("query").toString();
696 assertEquals(pos4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelef7059b2014-04-22 13:44:19 +0000697
698 // contains(<s>,[pos=N]*)
699 String pos5 =
700 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
701 "{@type=korap:span, key=s}," +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000702 "{@type=korap:group, operation=operation:repetition, " +
Joachim Bingel0900a892014-06-30 16:26:21 +0000703 "operands=[{@type=korap:token, wrap={@type=korap:term, layer=pos, key=N, match=match:eq}}" +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000704 "], min=0, max=100" +
Joachim Bingelef7059b2014-04-22 13:44:19 +0000705 "}" +
706 "]}";
707 ppt = new PoliqarpPlusTree("contains(<s>,[pos=N]*)");
708 map = ppt.getRequestMap().get("query").toString();
709 assertEquals(pos5.replaceAll(" ", ""), map.replaceAll(" ", ""));
710
711 // [base=Auto]contains(<s>,[pos=N]*)
712 String pos6 =
713 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000714 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Auto, match=match:eq}}," +
Joachim Bingelef7059b2014-04-22 13:44:19 +0000715 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
716 "{@type=korap:span, key=s}," +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000717 "{@type=korap:group, operation=operation:repetition, " +
Joachim Bingel0900a892014-06-30 16:26:21 +0000718 "operands=[{@type=korap:token, wrap={@type=korap:term, layer=pos, key=N, match=match:eq}}" +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000719 "], min=0, max=100" +
Joachim Bingelef7059b2014-04-22 13:44:19 +0000720 "}" +
721 "]}" +
722 "]}";
723 ppt = new PoliqarpPlusTree("[base=Auto]contains(<s>,[pos=N]*)");
724 map = ppt.getRequestMap().get("query").toString();
725 assertEquals(pos6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000726 }
727
728 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000729 public void testNestedPositions() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000730 // contains(<s>,startswith(<np>,[orth=Der]))
731 String npos1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000732 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
733 "{@type=korap:span, key=s}," +
734 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
735 "{@type=korap:span, key=np}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000736 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000737 "]}" +
738 "]}";
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000739 ppt = new PoliqarpPlusTree("contains(<s>, startswith(<np>,[orth=Der]))");
Joachim Bingel53333e62013-12-09 19:25:52 +0000740 map = ppt.getRequestMap().get("query").toString();
741 assertEquals(npos1.replaceAll(" ", ""), map.replaceAll(" ", ""));
742 }
743
744 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000745 public void testShrinkSplit() throws QueryException {
Joachim Bingel0900a892014-06-30 16:26:21 +0000746 // focus([orth=Der]{[orth=Mann]})
Joachim Bingel53333e62013-12-09 19:25:52 +0000747 String shr1 =
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000748 "{@type=korap:reference, classRef=[0], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000749 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000750 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000751 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000752 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000753 "]}" +
754 "]}" +
755 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000756 ppt = new PoliqarpPlusTree("focus([orth=Der]{[orth=Mann]})");
Joachim Bingel53333e62013-12-09 19:25:52 +0000757 map = ppt.getRequestMap().get("query").toString();
758 assertEquals(shr1.replaceAll(" ", ""), map.replaceAll(" ", ""));
759
Joachim Bingel0900a892014-06-30 16:26:21 +0000760 // focus([orth=Der]{[orth=Mann][orth=geht]})
Joachim Bingel53333e62013-12-09 19:25:52 +0000761 String shr2 =
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000762 "{@type=korap:reference, classRef=[0], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000763 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000764 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000765 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
766 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000767 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}," +
768 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=geht, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000769 "]}" +
770 "]}" +
771 "]}" +
772 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000773 ppt = new PoliqarpPlusTree("focus([orth=Der]{[orth=Mann][orth=geht]})");
Joachim Bingel53333e62013-12-09 19:25:52 +0000774 map = ppt.getRequestMap().get("query").toString();
775 assertEquals(shr2.replaceAll(" ", ""), map.replaceAll(" ", ""));
776
Joachim Bingel0900a892014-06-30 16:26:21 +0000777 // focus(1:[orth=Der]{1:[orth=Mann][orth=geht]})
Joachim Bingel53333e62013-12-09 19:25:52 +0000778 String shr3 =
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000779 "{@type=korap:reference, classRef=[1], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000780 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000781 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000782 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
783 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000784 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}," +
785 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=geht, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000786 "]}" +
787 "]}" +
788 "]}" +
789 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000790 ppt = new PoliqarpPlusTree("focus(1:[orth=Der]{1:[orth=Mann][orth=geht]})");
Joachim Bingel53333e62013-12-09 19:25:52 +0000791 map = ppt.getRequestMap().get("query").toString();
792 assertEquals(shr3.replaceAll(" ", ""), map.replaceAll(" ", ""));
793
Joachim Bingel0900a892014-06-30 16:26:21 +0000794 // focus(1:startswith(<s>,{1:<np>}))
Joachim Bingel53333e62013-12-09 19:25:52 +0000795 String shr4 =
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000796 "{@type=korap:reference, classRef=[1], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000797 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
798 "{@type=korap:span, key=s}," +
799 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
800 "{@type=korap:span, key=np}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000801 "]}" +
802 "]}" +
803 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000804 ppt = new PoliqarpPlusTree("focus(1:startswith(<s>,{1:<np>}))");
Joachim Bingel53333e62013-12-09 19:25:52 +0000805 map = ppt.getRequestMap().get("query").toString();
806 assertEquals(shr4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000807
Joachim Bingel0900a892014-06-30 16:26:21 +0000808 // focus(3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000809 String shr5 =
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000810 "{@type=korap:reference, classRef=[3], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000811 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
812 "{@type=korap:span, key=s}," +
813 "{@type=korap:group, operation=operation:class, class=3, operands=[" +
814 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000815 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000816 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
817 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000818 "{@type=korap:token, wrap={@type=korap:term, foundry=mate, layer=p, key=ADJA, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000819 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000820 "{@type=korap:token, wrap={@type=korap:term, foundry=tt, layer=p, key=NN, match=match:eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000821 "]}" +
822 "]}" +
823 "]}" +
824 "]}" +
825 "]}" +
826 "]}" +
827 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000828 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 +0000829 map = ppt.getRequestMap().get("query").toString();
830 assertEquals(shr5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000831
832 // split(3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))
833 String shr6 =
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000834 "{@type=korap:reference, classRef=[3], operation=operation:split, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000835 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
836 "{@type=korap:span, key=s}," +
837 "{@type=korap:group, operation=operation:class, class=3, operands=[" +
838 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000839 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000840 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
841 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000842 "{@type=korap:token, wrap={@type=korap:term, foundry=mate, layer=p, key=ADJA, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000843 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000844 "{@type=korap:token, wrap={@type=korap:term, foundry=tt, layer=p, key=NN, match=match:eq}}" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000845 "]}" +
846 "]}" +
847 "]}" +
848 "]}" +
849 "]}" +
850 "]}" +
851 "]}";
852 ppt = new PoliqarpPlusTree("split(3:startswith(<s>,{3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) ");
853 map = ppt.getRequestMap().get("query").toString();
854 assertEquals(shr6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel8c640e42014-02-07 16:20:47 +0000855
856 // split(2|3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))
857 String shr7 =
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000858 "{@type=korap:reference, classRef=[2, 3], operation=operation:split, classRefOp=classRefOp:intersection, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000859 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
860 "{@type=korap:span, key=s}," +
861 "{@type=korap:group, operation=operation:class, class=3, operands=[" +
862 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000863 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000864 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
865 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000866 "{@type=korap:token, wrap={@type=korap:term, foundry=mate, layer=p, key=ADJA, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000867 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000868 "{@type=korap:token, wrap={@type=korap:term, foundry=tt, layer=p, key=NN, match=match:eq}}" +
Joachim Bingel8c640e42014-02-07 16:20:47 +0000869 "]}" +
870 "]}" +
871 "]}" +
872 "]}" +
873 "]}" +
874 "]}" +
875 "]}";
876 ppt = new PoliqarpPlusTree("split(2|3:startswith(<s>,{3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) ");
877 map = ppt.getRequestMap().get("query").toString();
878 assertEquals(shr7.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel5146ebe2014-06-12 08:49:21 +0000879
880
881 String shr8 =
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000882 "{@type=korap:reference, classRef=[1], operands=[" +
Joachim Bingeladd0fb12014-06-24 08:54:14 +0000883 "{@type=korap:group, operation=operation:sequence, operands=[" +
884 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000885 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}" +
Joachim Bingeladd0fb12014-06-24 08:54:14 +0000886 "]}," +
887 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000888 "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=ADJA, match=match:eq}}" +
Joachim Bingel5146ebe2014-06-12 08:49:21 +0000889 "]}" +
Joachim Bingeladd0fb12014-06-24 08:54:14 +0000890 "]}" +
891 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000892 ppt = new PoliqarpPlusTree("focus(1:{[base=der]}{1:[pos=ADJA]})");
Joachim Bingeladd0fb12014-06-24 08:54:14 +0000893 map = ppt.getRequestMap().get("query").toString();
894 assertEquals(shr8.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel5146ebe2014-06-12 08:49:21 +0000895
Joachim Bingel53333e62013-12-09 19:25:52 +0000896 }
897
Joachim Bingel03882702013-12-31 19:53:05 +0000898
Joachim Bingel53333e62013-12-09 19:25:52 +0000899 @Test
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000900 public void testFoundries() throws QueryException {
901 // [tt/base=Mann]
Joachim Bingel0900a892014-06-30 16:26:21 +0000902 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 +0000903 ppt = new PoliqarpPlusTree("[tt/base=Mann]");
904 map = ppt.getRequestMap().get("query").toString();
905 assertEquals(layer1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000906
907 }
Joachim Bingel16da4e12013-12-17 09:48:12 +0000908
909 @Test
Joachim Bingel8c640e42014-02-07 16:20:47 +0000910 public void testAlign() throws QueryException {
Joachim Bingel16da4e12013-12-17 09:48:12 +0000911 // [orth=der]^[orth=Mann]
912 String align1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000913 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000914 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
915 "{@type=korap:group, operation=operation:alignment, operands=[" +
916 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" +
917 "], align=align:left}" +
Joachim Bingel16da4e12013-12-17 09:48:12 +0000918 "]}";
919 ppt = new PoliqarpPlusTree("[orth=der]^[orth=Mann]");
920 map = ppt.getRequestMap().get("query").toString();
921 assertEquals(align1.replaceAll(" ", ""), map.replaceAll(" ", ""));
922
Joachim Bingel84e33df2014-01-31 14:02:46 +0000923 // [orth=der]^[orth=große][orth=Mann]
924 String query = "[orth=der]^[orth=große][orth=Mann]";
925 String align1b =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000926 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000927 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," +
928 "{@type=korap:group, operation=operation:alignment, operands=[" +
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=große, match=match:eq}}," +
931 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +0000932 "]}" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000933 "], align=align:left}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +0000934 "]}";
935 ppt = new PoliqarpPlusTree(query);
936 map = ppt.getRequestMap().get("query").toString();
937 assertEquals(align1b.replaceAll(" ", ""), map.replaceAll(" ", ""));
938
Joachim Bingel16da4e12013-12-17 09:48:12 +0000939 // "([base=a]^[base=b])|[base=c]",
940 String align2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000941 "{@type=korap:group, operation=operation:or, operands=[" +
942 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000943 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=a, match=match:eq}}," +
944 "{@type=korap:group, operation=operation:alignment, operands=[" +
945 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=b, match=match:eq}}" +
946 "], align=align:left}" +
Joachim Bingel16da4e12013-12-17 09:48:12 +0000947 "]}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000948 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=c, match=match:eq}}" +
Joachim Bingel16da4e12013-12-17 09:48:12 +0000949 "]}";
950 ppt = new PoliqarpPlusTree("([base=a]^[base=b])|[base=c]");
951 map = ppt.getRequestMap().get("query").toString();
952 assertEquals(align2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingela67e6a32014-01-02 18:35:24 +0000953
954 // "([base=a]^[base=b][base=c])|[base=d]",
955 String align3 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000956 "{@type=korap:group, operation=operation:or, operands=[" +
957 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000958 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=a, match=match:eq}}," +
959 "{@type=korap:group, operation=operation:alignment, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000960 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000961 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=b, match=match:eq}}," +
962 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=c, match=match:eq}}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +0000963 "]}" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000964 "], align=align:left}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000965 "]}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000966 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=d, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000967 "]}";
968 ppt = new PoliqarpPlusTree("([base=a]^[base=b][base=c])|[base=d]");
969 map = ppt.getRequestMap().get("query").toString();
970 assertEquals(align3.replaceAll(" ", ""), map.replaceAll(" ", ""));
971
972 // "([base=a]^[base=b]^[base=c])|[base=d]",
973 String align4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000974 "{@type=korap:group, operation=operation:or, operands=[" +
975 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000976 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=a, match=match:eq}}," +
977 "{@type=korap:group, operation=operation:alignment, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000978 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000979 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=b, match=match:eq}}," +
980 "{@type=korap:group, operation=operation:alignment, operands=[" +
981 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=c, match=match:eq}}" +
982 "], align=align:left}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +0000983 "]}" +
Joachim Bingel0900a892014-06-30 16:26:21 +0000984 "], align=align:left}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000985 "]}," +
Joachim Bingel0900a892014-06-30 16:26:21 +0000986 "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=d, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000987 "]}";
988 ppt = new PoliqarpPlusTree("([base=a]^[base=b]^[base=c])|[base=d]");
989 map = ppt.getRequestMap().get("query").toString();
990 assertEquals(align4.replaceAll(" ", ""), map.replaceAll(" ", ""));
991
992
Joachim Bingel16da4e12013-12-17 09:48:12 +0000993 }
994
995 @Test
Joachim Bingel8c640e42014-02-07 16:20:47 +0000996 public void testSimpleQueries() throws QueryException {
Joachim Bingela67e6a32014-01-02 18:35:24 +0000997 // Baum
998 String simple1 =
Joachim Bingel0900a892014-06-30 16:26:21 +0000999 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq}}";
Joachim Bingela67e6a32014-01-02 18:35:24 +00001000 ppt = new PoliqarpPlusTree("Baum");
1001 map = ppt.getRequestMap().get("query").toString();
1002 assertEquals(simple1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel0900a892014-06-30 16:26:21 +00001003
1004 // Baum/i
1005 String simple1b =
1006 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq, caseInsensitive=true}}";
1007 ppt = new PoliqarpPlusTree("Baum/i");
1008 map = ppt.getRequestMap().get("query").toString();
1009 assertEquals(simple1b.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel16da4e12013-12-17 09:48:12 +00001010
Joachim Bingela67e6a32014-01-02 18:35:24 +00001011 // Der Baum
1012 String simple2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001013 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001014 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}, " +
1015 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +00001016 "]}";
1017 ppt = new PoliqarpPlusTree("Der Baum");
1018 map = ppt.getRequestMap().get("query").toString();
1019 assertEquals(simple2.replaceAll(" ", ""), map.replaceAll(" ", ""));
1020
Joachim Bingel0900a892014-06-30 16:26:21 +00001021 // Der Baum/i
1022 String simple2b =
1023 "{@type=korap:group, operation=operation:sequence, operands=[" +
1024 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}, " +
1025 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq, caseInsensitive=true}}" +
1026 "]}";
1027 ppt = new PoliqarpPlusTree("Der Baum/i");
1028 map = ppt.getRequestMap().get("query").toString();
1029 assertEquals(simple2b.replaceAll(" ", ""), map.replaceAll(" ", ""));
1030
Joachim Bingela67e6a32014-01-02 18:35:24 +00001031 // Der große Baum
1032 String simple3 =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001033 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001034 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}, " +
1035 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=große, match=match:eq}}, " +
1036 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +00001037 "]}";
1038 ppt = new PoliqarpPlusTree("Der große Baum");
1039 map = ppt.getRequestMap().get("query").toString();
1040 assertEquals(simple3.replaceAll(" ", ""), map.replaceAll(" ", ""));
1041
1042 // Baum | Stein
1043 String simple4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001044 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001045 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq}}, " +
1046 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Stein, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +00001047 "]}";
1048 ppt = new PoliqarpPlusTree("Baum | Stein");
1049 map = ppt.getRequestMap().get("query").toString();
1050 assertEquals(simple4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel84e33df2014-01-31 14:02:46 +00001051
1052 // Baum | Stein Haus
1053 String query = "(Baum | Stein) Haus";
1054 String simple5 =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001055 "{@type=korap:group, operation=operation:sequence, operands=[" +
1056 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingel0900a892014-06-30 16:26:21 +00001057 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq}}, " +
1058 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Stein, match=match:eq}}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +00001059 "]}," +
Joachim Bingel0900a892014-06-30 16:26:21 +00001060 "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Haus, match=match:eq}} " +
Joachim Bingel84e33df2014-01-31 14:02:46 +00001061 "]}";
1062 ppt = new PoliqarpPlusTree(query);
1063 map = ppt.getRequestMap().get("query").toString();
1064 assertEquals(simple5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel16da4e12013-12-17 09:48:12 +00001065 }
Joachim Bingel53333e62013-12-09 19:25:52 +00001066}
1067