blob: d2ffe72dbef4dacf16e67775f99a4cab2f1e2d6d [file] [log] [blame]
Joachim Bingel53333e62013-12-09 19:25:52 +00001import static org.junit.Assert.*;
2
3import org.junit.Test;
4
Joachim Bingel2daf9862014-02-12 10:18:54 +00005import de.ids_mannheim.korap.query.serialize.CosmasTree;
Joachim Bingel53333e62013-12-09 19:25:52 +00006import de.ids_mannheim.korap.query.serialize.PoliqarpPlusTree;
Joachim Bingel16da4e12013-12-17 09:48:12 +00007import de.ids_mannheim.korap.util.QueryException;
Joachim Bingel53333e62013-12-09 19:25:52 +00008
9public class PoliqarpPlusTreeTest {
10
11 PoliqarpPlusTree ppt;
12 String map;
13
14 private boolean equalsContent(String str, Object map) {
15 str = str.replaceAll(" ", "");
16 String mapStr = map.toString().replaceAll(" ", "");
17 return str.equals(mapStr);
18 }
19
Joachim Bingel16da4e12013-12-17 09:48:12 +000020 private boolean equalsQueryContent(String res, String query) throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +000021 res = res.replaceAll(" ", "");
22 ppt = new PoliqarpPlusTree(query);
23 String queryMap = ppt.getRequestMap().get("query").toString().replaceAll(" ", "");
24 return res.equals(queryMap);
25 }
26
Joachim Bingel11d5b152014-02-11 21:33:47 +000027// @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +000028 public void testContext() throws QueryException {
Joachim Bingel2daf9862014-02-12 10:18:54 +000029 String contextString = "{korap = http://korap.ids-mannheim.de/ns/KorAP/json-ld/v0.1/, " +
30 "boundary = korap:boundary/,"+
31 "group = korap:group/,"+
32 "operation = {@id = group:operation/, @type = @id},"+
33 "class = {@id = group:class, @type = xsd:integer},"+
34 "operands = {@id = group:operands, @container = @list},"+
35 "frame = {@id = group:frame/, @type = @id},"+
36 "classRef = {@id = group:classRef, @type = xsd:integer},"+
37 "spanRef = {@id = group:spanRef, @type = xsd:integer},"+
38 "classRefOp = {@id = group:classRefOp, @type = @id},"+
39 "min = {@id = boundary:min, @type = xsd:integer},"+
40 "max = {@id = boundary:max, @type = xsd:integer},"+
41 "exclude = {@id = group:exclude, @type = xsd:boolean},"+
42 "distances = {@id = group:distances, @container = @list},"+
43 "inOrder = {@id = group:inOrder, @type = xsd:boolean}"+
44 "}";
45 ppt = new PoliqarpPlusTree("Test");
46 assertEquals(contextString.replaceAll(" ", ""), ppt.getRequestMap().get("@context").toString().replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +000047 }
48
49 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +000050 public void testSingleTokens() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +000051 // [base=Mann]
Joachim Bingelee3b21d2014-02-12 12:34:59 +000052 String token1 = "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}";
Joachim Bingel53333e62013-12-09 19:25:52 +000053 assertTrue(equalsQueryContent(token1, "[base=Mann]"));
54
55 // [orth!=Frau]
Joachim Bingelee3b21d2014-02-12 12:34:59 +000056 String token2 = "{@type=korap:token, wrap={@type=korap:term, key=Frau, layer=orth, match=match:ne}}";
Joachim Bingel53333e62013-12-09 19:25:52 +000057 assertTrue(equalsQueryContent(token2, "[orth!=Frau]"));
58
59 // [!p=NN]
Joachim Bingelee3b21d2014-02-12 12:34:59 +000060 String token3 = "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, match=match:ne}}";
Joachim Bingel53333e62013-12-09 19:25:52 +000061 assertTrue(equalsQueryContent(token3, "[!p=NN]"));
62
63 // [!p!=NN]
Joachim Bingelee3b21d2014-02-12 12:34:59 +000064 String token4 = "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, match=match:eq}}";
Joachim Bingel53333e62013-12-09 19:25:52 +000065 assertTrue(equalsQueryContent(token4, "[!p!=NN]"));
66 }
67
68 @Test
Joachim Bingel41e112e2014-02-12 10:46:18 +000069 public void testRegex() throws QueryException {
70 String query = "[orth=\"M(a|ä)nn(er)?\"]";
Joachim Bingelbc537b62014-02-12 12:47:45 +000071 String re1 = "{@type=korap:token, wrap={@type=korap:term, type=type:regex, key=M(a|ä)nn(er)?, layer=orth, match=match:eq}}";
Joachim Bingel41e112e2014-02-12 10:46:18 +000072 ppt = new PoliqarpPlusTree(query);
73 map = ppt.getRequestMap().get("query").toString();
74 assertEquals(re1.replaceAll(" ", ""), map.replaceAll(" ", ""));
75 }
76
77 @Test
Joachim Bingel0207d5e2014-02-12 14:18:41 +000078 public void testCaseSensitivityFlag() throws QueryException {
79 String query="[orth=deutscher/i]";
80 String cs1 =
81 "{@type=korap:token, wrap={@type=korap:term, key=deutscher, layer=orth, match=match:eq, caseInsensitive=true}}";
82 ppt = new PoliqarpPlusTree(query);
83 map = ppt.getRequestMap().get("query").toString();
84 assertEquals(cs1.replaceAll(" ", ""), map.replaceAll(" ", ""));
85
86 query="[orth=deutscher/i][orth=Bundestag]";
87 String cs2 =
88 "{@type=korap:group, operation=operation:sequence, operands=[" +
89 "{@type=korap:token, wrap={@type=korap:term, key=deutscher, layer=orth, match=match:eq, caseInsensitive=true}}," +
90 "{@type=korap:token, wrap={@type=korap:term, key=Bundestag, layer=orth, match=match:eq}}" +
91 "]}";
92 ppt = new PoliqarpPlusTree(query);
93 map = ppt.getRequestMap().get("query").toString();
94 assertEquals(cs2.replaceAll(" ", ""), map.replaceAll(" ", ""));
95 }
96
97 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +000098 public void testElements() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +000099 // <s>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000100 String elem1 = "{@type=korap:span, key=s}";
Joachim Bingel53333e62013-12-09 19:25:52 +0000101 assertTrue(equalsQueryContent(elem1, "<s>"));
102
103 // <vp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000104 String elem2 = "{@type=korap:span, key=vp}";
Joachim Bingel53333e62013-12-09 19:25:52 +0000105 assertTrue(equalsQueryContent(elem2, "<vp>"));
106 }
Joachim Bingel87480d02014-01-17 14:07:46 +0000107
108 @Test
109 public void testEmptyTokens() throws QueryException {
110 // [base=der][][base=Mann]
111 String et1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000112 "{@type=korap:group, operation=operation:sequence, inOrder=true, distances=[" +
113 "{@type=korap:distance, key=w, min=1, max=1}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000114 "], " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000115 "operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000116 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=match:eq}}," +
117 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000118 "]}";
119 ppt = new PoliqarpPlusTree("[base=der][][base=Mann]");
120 map = ppt.getRequestMap().get("query").toString();
121 assertEquals(et1.replaceAll(" ", ""), map.replaceAll(" ", ""));
122
123 // [base=der][][][base=Mann]
124 String et2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000125 "{@type=korap:group, operation=operation:sequence, inOrder=true, distances=[" +
126 "{@type=korap:distance, key=w, min=2, max=2}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000127 "], " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000128 "operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000129 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=match:eq}}," +
130 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000131 "]}";
Joachim Bingelffd65e32014-01-22 14:22:57 +0000132 ppt = new PoliqarpPlusTree("[base=der][][][base=Mann]");
Joachim Bingel87480d02014-01-17 14:07:46 +0000133 map = ppt.getRequestMap().get("query").toString();
134 assertEquals(et2.replaceAll(" ", ""), map.replaceAll(" ", ""));
135
136 // [base=der][][]?[base=Mann]
137 String et3 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000138 "{@type=korap:group, operation=operation:sequence, inOrder=true, distances=[" +
139 "{@type=korap:distance, key=w, min=1, max=2}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000140 "], " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000141 "operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000142 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=match:eq}}," +
143 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000144 "]}";
145 ppt = new PoliqarpPlusTree("[base=der][][]?[base=Mann]");
146 map = ppt.getRequestMap().get("query").toString();
147 assertEquals(et3.replaceAll(" ", ""), map.replaceAll(" ", ""));
148
Joachim Bingel87480d02014-01-17 14:07:46 +0000149
150 // startswith(<s>, [][base=Mann]
Joachim Bingelffd65e32014-01-22 14:22:57 +0000151 String et4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000152 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
153 "{@type=korap:span, key=s}," +
154 "{@type=korap:group, operation=operation:sequence, offset-min=1, offset-max=1, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000155 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000156 "]}" +
157 "]}";
Joachim Bingelffd65e32014-01-22 14:22:57 +0000158 ppt = new PoliqarpPlusTree("startswith(<s>, [][base=Mann])");
159 map = ppt.getRequestMap().get("query").toString();
160 assertEquals(et4.replaceAll(" ", ""), map.replaceAll(" ", ""));
161
Joachim Bingel11d5b152014-02-11 21:33:47 +0000162 // [base=der][]{2,5}[base=Mann][]?[][base=Frau] nested distances=
Joachim Bingelffd65e32014-01-22 14:22:57 +0000163 String et5 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000164 "{@type=korap:group, operation=operation:sequence, inOrder=true, distances=[" +
165 "{@type=korap:distance, key=w, min=2, max=5}" +
Joachim Bingelffd65e32014-01-22 14:22:57 +0000166 "], " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000167 "operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000168 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000169 "{@type=korap:group, operation=operation:sequence, inOrder=true, distances=[" +
170 "{@type=korap:distance, key=w, min=1, max=2}" +
Joachim Bingelffd65e32014-01-22 14:22:57 +0000171 "], " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000172 "operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000173 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}," +
174 "{@type=korap:token, wrap={@type=korap:term, key=Frau, layer=lemma, match=match:eq}}" +
Joachim Bingelffd65e32014-01-22 14:22:57 +0000175 "]}" +
176 "]}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000177 ppt = new PoliqarpPlusTree("[base=der][]{2,5}[base=Mann][]?[][base=Frau]");
Joachim Bingel87480d02014-01-17 14:07:46 +0000178 map = ppt.getRequestMap().get("query").toString();
179 assertEquals(et5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel87480d02014-01-17 14:07:46 +0000180
181 }
Joachim Bingel53333e62013-12-09 19:25:52 +0000182
183 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000184 public void testCoordinatedFields() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000185 // [base=Mann&(cas=N|cas=A)]
186 String cof1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000187 "{@type=korap:token, wrap=" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000188 "{@type=korap:termGroup, relation=and, operands=[" +
189 "{@type=korap:term, key=Mann, layer=lemma, match=match:eq}," +
190 "{@type=korap:termGroup, relation=or, operands=[" +
191 "{@type=korap:term, key=N, layer=cas, match=match:eq}," +
192 "{@type=korap:term, key=A, layer=cas, match=match:eq}" +
193 "]}" +
194 "]}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000195 "}";
196 ppt = new PoliqarpPlusTree("[base=Mann&(cas=N|cas=A)]");
197 map = ppt.getRequestMap().get("query").toString();
198 assertEquals(cof1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Nils Diewald7d486c22013-12-13 16:32:18 +0000199
200
201 assertEquals(
202 new PoliqarpPlusTree(" [ base=Mann & ( cas=N | cas=A)] ").getRequestMap().get("query").toString(),
203 new PoliqarpPlusTree("[base=Mann &(cas=N|cas=A)]").getRequestMap().get("query").toString()
204 );
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000205
206 // [base=Mann&cas=N&gen=m]
207 String cof2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000208 "{@type=korap:token, wrap=" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000209 "{@type=korap:termGroup, relation=and, operands=[" +
210 "{@type=korap:term, key=Mann, layer=lemma, match=match:eq}," +
211 "{@type=korap:term, key=N, layer=cas, match=match:eq}," +
212 "{@type=korap:term, key=m, layer=gen, match=match:eq}" +
213 "]}" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000214 "}";
215 ppt = new PoliqarpPlusTree("[base=Mann&cas=N&gen=m]");
216 map = ppt.getRequestMap().get("query").toString();
217 assertEquals(cof2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000218 }
219
220 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000221 public void testOccurrence() throws QueryException {
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000222 // [base=foo]*
Joachim Bingel2daf9862014-02-12 10:18:54 +0000223 String occ1 = "{@type=korap:group, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000224 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000225 "], operation=operation:repetition, min=0, max=100}";
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000226 ppt = new PoliqarpPlusTree("[base=foo]*");
227 map = ppt.getRequestMap().get("query").toString();
228 assertEquals(occ1.replaceAll(" ", ""), map.replaceAll(" ", ""));
229
230 // [base=foo]*[base=bar]
231 String occ2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000232 "{@type=korap:group, operation=operation:sequence, operands=[" +
233 "{@type=korap:group, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000234 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000235 "], operation=operation:repetition, min=0, max=100 }," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000236 "{@type=korap:token, wrap={@type=korap:term, key=bar, layer=lemma, match=match:eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000237 "]}";
238 ppt = new PoliqarpPlusTree("[base=foo]*[base=bar]");
239 map = ppt.getRequestMap().get("query").toString();
240 assertEquals(occ2.replaceAll(" ", ""), map.replaceAll(" ", ""));
241
242 // [base=bar][base=foo]*
243 String occ3 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000244 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000245 "{@type=korap:token, wrap={@type=korap:term, key=bar, layer=lemma, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000246 "{@type=korap:group, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000247 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000248 "], operation=operation:repetition, min=0, max=100 }" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000249 "]}";
250 ppt = new PoliqarpPlusTree("[base=bar][base=foo]*");
251 map = ppt.getRequestMap().get("query").toString();
252 assertEquals(occ3.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb4da7022013-12-09 23:17:24 +0000253
254 // ([base=bar][base=foo])*
255 String occ4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000256 "{@type=korap:group, operands=[" +
257 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000258 "{@type=korap:token, wrap={@type=korap:term, key=bar, layer=lemma, match=match:eq}}," +
259 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000260 "]}" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000261 "], operation=operation:repetition, min=0, max=100 }" ;
Joachim Bingelb4da7022013-12-09 23:17:24 +0000262 ppt = new PoliqarpPlusTree("([base=bar][base=foo])*");
263 map = ppt.getRequestMap().get("query").toString();
264 assertEquals(occ4.replaceAll(" ", ""), map.replaceAll(" ", ""));
265
266 // <s>([base=bar][base=foo])*
267 String occ5 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000268 "{@type=korap:group, operation=operation:sequence, operands=[" +
269 "{@type=korap:span, key=s}," +
270 "{@type=korap:group, operands=[" +
271 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000272 "{@type=korap:token, wrap={@type=korap:term, key=bar, layer=lemma, match=match:eq}}," +
273 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000274 "]}" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000275 "], operation=operation:repetition, min=0, max=100 }" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000276 "]}" ;
277 ppt = new PoliqarpPlusTree("<s>([base=bar][base=foo])*");
278 map = ppt.getRequestMap().get("query").toString();
279 assertEquals(occ5.replaceAll(" ", ""), map.replaceAll(" ", ""));
280
281 // <s><np>([base=bar][base=foo])*
Joachim Bingelb4da7022013-12-09 23:17:24 +0000282 String occ6 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000283 "{@type=korap:group, operation=operation:sequence, operands=[" +
284 "{@type=korap:span, key=s}," +
285 "{@type=korap:span, key=np}," +
286 "{@type=korap:group, operands=[" +
287 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000288 "{@type=korap:token, wrap={@type=korap:term, key=bar, layer=lemma, match=match:eq}}," +
289 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000290 "]}" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000291 "], operation=operation:repetition, min=0, max=100 }" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000292 "]}" ;
293 ppt = new PoliqarpPlusTree("<s><np>([base=bar][base=foo])*");
294 map = ppt.getRequestMap().get("query").toString();
295 assertEquals(occ6.replaceAll(" ", ""), map.replaceAll(" ", ""));
296
297 // <s><np>([base=bar][base=foo])*[p=NN]
298 // comment: embedded sequence shouldn't really be here, but does not really hurt, either. (?)
299 // really hard to get this behaviour out of the PQPlus grammar...
300 String occ7 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000301 "{@type=korap:group, operation=operation:sequence, operands=[" +
302 "{@type=korap:span, key=s}," +
303 "{@type=korap:span, key=np}," +
304 "{@type=korap:group, operands=[" +
305 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000306 "{@type=korap:token, wrap={@type=korap:term, key=bar, layer=lemma, match=match:eq}}," +
307 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000308 "]}" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000309 "], operation=operation:repetition, min=0, max=100 }," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000310 "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000311 "]}" ;
312 ppt = new PoliqarpPlusTree("<s><np>([base=bar][base=foo])*[p=NN]");
313 map = ppt.getRequestMap().get("query").toString();
314 assertEquals(occ7.replaceAll(" ", ""), map.replaceAll(" ", ""));
315
316 // ([base=bar][base=foo])*[p=NN]
Joachim Bingelb4da7022013-12-09 23:17:24 +0000317 String occ8 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000318 "{@type=korap:group, operation=operation:sequence, operands=[" +
319 "{@type=korap:group, operands=[" +
320 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000321 "{@type=korap:token, wrap={@type=korap:term, key=bar, layer=lemma, match=match:eq}}," +
322 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000323 "]}" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000324 "], operation=operation:repetition, min=0, max=100 }," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000325 "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000326 "]}" ;
327 ppt = new PoliqarpPlusTree("([base=bar][base=foo])*[p=NN]");
328 map = ppt.getRequestMap().get("query").toString();
329 assertEquals(occ8.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000330
331 // [base=foo]+
Joachim Bingel2daf9862014-02-12 10:18:54 +0000332 String occ9 = "{@type=korap:group, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000333 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000334 "], operation=operation:repetition, min=1, max=100}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000335 ppt = new PoliqarpPlusTree("[base=foo]+");
336 map = ppt.getRequestMap().get("query").toString();
337 assertEquals(occ9.replaceAll(" ", ""), map.replaceAll(" ", ""));
338
339 // [base=foo]?
Joachim Bingel2daf9862014-02-12 10:18:54 +0000340 String occ10 = "{@type=korap:group, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000341 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000342 "], operation=operation:repetition, min=0, max=1}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000343 ppt = new PoliqarpPlusTree("[base=foo]?");
344 map = ppt.getRequestMap().get("query").toString();
345 assertEquals(occ10.replaceAll(" ", ""), map.replaceAll(" ", ""));
346
347 // [base=foo]{2,5}
Joachim Bingel2daf9862014-02-12 10:18:54 +0000348 String occ11 = "{@type=korap:group, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000349 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000350 "], operation=operation:repetition, min=2, max=5}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000351 ppt = new PoliqarpPlusTree("[base=foo]{2,5}");
352 map = ppt.getRequestMap().get("query").toString();
353 assertEquals(occ11.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000354 }
355
356 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000357 public void testTokenSequence() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000358 // [base=Mann][orth=Frau]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000359 String seq1 = "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000360 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}, " +
361 "{@type=korap:token, wrap={@type=korap:term, key=Frau, layer=orth, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000362 "]}";
363 assertTrue(equalsQueryContent(seq1, "[base=Mann][orth=Frau]"));
364
365 // [base=Mann][orth=Frau][p=NN]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000366 String seq2 = "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000367 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}, " +
368 "{@type=korap:token, wrap={@type=korap:term, key=Frau, layer=orth, match=match:eq}}, " +
369 "{@type=korap:token, wrap={@type=korap:term, key=NN,layer=p, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000370 "]}";
371 assertTrue(equalsQueryContent(seq2, "[base=Mann][orth=Frau][p=NN]"));
372 }
373
374 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000375 public void testDisjSegments() throws QueryException {
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000376 // ([base=der]|[base=das])[base=Schild]
377 String disj1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000378 "{@type=korap:group, operation=operation:sequence, operands=[" +
379 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000380 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=match:eq}}," +
381 "{@type=korap:token, wrap={@type=korap:term, key=das, layer=lemma, match=match:eq}}" +
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000382 "]}," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000383 "{@type=korap:token, wrap={@type=korap:term, key=Schild, layer=lemma, match=match:eq}}" +
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000384 "]}";
385 ppt = new PoliqarpPlusTree("([base=der]|[base=das])[base=Schild]");
386 map = ppt.getRequestMap().get("query").toString();
387 assertEquals(disj1.replaceAll(" ", ""), map.replaceAll(" ", ""));
388
389 // [base=Schild]([base=der]|[base=das])
390 String disj2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000391 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000392 "{@type=korap:token, wrap={@type=korap:term, key=Schild, layer=lemma, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000393 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000394 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=match:eq}}," +
395 "{@type=korap:token, wrap={@type=korap:term, key=das, layer=lemma, match=match:eq}}" +
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000396 "]}" +
397 "]}";
398 ppt = new PoliqarpPlusTree("[base=Schild]([base=der]|[base=das])");
399 map = ppt.getRequestMap().get("query").toString();
400 assertEquals(disj2.replaceAll(" ", ""), map.replaceAll(" ", ""));
401 }
402
403 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000404 public void testTokenElemSequence() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000405 // [base=Mann]<vp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000406 String seq1 = "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000407 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}, " +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000408 "{@type=korap:span, key=vp}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000409 "]}";
410 assertTrue(equalsQueryContent(seq1, "[base=Mann]<vp>"));
411
412 // <vp>[base=Mann]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000413 String seq2 = "{@type=korap:group, operation=operation:sequence, operands=[" +
414 "{@type=korap:span, key=vp}, "+
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000415 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}} " +
Joachim Bingel53333e62013-12-09 19:25:52 +0000416 "]}";
417 assertTrue(equalsQueryContent(seq2, "<vp>[base=Mann]"));
418
419 // <vp>[base=Mann]<pp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000420 String seq3 = "{@type=korap:group, operation=operation:sequence, operands=[" +
421 "{@type=korap:span, key=vp}, "+
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000422 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}, " +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000423 "{@type=korap:span, key=pp} "+
Joachim Bingel53333e62013-12-09 19:25:52 +0000424 "]}";
425 assertTrue(equalsQueryContent(seq3, "<vp>[base=Mann]<pp>"));
426 }
427
428 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000429 public void testElemSequence() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000430 // <np><vp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000431 String seq1 = "{@type=korap:group, operation=operation:sequence, operands=[" +
432 "{@type=korap:span, key=np}," +
433 "{@type=korap:span, key=vp}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000434 "]}";
435 assertTrue(equalsQueryContent(seq1, "<np><vp>"));
436
437 // <np><vp><pp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000438 String seq2 = "{@type=korap:group, operation=operation:sequence, operands=[" +
439 "{@type=korap:span, key=np}," +
440 "{@type=korap:span, key=vp}," +
441 "{@type=korap:span, key=pp}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000442 "]}";
443 assertTrue(equalsQueryContent(seq2, "<np><vp><pp>"));
444 }
445
446 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000447 public void testClasses() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000448 // {[base=Mann]}
Joachim Bingel2daf9862014-02-12 10:18:54 +0000449 String cls1 = "{@type=korap:group, operation=operation:class, class=0, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000450 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000451 "]}";
Joachim Bingel8c640e42014-02-07 16:20:47 +0000452 ppt = new PoliqarpPlusTree("{[base=Mann]}");
453 map = ppt.getRequestMap().get("query").toString();
454 assertEquals(cls1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000455
456 // {[base=Mann][orth=Frau]}
Joachim Bingel2daf9862014-02-12 10:18:54 +0000457 String cls2 = "{@type=korap:group, operation=operation:class, class=0, operands=[" +
458 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000459 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}," +
460 "{@type=korap:token, wrap={@type=korap:term, key=Frau, layer=orth, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000461 "]}" +
462 "]}";
463 assertTrue(equalsQueryContent(cls2, "{[base=Mann][orth=Frau]}"));
464
465 // [p=NN]{[base=Mann][orth=Frau]}
Joachim Bingel2daf9862014-02-12 10:18:54 +0000466 String cls3 = "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000467 "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000468 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
469 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000470 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}," +
471 "{@type=korap:token, wrap={@type=korap:term, key=Frau, layer=orth, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000472 "]}" +
473 "]}" +
474 "]}";
475 assertTrue(equalsQueryContent(cls3, "[p=NN]{[base=Mann][orth=Frau]}"));
476
477 // {[base=Mann][orth=Frau]}[p=NN]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000478 String cls4 = "{@type=korap:group, operation=operation:sequence, operands=[" +
479 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
480 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000481 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}," +
482 "{@type=korap:token, wrap={@type=korap:term, key=Frau, layer=orth, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000483 "]}" +
484 "]}," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000485 "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000486 "]}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000487 ppt = new PoliqarpPlusTree("{[base=Mann][orth=Frau]}[p=NN]");
488 map = ppt.getRequestMap().get("query").toString();
489 assertEquals(cls4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000490
491 // {2:{1:[tt/p=ADJA]}[mate/p=NN]}"
Joachim Bingel2daf9862014-02-12 10:18:54 +0000492 String cls5 = "{@type=korap:group, operation=operation:class, class=2, operands=[" +
493 "{@type=korap:group, operation=operation:sequence, operands=[" +
494 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000495 "{@type=korap:token, wrap={@type=korap:term, key=ADJA, layer=p, foundry=tt, match=match:eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000496 "]}," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000497 "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, foundry=mate, match=match:eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000498 "]}" +
499 "]}";
500 ppt = new PoliqarpPlusTree("{2: {1:[tt/p=ADJA]}[mate/p=NN]}");
501 map = ppt.getRequestMap().get("query").toString();
502 assertEquals(cls5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000503 }
504
505 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000506 public void testPositions() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000507 // contains(<s>,<np>)
Joachim Bingel2daf9862014-02-12 10:18:54 +0000508 String pos1 = "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
509 "{@type=korap:span, key=s}," +
510 "{@type=korap:span, key=np}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000511 "]}";
512 assertTrue(equalsQueryContent(pos1, "contains(<s>,<np>)"));
513
514 // contains(<s>,[base=Mann])
Joachim Bingel2daf9862014-02-12 10:18:54 +0000515 String pos2 = "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
516 "{@type=korap:span, key=s}," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000517 "{@type=korap:token, wrap= {@type=korap:term, key=Mann, layer=lemma, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000518 "]}";
519 assertTrue(equalsQueryContent(pos2, "contains(<s>,[base=Mann])"));
520
521 // contains(<s>,[orth=der][orth=Mann])
Joachim Bingel2daf9862014-02-12 10:18:54 +0000522 String pos3 = "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
523 "{@type=korap:span, key=s}," +
524 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000525 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
526 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000527 "]}" +
528 "]}";
529 ppt = new PoliqarpPlusTree("contains(<s>,[orth=der][orth=Mann])");
530 map = ppt.getRequestMap().get("query").toString();
531 assertEquals(pos3.replaceAll(" ", ""), map.replaceAll(" ", ""));
532
533 // [base=Auto]contains(<s>,[base=Mann])
534 String pos4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000535 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000536 "{@type=korap:token, wrap={@type=korap:term, key=Auto, layer=lemma, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000537 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
538 "{@type=korap:span, key=s}," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000539 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000540 "]}" +
541 "]}";
542 ppt = new PoliqarpPlusTree("[base=Auto]contains(<s>,[base=Mann])");
543 map = ppt.getRequestMap().get("query").toString();
544 assertEquals(pos4.replaceAll(" ", ""), map.replaceAll(" ", ""));
545 }
546
547 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000548 public void testNestedPositions() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000549 // contains(<s>,startswith(<np>,[orth=Der]))
550 String npos1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000551 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
552 "{@type=korap:span, key=s}," +
553 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
554 "{@type=korap:span, key=np}," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000555 "{@type=korap:token, wrap={@type=korap:term, key=Der, layer=orth, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000556 "]}" +
557 "]}";
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000558 ppt = new PoliqarpPlusTree("contains(<s>, startswith(<np>,[orth=Der]))");
Joachim Bingel53333e62013-12-09 19:25:52 +0000559 map = ppt.getRequestMap().get("query").toString();
560 assertEquals(npos1.replaceAll(" ", ""), map.replaceAll(" ", ""));
561 }
562
563 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000564 public void testShrinkSplit() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000565 // shrink([orth=Der]{[orth=Mann]})
566 String shr1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000567 "{@type=korap:group, operation=operation:submatch, classRef=[0], operands=[" +
568 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000569 "{@type=korap:token, wrap={@type=korap:term, key=Der, layer=orth, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000570 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000571 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000572 "]}" +
573 "]}" +
574 "]}";
575 ppt = new PoliqarpPlusTree("shrink([orth=Der]{[orth=Mann]})");
576 map = ppt.getRequestMap().get("query").toString();
577 assertEquals(shr1.replaceAll(" ", ""), map.replaceAll(" ", ""));
578
579 // shrink([orth=Der]{[orth=Mann][orth=geht]})
580 String shr2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000581 "{@type=korap:group, operation=operation:submatch, classRef=[0], operands=[" +
582 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000583 "{@type=korap:token, wrap={@type=korap:term, key=Der, layer=orth, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000584 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
585 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000586 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}," +
587 "{@type=korap:token, wrap={@type=korap:term, key=geht, layer=orth, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000588 "]}" +
589 "]}" +
590 "]}" +
591 "]}";
592 ppt = new PoliqarpPlusTree("shrink([orth=Der]{[orth=Mann][orth=geht]})");
593 map = ppt.getRequestMap().get("query").toString();
594 assertEquals(shr2.replaceAll(" ", ""), map.replaceAll(" ", ""));
595
596 // shrink(1:[orth=Der]{1:[orth=Mann][orth=geht]})
597 String shr3 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000598 "{@type=korap:group, operation=operation:submatch, classRef=[1], operands=[" +
599 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000600 "{@type=korap:token, wrap={@type=korap:term, key=Der, layer=orth, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000601 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
602 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000603 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}," +
604 "{@type=korap:token, wrap={@type=korap:term, key=geht, layer=orth, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000605 "]}" +
606 "]}" +
607 "]}" +
608 "]}";
609 ppt = new PoliqarpPlusTree("shrink(1:[orth=Der]{1:[orth=Mann][orth=geht]})");
610 map = ppt.getRequestMap().get("query").toString();
611 assertEquals(shr3.replaceAll(" ", ""), map.replaceAll(" ", ""));
612
613 // shrink(1:startswith(<s>,{1:<np>}))
614 String shr4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000615 "{@type=korap:group, operation=operation:submatch, classRef=[1], operands=[" +
616 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
617 "{@type=korap:span, key=s}," +
618 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
619 "{@type=korap:span, key=np}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000620 "]}" +
621 "]}" +
622 "]}";
Joachim Bingeladefa622013-12-13 10:51:48 +0000623 ppt = new PoliqarpPlusTree("shrink(1:startswith(<s>,{1:<np>}))");
Joachim Bingel53333e62013-12-09 19:25:52 +0000624 map = ppt.getRequestMap().get("query").toString();
625 assertEquals(shr4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000626
627 // shrink(3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))
628 String shr5 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000629 "{@type=korap:group, operation=operation:submatch, classRef=[3], operands=[" +
630 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
631 "{@type=korap:span, key=s}," +
632 "{@type=korap:group, operation=operation:class, class=3, operands=[" +
633 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000634 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000635 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
636 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000637 "{@type=korap:token, wrap={@type=korap:term, key=ADJA, layer=p, foundry=mate, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000638 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000639 "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, foundry=tt, match=match:eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000640 "]}" +
641 "]}" +
642 "]}" +
643 "]}" +
644 "]}" +
645 "]}" +
646 "]}";
Joachim Bingeladefa622013-12-13 10:51:48 +0000647 ppt = new PoliqarpPlusTree("shrink(3:startswith(<s>,{3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) ");
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000648 map = ppt.getRequestMap().get("query").toString();
649 assertEquals(shr5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000650
651 // split(3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))
652 String shr6 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000653 "{@type=korap:group, operation=operation:split, classRef=[3], operands=[" +
654 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
655 "{@type=korap:span, key=s}," +
656 "{@type=korap:group, operation=operation:class, class=3, operands=[" +
657 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000658 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000659 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
660 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000661 "{@type=korap:token, wrap={@type=korap:term, key=ADJA, layer=p, foundry=mate, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000662 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000663 "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, foundry=tt, match=match:eq}}" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000664 "]}" +
665 "]}" +
666 "]}" +
667 "]}" +
668 "]}" +
669 "]}" +
670 "]}";
671 ppt = new PoliqarpPlusTree("split(3:startswith(<s>,{3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) ");
672 map = ppt.getRequestMap().get("query").toString();
673 assertEquals(shr6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel8c640e42014-02-07 16:20:47 +0000674
675 // split(2|3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))
676 String shr7 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000677 "{@type=korap:group, operation=operation:split, classRef=[2, 3], classRefOp=classRefOp:intersection, operands=[" +
678 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
679 "{@type=korap:span, key=s}," +
680 "{@type=korap:group, operation=operation:class, class=3, operands=[" +
681 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000682 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000683 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
684 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000685 "{@type=korap:token, wrap={@type=korap:term, key=ADJA, layer=p, foundry=mate, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000686 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000687 "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, foundry=tt, match=match:eq}}" +
Joachim Bingel8c640e42014-02-07 16:20:47 +0000688 "]}" +
689 "]}" +
690 "]}" +
691 "]}" +
692 "]}" +
693 "]}" +
694 "]}";
695 ppt = new PoliqarpPlusTree("split(2|3:startswith(<s>,{3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) ");
696 map = ppt.getRequestMap().get("query").toString();
697 assertEquals(shr7.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000698 }
699
Joachim Bingel03882702013-12-31 19:53:05 +0000700
Joachim Bingel53333e62013-12-09 19:25:52 +0000701 @Test
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000702 public void testFoundries() throws QueryException {
703 // [tt/base=Mann]
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000704 String layer1 = "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=base, foundry=tt, match=match:eq}}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000705 ppt = new PoliqarpPlusTree("[tt/base=Mann]");
706 map = ppt.getRequestMap().get("query").toString();
707 assertEquals(layer1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000708
709 }
Joachim Bingel16da4e12013-12-17 09:48:12 +0000710
711 @Test
Joachim Bingel8c640e42014-02-07 16:20:47 +0000712 public void testAlign() throws QueryException {
Joachim Bingel16da4e12013-12-17 09:48:12 +0000713 // [orth=der]^[orth=Mann]
714 String align1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000715 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000716 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000717 "{@type=korap:group, alignment=left, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000718 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
Joachim Bingel03882702013-12-31 19:53:05 +0000719 "]}" +
Joachim Bingel16da4e12013-12-17 09:48:12 +0000720 "]}";
721 ppt = new PoliqarpPlusTree("[orth=der]^[orth=Mann]");
722 map = ppt.getRequestMap().get("query").toString();
723 assertEquals(align1.replaceAll(" ", ""), map.replaceAll(" ", ""));
724
Joachim Bingel84e33df2014-01-31 14:02:46 +0000725 // [orth=der]^[orth=große][orth=Mann]
726 String query = "[orth=der]^[orth=große][orth=Mann]";
727 String align1b =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000728 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000729 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000730 "{@type=korap:group, alignment=left, operands=[" +
731 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000732 "{@type=korap:token, wrap={@type=korap:term, key=große, layer=orth, match=match:eq}}," +
733 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +0000734 "]}" +
735 "]}" +
736 "]}";
737 ppt = new PoliqarpPlusTree(query);
738 map = ppt.getRequestMap().get("query").toString();
739 assertEquals(align1b.replaceAll(" ", ""), map.replaceAll(" ", ""));
740
Joachim Bingel16da4e12013-12-17 09:48:12 +0000741 // "([base=a]^[base=b])|[base=c]",
742 String align2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000743 "{@type=korap:group, operation=operation:or, operands=[" +
744 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000745 "{@type=korap:token, wrap={@type=korap:term, key=a, layer=lemma, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000746 "{@type=korap:group, alignment=left, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000747 "{@type=korap:token, wrap={@type=korap:term, key=b, layer=lemma, match=match:eq}}" +
Joachim Bingel03882702013-12-31 19:53:05 +0000748 "]}" +
Joachim Bingel16da4e12013-12-17 09:48:12 +0000749 "]}," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000750 "{@type=korap:token, wrap={@type=korap:term, key=c, layer=lemma, match=match:eq}}" +
Joachim Bingel16da4e12013-12-17 09:48:12 +0000751 "]}";
752 ppt = new PoliqarpPlusTree("([base=a]^[base=b])|[base=c]");
753 map = ppt.getRequestMap().get("query").toString();
754 assertEquals(align2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingela67e6a32014-01-02 18:35:24 +0000755
756 // "([base=a]^[base=b][base=c])|[base=d]",
757 String align3 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000758 "{@type=korap:group, operation=operation:or, operands=[" +
759 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000760 "{@type=korap:token, wrap={@type=korap:term, key=a, layer=lemma, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000761 "{@type=korap:group, alignment=left, operands=[" +
762 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000763 "{@type=korap:token, wrap={@type=korap:term, key=b, layer=lemma, match=match:eq}}," +
764 "{@type=korap:token, wrap={@type=korap:term, key=c, layer=lemma, match=match:eq}}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +0000765 "]}" +
766 "]}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000767 "]}," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000768 "{@type=korap:token, wrap={@type=korap:term, key=d, layer=lemma, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000769 "]}";
770 ppt = new PoliqarpPlusTree("([base=a]^[base=b][base=c])|[base=d]");
771 map = ppt.getRequestMap().get("query").toString();
772 assertEquals(align3.replaceAll(" ", ""), map.replaceAll(" ", ""));
773
774 // "([base=a]^[base=b]^[base=c])|[base=d]",
775 String align4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000776 "{@type=korap:group, operation=operation:or, operands=[" +
777 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000778 "{@type=korap:token, wrap={@type=korap:term, key=a, layer=lemma, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000779 "{@type=korap:group, alignment=left, operands=[" +
780 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000781 "{@type=korap:token, wrap={@type=korap:term, key=b, layer=lemma, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000782 "{@type=korap:group, alignment=left, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000783 "{@type=korap:token, wrap={@type=korap:term, key=c, layer=lemma, match=match:eq}}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +0000784 "]}" +
785 "]}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000786 "]}" +
787 "]}," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000788 "{@type=korap:token, wrap={@type=korap:term, key=d, layer=lemma, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000789 "]}";
790 ppt = new PoliqarpPlusTree("([base=a]^[base=b]^[base=c])|[base=d]");
791 map = ppt.getRequestMap().get("query").toString();
792 assertEquals(align4.replaceAll(" ", ""), map.replaceAll(" ", ""));
793
794
Joachim Bingel16da4e12013-12-17 09:48:12 +0000795 }
796
797 @Test
Joachim Bingel8c640e42014-02-07 16:20:47 +0000798 public void testSimpleQueries() throws QueryException {
Joachim Bingela67e6a32014-01-02 18:35:24 +0000799 // Baum
800 String simple1 =
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000801 "{@type=korap:token, wrap={@type=korap:term, key=Baum, layer=orth, match=match:eq}}";
Joachim Bingela67e6a32014-01-02 18:35:24 +0000802 ppt = new PoliqarpPlusTree("Baum");
803 map = ppt.getRequestMap().get("query").toString();
804 assertEquals(simple1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel16da4e12013-12-17 09:48:12 +0000805
Joachim Bingela67e6a32014-01-02 18:35:24 +0000806 // Der Baum
807 String simple2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000808 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000809 "{@type=korap:token, wrap={@type=korap:term, key=Der, layer=orth, match=match:eq}}, " +
810 "{@type=korap:token, wrap={@type=korap:term, key=Baum, layer=orth, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000811 "]}";
812 ppt = new PoliqarpPlusTree("Der Baum");
813 map = ppt.getRequestMap().get("query").toString();
814 assertEquals(simple2.replaceAll(" ", ""), map.replaceAll(" ", ""));
815
816 // Der große Baum
817 String simple3 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000818 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000819 "{@type=korap:token, wrap={@type=korap:term, key=Der, layer=orth, match=match:eq}}, " +
820 "{@type=korap:token, wrap={@type=korap:term, key=große, layer=orth, match=match:eq}}, " +
821 "{@type=korap:token, wrap={@type=korap:term, key=Baum, layer=orth, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000822 "]}";
823 ppt = new PoliqarpPlusTree("Der große Baum");
824 map = ppt.getRequestMap().get("query").toString();
825 assertEquals(simple3.replaceAll(" ", ""), map.replaceAll(" ", ""));
826
827 // Baum | Stein
828 String simple4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000829 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000830 "{@type=korap:token, wrap={@type=korap:term, key=Baum, layer=orth, match=match:eq}}, " +
831 "{@type=korap:token, wrap={@type=korap:term, key=Stein, layer=orth, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000832 "]}";
833 ppt = new PoliqarpPlusTree("Baum | Stein");
834 map = ppt.getRequestMap().get("query").toString();
835 assertEquals(simple4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel84e33df2014-01-31 14:02:46 +0000836
837 // Baum | Stein Haus
838 String query = "(Baum | Stein) Haus";
839 String simple5 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000840 "{@type=korap:group, operation=operation:sequence, operands=[" +
841 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000842 "{@type=korap:token, wrap={@type=korap:term, key=Baum, layer=orth, match=match:eq}}, " +
843 "{@type=korap:token, wrap={@type=korap:term, key=Stein, layer=orth, match=match:eq}}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +0000844 "]}," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000845 "{@type=korap:token, wrap={@type=korap:term, key=Haus, layer=orth, match=match:eq}} " +
Joachim Bingel84e33df2014-01-31 14:02:46 +0000846 "]}";
847 ppt = new PoliqarpPlusTree(query);
848 map = ppt.getRequestMap().get("query").toString();
849 assertEquals(simple5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel16da4e12013-12-17 09:48:12 +0000850 }
Joachim Bingel53333e62013-12-09 19:25:52 +0000851}
852