blob: 5a69053fcc6647fa9a609e79f61986d5ea0d3e72 [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 Bingel2daf9862014-02-12 10:18:54 +000052 String token1 = "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=eq}}";
Joachim Bingel53333e62013-12-09 19:25:52 +000053 assertTrue(equalsQueryContent(token1, "[base=Mann]"));
54
55 // [orth!=Frau]
Joachim Bingel2daf9862014-02-12 10:18:54 +000056 String token2 = "{@type=korap:token, wrap={@type=korap:term, key=Frau, layer=orth, match=ne}}";
Joachim Bingel53333e62013-12-09 19:25:52 +000057 assertTrue(equalsQueryContent(token2, "[orth!=Frau]"));
58
59 // [!p=NN]
Joachim Bingel2daf9862014-02-12 10:18:54 +000060 String token3 = "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, match=ne}}";
Joachim Bingel53333e62013-12-09 19:25:52 +000061 assertTrue(equalsQueryContent(token3, "[!p=NN]"));
62
63 // [!p!=NN]
Joachim Bingel2daf9862014-02-12 10:18:54 +000064 String token4 = "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, match=eq}}";
Joachim Bingel53333e62013-12-09 19:25:52 +000065 assertTrue(equalsQueryContent(token4, "[!p!=NN]"));
66 }
67
68 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +000069 public void testElements() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +000070 // <s>
Joachim Bingel2daf9862014-02-12 10:18:54 +000071 String elem1 = "{@type=korap:span, key=s}";
Joachim Bingel53333e62013-12-09 19:25:52 +000072 assertTrue(equalsQueryContent(elem1, "<s>"));
73
74 // <vp>
Joachim Bingel2daf9862014-02-12 10:18:54 +000075 String elem2 = "{@type=korap:span, key=vp}";
Joachim Bingel53333e62013-12-09 19:25:52 +000076 assertTrue(equalsQueryContent(elem2, "<vp>"));
77 }
Joachim Bingel87480d02014-01-17 14:07:46 +000078
79 @Test
80 public void testEmptyTokens() throws QueryException {
81 // [base=der][][base=Mann]
82 String et1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +000083 "{@type=korap:group, operation=operation:sequence, inOrder=true, distances=[" +
84 "{@type=korap:distance, key=w, min=1, max=1}" +
Joachim Bingel87480d02014-01-17 14:07:46 +000085 "], " +
Joachim Bingel11d5b152014-02-11 21:33:47 +000086 "operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +000087 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=eq}}," +
88 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=eq}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +000089 "]}";
90 ppt = new PoliqarpPlusTree("[base=der][][base=Mann]");
91 map = ppt.getRequestMap().get("query").toString();
92 assertEquals(et1.replaceAll(" ", ""), map.replaceAll(" ", ""));
93
94 // [base=der][][][base=Mann]
95 String et2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +000096 "{@type=korap:group, operation=operation:sequence, inOrder=true, distances=[" +
97 "{@type=korap:distance, key=w, min=2, max=2}" +
Joachim Bingel87480d02014-01-17 14:07:46 +000098 "], " +
Joachim Bingel11d5b152014-02-11 21:33:47 +000099 "operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000100 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=eq}}," +
101 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=eq}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000102 "]}";
Joachim Bingelffd65e32014-01-22 14:22:57 +0000103 ppt = new PoliqarpPlusTree("[base=der][][][base=Mann]");
Joachim Bingel87480d02014-01-17 14:07:46 +0000104 map = ppt.getRequestMap().get("query").toString();
105 assertEquals(et2.replaceAll(" ", ""), map.replaceAll(" ", ""));
106
107 // [base=der][][]?[base=Mann]
108 String et3 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000109 "{@type=korap:group, operation=operation:sequence, inOrder=true, distances=[" +
110 "{@type=korap:distance, key=w, min=1, max=2}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000111 "], " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000112 "operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000113 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=eq}}," +
114 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=eq}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000115 "]}";
116 ppt = new PoliqarpPlusTree("[base=der][][]?[base=Mann]");
117 map = ppt.getRequestMap().get("query").toString();
118 assertEquals(et3.replaceAll(" ", ""), map.replaceAll(" ", ""));
119
Joachim Bingel87480d02014-01-17 14:07:46 +0000120
121 // startswith(<s>, [][base=Mann]
Joachim Bingelffd65e32014-01-22 14:22:57 +0000122 String et4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000123 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
124 "{@type=korap:span, key=s}," +
125 "{@type=korap:group, operation=operation:sequence, offset-min=1, offset-max=1, operands=[" +
126 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=eq}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000127 "]}" +
128 "]}";
Joachim Bingelffd65e32014-01-22 14:22:57 +0000129 ppt = new PoliqarpPlusTree("startswith(<s>, [][base=Mann])");
130 map = ppt.getRequestMap().get("query").toString();
131 assertEquals(et4.replaceAll(" ", ""), map.replaceAll(" ", ""));
132
Joachim Bingel11d5b152014-02-11 21:33:47 +0000133 // [base=der][]{2,5}[base=Mann][]?[][base=Frau] nested distances=
Joachim Bingelffd65e32014-01-22 14:22:57 +0000134 String et5 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000135 "{@type=korap:group, operation=operation:sequence, inOrder=true, distances=[" +
136 "{@type=korap:distance, key=w, min=2, max=5}" +
Joachim Bingelffd65e32014-01-22 14:22:57 +0000137 "], " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000138 "operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000139 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=eq}}," +
140 "{@type=korap:group, operation=operation:sequence, inOrder=true, distances=[" +
141 "{@type=korap:distance, key=w, min=1, max=2}" +
Joachim Bingelffd65e32014-01-22 14:22:57 +0000142 "], " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000143 "operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000144 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=eq}}," +
145 "{@type=korap:token, wrap={@type=korap:term, key=Frau, layer=lemma, match=eq}}" +
Joachim Bingelffd65e32014-01-22 14:22:57 +0000146 "]}" +
147 "]}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000148 ppt = new PoliqarpPlusTree("[base=der][]{2,5}[base=Mann][]?[][base=Frau]");
Joachim Bingel87480d02014-01-17 14:07:46 +0000149 map = ppt.getRequestMap().get("query").toString();
150 assertEquals(et5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel87480d02014-01-17 14:07:46 +0000151
152 }
Joachim Bingel53333e62013-12-09 19:25:52 +0000153
154 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000155 public void testCoordinatedFields() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000156 // [base=Mann&(cas=N|cas=A)]
157 String cof1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000158 "{@type=korap:token, wrap=" +
159 "{@type=korap:group, operands=[" +
160 "{@type=korap:term, key=Mann, layer=lemma, match=eq}," +
161 "{@type=korap:group, operands=[" +
162 "{@type=korap:term, key=N, layer=cas, match=eq}," +
163 "{@type=korap:term, key=A, layer=cas, match=eq}" +
164 "], operation=operation:or}" +
165 "], operation=operation:and}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000166 "}";
167 ppt = new PoliqarpPlusTree("[base=Mann&(cas=N|cas=A)]");
168 map = ppt.getRequestMap().get("query").toString();
169 assertEquals(cof1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Nils Diewald7d486c22013-12-13 16:32:18 +0000170
171
172 assertEquals(
173 new PoliqarpPlusTree(" [ base=Mann & ( cas=N | cas=A)] ").getRequestMap().get("query").toString(),
174 new PoliqarpPlusTree("[base=Mann &(cas=N|cas=A)]").getRequestMap().get("query").toString()
175 );
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000176
177 // [base=Mann&cas=N&gen=m]
178 String cof2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000179 "{@type=korap:token, wrap=" +
180 "{@type=korap:group, operands=[" +
181 "{@type=korap:term, key=Mann, layer=lemma, match=eq}," +
182 "{@type=korap:term, key=N, layer=cas, match=eq}," +
183 "{@type=korap:term, key=m, layer=gen, match=eq}" +
184 "], operation=operation:and}" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000185 "}";
186 ppt = new PoliqarpPlusTree("[base=Mann&cas=N&gen=m]");
187 map = ppt.getRequestMap().get("query").toString();
188 assertEquals(cof2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000189 }
190
191 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000192 public void testOccurrence() throws QueryException {
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000193 // [base=foo]*
Joachim Bingel2daf9862014-02-12 10:18:54 +0000194 String occ1 = "{@type=korap:group, operands=[" +
195 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=eq}}" +
196 "], operation=operation:repetition, min=0, max=100}";
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000197 ppt = new PoliqarpPlusTree("[base=foo]*");
198 map = ppt.getRequestMap().get("query").toString();
199 assertEquals(occ1.replaceAll(" ", ""), map.replaceAll(" ", ""));
200
201 // [base=foo]*[base=bar]
202 String occ2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000203 "{@type=korap:group, operation=operation:sequence, operands=[" +
204 "{@type=korap:group, operands=[" +
205 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=eq}}" +
206 "], operation=operation:repetition, min=0, max=100 }," +
207 "{@type=korap:token, wrap={@type=korap:term, key=bar, layer=lemma, match=eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000208 "]}";
209 ppt = new PoliqarpPlusTree("[base=foo]*[base=bar]");
210 map = ppt.getRequestMap().get("query").toString();
211 assertEquals(occ2.replaceAll(" ", ""), map.replaceAll(" ", ""));
212
213 // [base=bar][base=foo]*
214 String occ3 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000215 "{@type=korap:group, operation=operation:sequence, operands=[" +
216 "{@type=korap:token, wrap={@type=korap:term, key=bar, layer=lemma, match=eq}}," +
217 "{@type=korap:group, operands=[" +
218 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=eq}}" +
219 "], operation=operation:repetition, min=0, max=100 }" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000220 "]}";
221 ppt = new PoliqarpPlusTree("[base=bar][base=foo]*");
222 map = ppt.getRequestMap().get("query").toString();
223 assertEquals(occ3.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb4da7022013-12-09 23:17:24 +0000224
225 // ([base=bar][base=foo])*
226 String occ4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000227 "{@type=korap:group, operands=[" +
228 "{@type=korap:group, operation=operation:sequence, operands=[" +
229 "{@type=korap:token, wrap={@type=korap:term, key=bar, layer=lemma, match=eq}}," +
230 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000231 "]}" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000232 "], operation=operation:repetition, min=0, max=100 }" ;
Joachim Bingelb4da7022013-12-09 23:17:24 +0000233 ppt = new PoliqarpPlusTree("([base=bar][base=foo])*");
234 map = ppt.getRequestMap().get("query").toString();
235 assertEquals(occ4.replaceAll(" ", ""), map.replaceAll(" ", ""));
236
237 // <s>([base=bar][base=foo])*
238 String occ5 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000239 "{@type=korap:group, operation=operation:sequence, operands=[" +
240 "{@type=korap:span, key=s}," +
241 "{@type=korap:group, operands=[" +
242 "{@type=korap:group, operation=operation:sequence, operands=[" +
243 "{@type=korap:token, wrap={@type=korap:term, key=bar, layer=lemma, match=eq}}," +
244 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000245 "]}" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000246 "], operation=operation:repetition, min=0, max=100 }" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000247 "]}" ;
248 ppt = new PoliqarpPlusTree("<s>([base=bar][base=foo])*");
249 map = ppt.getRequestMap().get("query").toString();
250 assertEquals(occ5.replaceAll(" ", ""), map.replaceAll(" ", ""));
251
252 // <s><np>([base=bar][base=foo])*
Joachim Bingelb4da7022013-12-09 23:17:24 +0000253 String occ6 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000254 "{@type=korap:group, operation=operation:sequence, operands=[" +
255 "{@type=korap:span, key=s}," +
256 "{@type=korap:span, key=np}," +
257 "{@type=korap:group, operands=[" +
258 "{@type=korap:group, operation=operation:sequence, operands=[" +
259 "{@type=korap:token, wrap={@type=korap:term, key=bar, layer=lemma, match=eq}}," +
260 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000261 "]}" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000262 "], operation=operation:repetition, min=0, max=100 }" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000263 "]}" ;
264 ppt = new PoliqarpPlusTree("<s><np>([base=bar][base=foo])*");
265 map = ppt.getRequestMap().get("query").toString();
266 assertEquals(occ6.replaceAll(" ", ""), map.replaceAll(" ", ""));
267
268 // <s><np>([base=bar][base=foo])*[p=NN]
269 // comment: embedded sequence shouldn't really be here, but does not really hurt, either. (?)
270 // really hard to get this behaviour out of the PQPlus grammar...
271 String occ7 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000272 "{@type=korap:group, operation=operation:sequence, operands=[" +
273 "{@type=korap:span, key=s}," +
274 "{@type=korap:span, key=np}," +
275 "{@type=korap:group, operands=[" +
276 "{@type=korap:group, operation=operation:sequence, operands=[" +
277 "{@type=korap:token, wrap={@type=korap:term, key=bar, layer=lemma, match=eq}}," +
278 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000279 "]}" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000280 "], operation=operation:repetition, min=0, max=100 }," +
281 "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, match=eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000282 "]}" ;
283 ppt = new PoliqarpPlusTree("<s><np>([base=bar][base=foo])*[p=NN]");
284 map = ppt.getRequestMap().get("query").toString();
285 assertEquals(occ7.replaceAll(" ", ""), map.replaceAll(" ", ""));
286
287 // ([base=bar][base=foo])*[p=NN]
Joachim Bingelb4da7022013-12-09 23:17:24 +0000288 String occ8 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000289 "{@type=korap:group, operation=operation:sequence, operands=[" +
290 "{@type=korap:group, operands=[" +
291 "{@type=korap:group, operation=operation:sequence, operands=[" +
292 "{@type=korap:token, wrap={@type=korap:term, key=bar, layer=lemma, match=eq}}," +
293 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000294 "]}" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000295 "], operation=operation:repetition, min=0, max=100 }," +
296 "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, match=eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000297 "]}" ;
298 ppt = new PoliqarpPlusTree("([base=bar][base=foo])*[p=NN]");
299 map = ppt.getRequestMap().get("query").toString();
300 assertEquals(occ8.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000301
302 // [base=foo]+
Joachim Bingel2daf9862014-02-12 10:18:54 +0000303 String occ9 = "{@type=korap:group, operands=[" +
304 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=eq}}" +
305 "], operation=operation:repetition, min=1, max=100}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000306 ppt = new PoliqarpPlusTree("[base=foo]+");
307 map = ppt.getRequestMap().get("query").toString();
308 assertEquals(occ9.replaceAll(" ", ""), map.replaceAll(" ", ""));
309
310 // [base=foo]?
Joachim Bingel2daf9862014-02-12 10:18:54 +0000311 String occ10 = "{@type=korap:group, operands=[" +
312 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=eq}}" +
313 "], operation=operation:repetition, min=0, max=1}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000314 ppt = new PoliqarpPlusTree("[base=foo]?");
315 map = ppt.getRequestMap().get("query").toString();
316 assertEquals(occ10.replaceAll(" ", ""), map.replaceAll(" ", ""));
317
318 // [base=foo]{2,5}
Joachim Bingel2daf9862014-02-12 10:18:54 +0000319 String occ11 = "{@type=korap:group, operands=[" +
320 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=eq}}" +
321 "], operation=operation:repetition, min=2, max=5}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000322 ppt = new PoliqarpPlusTree("[base=foo]{2,5}");
323 map = ppt.getRequestMap().get("query").toString();
324 assertEquals(occ11.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000325 }
326
327 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000328 public void testTokenSequence() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000329 // [base=Mann][orth=Frau]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000330 String seq1 = "{@type=korap:group, operation=operation:sequence, operands=[" +
331 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=eq}}, " +
332 "{@type=korap:token, wrap={@type=korap:term, key=Frau, layer=orth, match=eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000333 "]}";
334 assertTrue(equalsQueryContent(seq1, "[base=Mann][orth=Frau]"));
335
336 // [base=Mann][orth=Frau][p=NN]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000337 String seq2 = "{@type=korap:group, operation=operation:sequence, operands=[" +
338 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=eq}}, " +
339 "{@type=korap:token, wrap={@type=korap:term, key=Frau, layer=orth, match=eq}}, " +
340 "{@type=korap:token, wrap={@type=korap:term, key=NN,layer=p, match=eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000341 "]}";
342 assertTrue(equalsQueryContent(seq2, "[base=Mann][orth=Frau][p=NN]"));
343 }
344
345 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000346 public void testDisjSegments() throws QueryException {
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000347 // ([base=der]|[base=das])[base=Schild]
348 String disj1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000349 "{@type=korap:group, operation=operation:sequence, operands=[" +
350 "{@type=korap:group, operation=operation:or, operands=[" +
351 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=eq}}," +
352 "{@type=korap:token, wrap={@type=korap:term, key=das, layer=lemma, match=eq}}" +
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000353 "]}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000354 "{@type=korap:token, wrap={@type=korap:term, key=Schild, layer=lemma, match=eq}}" +
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000355 "]}";
356 ppt = new PoliqarpPlusTree("([base=der]|[base=das])[base=Schild]");
357 map = ppt.getRequestMap().get("query").toString();
358 assertEquals(disj1.replaceAll(" ", ""), map.replaceAll(" ", ""));
359
360 // [base=Schild]([base=der]|[base=das])
361 String disj2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000362 "{@type=korap:group, operation=operation:sequence, operands=[" +
363 "{@type=korap:token, wrap={@type=korap:term, key=Schild, layer=lemma, match=eq}}," +
364 "{@type=korap:group, operation=operation:or, operands=[" +
365 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=eq}}," +
366 "{@type=korap:token, wrap={@type=korap:term, key=das, layer=lemma, match=eq}}" +
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000367 "]}" +
368 "]}";
369 ppt = new PoliqarpPlusTree("[base=Schild]([base=der]|[base=das])");
370 map = ppt.getRequestMap().get("query").toString();
371 assertEquals(disj2.replaceAll(" ", ""), map.replaceAll(" ", ""));
372 }
373
374 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000375 public void testTokenElemSequence() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000376 // [base=Mann]<vp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000377 String seq1 = "{@type=korap:group, operation=operation:sequence, operands=[" +
378 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=eq}}, " +
379 "{@type=korap:span, key=vp}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000380 "]}";
381 assertTrue(equalsQueryContent(seq1, "[base=Mann]<vp>"));
382
383 // <vp>[base=Mann]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000384 String seq2 = "{@type=korap:group, operation=operation:sequence, operands=[" +
385 "{@type=korap:span, key=vp}, "+
386 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=eq}} " +
Joachim Bingel53333e62013-12-09 19:25:52 +0000387 "]}";
388 assertTrue(equalsQueryContent(seq2, "<vp>[base=Mann]"));
389
390 // <vp>[base=Mann]<pp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000391 String seq3 = "{@type=korap:group, operation=operation:sequence, operands=[" +
392 "{@type=korap:span, key=vp}, "+
393 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=eq}}, " +
394 "{@type=korap:span, key=pp} "+
Joachim Bingel53333e62013-12-09 19:25:52 +0000395 "]}";
396 assertTrue(equalsQueryContent(seq3, "<vp>[base=Mann]<pp>"));
397 }
398
399 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000400 public void testElemSequence() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000401 // <np><vp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000402 String seq1 = "{@type=korap:group, operation=operation:sequence, operands=[" +
403 "{@type=korap:span, key=np}," +
404 "{@type=korap:span, key=vp}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000405 "]}";
406 assertTrue(equalsQueryContent(seq1, "<np><vp>"));
407
408 // <np><vp><pp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000409 String seq2 = "{@type=korap:group, operation=operation:sequence, operands=[" +
410 "{@type=korap:span, key=np}," +
411 "{@type=korap:span, key=vp}," +
412 "{@type=korap:span, key=pp}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000413 "]}";
414 assertTrue(equalsQueryContent(seq2, "<np><vp><pp>"));
415 }
416
417 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000418 public void testClasses() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000419 // {[base=Mann]}
Joachim Bingel2daf9862014-02-12 10:18:54 +0000420 String cls1 = "{@type=korap:group, operation=operation:class, class=0, operands=[" +
421 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000422 "]}";
Joachim Bingel8c640e42014-02-07 16:20:47 +0000423 ppt = new PoliqarpPlusTree("{[base=Mann]}");
424 map = ppt.getRequestMap().get("query").toString();
425 assertEquals(cls1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000426
427 // {[base=Mann][orth=Frau]}
Joachim Bingel2daf9862014-02-12 10:18:54 +0000428 String cls2 = "{@type=korap:group, operation=operation:class, class=0, operands=[" +
429 "{@type=korap:group, operation=operation:sequence, operands=[" +
430 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=eq}}," +
431 "{@type=korap:token, wrap={@type=korap:term, key=Frau, layer=orth, match=eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000432 "]}" +
433 "]}";
434 assertTrue(equalsQueryContent(cls2, "{[base=Mann][orth=Frau]}"));
435
436 // [p=NN]{[base=Mann][orth=Frau]}
Joachim Bingel2daf9862014-02-12 10:18:54 +0000437 String cls3 = "{@type=korap:group, operation=operation:sequence, operands=[" +
438 "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, match=eq}}," +
439 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
440 "{@type=korap:group, operation=operation:sequence, operands=[" +
441 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=eq}}," +
442 "{@type=korap:token, wrap={@type=korap:term, key=Frau, layer=orth, match=eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000443 "]}" +
444 "]}" +
445 "]}";
446 assertTrue(equalsQueryContent(cls3, "[p=NN]{[base=Mann][orth=Frau]}"));
447
448 // {[base=Mann][orth=Frau]}[p=NN]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000449 String cls4 = "{@type=korap:group, operation=operation:sequence, operands=[" +
450 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
451 "{@type=korap:group, operation=operation:sequence, operands=[" +
452 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=eq}}," +
453 "{@type=korap:token, wrap={@type=korap:term, key=Frau, layer=orth, match=eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000454 "]}" +
455 "]}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000456 "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, match=eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000457 "]}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000458 ppt = new PoliqarpPlusTree("{[base=Mann][orth=Frau]}[p=NN]");
459 map = ppt.getRequestMap().get("query").toString();
460 assertEquals(cls4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000461
462 // {2:{1:[tt/p=ADJA]}[mate/p=NN]}"
Joachim Bingel2daf9862014-02-12 10:18:54 +0000463 String cls5 = "{@type=korap:group, operation=operation:class, class=2, operands=[" +
464 "{@type=korap:group, operation=operation:sequence, operands=[" +
465 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
466 "{@type=korap:token, wrap={@type=korap:term, key=ADJA, layer=p, foundry=tt, match=eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000467 "]}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000468 "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, foundry=mate, match=eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000469 "]}" +
470 "]}";
471 ppt = new PoliqarpPlusTree("{2: {1:[tt/p=ADJA]}[mate/p=NN]}");
472 map = ppt.getRequestMap().get("query").toString();
473 assertEquals(cls5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000474 }
475
476 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000477 public void testPositions() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000478 // contains(<s>,<np>)
Joachim Bingel2daf9862014-02-12 10:18:54 +0000479 String pos1 = "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
480 "{@type=korap:span, key=s}," +
481 "{@type=korap:span, key=np}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000482 "]}";
483 assertTrue(equalsQueryContent(pos1, "contains(<s>,<np>)"));
484
485 // contains(<s>,[base=Mann])
Joachim Bingel2daf9862014-02-12 10:18:54 +0000486 String pos2 = "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
487 "{@type=korap:span, key=s}," +
488 "{@type=korap:token, wrap= {@type=korap:term, key=Mann, layer=lemma, match=eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000489 "]}";
490 assertTrue(equalsQueryContent(pos2, "contains(<s>,[base=Mann])"));
491
492 // contains(<s>,[orth=der][orth=Mann])
Joachim Bingel2daf9862014-02-12 10:18:54 +0000493 String pos3 = "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
494 "{@type=korap:span, key=s}," +
495 "{@type=korap:group, operation=operation:sequence, operands=[" +
496 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=eq}}," +
497 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000498 "]}" +
499 "]}";
500 ppt = new PoliqarpPlusTree("contains(<s>,[orth=der][orth=Mann])");
501 map = ppt.getRequestMap().get("query").toString();
502 assertEquals(pos3.replaceAll(" ", ""), map.replaceAll(" ", ""));
503
504 // [base=Auto]contains(<s>,[base=Mann])
505 String pos4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000506 "{@type=korap:group, operation=operation:sequence, operands=[" +
507 "{@type=korap:token, wrap={@type=korap:term, key=Auto, layer=lemma, match=eq}}," +
508 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
509 "{@type=korap:span, key=s}," +
510 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000511 "]}" +
512 "]}";
513 ppt = new PoliqarpPlusTree("[base=Auto]contains(<s>,[base=Mann])");
514 map = ppt.getRequestMap().get("query").toString();
515 assertEquals(pos4.replaceAll(" ", ""), map.replaceAll(" ", ""));
516 }
517
518 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000519 public void testNestedPositions() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000520 // contains(<s>,startswith(<np>,[orth=Der]))
521 String npos1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000522 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
523 "{@type=korap:span, key=s}," +
524 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
525 "{@type=korap:span, key=np}," +
526 "{@type=korap:token, wrap={@type=korap:term, key=Der, layer=orth, match=eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000527 "]}" +
528 "]}";
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000529 ppt = new PoliqarpPlusTree("contains(<s>, startswith(<np>,[orth=Der]))");
Joachim Bingel53333e62013-12-09 19:25:52 +0000530 map = ppt.getRequestMap().get("query").toString();
531 assertEquals(npos1.replaceAll(" ", ""), map.replaceAll(" ", ""));
532 }
533
534 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000535 public void testShrinkSplit() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000536 // shrink([orth=Der]{[orth=Mann]})
537 String shr1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000538 "{@type=korap:group, operation=operation:submatch, classRef=[0], operands=[" +
539 "{@type=korap:group, operation=operation:sequence, operands=[" +
540 "{@type=korap:token, wrap={@type=korap:term, key=Der, layer=orth, match=eq}}," +
541 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
542 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000543 "]}" +
544 "]}" +
545 "]}";
546 ppt = new PoliqarpPlusTree("shrink([orth=Der]{[orth=Mann]})");
547 map = ppt.getRequestMap().get("query").toString();
548 assertEquals(shr1.replaceAll(" ", ""), map.replaceAll(" ", ""));
549
550 // shrink([orth=Der]{[orth=Mann][orth=geht]})
551 String shr2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000552 "{@type=korap:group, operation=operation:submatch, classRef=[0], operands=[" +
553 "{@type=korap:group, operation=operation:sequence, operands=[" +
554 "{@type=korap:token, wrap={@type=korap:term, key=Der, layer=orth, match=eq}}," +
555 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
556 "{@type=korap:group, operation=operation:sequence, operands=[" +
557 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=eq}}," +
558 "{@type=korap:token, wrap={@type=korap:term, key=geht, layer=orth, match=eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000559 "]}" +
560 "]}" +
561 "]}" +
562 "]}";
563 ppt = new PoliqarpPlusTree("shrink([orth=Der]{[orth=Mann][orth=geht]})");
564 map = ppt.getRequestMap().get("query").toString();
565 assertEquals(shr2.replaceAll(" ", ""), map.replaceAll(" ", ""));
566
567 // shrink(1:[orth=Der]{1:[orth=Mann][orth=geht]})
568 String shr3 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000569 "{@type=korap:group, operation=operation:submatch, classRef=[1], operands=[" +
570 "{@type=korap:group, operation=operation:sequence, operands=[" +
571 "{@type=korap:token, wrap={@type=korap:term, key=Der, layer=orth, match=eq}}," +
572 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
573 "{@type=korap:group, operation=operation:sequence, operands=[" +
574 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=eq}}," +
575 "{@type=korap:token, wrap={@type=korap:term, key=geht, layer=orth, match=eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000576 "]}" +
577 "]}" +
578 "]}" +
579 "]}";
580 ppt = new PoliqarpPlusTree("shrink(1:[orth=Der]{1:[orth=Mann][orth=geht]})");
581 map = ppt.getRequestMap().get("query").toString();
582 assertEquals(shr3.replaceAll(" ", ""), map.replaceAll(" ", ""));
583
584 // shrink(1:startswith(<s>,{1:<np>}))
585 String shr4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000586 "{@type=korap:group, operation=operation:submatch, classRef=[1], operands=[" +
587 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
588 "{@type=korap:span, key=s}," +
589 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
590 "{@type=korap:span, key=np}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000591 "]}" +
592 "]}" +
593 "]}";
Joachim Bingeladefa622013-12-13 10:51:48 +0000594 ppt = new PoliqarpPlusTree("shrink(1:startswith(<s>,{1:<np>}))");
Joachim Bingel53333e62013-12-09 19:25:52 +0000595 map = ppt.getRequestMap().get("query").toString();
596 assertEquals(shr4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000597
598 // shrink(3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))
599 String shr5 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000600 "{@type=korap:group, operation=operation:submatch, classRef=[3], operands=[" +
601 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
602 "{@type=korap:span, key=s}," +
603 "{@type=korap:group, operation=operation:class, class=3, operands=[" +
604 "{@type=korap:group, operation=operation:sequence, operands=[" +
605 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=eq}}," +
606 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
607 "{@type=korap:group, operation=operation:sequence, operands=[" +
608 "{@type=korap:token, wrap={@type=korap:term, key=ADJA, layer=p, foundry=mate, match=eq}}," +
609 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
610 "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, foundry=tt, match=eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000611 "]}" +
612 "]}" +
613 "]}" +
614 "]}" +
615 "]}" +
616 "]}" +
617 "]}";
Joachim Bingeladefa622013-12-13 10:51:48 +0000618 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 +0000619 map = ppt.getRequestMap().get("query").toString();
620 assertEquals(shr5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000621
622 // split(3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))
623 String shr6 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000624 "{@type=korap:group, operation=operation:split, classRef=[3], operands=[" +
625 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
626 "{@type=korap:span, key=s}," +
627 "{@type=korap:group, operation=operation:class, class=3, operands=[" +
628 "{@type=korap:group, operation=operation:sequence, operands=[" +
629 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=eq}}," +
630 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
631 "{@type=korap:group, operation=operation:sequence, operands=[" +
632 "{@type=korap:token, wrap={@type=korap:term, key=ADJA, layer=p, foundry=mate, match=eq}}," +
633 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
634 "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, foundry=tt, match=eq}}" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000635 "]}" +
636 "]}" +
637 "]}" +
638 "]}" +
639 "]}" +
640 "]}" +
641 "]}";
642 ppt = new PoliqarpPlusTree("split(3:startswith(<s>,{3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) ");
643 map = ppt.getRequestMap().get("query").toString();
644 assertEquals(shr6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel8c640e42014-02-07 16:20:47 +0000645
646 // split(2|3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))
647 String shr7 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000648 "{@type=korap:group, operation=operation:split, classRef=[2, 3], classRefOp=classRefOp:intersection, operands=[" +
649 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
650 "{@type=korap:span, key=s}," +
651 "{@type=korap:group, operation=operation:class, class=3, operands=[" +
652 "{@type=korap:group, operation=operation:sequence, operands=[" +
653 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=eq}}," +
654 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
655 "{@type=korap:group, operation=operation:sequence, operands=[" +
656 "{@type=korap:token, wrap={@type=korap:term, key=ADJA, layer=p, foundry=mate, match=eq}}," +
657 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
658 "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, foundry=tt, match=eq}}" +
Joachim Bingel8c640e42014-02-07 16:20:47 +0000659 "]}" +
660 "]}" +
661 "]}" +
662 "]}" +
663 "]}" +
664 "]}" +
665 "]}";
666 ppt = new PoliqarpPlusTree("split(2|3:startswith(<s>,{3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) ");
667 map = ppt.getRequestMap().get("query").toString();
668 assertEquals(shr7.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000669 }
670
Joachim Bingel03882702013-12-31 19:53:05 +0000671
Joachim Bingel53333e62013-12-09 19:25:52 +0000672 @Test
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000673 public void testFoundries() throws QueryException {
674 // [tt/base=Mann]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000675 String layer1 = "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=base, foundry=tt, match=eq}}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000676 ppt = new PoliqarpPlusTree("[tt/base=Mann]");
677 map = ppt.getRequestMap().get("query").toString();
678 assertEquals(layer1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000679
680 }
Joachim Bingel16da4e12013-12-17 09:48:12 +0000681
682 @Test
Joachim Bingel8c640e42014-02-07 16:20:47 +0000683 public void testAlign() throws QueryException {
Joachim Bingel16da4e12013-12-17 09:48:12 +0000684 // [orth=der]^[orth=Mann]
685 String align1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000686 "{@type=korap:group, operation=operation:sequence, operands=[" +
687 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=eq}}," +
688 "{@type=korap:group, alignment=left, operands=[" +
689 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=eq}}" +
Joachim Bingel03882702013-12-31 19:53:05 +0000690 "]}" +
Joachim Bingel16da4e12013-12-17 09:48:12 +0000691 "]}";
692 ppt = new PoliqarpPlusTree("[orth=der]^[orth=Mann]");
693 map = ppt.getRequestMap().get("query").toString();
694 assertEquals(align1.replaceAll(" ", ""), map.replaceAll(" ", ""));
695
Joachim Bingel84e33df2014-01-31 14:02:46 +0000696 // [orth=der]^[orth=große][orth=Mann]
697 String query = "[orth=der]^[orth=große][orth=Mann]";
698 String align1b =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000699 "{@type=korap:group, operation=operation:sequence, operands=[" +
700 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=eq}}," +
701 "{@type=korap:group, alignment=left, operands=[" +
702 "{@type=korap:group, operation=operation:sequence, operands=[" +
703 "{@type=korap:token, wrap={@type=korap:term, key=große, layer=orth, match=eq}}," +
704 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=eq}}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +0000705 "]}" +
706 "]}" +
707 "]}";
708 ppt = new PoliqarpPlusTree(query);
709 map = ppt.getRequestMap().get("query").toString();
710 assertEquals(align1b.replaceAll(" ", ""), map.replaceAll(" ", ""));
711
Joachim Bingel16da4e12013-12-17 09:48:12 +0000712 // "([base=a]^[base=b])|[base=c]",
713 String align2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000714 "{@type=korap:group, operation=operation:or, operands=[" +
715 "{@type=korap:group, operation=operation:sequence, operands=[" +
716 "{@type=korap:token, wrap={@type=korap:term, key=a, layer=lemma, match=eq}}," +
717 "{@type=korap:group, alignment=left, operands=[" +
718 "{@type=korap:token, wrap={@type=korap:term, key=b, layer=lemma, match=eq}}" +
Joachim Bingel03882702013-12-31 19:53:05 +0000719 "]}" +
Joachim Bingel16da4e12013-12-17 09:48:12 +0000720 "]}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000721 "{@type=korap:token, wrap={@type=korap:term, key=c, layer=lemma, match=eq}}" +
Joachim Bingel16da4e12013-12-17 09:48:12 +0000722 "]}";
723 ppt = new PoliqarpPlusTree("([base=a]^[base=b])|[base=c]");
724 map = ppt.getRequestMap().get("query").toString();
725 assertEquals(align2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingela67e6a32014-01-02 18:35:24 +0000726
727 // "([base=a]^[base=b][base=c])|[base=d]",
728 String align3 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000729 "{@type=korap:group, operation=operation:or, operands=[" +
730 "{@type=korap:group, operation=operation:sequence, operands=[" +
731 "{@type=korap:token, wrap={@type=korap:term, key=a, layer=lemma, match=eq}}," +
732 "{@type=korap:group, alignment=left, operands=[" +
733 "{@type=korap:group, operation=operation:sequence, operands=[" +
734 "{@type=korap:token, wrap={@type=korap:term, key=b, layer=lemma, match=eq}}," +
735 "{@type=korap:token, wrap={@type=korap:term, key=c, layer=lemma, match=eq}}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +0000736 "]}" +
737 "]}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000738 "]}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000739 "{@type=korap:token, wrap={@type=korap:term, key=d, layer=lemma, match=eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000740 "]}";
741 ppt = new PoliqarpPlusTree("([base=a]^[base=b][base=c])|[base=d]");
742 map = ppt.getRequestMap().get("query").toString();
743 assertEquals(align3.replaceAll(" ", ""), map.replaceAll(" ", ""));
744
745 // "([base=a]^[base=b]^[base=c])|[base=d]",
746 String align4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000747 "{@type=korap:group, operation=operation:or, operands=[" +
748 "{@type=korap:group, operation=operation:sequence, operands=[" +
749 "{@type=korap:token, wrap={@type=korap:term, key=a, layer=lemma, match=eq}}," +
750 "{@type=korap:group, alignment=left, operands=[" +
751 "{@type=korap:group, operation=operation:sequence, operands=[" +
752 "{@type=korap:token, wrap={@type=korap:term, key=b, layer=lemma, match=eq}}," +
753 "{@type=korap:group, alignment=left, operands=[" +
754 "{@type=korap:token, wrap={@type=korap:term, key=c, layer=lemma, match=eq}}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +0000755 "]}" +
756 "]}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000757 "]}" +
758 "]}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000759 "{@type=korap:token, wrap={@type=korap:term, key=d, layer=lemma, match=eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000760 "]}";
761 ppt = new PoliqarpPlusTree("([base=a]^[base=b]^[base=c])|[base=d]");
762 map = ppt.getRequestMap().get("query").toString();
763 assertEquals(align4.replaceAll(" ", ""), map.replaceAll(" ", ""));
764
765
Joachim Bingel16da4e12013-12-17 09:48:12 +0000766 }
767
768 @Test
Joachim Bingel8c640e42014-02-07 16:20:47 +0000769 public void testSimpleQueries() throws QueryException {
Joachim Bingela67e6a32014-01-02 18:35:24 +0000770 // Baum
771 String simple1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000772 "{@type=korap:token, wrap={@type=korap:term, key=Baum, layer=orth, match=eq}}";
Joachim Bingela67e6a32014-01-02 18:35:24 +0000773 ppt = new PoliqarpPlusTree("Baum");
774 map = ppt.getRequestMap().get("query").toString();
775 assertEquals(simple1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel16da4e12013-12-17 09:48:12 +0000776
Joachim Bingela67e6a32014-01-02 18:35:24 +0000777 // Der Baum
778 String simple2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000779 "{@type=korap:group, operation=operation:sequence, operands=[" +
780 "{@type=korap:token, wrap={@type=korap:term, key=Der, layer=orth, match=eq}}, " +
781 "{@type=korap:token, wrap={@type=korap:term, key=Baum, layer=orth, match=eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000782 "]}";
783 ppt = new PoliqarpPlusTree("Der Baum");
784 map = ppt.getRequestMap().get("query").toString();
785 assertEquals(simple2.replaceAll(" ", ""), map.replaceAll(" ", ""));
786
787 // Der große Baum
788 String simple3 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000789 "{@type=korap:group, operation=operation:sequence, operands=[" +
790 "{@type=korap:token, wrap={@type=korap:term, key=Der, layer=orth, match=eq}}, " +
791 "{@type=korap:token, wrap={@type=korap:term, key=große, layer=orth, match=eq}}, " +
792 "{@type=korap:token, wrap={@type=korap:term, key=Baum, layer=orth, match=eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000793 "]}";
794 ppt = new PoliqarpPlusTree("Der große Baum");
795 map = ppt.getRequestMap().get("query").toString();
796 assertEquals(simple3.replaceAll(" ", ""), map.replaceAll(" ", ""));
797
798 // Baum | Stein
799 String simple4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000800 "{@type=korap:group, operation=operation:or, operands=[" +
801 "{@type=korap:token, wrap={@type=korap:term, key=Baum, layer=orth, match=eq}}, " +
802 "{@type=korap:token, wrap={@type=korap:term, key=Stein, layer=orth, match=eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000803 "]}";
804 ppt = new PoliqarpPlusTree("Baum | Stein");
805 map = ppt.getRequestMap().get("query").toString();
806 assertEquals(simple4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel84e33df2014-01-31 14:02:46 +0000807
808 // Baum | Stein Haus
809 String query = "(Baum | Stein) Haus";
810 String simple5 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000811 "{@type=korap:group, operation=operation:sequence, operands=[" +
812 "{@type=korap:group, operation=operation:or, operands=[" +
813 "{@type=korap:token, wrap={@type=korap:term, key=Baum, layer=orth, match=eq}}, " +
814 "{@type=korap:token, wrap={@type=korap:term, key=Stein, layer=orth, match=eq}}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +0000815 "]}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000816 "{@type=korap:token, wrap={@type=korap:term, key=Haus, layer=orth, match=eq}} " +
Joachim Bingel84e33df2014-01-31 14:02:46 +0000817 "]}";
818 ppt = new PoliqarpPlusTree(query);
819 map = ppt.getRequestMap().get("query").toString();
820 assertEquals(simple5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel16da4e12013-12-17 09:48:12 +0000821 }
Joachim Bingel53333e62013-12-09 19:25:52 +0000822}
823