blob: 9b194474e20ce951d08854437c243a8bc0c021a8 [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 Bingelee3b21d2014-02-12 12:34:59 +000071 String re1 = "{@type=korap:token, wrap={@type=korap:term, @subtype=term: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 Bingel16da4e12013-12-17 09:48:12 +000078 public void testElements() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +000079 // <s>
Joachim Bingel2daf9862014-02-12 10:18:54 +000080 String elem1 = "{@type=korap:span, key=s}";
Joachim Bingel53333e62013-12-09 19:25:52 +000081 assertTrue(equalsQueryContent(elem1, "<s>"));
82
83 // <vp>
Joachim Bingel2daf9862014-02-12 10:18:54 +000084 String elem2 = "{@type=korap:span, key=vp}";
Joachim Bingel53333e62013-12-09 19:25:52 +000085 assertTrue(equalsQueryContent(elem2, "<vp>"));
86 }
Joachim Bingel87480d02014-01-17 14:07:46 +000087
88 @Test
89 public void testEmptyTokens() throws QueryException {
90 // [base=der][][base=Mann]
91 String et1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +000092 "{@type=korap:group, operation=operation:sequence, inOrder=true, distances=[" +
93 "{@type=korap:distance, key=w, min=1, max=1}" +
Joachim Bingel87480d02014-01-17 14:07:46 +000094 "], " +
Joachim Bingel11d5b152014-02-11 21:33:47 +000095 "operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +000096 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=match:eq}}," +
97 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +000098 "]}";
99 ppt = new PoliqarpPlusTree("[base=der][][base=Mann]");
100 map = ppt.getRequestMap().get("query").toString();
101 assertEquals(et1.replaceAll(" ", ""), map.replaceAll(" ", ""));
102
103 // [base=der][][][base=Mann]
104 String et2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000105 "{@type=korap:group, operation=operation:sequence, inOrder=true, distances=[" +
106 "{@type=korap:distance, key=w, min=2, max=2}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000107 "], " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000108 "operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000109 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=match:eq}}," +
110 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000111 "]}";
Joachim Bingelffd65e32014-01-22 14:22:57 +0000112 ppt = new PoliqarpPlusTree("[base=der][][][base=Mann]");
Joachim Bingel87480d02014-01-17 14:07:46 +0000113 map = ppt.getRequestMap().get("query").toString();
114 assertEquals(et2.replaceAll(" ", ""), map.replaceAll(" ", ""));
115
116 // [base=der][][]?[base=Mann]
117 String et3 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000118 "{@type=korap:group, operation=operation:sequence, inOrder=true, distances=[" +
119 "{@type=korap:distance, key=w, min=1, max=2}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000120 "], " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000121 "operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000122 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=match:eq}}," +
123 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000124 "]}";
125 ppt = new PoliqarpPlusTree("[base=der][][]?[base=Mann]");
126 map = ppt.getRequestMap().get("query").toString();
127 assertEquals(et3.replaceAll(" ", ""), map.replaceAll(" ", ""));
128
Joachim Bingel87480d02014-01-17 14:07:46 +0000129
130 // startswith(<s>, [][base=Mann]
Joachim Bingelffd65e32014-01-22 14:22:57 +0000131 String et4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000132 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
133 "{@type=korap:span, key=s}," +
134 "{@type=korap:group, operation=operation:sequence, offset-min=1, offset-max=1, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000135 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000136 "]}" +
137 "]}";
Joachim Bingelffd65e32014-01-22 14:22:57 +0000138 ppt = new PoliqarpPlusTree("startswith(<s>, [][base=Mann])");
139 map = ppt.getRequestMap().get("query").toString();
140 assertEquals(et4.replaceAll(" ", ""), map.replaceAll(" ", ""));
141
Joachim Bingel11d5b152014-02-11 21:33:47 +0000142 // [base=der][]{2,5}[base=Mann][]?[][base=Frau] nested distances=
Joachim Bingelffd65e32014-01-22 14:22:57 +0000143 String et5 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000144 "{@type=korap:group, operation=operation:sequence, inOrder=true, distances=[" +
145 "{@type=korap:distance, key=w, min=2, max=5}" +
Joachim Bingelffd65e32014-01-22 14:22:57 +0000146 "], " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000147 "operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000148 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000149 "{@type=korap:group, operation=operation:sequence, inOrder=true, distances=[" +
150 "{@type=korap:distance, key=w, min=1, max=2}" +
Joachim Bingelffd65e32014-01-22 14:22:57 +0000151 "], " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000152 "operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000153 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}," +
154 "{@type=korap:token, wrap={@type=korap:term, key=Frau, layer=lemma, match=match:eq}}" +
Joachim Bingelffd65e32014-01-22 14:22:57 +0000155 "]}" +
156 "]}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000157 ppt = new PoliqarpPlusTree("[base=der][]{2,5}[base=Mann][]?[][base=Frau]");
Joachim Bingel87480d02014-01-17 14:07:46 +0000158 map = ppt.getRequestMap().get("query").toString();
159 assertEquals(et5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel87480d02014-01-17 14:07:46 +0000160
161 }
Joachim Bingel53333e62013-12-09 19:25:52 +0000162
163 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000164 public void testCoordinatedFields() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000165 // [base=Mann&(cas=N|cas=A)]
166 String cof1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000167 "{@type=korap:token, wrap=" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000168 "{@type=korap:termGroup, relation=and, operands=[" +
169 "{@type=korap:term, key=Mann, layer=lemma, match=match:eq}," +
170 "{@type=korap:termGroup, relation=or, operands=[" +
171 "{@type=korap:term, key=N, layer=cas, match=match:eq}," +
172 "{@type=korap:term, key=A, layer=cas, match=match:eq}" +
173 "]}" +
174 "]}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000175 "}";
176 ppt = new PoliqarpPlusTree("[base=Mann&(cas=N|cas=A)]");
177 map = ppt.getRequestMap().get("query").toString();
178 assertEquals(cof1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Nils Diewald7d486c22013-12-13 16:32:18 +0000179
180
181 assertEquals(
182 new PoliqarpPlusTree(" [ base=Mann & ( cas=N | cas=A)] ").getRequestMap().get("query").toString(),
183 new PoliqarpPlusTree("[base=Mann &(cas=N|cas=A)]").getRequestMap().get("query").toString()
184 );
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000185
186 // [base=Mann&cas=N&gen=m]
187 String cof2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000188 "{@type=korap:token, wrap=" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000189 "{@type=korap:termGroup, relation=and, operands=[" +
190 "{@type=korap:term, key=Mann, layer=lemma, match=match:eq}," +
191 "{@type=korap:term, key=N, layer=cas, match=match:eq}," +
192 "{@type=korap:term, key=m, layer=gen, match=match:eq}" +
193 "]}" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000194 "}";
195 ppt = new PoliqarpPlusTree("[base=Mann&cas=N&gen=m]");
196 map = ppt.getRequestMap().get("query").toString();
197 assertEquals(cof2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000198 }
199
200 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000201 public void testOccurrence() throws QueryException {
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000202 // [base=foo]*
Joachim Bingel2daf9862014-02-12 10:18:54 +0000203 String occ1 = "{@type=korap:group, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000204 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000205 "], operation=operation:repetition, min=0, max=100}";
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000206 ppt = new PoliqarpPlusTree("[base=foo]*");
207 map = ppt.getRequestMap().get("query").toString();
208 assertEquals(occ1.replaceAll(" ", ""), map.replaceAll(" ", ""));
209
210 // [base=foo]*[base=bar]
211 String occ2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000212 "{@type=korap:group, operation=operation:sequence, operands=[" +
213 "{@type=korap:group, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000214 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000215 "], operation=operation:repetition, min=0, max=100 }," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000216 "{@type=korap:token, wrap={@type=korap:term, key=bar, layer=lemma, match=match:eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000217 "]}";
218 ppt = new PoliqarpPlusTree("[base=foo]*[base=bar]");
219 map = ppt.getRequestMap().get("query").toString();
220 assertEquals(occ2.replaceAll(" ", ""), map.replaceAll(" ", ""));
221
222 // [base=bar][base=foo]*
223 String occ3 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000224 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000225 "{@type=korap:token, wrap={@type=korap:term, key=bar, layer=lemma, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000226 "{@type=korap:group, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000227 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000228 "], operation=operation:repetition, min=0, max=100 }" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000229 "]}";
230 ppt = new PoliqarpPlusTree("[base=bar][base=foo]*");
231 map = ppt.getRequestMap().get("query").toString();
232 assertEquals(occ3.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb4da7022013-12-09 23:17:24 +0000233
234 // ([base=bar][base=foo])*
235 String occ4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000236 "{@type=korap:group, operands=[" +
237 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000238 "{@type=korap:token, wrap={@type=korap:term, key=bar, layer=lemma, match=match:eq}}," +
239 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000240 "]}" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000241 "], operation=operation:repetition, min=0, max=100 }" ;
Joachim Bingelb4da7022013-12-09 23:17:24 +0000242 ppt = new PoliqarpPlusTree("([base=bar][base=foo])*");
243 map = ppt.getRequestMap().get("query").toString();
244 assertEquals(occ4.replaceAll(" ", ""), map.replaceAll(" ", ""));
245
246 // <s>([base=bar][base=foo])*
247 String occ5 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000248 "{@type=korap:group, operation=operation:sequence, operands=[" +
249 "{@type=korap:span, key=s}," +
250 "{@type=korap:group, operands=[" +
251 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000252 "{@type=korap:token, wrap={@type=korap:term, key=bar, layer=lemma, match=match:eq}}," +
253 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000254 "]}" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000255 "], operation=operation:repetition, min=0, max=100 }" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000256 "]}" ;
257 ppt = new PoliqarpPlusTree("<s>([base=bar][base=foo])*");
258 map = ppt.getRequestMap().get("query").toString();
259 assertEquals(occ5.replaceAll(" ", ""), map.replaceAll(" ", ""));
260
261 // <s><np>([base=bar][base=foo])*
Joachim Bingelb4da7022013-12-09 23:17:24 +0000262 String occ6 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000263 "{@type=korap:group, operation=operation:sequence, operands=[" +
264 "{@type=korap:span, key=s}," +
265 "{@type=korap:span, key=np}," +
266 "{@type=korap:group, operands=[" +
267 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000268 "{@type=korap:token, wrap={@type=korap:term, key=bar, layer=lemma, match=match:eq}}," +
269 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000270 "]}" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000271 "], operation=operation:repetition, min=0, max=100 }" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000272 "]}" ;
273 ppt = new PoliqarpPlusTree("<s><np>([base=bar][base=foo])*");
274 map = ppt.getRequestMap().get("query").toString();
275 assertEquals(occ6.replaceAll(" ", ""), map.replaceAll(" ", ""));
276
277 // <s><np>([base=bar][base=foo])*[p=NN]
278 // comment: embedded sequence shouldn't really be here, but does not really hurt, either. (?)
279 // really hard to get this behaviour out of the PQPlus grammar...
280 String occ7 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000281 "{@type=korap:group, operation=operation:sequence, operands=[" +
282 "{@type=korap:span, key=s}," +
283 "{@type=korap:span, key=np}," +
284 "{@type=korap:group, operands=[" +
285 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000286 "{@type=korap:token, wrap={@type=korap:term, key=bar, layer=lemma, match=match:eq}}," +
287 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000288 "]}" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000289 "], operation=operation:repetition, min=0, max=100 }," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000290 "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000291 "]}" ;
292 ppt = new PoliqarpPlusTree("<s><np>([base=bar][base=foo])*[p=NN]");
293 map = ppt.getRequestMap().get("query").toString();
294 assertEquals(occ7.replaceAll(" ", ""), map.replaceAll(" ", ""));
295
296 // ([base=bar][base=foo])*[p=NN]
Joachim Bingelb4da7022013-12-09 23:17:24 +0000297 String occ8 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000298 "{@type=korap:group, operation=operation:sequence, operands=[" +
299 "{@type=korap:group, operands=[" +
300 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000301 "{@type=korap:token, wrap={@type=korap:term, key=bar, layer=lemma, match=match:eq}}," +
302 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000303 "]}" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000304 "], operation=operation:repetition, min=0, max=100 }," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000305 "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000306 "]}" ;
307 ppt = new PoliqarpPlusTree("([base=bar][base=foo])*[p=NN]");
308 map = ppt.getRequestMap().get("query").toString();
309 assertEquals(occ8.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000310
311 // [base=foo]+
Joachim Bingel2daf9862014-02-12 10:18:54 +0000312 String occ9 = "{@type=korap:group, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000313 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000314 "], operation=operation:repetition, min=1, max=100}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000315 ppt = new PoliqarpPlusTree("[base=foo]+");
316 map = ppt.getRequestMap().get("query").toString();
317 assertEquals(occ9.replaceAll(" ", ""), map.replaceAll(" ", ""));
318
319 // [base=foo]?
Joachim Bingel2daf9862014-02-12 10:18:54 +0000320 String occ10 = "{@type=korap:group, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000321 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000322 "], operation=operation:repetition, min=0, max=1}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000323 ppt = new PoliqarpPlusTree("[base=foo]?");
324 map = ppt.getRequestMap().get("query").toString();
325 assertEquals(occ10.replaceAll(" ", ""), map.replaceAll(" ", ""));
326
327 // [base=foo]{2,5}
Joachim Bingel2daf9862014-02-12 10:18:54 +0000328 String occ11 = "{@type=korap:group, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000329 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000330 "], operation=operation:repetition, min=2, max=5}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000331 ppt = new PoliqarpPlusTree("[base=foo]{2,5}");
332 map = ppt.getRequestMap().get("query").toString();
333 assertEquals(occ11.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000334 }
335
336 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000337 public void testTokenSequence() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000338 // [base=Mann][orth=Frau]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000339 String seq1 = "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000340 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}, " +
341 "{@type=korap:token, wrap={@type=korap:term, key=Frau, layer=orth, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000342 "]}";
343 assertTrue(equalsQueryContent(seq1, "[base=Mann][orth=Frau]"));
344
345 // [base=Mann][orth=Frau][p=NN]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000346 String seq2 = "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000347 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}, " +
348 "{@type=korap:token, wrap={@type=korap:term, key=Frau, layer=orth, match=match:eq}}, " +
349 "{@type=korap:token, wrap={@type=korap:term, key=NN,layer=p, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000350 "]}";
351 assertTrue(equalsQueryContent(seq2, "[base=Mann][orth=Frau][p=NN]"));
352 }
353
354 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000355 public void testDisjSegments() throws QueryException {
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000356 // ([base=der]|[base=das])[base=Schild]
357 String disj1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000358 "{@type=korap:group, operation=operation:sequence, operands=[" +
359 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000360 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=match:eq}}," +
361 "{@type=korap:token, wrap={@type=korap:term, key=das, layer=lemma, match=match:eq}}" +
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000362 "]}," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000363 "{@type=korap:token, wrap={@type=korap:term, key=Schild, layer=lemma, match=match:eq}}" +
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000364 "]}";
365 ppt = new PoliqarpPlusTree("([base=der]|[base=das])[base=Schild]");
366 map = ppt.getRequestMap().get("query").toString();
367 assertEquals(disj1.replaceAll(" ", ""), map.replaceAll(" ", ""));
368
369 // [base=Schild]([base=der]|[base=das])
370 String disj2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000371 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000372 "{@type=korap:token, wrap={@type=korap:term, key=Schild, layer=lemma, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000373 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000374 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=match:eq}}," +
375 "{@type=korap:token, wrap={@type=korap:term, key=das, layer=lemma, match=match:eq}}" +
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000376 "]}" +
377 "]}";
378 ppt = new PoliqarpPlusTree("[base=Schild]([base=der]|[base=das])");
379 map = ppt.getRequestMap().get("query").toString();
380 assertEquals(disj2.replaceAll(" ", ""), map.replaceAll(" ", ""));
381 }
382
383 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000384 public void testTokenElemSequence() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000385 // [base=Mann]<vp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000386 String seq1 = "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000387 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}, " +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000388 "{@type=korap:span, key=vp}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000389 "]}";
390 assertTrue(equalsQueryContent(seq1, "[base=Mann]<vp>"));
391
392 // <vp>[base=Mann]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000393 String seq2 = "{@type=korap:group, operation=operation:sequence, operands=[" +
394 "{@type=korap:span, key=vp}, "+
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000395 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}} " +
Joachim Bingel53333e62013-12-09 19:25:52 +0000396 "]}";
397 assertTrue(equalsQueryContent(seq2, "<vp>[base=Mann]"));
398
399 // <vp>[base=Mann]<pp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000400 String seq3 = "{@type=korap:group, operation=operation:sequence, operands=[" +
401 "{@type=korap:span, key=vp}, "+
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000402 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}, " +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000403 "{@type=korap:span, key=pp} "+
Joachim Bingel53333e62013-12-09 19:25:52 +0000404 "]}";
405 assertTrue(equalsQueryContent(seq3, "<vp>[base=Mann]<pp>"));
406 }
407
408 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000409 public void testElemSequence() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000410 // <np><vp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000411 String seq1 = "{@type=korap:group, operation=operation:sequence, operands=[" +
412 "{@type=korap:span, key=np}," +
413 "{@type=korap:span, key=vp}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000414 "]}";
415 assertTrue(equalsQueryContent(seq1, "<np><vp>"));
416
417 // <np><vp><pp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000418 String seq2 = "{@type=korap:group, operation=operation:sequence, operands=[" +
419 "{@type=korap:span, key=np}," +
420 "{@type=korap:span, key=vp}," +
421 "{@type=korap:span, key=pp}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000422 "]}";
423 assertTrue(equalsQueryContent(seq2, "<np><vp><pp>"));
424 }
425
426 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000427 public void testClasses() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000428 // {[base=Mann]}
Joachim Bingel2daf9862014-02-12 10:18:54 +0000429 String cls1 = "{@type=korap:group, operation=operation:class, class=0, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000430 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000431 "]}";
Joachim Bingel8c640e42014-02-07 16:20:47 +0000432 ppt = new PoliqarpPlusTree("{[base=Mann]}");
433 map = ppt.getRequestMap().get("query").toString();
434 assertEquals(cls1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000435
436 // {[base=Mann][orth=Frau]}
Joachim Bingel2daf9862014-02-12 10:18:54 +0000437 String cls2 = "{@type=korap:group, operation=operation:class, class=0, operands=[" +
438 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000439 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}," +
440 "{@type=korap:token, wrap={@type=korap:term, key=Frau, layer=orth, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000441 "]}" +
442 "]}";
443 assertTrue(equalsQueryContent(cls2, "{[base=Mann][orth=Frau]}"));
444
445 // [p=NN]{[base=Mann][orth=Frau]}
Joachim Bingel2daf9862014-02-12 10:18:54 +0000446 String cls3 = "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000447 "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000448 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
449 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000450 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}," +
451 "{@type=korap:token, wrap={@type=korap:term, key=Frau, layer=orth, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000452 "]}" +
453 "]}" +
454 "]}";
455 assertTrue(equalsQueryContent(cls3, "[p=NN]{[base=Mann][orth=Frau]}"));
456
457 // {[base=Mann][orth=Frau]}[p=NN]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000458 String cls4 = "{@type=korap:group, operation=operation:sequence, operands=[" +
459 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
460 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000461 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}," +
462 "{@type=korap:token, wrap={@type=korap:term, key=Frau, layer=orth, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000463 "]}" +
464 "]}," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000465 "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000466 "]}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000467 ppt = new PoliqarpPlusTree("{[base=Mann][orth=Frau]}[p=NN]");
468 map = ppt.getRequestMap().get("query").toString();
469 assertEquals(cls4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000470
471 // {2:{1:[tt/p=ADJA]}[mate/p=NN]}"
Joachim Bingel2daf9862014-02-12 10:18:54 +0000472 String cls5 = "{@type=korap:group, operation=operation:class, class=2, operands=[" +
473 "{@type=korap:group, operation=operation:sequence, operands=[" +
474 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000475 "{@type=korap:token, wrap={@type=korap:term, key=ADJA, layer=p, foundry=tt, match=match:eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000476 "]}," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000477 "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, foundry=mate, match=match:eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000478 "]}" +
479 "]}";
480 ppt = new PoliqarpPlusTree("{2: {1:[tt/p=ADJA]}[mate/p=NN]}");
481 map = ppt.getRequestMap().get("query").toString();
482 assertEquals(cls5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000483 }
484
485 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000486 public void testPositions() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000487 // contains(<s>,<np>)
Joachim Bingel2daf9862014-02-12 10:18:54 +0000488 String pos1 = "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
489 "{@type=korap:span, key=s}," +
490 "{@type=korap:span, key=np}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000491 "]}";
492 assertTrue(equalsQueryContent(pos1, "contains(<s>,<np>)"));
493
494 // contains(<s>,[base=Mann])
Joachim Bingel2daf9862014-02-12 10:18:54 +0000495 String pos2 = "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
496 "{@type=korap:span, key=s}," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000497 "{@type=korap:token, wrap= {@type=korap:term, key=Mann, layer=lemma, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000498 "]}";
499 assertTrue(equalsQueryContent(pos2, "contains(<s>,[base=Mann])"));
500
501 // contains(<s>,[orth=der][orth=Mann])
Joachim Bingel2daf9862014-02-12 10:18:54 +0000502 String pos3 = "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
503 "{@type=korap:span, key=s}," +
504 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000505 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
506 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000507 "]}" +
508 "]}";
509 ppt = new PoliqarpPlusTree("contains(<s>,[orth=der][orth=Mann])");
510 map = ppt.getRequestMap().get("query").toString();
511 assertEquals(pos3.replaceAll(" ", ""), map.replaceAll(" ", ""));
512
513 // [base=Auto]contains(<s>,[base=Mann])
514 String pos4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000515 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000516 "{@type=korap:token, wrap={@type=korap:term, key=Auto, layer=lemma, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000517 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
518 "{@type=korap:span, key=s}," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000519 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000520 "]}" +
521 "]}";
522 ppt = new PoliqarpPlusTree("[base=Auto]contains(<s>,[base=Mann])");
523 map = ppt.getRequestMap().get("query").toString();
524 assertEquals(pos4.replaceAll(" ", ""), map.replaceAll(" ", ""));
525 }
526
527 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000528 public void testNestedPositions() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000529 // contains(<s>,startswith(<np>,[orth=Der]))
530 String npos1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000531 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
532 "{@type=korap:span, key=s}," +
533 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
534 "{@type=korap:span, key=np}," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000535 "{@type=korap:token, wrap={@type=korap:term, key=Der, layer=orth, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000536 "]}" +
537 "]}";
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000538 ppt = new PoliqarpPlusTree("contains(<s>, startswith(<np>,[orth=Der]))");
Joachim Bingel53333e62013-12-09 19:25:52 +0000539 map = ppt.getRequestMap().get("query").toString();
540 assertEquals(npos1.replaceAll(" ", ""), map.replaceAll(" ", ""));
541 }
542
543 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000544 public void testShrinkSplit() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000545 // shrink([orth=Der]{[orth=Mann]})
546 String shr1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000547 "{@type=korap:group, operation=operation:submatch, classRef=[0], operands=[" +
548 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000549 "{@type=korap:token, wrap={@type=korap:term, key=Der, layer=orth, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000550 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000551 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000552 "]}" +
553 "]}" +
554 "]}";
555 ppt = new PoliqarpPlusTree("shrink([orth=Der]{[orth=Mann]})");
556 map = ppt.getRequestMap().get("query").toString();
557 assertEquals(shr1.replaceAll(" ", ""), map.replaceAll(" ", ""));
558
559 // shrink([orth=Der]{[orth=Mann][orth=geht]})
560 String shr2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000561 "{@type=korap:group, operation=operation:submatch, classRef=[0], operands=[" +
562 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000563 "{@type=korap:token, wrap={@type=korap:term, key=Der, layer=orth, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000564 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
565 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000566 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}," +
567 "{@type=korap:token, wrap={@type=korap:term, key=geht, layer=orth, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000568 "]}" +
569 "]}" +
570 "]}" +
571 "]}";
572 ppt = new PoliqarpPlusTree("shrink([orth=Der]{[orth=Mann][orth=geht]})");
573 map = ppt.getRequestMap().get("query").toString();
574 assertEquals(shr2.replaceAll(" ", ""), map.replaceAll(" ", ""));
575
576 // shrink(1:[orth=Der]{1:[orth=Mann][orth=geht]})
577 String shr3 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000578 "{@type=korap:group, operation=operation:submatch, classRef=[1], operands=[" +
579 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000580 "{@type=korap:token, wrap={@type=korap:term, key=Der, layer=orth, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000581 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
582 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000583 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}," +
584 "{@type=korap:token, wrap={@type=korap:term, key=geht, layer=orth, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000585 "]}" +
586 "]}" +
587 "]}" +
588 "]}";
589 ppt = new PoliqarpPlusTree("shrink(1:[orth=Der]{1:[orth=Mann][orth=geht]})");
590 map = ppt.getRequestMap().get("query").toString();
591 assertEquals(shr3.replaceAll(" ", ""), map.replaceAll(" ", ""));
592
593 // shrink(1:startswith(<s>,{1:<np>}))
594 String shr4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000595 "{@type=korap:group, operation=operation:submatch, classRef=[1], operands=[" +
596 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
597 "{@type=korap:span, key=s}," +
598 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
599 "{@type=korap:span, key=np}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000600 "]}" +
601 "]}" +
602 "]}";
Joachim Bingeladefa622013-12-13 10:51:48 +0000603 ppt = new PoliqarpPlusTree("shrink(1:startswith(<s>,{1:<np>}))");
Joachim Bingel53333e62013-12-09 19:25:52 +0000604 map = ppt.getRequestMap().get("query").toString();
605 assertEquals(shr4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000606
607 // shrink(3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))
608 String shr5 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000609 "{@type=korap:group, operation=operation:submatch, classRef=[3], operands=[" +
610 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
611 "{@type=korap:span, key=s}," +
612 "{@type=korap:group, operation=operation:class, class=3, operands=[" +
613 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000614 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000615 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
616 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000617 "{@type=korap:token, wrap={@type=korap:term, key=ADJA, layer=p, foundry=mate, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000618 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000619 "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, foundry=tt, match=match:eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000620 "]}" +
621 "]}" +
622 "]}" +
623 "]}" +
624 "]}" +
625 "]}" +
626 "]}";
Joachim Bingeladefa622013-12-13 10:51:48 +0000627 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 +0000628 map = ppt.getRequestMap().get("query").toString();
629 assertEquals(shr5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000630
631 // split(3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))
632 String shr6 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000633 "{@type=korap:group, operation=operation:split, classRef=[3], operands=[" +
634 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
635 "{@type=korap:span, key=s}," +
636 "{@type=korap:group, operation=operation:class, class=3, operands=[" +
637 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000638 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000639 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
640 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000641 "{@type=korap:token, wrap={@type=korap:term, key=ADJA, layer=p, foundry=mate, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000642 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000643 "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, foundry=tt, match=match:eq}}" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000644 "]}" +
645 "]}" +
646 "]}" +
647 "]}" +
648 "]}" +
649 "]}" +
650 "]}";
651 ppt = new PoliqarpPlusTree("split(3:startswith(<s>,{3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) ");
652 map = ppt.getRequestMap().get("query").toString();
653 assertEquals(shr6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel8c640e42014-02-07 16:20:47 +0000654
655 // split(2|3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))
656 String shr7 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000657 "{@type=korap:group, operation=operation:split, classRef=[2, 3], classRefOp=classRefOp:intersection, operands=[" +
658 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
659 "{@type=korap:span, key=s}," +
660 "{@type=korap:group, operation=operation:class, class=3, operands=[" +
661 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000662 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000663 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
664 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000665 "{@type=korap:token, wrap={@type=korap:term, key=ADJA, layer=p, foundry=mate, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000666 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000667 "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, foundry=tt, match=match:eq}}" +
Joachim Bingel8c640e42014-02-07 16:20:47 +0000668 "]}" +
669 "]}" +
670 "]}" +
671 "]}" +
672 "]}" +
673 "]}" +
674 "]}";
675 ppt = new PoliqarpPlusTree("split(2|3:startswith(<s>,{3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) ");
676 map = ppt.getRequestMap().get("query").toString();
677 assertEquals(shr7.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000678 }
679
Joachim Bingel03882702013-12-31 19:53:05 +0000680
Joachim Bingel53333e62013-12-09 19:25:52 +0000681 @Test
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000682 public void testFoundries() throws QueryException {
683 // [tt/base=Mann]
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000684 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 +0000685 ppt = new PoliqarpPlusTree("[tt/base=Mann]");
686 map = ppt.getRequestMap().get("query").toString();
687 assertEquals(layer1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000688
689 }
Joachim Bingel16da4e12013-12-17 09:48:12 +0000690
691 @Test
Joachim Bingel8c640e42014-02-07 16:20:47 +0000692 public void testAlign() throws QueryException {
Joachim Bingel16da4e12013-12-17 09:48:12 +0000693 // [orth=der]^[orth=Mann]
694 String align1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000695 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000696 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000697 "{@type=korap:group, alignment=left, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000698 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
Joachim Bingel03882702013-12-31 19:53:05 +0000699 "]}" +
Joachim Bingel16da4e12013-12-17 09:48:12 +0000700 "]}";
701 ppt = new PoliqarpPlusTree("[orth=der]^[orth=Mann]");
702 map = ppt.getRequestMap().get("query").toString();
703 assertEquals(align1.replaceAll(" ", ""), map.replaceAll(" ", ""));
704
Joachim Bingel84e33df2014-01-31 14:02:46 +0000705 // [orth=der]^[orth=große][orth=Mann]
706 String query = "[orth=der]^[orth=große][orth=Mann]";
707 String align1b =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000708 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000709 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000710 "{@type=korap:group, alignment=left, operands=[" +
711 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000712 "{@type=korap:token, wrap={@type=korap:term, key=große, layer=orth, match=match:eq}}," +
713 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +0000714 "]}" +
715 "]}" +
716 "]}";
717 ppt = new PoliqarpPlusTree(query);
718 map = ppt.getRequestMap().get("query").toString();
719 assertEquals(align1b.replaceAll(" ", ""), map.replaceAll(" ", ""));
720
Joachim Bingel16da4e12013-12-17 09:48:12 +0000721 // "([base=a]^[base=b])|[base=c]",
722 String align2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000723 "{@type=korap:group, operation=operation:or, operands=[" +
724 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000725 "{@type=korap:token, wrap={@type=korap:term, key=a, layer=lemma, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000726 "{@type=korap:group, alignment=left, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000727 "{@type=korap:token, wrap={@type=korap:term, key=b, layer=lemma, match=match:eq}}" +
Joachim Bingel03882702013-12-31 19:53:05 +0000728 "]}" +
Joachim Bingel16da4e12013-12-17 09:48:12 +0000729 "]}," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000730 "{@type=korap:token, wrap={@type=korap:term, key=c, layer=lemma, match=match:eq}}" +
Joachim Bingel16da4e12013-12-17 09:48:12 +0000731 "]}";
732 ppt = new PoliqarpPlusTree("([base=a]^[base=b])|[base=c]");
733 map = ppt.getRequestMap().get("query").toString();
734 assertEquals(align2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingela67e6a32014-01-02 18:35:24 +0000735
736 // "([base=a]^[base=b][base=c])|[base=d]",
737 String align3 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000738 "{@type=korap:group, operation=operation:or, operands=[" +
739 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000740 "{@type=korap:token, wrap={@type=korap:term, key=a, layer=lemma, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000741 "{@type=korap:group, alignment=left, operands=[" +
742 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000743 "{@type=korap:token, wrap={@type=korap:term, key=b, layer=lemma, match=match:eq}}," +
744 "{@type=korap:token, wrap={@type=korap:term, key=c, layer=lemma, match=match:eq}}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +0000745 "]}" +
746 "]}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000747 "]}," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000748 "{@type=korap:token, wrap={@type=korap:term, key=d, layer=lemma, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000749 "]}";
750 ppt = new PoliqarpPlusTree("([base=a]^[base=b][base=c])|[base=d]");
751 map = ppt.getRequestMap().get("query").toString();
752 assertEquals(align3.replaceAll(" ", ""), map.replaceAll(" ", ""));
753
754 // "([base=a]^[base=b]^[base=c])|[base=d]",
755 String align4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000756 "{@type=korap:group, operation=operation:or, operands=[" +
757 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000758 "{@type=korap:token, wrap={@type=korap:term, key=a, layer=lemma, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000759 "{@type=korap:group, alignment=left, operands=[" +
760 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000761 "{@type=korap:token, wrap={@type=korap:term, key=b, layer=lemma, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000762 "{@type=korap:group, alignment=left, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000763 "{@type=korap:token, wrap={@type=korap:term, key=c, layer=lemma, match=match:eq}}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +0000764 "]}" +
765 "]}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000766 "]}" +
767 "]}," +
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(align4.replaceAll(" ", ""), map.replaceAll(" ", ""));
773
774
Joachim Bingel16da4e12013-12-17 09:48:12 +0000775 }
776
777 @Test
Joachim Bingel8c640e42014-02-07 16:20:47 +0000778 public void testSimpleQueries() throws QueryException {
Joachim Bingela67e6a32014-01-02 18:35:24 +0000779 // Baum
780 String simple1 =
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000781 "{@type=korap:token, wrap={@type=korap:term, key=Baum, layer=orth, match=match:eq}}";
Joachim Bingela67e6a32014-01-02 18:35:24 +0000782 ppt = new PoliqarpPlusTree("Baum");
783 map = ppt.getRequestMap().get("query").toString();
784 assertEquals(simple1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel16da4e12013-12-17 09:48:12 +0000785
Joachim Bingela67e6a32014-01-02 18:35:24 +0000786 // Der Baum
787 String simple2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000788 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000789 "{@type=korap:token, wrap={@type=korap:term, key=Der, layer=orth, match=match:eq}}, " +
790 "{@type=korap:token, wrap={@type=korap:term, key=Baum, layer=orth, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000791 "]}";
792 ppt = new PoliqarpPlusTree("Der Baum");
793 map = ppt.getRequestMap().get("query").toString();
794 assertEquals(simple2.replaceAll(" ", ""), map.replaceAll(" ", ""));
795
796 // Der große Baum
797 String simple3 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000798 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000799 "{@type=korap:token, wrap={@type=korap:term, key=Der, layer=orth, match=match:eq}}, " +
800 "{@type=korap:token, wrap={@type=korap:term, key=große, layer=orth, match=match:eq}}, " +
801 "{@type=korap:token, wrap={@type=korap:term, key=Baum, layer=orth, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000802 "]}";
803 ppt = new PoliqarpPlusTree("Der große Baum");
804 map = ppt.getRequestMap().get("query").toString();
805 assertEquals(simple3.replaceAll(" ", ""), map.replaceAll(" ", ""));
806
807 // Baum | Stein
808 String simple4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000809 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000810 "{@type=korap:token, wrap={@type=korap:term, key=Baum, layer=orth, match=match:eq}}, " +
811 "{@type=korap:token, wrap={@type=korap:term, key=Stein, layer=orth, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000812 "]}";
813 ppt = new PoliqarpPlusTree("Baum | Stein");
814 map = ppt.getRequestMap().get("query").toString();
815 assertEquals(simple4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel84e33df2014-01-31 14:02:46 +0000816
817 // Baum | Stein Haus
818 String query = "(Baum | Stein) Haus";
819 String simple5 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000820 "{@type=korap:group, operation=operation:sequence, operands=[" +
821 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000822 "{@type=korap:token, wrap={@type=korap:term, key=Baum, layer=orth, match=match:eq}}, " +
823 "{@type=korap:token, wrap={@type=korap:term, key=Stein, layer=orth, match=match:eq}}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +0000824 "]}," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000825 "{@type=korap:token, wrap={@type=korap:term, key=Haus, layer=orth, match=match:eq}} " +
Joachim Bingel84e33df2014-01-31 14:02:46 +0000826 "]}";
827 ppt = new PoliqarpPlusTree(query);
828 map = ppt.getRequestMap().get("query").toString();
829 assertEquals(simple5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel16da4e12013-12-17 09:48:12 +0000830 }
Joachim Bingel53333e62013-12-09 19:25:52 +0000831}
832