blob: 70c8231c1a4a85587e41ca2374e212094c92f012 [file] [log] [blame]
Joachim Bingel53333e62013-12-09 19:25:52 +00001import static org.junit.Assert.*;
2
3import org.junit.Test;
4
5import de.ids_mannheim.korap.query.serialize.PoliqarpPlusTree;
Joachim Bingel16da4e12013-12-17 09:48:12 +00006import de.ids_mannheim.korap.util.QueryException;
Joachim Bingel53333e62013-12-09 19:25:52 +00007
8public class PoliqarpPlusTreeTest {
9
10 PoliqarpPlusTree ppt;
11 String map;
12
13 private boolean equalsContent(String str, Object map) {
14 str = str.replaceAll(" ", "");
15 String mapStr = map.toString().replaceAll(" ", "");
16 return str.equals(mapStr);
17 }
18
Joachim Bingel16da4e12013-12-17 09:48:12 +000019 private boolean equalsQueryContent(String res, String query) throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +000020 res = res.replaceAll(" ", "");
21 ppt = new PoliqarpPlusTree(query);
22 String queryMap = ppt.getRequestMap().get("query").toString().replaceAll(" ", "");
23 return res.equals(queryMap);
24 }
25
26 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +000027 public void testContext() throws QueryException {
Joachim Bingelba9a0ab2014-01-29 10:12:25 +000028 String contextString = "{korap=http://korap.ids-mannheim.de/ns/query, @language=de, @operands={@id=korap:operands, @container=@list}, @relation={@id=korap:relation, @type=korap:relation#types}, class={@id=korap:class, @type=xsd:integer}, query=korap:query, filter=korap:filter, meta=korap:meta}";
Joachim Bingel53333e62013-12-09 19:25:52 +000029 ppt = new PoliqarpPlusTree("[base=test]");
30 assertTrue(equalsContent(contextString, ppt.getRequestMap().get("@context")));
31 }
32
33 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +000034 public void testSingleTokens() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +000035 // [base=Mann]
Joachim Bingelba9a0ab2014-01-29 10:12:25 +000036 String token1 = "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=base, @relation==}}";
Joachim Bingel53333e62013-12-09 19:25:52 +000037 assertTrue(equalsQueryContent(token1, "[base=Mann]"));
38
39 // [orth!=Frau]
Joachim Bingelba9a0ab2014-01-29 10:12:25 +000040 String token2 = "{@type=korap:token, @value={@type=korap:term, @value=Frau, @attr=orth, @relation=!=}}";
Joachim Bingel53333e62013-12-09 19:25:52 +000041 assertTrue(equalsQueryContent(token2, "[orth!=Frau]"));
42
43 // [!p=NN]
Joachim Bingelba9a0ab2014-01-29 10:12:25 +000044 String token3 = "{@type=korap:token, @value={@type=korap:term, @value=NN, @attr=p, @relation=!=}}";
Joachim Bingel53333e62013-12-09 19:25:52 +000045 assertTrue(equalsQueryContent(token3, "[!p=NN]"));
46
47 // [!p!=NN]
Joachim Bingelba9a0ab2014-01-29 10:12:25 +000048 String token4 = "{@type=korap:token, @value={@type=korap:term, @value=NN, @attr=p, @relation==}}";
Joachim Bingel53333e62013-12-09 19:25:52 +000049 assertTrue(equalsQueryContent(token4, "[!p!=NN]"));
50 }
51
52 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +000053 public void testElements() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +000054 // <s>
Joachim Bingelba9a0ab2014-01-29 10:12:25 +000055 String elem1 = "{@type=korap:span, @value=s}";
Joachim Bingel53333e62013-12-09 19:25:52 +000056 assertTrue(equalsQueryContent(elem1, "<s>"));
57
58 // <vp>
Joachim Bingelba9a0ab2014-01-29 10:12:25 +000059 String elem2 = "{@type=korap:span, @value=vp}";
Joachim Bingel53333e62013-12-09 19:25:52 +000060 assertTrue(equalsQueryContent(elem2, "<vp>"));
61 }
Joachim Bingel87480d02014-01-17 14:07:46 +000062
63 @Test
64 public void testEmptyTokens() throws QueryException {
65 // [base=der][][base=Mann]
66 String et1 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +000067 "{@type=korap:sequence, @inOrder=true, @constraints=[" +
68 "{@type=korap:distance, measure=w, min=1, max=1}" +
Joachim Bingel87480d02014-01-17 14:07:46 +000069 "], " +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +000070 "@operands=[" +
71 "{@type=korap:token, @value={@type=korap:term, @value=der, @attr=base, @relation==}}," +
72 "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=base, @relation==}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +000073 "]}";
74 ppt = new PoliqarpPlusTree("[base=der][][base=Mann]");
75 map = ppt.getRequestMap().get("query").toString();
76 assertEquals(et1.replaceAll(" ", ""), map.replaceAll(" ", ""));
77
78 // [base=der][][][base=Mann]
79 String et2 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +000080 "{@type=korap:sequence, @inOrder=true, @constraints=[" +
81 "{@type=korap:distance, measure=w, min=2, max=2}" +
Joachim Bingel87480d02014-01-17 14:07:46 +000082 "], " +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +000083 "@operands=[" +
84 "{@type=korap:token, @value={@type=korap:term, @value=der, @attr=base, @relation==}}," +
85 "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=base, @relation==}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +000086 "]}";
Joachim Bingelffd65e32014-01-22 14:22:57 +000087 ppt = new PoliqarpPlusTree("[base=der][][][base=Mann]");
Joachim Bingel87480d02014-01-17 14:07:46 +000088 map = ppt.getRequestMap().get("query").toString();
89 assertEquals(et2.replaceAll(" ", ""), map.replaceAll(" ", ""));
90
91 // [base=der][][]?[base=Mann]
92 String et3 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +000093 "{@type=korap:sequence, @inOrder=true, @constraints=[" +
94 "{@type=korap:distance, measure=w, min=1, max=2}" +
Joachim Bingel87480d02014-01-17 14:07:46 +000095 "], " +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +000096 "@operands=[" +
97 "{@type=korap:token, @value={@type=korap:term, @value=der, @attr=base, @relation==}}," +
98 "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=base, @relation==}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +000099 "]}";
100 ppt = new PoliqarpPlusTree("[base=der][][]?[base=Mann]");
101 map = ppt.getRequestMap().get("query").toString();
102 assertEquals(et3.replaceAll(" ", ""), map.replaceAll(" ", ""));
103
Joachim Bingel87480d02014-01-17 14:07:46 +0000104
105 // startswith(<s>, [][base=Mann]
Joachim Bingelffd65e32014-01-22 14:22:57 +0000106 String et4 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000107 "{@type=korap:group, @relation=position, @position=startswith, @operands=[" +
108 "{@type=korap:span, @value=s}," +
109 "{@type=korap:sequence, offset-min=1, offset-max=1, @operands=[" +
110 "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=base, @relation==}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000111 "]}" +
112 "]}";
Joachim Bingelffd65e32014-01-22 14:22:57 +0000113 ppt = new PoliqarpPlusTree("startswith(<s>, [][base=Mann])");
114 map = ppt.getRequestMap().get("query").toString();
115 assertEquals(et4.replaceAll(" ", ""), map.replaceAll(" ", ""));
116
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000117 // [base=der][]{2,5}[base=Mann][]?[][base=Frau] nested distances
Joachim Bingelffd65e32014-01-22 14:22:57 +0000118 String et5 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000119 "{@type=korap:sequence, @inOrder=true, @constraints=[" +
120 "{@type=korap:distance, measure=w, min=2, max=5}" +
Joachim Bingelffd65e32014-01-22 14:22:57 +0000121 "], " +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000122 "@operands=[" +
123 "{@type=korap:token, @value={@type=korap:term, @value=der, @attr=base, @relation==}}," +
124 "{@type=korap:sequence, @inOrder=true, @constraints=[" +
125 "{@type=korap:distance, measure=w, min=1, max=2}" +
Joachim Bingelffd65e32014-01-22 14:22:57 +0000126 "], " +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000127 "@operands=[" +
128 "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=base, @relation==}}," +
129 "{@type=korap:token, @value={@type=korap:term, @value=Frau, @attr=base, @relation==}}" +
Joachim Bingelffd65e32014-01-22 14:22:57 +0000130 "]}" +
131 "]}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000132 ppt = new PoliqarpPlusTree("[base=der][]{2,5}[base=Mann][]?[][base=Frau]");
Joachim Bingel87480d02014-01-17 14:07:46 +0000133 map = ppt.getRequestMap().get("query").toString();
134 assertEquals(et5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel87480d02014-01-17 14:07:46 +0000135
136 }
Joachim Bingel53333e62013-12-09 19:25:52 +0000137
138 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000139 public void testCoordinatedFields() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000140 // [base=Mann&(cas=N|cas=A)]
141 String cof1 =
142 "{@type=korap:token, @value=" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000143 "{@type=korap:group, @operands=[" +
144 "{@type=korap:term, @value=Mann, @attr=base, @relation==}," +
145 "{@type=korap:group, @operands=[" +
146 "{@type=korap:term, @value=N, @attr=cas, @relation==}," +
147 "{@type=korap:term, @value=A, @attr=cas, @relation==}" +
148 "], @relation=or}" +
149 "], @relation=and}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000150 "}";
151 ppt = new PoliqarpPlusTree("[base=Mann&(cas=N|cas=A)]");
152 map = ppt.getRequestMap().get("query").toString();
153 assertEquals(cof1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Nils Diewald7d486c22013-12-13 16:32:18 +0000154
155
156 assertEquals(
157 new PoliqarpPlusTree(" [ base=Mann & ( cas=N | cas=A)] ").getRequestMap().get("query").toString(),
158 new PoliqarpPlusTree("[base=Mann &(cas=N|cas=A)]").getRequestMap().get("query").toString()
159 );
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000160
161 // [base=Mann&cas=N&gen=m]
162 String cof2 =
163 "{@type=korap:token, @value=" +
164 "{@type=korap:group, @operands=[" +
165 "{@type=korap:term, @value=Mann, @attr=base, @relation==}," +
166 "{@type=korap:term, @value=N, @attr=cas, @relation==}," +
167 "{@type=korap:term, @value=m, @attr=gen, @relation==}" +
168 "], @relation=and}" +
169 "}";
170 ppt = new PoliqarpPlusTree("[base=Mann&cas=N&gen=m]");
171 map = ppt.getRequestMap().get("query").toString();
172 assertEquals(cof2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000173 }
174
175 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000176 public void testOccurrence() throws QueryException {
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000177 // [base=foo]*
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000178 String occ1 = "{@type=korap:group, @operands=[" +
179 "{@type=korap:token, @value={@type=korap:term, @value=foo, @attr=base, @relation==}}" +
180 "], @relation=repetition, @min=0, @max=100}";
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000181 ppt = new PoliqarpPlusTree("[base=foo]*");
182 map = ppt.getRequestMap().get("query").toString();
183 assertEquals(occ1.replaceAll(" ", ""), map.replaceAll(" ", ""));
184
185 // [base=foo]*[base=bar]
186 String occ2 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000187 "{@type=korap:sequence, @operands=[" +
188 "{@type=korap:group, @operands=[" +
189 "{@type=korap:token, @value={@type=korap:term, @value=foo, @attr=base, @relation==}}" +
190 "], @relation=repetition, @min=0, @max=100 }," +
191 "{@type=korap:token, @value={@type=korap:term, @value=bar, @attr=base, @relation==}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000192 "]}";
193 ppt = new PoliqarpPlusTree("[base=foo]*[base=bar]");
194 map = ppt.getRequestMap().get("query").toString();
195 assertEquals(occ2.replaceAll(" ", ""), map.replaceAll(" ", ""));
196
197 // [base=bar][base=foo]*
198 String occ3 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000199 "{@type=korap:sequence, @operands=[" +
200 "{@type=korap:token, @value={@type=korap:term, @value=bar, @attr=base, @relation==}}," +
201 "{@type=korap:group, @operands=[" +
202 "{@type=korap:token, @value={@type=korap:term, @value=foo, @attr=base, @relation==}}" +
203 "], @relation=repetition, @min=0, @max=100 }" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000204 "]}";
205 ppt = new PoliqarpPlusTree("[base=bar][base=foo]*");
206 map = ppt.getRequestMap().get("query").toString();
207 assertEquals(occ3.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb4da7022013-12-09 23:17:24 +0000208
209 // ([base=bar][base=foo])*
210 String occ4 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000211 "{@type=korap:group, @operands=[" +
212 "{@type=korap:sequence, @operands=[" +
213 "{@type=korap:token, @value={@type=korap:term, @value=bar, @attr=base, @relation==}}," +
214 "{@type=korap:token, @value={@type=korap:term, @value=foo, @attr=base, @relation==}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000215 "]}" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000216 "], @relation=repetition, @min=0, @max=100 }" ;
Joachim Bingelb4da7022013-12-09 23:17:24 +0000217 ppt = new PoliqarpPlusTree("([base=bar][base=foo])*");
218 map = ppt.getRequestMap().get("query").toString();
219 assertEquals(occ4.replaceAll(" ", ""), map.replaceAll(" ", ""));
220
221 // <s>([base=bar][base=foo])*
222 String occ5 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000223 "{@type=korap:sequence, @operands=[" +
224 "{@type=korap:span, @value=s}," +
225 "{@type=korap:group, @operands=[" +
226 "{@type=korap:sequence, @operands=[" +
227 "{@type=korap:token, @value={@type=korap:term, @value=bar, @attr=base, @relation==}}," +
228 "{@type=korap:token, @value={@type=korap:term, @value=foo, @attr=base, @relation==}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000229 "]}" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000230 "], @relation=repetition, @min=0, @max=100 }" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000231 "]}" ;
232 ppt = new PoliqarpPlusTree("<s>([base=bar][base=foo])*");
233 map = ppt.getRequestMap().get("query").toString();
234 assertEquals(occ5.replaceAll(" ", ""), map.replaceAll(" ", ""));
235
236 // <s><np>([base=bar][base=foo])*
Joachim Bingelb4da7022013-12-09 23:17:24 +0000237 String occ6 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000238 "{@type=korap:sequence, @operands=[" +
239 "{@type=korap:span, @value=s}," +
240 "{@type=korap:span, @value=np}," +
241 "{@type=korap:group, @operands=[" +
242 "{@type=korap:sequence, @operands=[" +
243 "{@type=korap:token, @value={@type=korap:term, @value=bar, @attr=base, @relation==}}," +
244 "{@type=korap:token, @value={@type=korap:term, @value=foo, @attr=base, @relation==}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000245 "]}" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000246 "], @relation=repetition, @min=0, @max=100 }" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000247 "]}" ;
248 ppt = new PoliqarpPlusTree("<s><np>([base=bar][base=foo])*");
249 map = ppt.getRequestMap().get("query").toString();
250 assertEquals(occ6.replaceAll(" ", ""), map.replaceAll(" ", ""));
251
252 // <s><np>([base=bar][base=foo])*[p=NN]
253 // comment: embedded sequence shouldn't really be here, but does not really hurt, either. (?)
254 // really hard to get this behaviour out of the PQPlus grammar...
255 String occ7 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000256 "{@type=korap:sequence, @operands=[" +
257 "{@type=korap:span, @value=s}," +
258 "{@type=korap:span, @value=np}," +
259 "{@type=korap:group, @operands=[" +
260 "{@type=korap:sequence, @operands=[" +
261 "{@type=korap:token, @value={@type=korap:term, @value=bar, @attr=base, @relation==}}," +
262 "{@type=korap:token, @value={@type=korap:term, @value=foo, @attr=base, @relation==}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000263 "]}" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000264 "], @relation=repetition, @min=0, @max=100 }," +
265 "{@type=korap:token, @value={@type=korap:term, @value=NN, @attr=p, @relation==}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000266 "]}" ;
267 ppt = new PoliqarpPlusTree("<s><np>([base=bar][base=foo])*[p=NN]");
268 map = ppt.getRequestMap().get("query").toString();
269 assertEquals(occ7.replaceAll(" ", ""), map.replaceAll(" ", ""));
270
271 // ([base=bar][base=foo])*[p=NN]
Joachim Bingelb4da7022013-12-09 23:17:24 +0000272 String occ8 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000273 "{@type=korap:sequence, @operands=[" +
274 "{@type=korap:group, @operands=[" +
275 "{@type=korap:sequence, @operands=[" +
276 "{@type=korap:token, @value={@type=korap:term, @value=bar, @attr=base, @relation==}}," +
277 "{@type=korap:token, @value={@type=korap:term, @value=foo, @attr=base, @relation==}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000278 "]}" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000279 "], @relation=repetition, @min=0, @max=100 }," +
280 "{@type=korap:token, @value={@type=korap:term, @value=NN, @attr=p, @relation==}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000281 "]}" ;
282 ppt = new PoliqarpPlusTree("([base=bar][base=foo])*[p=NN]");
283 map = ppt.getRequestMap().get("query").toString();
284 assertEquals(occ8.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000285
286 // [base=foo]+
287 String occ9 = "{@type=korap:group, @operands=[" +
288 "{@type=korap:token, @value={@type=korap:term, @value=foo, @attr=base, @relation==}}" +
289 "], @relation=repetition, @min=1, @max=100}";
290 ppt = new PoliqarpPlusTree("[base=foo]+");
291 map = ppt.getRequestMap().get("query").toString();
292 assertEquals(occ9.replaceAll(" ", ""), map.replaceAll(" ", ""));
293
294 // [base=foo]?
295 String occ10 = "{@type=korap:group, @operands=[" +
296 "{@type=korap:token, @value={@type=korap:term, @value=foo, @attr=base, @relation==}}" +
297 "], @relation=repetition, @min=0, @max=1}";
298 ppt = new PoliqarpPlusTree("[base=foo]?");
299 map = ppt.getRequestMap().get("query").toString();
300 assertEquals(occ10.replaceAll(" ", ""), map.replaceAll(" ", ""));
301
302 // [base=foo]{2,5}
303 String occ11 = "{@type=korap:group, @operands=[" +
304 "{@type=korap:token, @value={@type=korap:term, @value=foo, @attr=base, @relation==}}" +
305 "], @relation=repetition, @min=2, @max=5}";
306 ppt = new PoliqarpPlusTree("[base=foo]{2,5}");
307 map = ppt.getRequestMap().get("query").toString();
308 assertEquals(occ11.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000309 }
310
311 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000312 public void testTokenSequence() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000313 // [base=Mann][orth=Frau]
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000314 String seq1 = "{@type=korap:sequence, @operands=[" +
315 "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=base, @relation==}}, " +
316 "{@type=korap:token, @value={@type=korap:term, @value=Frau, @attr=orth, @relation==}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000317 "]}";
318 assertTrue(equalsQueryContent(seq1, "[base=Mann][orth=Frau]"));
319
320 // [base=Mann][orth=Frau][p=NN]
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000321 String seq2 = "{@type=korap:sequence, @operands=[" +
322 "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=base, @relation==}}, " +
323 "{@type=korap:token, @value={@type=korap:term, @value=Frau, @attr=orth, @relation==}}, " +
324 "{@type=korap:token, @value={@type=korap:term, @value=NN,@attr=p, @relation==}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000325 "]}";
326 assertTrue(equalsQueryContent(seq2, "[base=Mann][orth=Frau][p=NN]"));
327 }
328
329 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000330 public void testDisjSegments() throws QueryException {
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000331 // ([base=der]|[base=das])[base=Schild]
332 String disj1 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000333 "{@type=korap:sequence, @operands=[" +
334 "{@type=korap:group, @relation=or, @operands=[" +
335 "{@type=korap:token, @value={@type=korap:term, @value=der, @attr=base, @relation==}}," +
336 "{@type=korap:token, @value={@type=korap:term, @value=das, @attr=base, @relation==}}" +
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000337 "]}," +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000338 "{@type=korap:token, @value={@type=korap:term, @value=Schild, @attr=base, @relation==}}" +
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000339 "]}";
340 ppt = new PoliqarpPlusTree("([base=der]|[base=das])[base=Schild]");
341 map = ppt.getRequestMap().get("query").toString();
342 assertEquals(disj1.replaceAll(" ", ""), map.replaceAll(" ", ""));
343
344 // [base=Schild]([base=der]|[base=das])
345 String disj2 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000346 "{@type=korap:sequence, @operands=[" +
347 "{@type=korap:token, @value={@type=korap:term, @value=Schild, @attr=base, @relation==}}," +
348 "{@type=korap:group, @relation=or, @operands=[" +
349 "{@type=korap:token, @value={@type=korap:term, @value=der, @attr=base, @relation==}}," +
350 "{@type=korap:token, @value={@type=korap:term, @value=das, @attr=base, @relation==}}" +
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000351 "]}" +
352 "]}";
353 ppt = new PoliqarpPlusTree("[base=Schild]([base=der]|[base=das])");
354 map = ppt.getRequestMap().get("query").toString();
355 assertEquals(disj2.replaceAll(" ", ""), map.replaceAll(" ", ""));
356 }
357
358 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000359 public void testTokenElemSequence() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000360 // [base=Mann]<vp>
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000361 String seq1 = "{@type=korap:sequence, @operands=[" +
362 "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=base, @relation==}}, " +
363 "{@type=korap:span, @value=vp}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000364 "]}";
365 assertTrue(equalsQueryContent(seq1, "[base=Mann]<vp>"));
366
367 // <vp>[base=Mann]
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000368 String seq2 = "{@type=korap:sequence, @operands=[" +
369 "{@type=korap:span, @value=vp}, "+
370 "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=base, @relation==}} " +
Joachim Bingel53333e62013-12-09 19:25:52 +0000371 "]}";
372 assertTrue(equalsQueryContent(seq2, "<vp>[base=Mann]"));
373
374 // <vp>[base=Mann]<pp>
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000375 String seq3 = "{@type=korap:sequence, @operands=[" +
376 "{@type=korap:span, @value=vp}, "+
377 "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=base, @relation==}}, " +
378 "{@type=korap:span, @value=pp} "+
Joachim Bingel53333e62013-12-09 19:25:52 +0000379 "]}";
380 assertTrue(equalsQueryContent(seq3, "<vp>[base=Mann]<pp>"));
381 }
382
383 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000384 public void testElemSequence() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000385 // <np><vp>
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000386 String seq1 = "{@type=korap:sequence, @operands=[" +
387 "{@type=korap:span, @value=np}," +
388 "{@type=korap:span, @value=vp}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000389 "]}";
390 assertTrue(equalsQueryContent(seq1, "<np><vp>"));
391
392 // <np><vp><pp>
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000393 String seq2 = "{@type=korap:sequence, @operands=[" +
394 "{@type=korap:span, @value=np}," +
395 "{@type=korap:span, @value=vp}," +
396 "{@type=korap:span, @value=pp}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000397 "]}";
398 assertTrue(equalsQueryContent(seq2, "<np><vp><pp>"));
399 }
400
401 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000402 public void testClasses() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000403 // {[base=Mann]}
Joachim Bingel8c640e42014-02-07 16:20:47 +0000404 String cls1 = "{@type=korap:group, @relation=class, class=0, @operands=[" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000405 "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=base, @relation==}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000406 "]}";
Joachim Bingel8c640e42014-02-07 16:20:47 +0000407 ppt = new PoliqarpPlusTree("{[base=Mann]}");
408 map = ppt.getRequestMap().get("query").toString();
409 assertEquals(cls1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000410
411 // {[base=Mann][orth=Frau]}
Joachim Bingel8c640e42014-02-07 16:20:47 +0000412 String cls2 = "{@type=korap:group, @relation=class, class=0, @operands=[" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000413 "{@type=korap:sequence, @operands=[" +
414 "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=base, @relation==}}," +
415 "{@type=korap:token, @value={@type=korap:term, @value=Frau, @attr=orth, @relation==}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000416 "]}" +
417 "]}";
418 assertTrue(equalsQueryContent(cls2, "{[base=Mann][orth=Frau]}"));
419
420 // [p=NN]{[base=Mann][orth=Frau]}
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000421 String cls3 = "{@type=korap:sequence, @operands=[" +
422 "{@type=korap:token, @value={@type=korap:term, @value=NN, @attr=p, @relation==}}," +
Joachim Bingel8c640e42014-02-07 16:20:47 +0000423 "{@type=korap:group, @relation=class, class=0, @operands=[" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000424 "{@type=korap:sequence, @operands=[" +
425 "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=base, @relation==}}," +
426 "{@type=korap:token, @value={@type=korap:term, @value=Frau, @attr=orth, @relation==}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000427 "]}" +
428 "]}" +
429 "]}";
430 assertTrue(equalsQueryContent(cls3, "[p=NN]{[base=Mann][orth=Frau]}"));
431
432 // {[base=Mann][orth=Frau]}[p=NN]
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000433 String cls4 = "{@type=korap:sequence, @operands=[" +
Joachim Bingel8c640e42014-02-07 16:20:47 +0000434 "{@type=korap:group, @relation=class, class=0, @operands=[" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000435 "{@type=korap:sequence, @operands=[" +
436 "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=base, @relation==}}," +
437 "{@type=korap:token, @value={@type=korap:term, @value=Frau, @attr=orth, @relation==}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000438 "]}" +
439 "]}," +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000440 "{@type=korap:token, @value={@type=korap:term, @value=NN, @attr=p, @relation==}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000441 "]}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000442 ppt = new PoliqarpPlusTree("{[base=Mann][orth=Frau]}[p=NN]");
443 map = ppt.getRequestMap().get("query").toString();
444 assertEquals(cls4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000445
446 // {2:{1:[tt/p=ADJA]}[mate/p=NN]}"
Joachim Bingel8c640e42014-02-07 16:20:47 +0000447 String cls5 = "{@type=korap:group, @relation=class, class=2, @operands=[" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000448 "{@type=korap:sequence, @operands=[" +
Joachim Bingel8c640e42014-02-07 16:20:47 +0000449 "{@type=korap:group, @relation=class, class=1, @operands=[" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000450 "{@type=korap:token, @value={@type=korap:term, @value=ADJA, @attr=p, @foundry=tt, @relation==}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000451 "]}," +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000452 "{@type=korap:token, @value={@type=korap:term, @value=NN, @attr=p, @foundry=mate, @relation==}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000453 "]}" +
454 "]}";
455 ppt = new PoliqarpPlusTree("{2: {1:[tt/p=ADJA]}[mate/p=NN]}");
456 map = ppt.getRequestMap().get("query").toString();
457 assertEquals(cls5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000458 }
459
460 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000461 public void testPositions() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000462 // contains(<s>,<np>)
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000463 String pos1 = "{@type=korap:group, @relation=position, @position=contains, @operands=[" +
464 "{@type=korap:span, @value=s}," +
465 "{@type=korap:span, @value=np}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000466 "]}";
467 assertTrue(equalsQueryContent(pos1, "contains(<s>,<np>)"));
468
469 // contains(<s>,[base=Mann])
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000470 String pos2 = "{@type=korap:group, @relation=position, @position=contains, @operands=[" +
471 "{@type=korap:span, @value=s}," +
472 "{@type=korap:token, @value= {@type=korap:term, @value=Mann, @attr=base, @relation==}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000473 "]}";
474 assertTrue(equalsQueryContent(pos2, "contains(<s>,[base=Mann])"));
475
476 // contains(<s>,[orth=der][orth=Mann])
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000477 String pos3 = "{@type=korap:group, @relation=position, @position=contains, @operands=[" +
478 "{@type=korap:span, @value=s}," +
479 "{@type=korap:sequence, @operands=[" +
480 "{@type=korap:token, @value={@type=korap:term, @value=der, @attr=orth, @relation==}}," +
481 "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=orth, @relation==}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000482 "]}" +
483 "]}";
484 ppt = new PoliqarpPlusTree("contains(<s>,[orth=der][orth=Mann])");
485 map = ppt.getRequestMap().get("query").toString();
486 assertEquals(pos3.replaceAll(" ", ""), map.replaceAll(" ", ""));
487
488 // [base=Auto]contains(<s>,[base=Mann])
489 String pos4 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000490 "{@type=korap:sequence, @operands=[" +
491 "{@type=korap:token, @value={@type=korap:term, @value=Auto, @attr=base, @relation==}}," +
492 "{@type=korap:group, @relation=position, @position=contains, @operands=[" +
493 "{@type=korap:span, @value=s}," +
494 "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=base, @relation==}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000495 "]}" +
496 "]}";
497 ppt = new PoliqarpPlusTree("[base=Auto]contains(<s>,[base=Mann])");
498 map = ppt.getRequestMap().get("query").toString();
499 assertEquals(pos4.replaceAll(" ", ""), map.replaceAll(" ", ""));
500 }
501
502 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000503 public void testNestedPositions() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000504 // contains(<s>,startswith(<np>,[orth=Der]))
505 String npos1 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000506 "{@type=korap:group, @relation=position, @position=contains, @operands=[" +
507 "{@type=korap:span, @value=s}," +
508 "{@type=korap:group, @relation=position, @position=startswith, @operands=[" +
509 "{@type=korap:span, @value=np}," +
510 "{@type=korap:token, @value={@type=korap:term, @value=Der, @attr=orth, @relation==}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000511 "]}" +
512 "]}";
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000513 ppt = new PoliqarpPlusTree("contains(<s>, startswith(<np>,[orth=Der]))");
Joachim Bingel53333e62013-12-09 19:25:52 +0000514 map = ppt.getRequestMap().get("query").toString();
515 assertEquals(npos1.replaceAll(" ", ""), map.replaceAll(" ", ""));
516 }
517
518 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000519 public void testShrinkSplit() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000520 // shrink([orth=Der]{[orth=Mann]})
521 String shr1 =
Joachim Bingel8c640e42014-02-07 16:20:47 +0000522 "{@type=korap:group, @relation=shrink, classRef=[0], @operands=[" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000523 "{@type=korap:sequence, @operands=[" +
524 "{@type=korap:token, @value={@type=korap:term, @value=Der, @attr=orth, @relation==}}," +
Joachim Bingel8c640e42014-02-07 16:20:47 +0000525 "{@type=korap:group, @relation=class, class=0, @operands=[" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000526 "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=orth, @relation==}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000527 "]}" +
528 "]}" +
529 "]}";
530 ppt = new PoliqarpPlusTree("shrink([orth=Der]{[orth=Mann]})");
531 map = ppt.getRequestMap().get("query").toString();
532 assertEquals(shr1.replaceAll(" ", ""), map.replaceAll(" ", ""));
533
534 // shrink([orth=Der]{[orth=Mann][orth=geht]})
535 String shr2 =
Joachim Bingel8c640e42014-02-07 16:20:47 +0000536 "{@type=korap:group, @relation=shrink, classRef=[0], @operands=[" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000537 "{@type=korap:sequence, @operands=[" +
538 "{@type=korap:token, @value={@type=korap:term, @value=Der, @attr=orth, @relation==}}," +
Joachim Bingel8c640e42014-02-07 16:20:47 +0000539 "{@type=korap:group, @relation=class, class=0, @operands=[" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000540 "{@type=korap:sequence, @operands=[" +
541 "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=orth, @relation==}}," +
542 "{@type=korap:token, @value={@type=korap:term, @value=geht, @attr=orth, @relation==}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000543 "]}" +
544 "]}" +
545 "]}" +
546 "]}";
547 ppt = new PoliqarpPlusTree("shrink([orth=Der]{[orth=Mann][orth=geht]})");
548 map = ppt.getRequestMap().get("query").toString();
549 assertEquals(shr2.replaceAll(" ", ""), map.replaceAll(" ", ""));
550
551 // shrink(1:[orth=Der]{1:[orth=Mann][orth=geht]})
552 String shr3 =
Joachim Bingel8c640e42014-02-07 16:20:47 +0000553 "{@type=korap:group, @relation=shrink, classRef=[1], @operands=[" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000554 "{@type=korap:sequence, @operands=[" +
555 "{@type=korap:token, @value={@type=korap:term, @value=Der, @attr=orth, @relation==}}," +
Joachim Bingel8c640e42014-02-07 16:20:47 +0000556 "{@type=korap:group, @relation=class, class=1, @operands=[" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000557 "{@type=korap:sequence, @operands=[" +
558 "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=orth, @relation==}}," +
559 "{@type=korap:token, @value={@type=korap:term, @value=geht, @attr=orth, @relation==}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000560 "]}" +
561 "]}" +
562 "]}" +
563 "]}";
564 ppt = new PoliqarpPlusTree("shrink(1:[orth=Der]{1:[orth=Mann][orth=geht]})");
565 map = ppt.getRequestMap().get("query").toString();
566 assertEquals(shr3.replaceAll(" ", ""), map.replaceAll(" ", ""));
567
568 // shrink(1:startswith(<s>,{1:<np>}))
569 String shr4 =
Joachim Bingel8c640e42014-02-07 16:20:47 +0000570 "{@type=korap:group, @relation=shrink, classRef=[1], @operands=[" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000571 "{@type=korap:group, @relation=position, @position=startswith, @operands=[" +
572 "{@type=korap:span, @value=s}," +
Joachim Bingel8c640e42014-02-07 16:20:47 +0000573 "{@type=korap:group, @relation=class, class=1, @operands=[" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000574 "{@type=korap:span, @value=np}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000575 "]}" +
576 "]}" +
577 "]}";
Joachim Bingeladefa622013-12-13 10:51:48 +0000578 ppt = new PoliqarpPlusTree("shrink(1:startswith(<s>,{1:<np>}))");
Joachim Bingel53333e62013-12-09 19:25:52 +0000579 map = ppt.getRequestMap().get("query").toString();
580 assertEquals(shr4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000581
582 // shrink(3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))
583 String shr5 =
Joachim Bingel8c640e42014-02-07 16:20:47 +0000584 "{@type=korap:group, @relation=shrink, classRef=[3], @operands=[" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000585 "{@type=korap:group, @relation=position, @position=startswith, @operands=[" +
586 "{@type=korap:span, @value=s}," +
Joachim Bingel8c640e42014-02-07 16:20:47 +0000587 "{@type=korap:group, @relation=class, class=3, @operands=[" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000588 "{@type=korap:sequence, @operands=[" +
589 "{@type=korap:token, @value={@type=korap:term, @value=der, @attr=base, @relation==}}," +
Joachim Bingel8c640e42014-02-07 16:20:47 +0000590 "{@type=korap:group, @relation=class, class=1, @operands=[" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000591 "{@type=korap:sequence, @operands=[" +
592 "{@type=korap:token, @value={@type=korap:term, @value=ADJA, @attr=p, @foundry=mate, @relation==}}," +
Joachim Bingel8c640e42014-02-07 16:20:47 +0000593 "{@type=korap:group, @relation=class, class=2, @operands=[" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000594 "{@type=korap:token, @value={@type=korap:term, @value=NN, @attr=p, @foundry=tt, @relation==}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000595 "]}" +
596 "]}" +
597 "]}" +
598 "]}" +
599 "]}" +
600 "]}" +
601 "]}";
Joachim Bingeladefa622013-12-13 10:51:48 +0000602 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 +0000603 map = ppt.getRequestMap().get("query").toString();
604 assertEquals(shr5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000605
606 // split(3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))
607 String shr6 =
Joachim Bingel8c640e42014-02-07 16:20:47 +0000608 "{@type=korap:group, @relation=split, classRef=[3], @operands=[" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000609 "{@type=korap:group, @relation=position, @position=startswith, @operands=[" +
610 "{@type=korap:span, @value=s}," +
Joachim Bingel8c640e42014-02-07 16:20:47 +0000611 "{@type=korap:group, @relation=class, class=3, @operands=[" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000612 "{@type=korap:sequence, @operands=[" +
613 "{@type=korap:token, @value={@type=korap:term, @value=der, @attr=base, @relation==}}," +
Joachim Bingel8c640e42014-02-07 16:20:47 +0000614 "{@type=korap:group, @relation=class, class=1, @operands=[" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000615 "{@type=korap:sequence, @operands=[" +
616 "{@type=korap:token, @value={@type=korap:term, @value=ADJA, @attr=p, @foundry=mate, @relation==}}," +
Joachim Bingel8c640e42014-02-07 16:20:47 +0000617 "{@type=korap:group, @relation=class, class=2, @operands=[" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000618 "{@type=korap:token, @value={@type=korap:term, @value=NN, @attr=p, @foundry=tt, @relation==}}" +
619 "]}" +
620 "]}" +
621 "]}" +
622 "]}" +
623 "]}" +
624 "]}" +
625 "]}";
626 ppt = new PoliqarpPlusTree("split(3:startswith(<s>,{3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) ");
627 map = ppt.getRequestMap().get("query").toString();
628 assertEquals(shr6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel8c640e42014-02-07 16:20:47 +0000629
630 // split(2|3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))
631 String shr7 =
632 "{@type=korap:group, @relation=split, classRef=[2, 3], classRefOp=intersection, @operands=[" +
633 "{@type=korap:group, @relation=position, @position=startswith, @operands=[" +
634 "{@type=korap:span, @value=s}," +
635 "{@type=korap:group, @relation=class, class=3, @operands=[" +
636 "{@type=korap:sequence, @operands=[" +
637 "{@type=korap:token, @value={@type=korap:term, @value=der, @attr=base, @relation==}}," +
638 "{@type=korap:group, @relation=class, class=1, @operands=[" +
639 "{@type=korap:sequence, @operands=[" +
640 "{@type=korap:token, @value={@type=korap:term, @value=ADJA, @attr=p, @foundry=mate, @relation==}}," +
641 "{@type=korap:group, @relation=class, class=2, @operands=[" +
642 "{@type=korap:token, @value={@type=korap:term, @value=NN, @attr=p, @foundry=tt, @relation==}}" +
643 "]}" +
644 "]}" +
645 "]}" +
646 "]}" +
647 "]}" +
648 "]}" +
649 "]}";
650 ppt = new PoliqarpPlusTree("split(2|3:startswith(<s>,{3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) ");
651 map = ppt.getRequestMap().get("query").toString();
652 assertEquals(shr7.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000653 }
654
Joachim Bingel03882702013-12-31 19:53:05 +0000655
Joachim Bingel53333e62013-12-09 19:25:52 +0000656 @Test
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000657 public void testFoundries() throws QueryException {
658 // [tt/base=Mann]
659 String layer1 = "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=base, @foundry=tt, @relation==}}";
660 ppt = new PoliqarpPlusTree("[tt/base=Mann]");
661 map = ppt.getRequestMap().get("query").toString();
662 assertEquals(layer1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000663
664 }
Joachim Bingel16da4e12013-12-17 09:48:12 +0000665
666 @Test
Joachim Bingel8c640e42014-02-07 16:20:47 +0000667 public void testAlign() throws QueryException {
Joachim Bingel16da4e12013-12-17 09:48:12 +0000668 // [orth=der]^[orth=Mann]
669 String align1 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000670 "{@type=korap:sequence, @operands=[" +
671 "{@type=korap:token, @value={@type=korap:term, @value=der, @attr=orth, @relation==}}," +
Joachim Bingel84e33df2014-01-31 14:02:46 +0000672 "{@type=korap:group, @alignment=left, @operands=[" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000673 "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=orth, @relation==}}" +
Joachim Bingel03882702013-12-31 19:53:05 +0000674 "]}" +
Joachim Bingel16da4e12013-12-17 09:48:12 +0000675 "]}";
676 ppt = new PoliqarpPlusTree("[orth=der]^[orth=Mann]");
677 map = ppt.getRequestMap().get("query").toString();
678 assertEquals(align1.replaceAll(" ", ""), map.replaceAll(" ", ""));
679
Joachim Bingel84e33df2014-01-31 14:02:46 +0000680 // [orth=der]^[orth=große][orth=Mann]
681 String query = "[orth=der]^[orth=große][orth=Mann]";
682 String align1b =
683 "{@type=korap:sequence, @operands=[" +
684 "{@type=korap:token, @value={@type=korap:term, @value=der, @attr=orth, @relation==}}," +
685 "{@type=korap:group, @alignment=left, @operands=[" +
686 "{@type=korap:sequence, @operands=[" +
687 "{@type=korap:token, @value={@type=korap:term, @value=große, @attr=orth, @relation==}}," +
688 "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=orth, @relation==}}" +
689 "]}" +
690 "]}" +
691 "]}";
692 ppt = new PoliqarpPlusTree(query);
693 map = ppt.getRequestMap().get("query").toString();
694 assertEquals(align1b.replaceAll(" ", ""), map.replaceAll(" ", ""));
695
Joachim Bingel16da4e12013-12-17 09:48:12 +0000696 // "([base=a]^[base=b])|[base=c]",
697 String align2 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000698 "{@type=korap:group, @relation=or, @operands=[" +
699 "{@type=korap:sequence, @operands=[" +
700 "{@type=korap:token, @value={@type=korap:term, @value=a, @attr=base, @relation==}}," +
Joachim Bingel84e33df2014-01-31 14:02:46 +0000701 "{@type=korap:group, @alignment=left, @operands=[" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000702 "{@type=korap:token, @value={@type=korap:term, @value=b, @attr=base, @relation==}}" +
Joachim Bingel03882702013-12-31 19:53:05 +0000703 "]}" +
Joachim Bingel16da4e12013-12-17 09:48:12 +0000704 "]}," +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000705 "{@type=korap:token, @value={@type=korap:term, @value=c, @attr=base, @relation==}}" +
Joachim Bingel16da4e12013-12-17 09:48:12 +0000706 "]}";
707 ppt = new PoliqarpPlusTree("([base=a]^[base=b])|[base=c]");
708 map = ppt.getRequestMap().get("query").toString();
709 assertEquals(align2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingela67e6a32014-01-02 18:35:24 +0000710
711 // "([base=a]^[base=b][base=c])|[base=d]",
712 String align3 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000713 "{@type=korap:group, @relation=or, @operands=[" +
714 "{@type=korap:sequence, @operands=[" +
715 "{@type=korap:token, @value={@type=korap:term, @value=a, @attr=base, @relation==}}," +
Joachim Bingel84e33df2014-01-31 14:02:46 +0000716 "{@type=korap:group, @alignment=left, @operands=[" +
717 "{@type=korap:sequence, @operands=[" +
718 "{@type=korap:token, @value={@type=korap:term, @value=b, @attr=base, @relation==}}," +
719 "{@type=korap:token, @value={@type=korap:term, @value=c, @attr=base, @relation==}}" +
720 "]}" +
721 "]}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000722 "]}," +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000723 "{@type=korap:token, @value={@type=korap:term, @value=d, @attr=base, @relation==}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000724 "]}";
725 ppt = new PoliqarpPlusTree("([base=a]^[base=b][base=c])|[base=d]");
726 map = ppt.getRequestMap().get("query").toString();
727 assertEquals(align3.replaceAll(" ", ""), map.replaceAll(" ", ""));
728
729 // "([base=a]^[base=b]^[base=c])|[base=d]",
730 String align4 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000731 "{@type=korap:group, @relation=or, @operands=[" +
732 "{@type=korap:sequence, @operands=[" +
733 "{@type=korap:token, @value={@type=korap:term, @value=a, @attr=base, @relation==}}," +
Joachim Bingel84e33df2014-01-31 14:02:46 +0000734 "{@type=korap:group, @alignment=left, @operands=[" +
735 "{@type=korap:sequence, @operands=[" +
736 "{@type=korap:token, @value={@type=korap:term, @value=b, @attr=base, @relation==}}," +
737 "{@type=korap:group, @alignment=left, @operands=[" +
738 "{@type=korap:token, @value={@type=korap:term, @value=c, @attr=base, @relation==}}" +
739 "]}" +
740 "]}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000741 "]}" +
742 "]}," +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000743 "{@type=korap:token, @value={@type=korap:term, @value=d, @attr=base, @relation==}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000744 "]}";
745 ppt = new PoliqarpPlusTree("([base=a]^[base=b]^[base=c])|[base=d]");
746 map = ppt.getRequestMap().get("query").toString();
747 assertEquals(align4.replaceAll(" ", ""), map.replaceAll(" ", ""));
748
749
Joachim Bingel16da4e12013-12-17 09:48:12 +0000750 }
751
752 @Test
Joachim Bingel8c640e42014-02-07 16:20:47 +0000753 public void testSimpleQueries() throws QueryException {
Joachim Bingela67e6a32014-01-02 18:35:24 +0000754 // Baum
755 String simple1 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000756 "{@type=korap:token, @value={@type=korap:term, @value=Baum, @attr=orth, @relation==}}";
Joachim Bingela67e6a32014-01-02 18:35:24 +0000757 ppt = new PoliqarpPlusTree("Baum");
758 map = ppt.getRequestMap().get("query").toString();
759 assertEquals(simple1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel16da4e12013-12-17 09:48:12 +0000760
Joachim Bingela67e6a32014-01-02 18:35:24 +0000761 // Der Baum
762 String simple2 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000763 "{@type=korap:sequence, @operands=[" +
764 "{@type=korap:token, @value={@type=korap:term, @value=Der, @attr=orth, @relation==}}, " +
765 "{@type=korap:token, @value={@type=korap:term, @value=Baum, @attr=orth, @relation==}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000766 "]}";
767 ppt = new PoliqarpPlusTree("Der Baum");
768 map = ppt.getRequestMap().get("query").toString();
769 assertEquals(simple2.replaceAll(" ", ""), map.replaceAll(" ", ""));
770
771 // Der große Baum
772 String simple3 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000773 "{@type=korap:sequence, @operands=[" +
774 "{@type=korap:token, @value={@type=korap:term, @value=Der, @attr=orth, @relation==}}, " +
775 "{@type=korap:token, @value={@type=korap:term, @value=große, @attr=orth, @relation==}}, " +
776 "{@type=korap:token, @value={@type=korap:term, @value=Baum, @attr=orth, @relation==}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000777 "]}";
778 ppt = new PoliqarpPlusTree("Der große Baum");
779 map = ppt.getRequestMap().get("query").toString();
780 assertEquals(simple3.replaceAll(" ", ""), map.replaceAll(" ", ""));
781
782 // Baum | Stein
783 String simple4 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000784 "{@type=korap:group, @relation=or, @operands=[" +
785 "{@type=korap:token, @value={@type=korap:term, @value=Baum, @attr=orth, @relation==}}, " +
786 "{@type=korap:token, @value={@type=korap:term, @value=Stein, @attr=orth, @relation==}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000787 "]}";
788 ppt = new PoliqarpPlusTree("Baum | Stein");
789 map = ppt.getRequestMap().get("query").toString();
790 assertEquals(simple4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel84e33df2014-01-31 14:02:46 +0000791
792 // Baum | Stein Haus
793 String query = "(Baum | Stein) Haus";
794 String simple5 =
795 "{@type=korap:sequence, @operands=[" +
796 "{@type=korap:group, @relation=or, @operands=[" +
797 "{@type=korap:token, @value={@type=korap:term, @value=Baum, @attr=orth, @relation==}}, " +
798 "{@type=korap:token, @value={@type=korap:term, @value=Stein, @attr=orth, @relation==}}" +
799 "]}," +
800 "{@type=korap:token, @value={@type=korap:term, @value=Haus, @attr=orth, @relation==}} " +
801 "]}";
802 ppt = new PoliqarpPlusTree(query);
803 map = ppt.getRequestMap().get("query").toString();
804 assertEquals(simple5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel16da4e12013-12-17 09:48:12 +0000805 }
Joachim Bingel53333e62013-12-09 19:25:52 +0000806}
807