blob: 078cf8e0454fdf059c98b18af5b42f7892e0f98c [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 Bingelba9a0ab2014-01-29 10:12:25 +0000404 String cls1 = "{@type=korap:group, class=0, @operands=[" +
405 "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=base, @relation==}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000406 "]}";
407 assertTrue(equalsQueryContent(cls1, "{[base=Mann]}"));
408
409 // {[base=Mann][orth=Frau]}
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000410 String cls2 = "{@type=korap:group, class=0, @operands=[" +
411 "{@type=korap:sequence, @operands=[" +
412 "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=base, @relation==}}," +
413 "{@type=korap:token, @value={@type=korap:term, @value=Frau, @attr=orth, @relation==}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000414 "]}" +
415 "]}";
416 assertTrue(equalsQueryContent(cls2, "{[base=Mann][orth=Frau]}"));
417
418 // [p=NN]{[base=Mann][orth=Frau]}
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000419 String cls3 = "{@type=korap:sequence, @operands=[" +
420 "{@type=korap:token, @value={@type=korap:term, @value=NN, @attr=p, @relation==}}," +
421 "{@type=korap:group, class=0, @operands=[" +
422 "{@type=korap:sequence, @operands=[" +
423 "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=base, @relation==}}," +
424 "{@type=korap:token, @value={@type=korap:term, @value=Frau, @attr=orth, @relation==}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000425 "]}" +
426 "]}" +
427 "]}";
428 assertTrue(equalsQueryContent(cls3, "[p=NN]{[base=Mann][orth=Frau]}"));
429
430 // {[base=Mann][orth=Frau]}[p=NN]
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000431 String cls4 = "{@type=korap:sequence, @operands=[" +
432 "{@type=korap:group, class=0, @operands=[" +
433 "{@type=korap:sequence, @operands=[" +
434 "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=base, @relation==}}," +
435 "{@type=korap:token, @value={@type=korap:term, @value=Frau, @attr=orth, @relation==}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000436 "]}" +
437 "]}," +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000438 "{@type=korap:token, @value={@type=korap:term, @value=NN, @attr=p, @relation==}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000439 "]}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000440 ppt = new PoliqarpPlusTree("{[base=Mann][orth=Frau]}[p=NN]");
441 map = ppt.getRequestMap().get("query").toString();
442 assertEquals(cls4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000443
444 // {2:{1:[tt/p=ADJA]}[mate/p=NN]}"
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000445 String cls5 = "{@type=korap:group, class=2, @operands=[" +
446 "{@type=korap:sequence, @operands=[" +
447 "{@type=korap:group, class=1, @operands=[" +
448 "{@type=korap:token, @value={@type=korap:term, @value=ADJA, @attr=p, @foundry=tt, @relation==}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000449 "]}," +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000450 "{@type=korap:token, @value={@type=korap:term, @value=NN, @attr=p, @foundry=mate, @relation==}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000451 "]}" +
452 "]}";
453 ppt = new PoliqarpPlusTree("{2: {1:[tt/p=ADJA]}[mate/p=NN]}");
454 map = ppt.getRequestMap().get("query").toString();
455 assertEquals(cls5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000456 }
457
458 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000459 public void testPositions() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000460 // contains(<s>,<np>)
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000461 String pos1 = "{@type=korap:group, @relation=position, @position=contains, @operands=[" +
462 "{@type=korap:span, @value=s}," +
463 "{@type=korap:span, @value=np}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000464 "]}";
465 assertTrue(equalsQueryContent(pos1, "contains(<s>,<np>)"));
466
467 // contains(<s>,[base=Mann])
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000468 String pos2 = "{@type=korap:group, @relation=position, @position=contains, @operands=[" +
469 "{@type=korap:span, @value=s}," +
470 "{@type=korap:token, @value= {@type=korap:term, @value=Mann, @attr=base, @relation==}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000471 "]}";
472 assertTrue(equalsQueryContent(pos2, "contains(<s>,[base=Mann])"));
473
474 // contains(<s>,[orth=der][orth=Mann])
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000475 String pos3 = "{@type=korap:group, @relation=position, @position=contains, @operands=[" +
476 "{@type=korap:span, @value=s}," +
477 "{@type=korap:sequence, @operands=[" +
478 "{@type=korap:token, @value={@type=korap:term, @value=der, @attr=orth, @relation==}}," +
479 "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=orth, @relation==}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000480 "]}" +
481 "]}";
482 ppt = new PoliqarpPlusTree("contains(<s>,[orth=der][orth=Mann])");
483 map = ppt.getRequestMap().get("query").toString();
484 assertEquals(pos3.replaceAll(" ", ""), map.replaceAll(" ", ""));
485
486 // [base=Auto]contains(<s>,[base=Mann])
487 String pos4 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000488 "{@type=korap:sequence, @operands=[" +
489 "{@type=korap:token, @value={@type=korap:term, @value=Auto, @attr=base, @relation==}}," +
490 "{@type=korap:group, @relation=position, @position=contains, @operands=[" +
491 "{@type=korap:span, @value=s}," +
492 "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=base, @relation==}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000493 "]}" +
494 "]}";
495 ppt = new PoliqarpPlusTree("[base=Auto]contains(<s>,[base=Mann])");
496 map = ppt.getRequestMap().get("query").toString();
497 assertEquals(pos4.replaceAll(" ", ""), map.replaceAll(" ", ""));
498 }
499
500 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000501 public void testNestedPositions() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000502 // contains(<s>,startswith(<np>,[orth=Der]))
503 String npos1 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000504 "{@type=korap:group, @relation=position, @position=contains, @operands=[" +
505 "{@type=korap:span, @value=s}," +
506 "{@type=korap:group, @relation=position, @position=startswith, @operands=[" +
507 "{@type=korap:span, @value=np}," +
508 "{@type=korap:token, @value={@type=korap:term, @value=Der, @attr=orth, @relation==}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000509 "]}" +
510 "]}";
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000511 ppt = new PoliqarpPlusTree("contains(<s>, startswith(<np>,[orth=Der]))");
Joachim Bingel53333e62013-12-09 19:25:52 +0000512 map = ppt.getRequestMap().get("query").toString();
513 assertEquals(npos1.replaceAll(" ", ""), map.replaceAll(" ", ""));
514 }
515
516 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000517 public void testShrinkSplit() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000518 // shrink([orth=Der]{[orth=Mann]})
519 String shr1 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000520 "{@type=korap:group, @relation=shrink, classRef=0, @operands=[" +
521 "{@type=korap:sequence, @operands=[" +
522 "{@type=korap:token, @value={@type=korap:term, @value=Der, @attr=orth, @relation==}}," +
523 "{@type=korap:group, class=0, @operands=[" +
524 "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=orth, @relation==}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000525 "]}" +
526 "]}" +
527 "]}";
528 ppt = new PoliqarpPlusTree("shrink([orth=Der]{[orth=Mann]})");
529 map = ppt.getRequestMap().get("query").toString();
530 assertEquals(shr1.replaceAll(" ", ""), map.replaceAll(" ", ""));
531
532 // shrink([orth=Der]{[orth=Mann][orth=geht]})
533 String shr2 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000534 "{@type=korap:group, @relation=shrink, classRef=0, @operands=[" +
535 "{@type=korap:sequence, @operands=[" +
536 "{@type=korap:token, @value={@type=korap:term, @value=Der, @attr=orth, @relation==}}," +
537 "{@type=korap:group, class=0, @operands=[" +
538 "{@type=korap:sequence, @operands=[" +
539 "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=orth, @relation==}}," +
540 "{@type=korap:token, @value={@type=korap:term, @value=geht, @attr=orth, @relation==}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000541 "]}" +
542 "]}" +
543 "]}" +
544 "]}";
545 ppt = new PoliqarpPlusTree("shrink([orth=Der]{[orth=Mann][orth=geht]})");
546 map = ppt.getRequestMap().get("query").toString();
547 assertEquals(shr2.replaceAll(" ", ""), map.replaceAll(" ", ""));
548
549 // shrink(1:[orth=Der]{1:[orth=Mann][orth=geht]})
550 String shr3 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000551 "{@type=korap:group, @relation=shrink, classRef=1, @operands=[" +
552 "{@type=korap:sequence, @operands=[" +
553 "{@type=korap:token, @value={@type=korap:term, @value=Der, @attr=orth, @relation==}}," +
554 "{@type=korap:group, class=1, @operands=[" +
555 "{@type=korap:sequence, @operands=[" +
556 "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=orth, @relation==}}," +
557 "{@type=korap:token, @value={@type=korap:term, @value=geht, @attr=orth, @relation==}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000558 "]}" +
559 "]}" +
560 "]}" +
561 "]}";
562 ppt = new PoliqarpPlusTree("shrink(1:[orth=Der]{1:[orth=Mann][orth=geht]})");
563 map = ppt.getRequestMap().get("query").toString();
564 assertEquals(shr3.replaceAll(" ", ""), map.replaceAll(" ", ""));
565
566 // shrink(1:startswith(<s>,{1:<np>}))
567 String shr4 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000568 "{@type=korap:group, @relation=shrink, classRef=1, @operands=[" +
569 "{@type=korap:group, @relation=position, @position=startswith, @operands=[" +
570 "{@type=korap:span, @value=s}," +
571 "{@type=korap:group, class=1, @operands=[" +
572 "{@type=korap:span, @value=np}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000573 "]}" +
574 "]}" +
575 "]}";
Joachim Bingeladefa622013-12-13 10:51:48 +0000576 ppt = new PoliqarpPlusTree("shrink(1:startswith(<s>,{1:<np>}))");
Joachim Bingel53333e62013-12-09 19:25:52 +0000577 map = ppt.getRequestMap().get("query").toString();
578 assertEquals(shr4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000579
580 // shrink(3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))
581 String shr5 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000582 "{@type=korap:group, @relation=shrink, classRef=3, @operands=[" +
583 "{@type=korap:group, @relation=position, @position=startswith, @operands=[" +
584 "{@type=korap:span, @value=s}," +
585 "{@type=korap:group, class=3, @operands=[" +
586 "{@type=korap:sequence, @operands=[" +
587 "{@type=korap:token, @value={@type=korap:term, @value=der, @attr=base, @relation==}}," +
588 "{@type=korap:group, class=1, @operands=[" +
589 "{@type=korap:sequence, @operands=[" +
590 "{@type=korap:token, @value={@type=korap:term, @value=ADJA, @attr=p, @foundry=mate, @relation==}}," +
591 "{@type=korap:group, class=2, @operands=[" +
592 "{@type=korap:token, @value={@type=korap:term, @value=NN, @attr=p, @foundry=tt, @relation==}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000593 "]}" +
594 "]}" +
595 "]}" +
596 "]}" +
597 "]}" +
598 "]}" +
599 "]}";
Joachim Bingeladefa622013-12-13 10:51:48 +0000600 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 +0000601 map = ppt.getRequestMap().get("query").toString();
602 assertEquals(shr5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000603
604 // split(3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))
605 String shr6 =
606 "{@type=korap:group, @relation=split, classRef=3, @operands=[" +
607 "{@type=korap:group, @relation=position, @position=startswith, @operands=[" +
608 "{@type=korap:span, @value=s}," +
609 "{@type=korap:group, class=3, @operands=[" +
610 "{@type=korap:sequence, @operands=[" +
611 "{@type=korap:token, @value={@type=korap:term, @value=der, @attr=base, @relation==}}," +
612 "{@type=korap:group, class=1, @operands=[" +
613 "{@type=korap:sequence, @operands=[" +
614 "{@type=korap:token, @value={@type=korap:term, @value=ADJA, @attr=p, @foundry=mate, @relation==}}," +
615 "{@type=korap:group, class=2, @operands=[" +
616 "{@type=korap:token, @value={@type=korap:term, @value=NN, @attr=p, @foundry=tt, @relation==}}" +
617 "]}" +
618 "]}" +
619 "]}" +
620 "]}" +
621 "]}" +
622 "]}" +
623 "]}";
624 ppt = new PoliqarpPlusTree("split(3:startswith(<s>,{3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) ");
625 map = ppt.getRequestMap().get("query").toString();
626 assertEquals(shr6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000627 }
628
Joachim Bingel03882702013-12-31 19:53:05 +0000629
Joachim Bingel53333e62013-12-09 19:25:52 +0000630 @Test
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000631 public void testFoundries() throws QueryException {
632 // [tt/base=Mann]
633 String layer1 = "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=base, @foundry=tt, @relation==}}";
634 ppt = new PoliqarpPlusTree("[tt/base=Mann]");
635 map = ppt.getRequestMap().get("query").toString();
636 assertEquals(layer1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000637
638 }
Joachim Bingel16da4e12013-12-17 09:48:12 +0000639
640 @Test
641 public void testAlign() {
642 // [orth=der]^[orth=Mann]
643 String align1 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000644 "{@type=korap:sequence, @operands=[" +
645 "{@type=korap:token, @value={@type=korap:term, @value=der, @attr=orth, @relation==}}," +
Joachim Bingel84e33df2014-01-31 14:02:46 +0000646 "{@type=korap:group, @alignment=left, @operands=[" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000647 "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=orth, @relation==}}" +
Joachim Bingel03882702013-12-31 19:53:05 +0000648 "]}" +
Joachim Bingel16da4e12013-12-17 09:48:12 +0000649 "]}";
650 ppt = new PoliqarpPlusTree("[orth=der]^[orth=Mann]");
651 map = ppt.getRequestMap().get("query").toString();
652 assertEquals(align1.replaceAll(" ", ""), map.replaceAll(" ", ""));
653
Joachim Bingel84e33df2014-01-31 14:02:46 +0000654 // [orth=der]^[orth=große][orth=Mann]
655 String query = "[orth=der]^[orth=große][orth=Mann]";
656 String align1b =
657 "{@type=korap:sequence, @operands=[" +
658 "{@type=korap:token, @value={@type=korap:term, @value=der, @attr=orth, @relation==}}," +
659 "{@type=korap:group, @alignment=left, @operands=[" +
660 "{@type=korap:sequence, @operands=[" +
661 "{@type=korap:token, @value={@type=korap:term, @value=große, @attr=orth, @relation==}}," +
662 "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=orth, @relation==}}" +
663 "]}" +
664 "]}" +
665 "]}";
666 ppt = new PoliqarpPlusTree(query);
667 map = ppt.getRequestMap().get("query").toString();
668 assertEquals(align1b.replaceAll(" ", ""), map.replaceAll(" ", ""));
669
Joachim Bingel16da4e12013-12-17 09:48:12 +0000670 // "([base=a]^[base=b])|[base=c]",
671 String align2 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000672 "{@type=korap:group, @relation=or, @operands=[" +
673 "{@type=korap:sequence, @operands=[" +
674 "{@type=korap:token, @value={@type=korap:term, @value=a, @attr=base, @relation==}}," +
Joachim Bingel84e33df2014-01-31 14:02:46 +0000675 "{@type=korap:group, @alignment=left, @operands=[" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000676 "{@type=korap:token, @value={@type=korap:term, @value=b, @attr=base, @relation==}}" +
Joachim Bingel03882702013-12-31 19:53:05 +0000677 "]}" +
Joachim Bingel16da4e12013-12-17 09:48:12 +0000678 "]}," +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000679 "{@type=korap:token, @value={@type=korap:term, @value=c, @attr=base, @relation==}}" +
Joachim Bingel16da4e12013-12-17 09:48:12 +0000680 "]}";
681 ppt = new PoliqarpPlusTree("([base=a]^[base=b])|[base=c]");
682 map = ppt.getRequestMap().get("query").toString();
683 assertEquals(align2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingela67e6a32014-01-02 18:35:24 +0000684
685 // "([base=a]^[base=b][base=c])|[base=d]",
686 String align3 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000687 "{@type=korap:group, @relation=or, @operands=[" +
688 "{@type=korap:sequence, @operands=[" +
689 "{@type=korap:token, @value={@type=korap:term, @value=a, @attr=base, @relation==}}," +
Joachim Bingel84e33df2014-01-31 14:02:46 +0000690 "{@type=korap:group, @alignment=left, @operands=[" +
691 "{@type=korap:sequence, @operands=[" +
692 "{@type=korap:token, @value={@type=korap:term, @value=b, @attr=base, @relation==}}," +
693 "{@type=korap:token, @value={@type=korap:term, @value=c, @attr=base, @relation==}}" +
694 "]}" +
695 "]}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000696 "]}," +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000697 "{@type=korap:token, @value={@type=korap:term, @value=d, @attr=base, @relation==}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000698 "]}";
699 ppt = new PoliqarpPlusTree("([base=a]^[base=b][base=c])|[base=d]");
700 map = ppt.getRequestMap().get("query").toString();
701 assertEquals(align3.replaceAll(" ", ""), map.replaceAll(" ", ""));
702
703 // "([base=a]^[base=b]^[base=c])|[base=d]",
704 String align4 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000705 "{@type=korap:group, @relation=or, @operands=[" +
706 "{@type=korap:sequence, @operands=[" +
707 "{@type=korap:token, @value={@type=korap:term, @value=a, @attr=base, @relation==}}," +
Joachim Bingel84e33df2014-01-31 14:02:46 +0000708 "{@type=korap:group, @alignment=left, @operands=[" +
709 "{@type=korap:sequence, @operands=[" +
710 "{@type=korap:token, @value={@type=korap:term, @value=b, @attr=base, @relation==}}," +
711 "{@type=korap:group, @alignment=left, @operands=[" +
712 "{@type=korap:token, @value={@type=korap:term, @value=c, @attr=base, @relation==}}" +
713 "]}" +
714 "]}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000715 "]}" +
716 "]}," +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000717 "{@type=korap:token, @value={@type=korap:term, @value=d, @attr=base, @relation==}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000718 "]}";
719 ppt = new PoliqarpPlusTree("([base=a]^[base=b]^[base=c])|[base=d]");
720 map = ppt.getRequestMap().get("query").toString();
721 assertEquals(align4.replaceAll(" ", ""), map.replaceAll(" ", ""));
722
723
Joachim Bingel16da4e12013-12-17 09:48:12 +0000724 }
725
726 @Test
727 public void testSimpleQueries() {
Joachim Bingela67e6a32014-01-02 18:35:24 +0000728 // Baum
729 String simple1 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000730 "{@type=korap:token, @value={@type=korap:term, @value=Baum, @attr=orth, @relation==}}";
Joachim Bingela67e6a32014-01-02 18:35:24 +0000731 ppt = new PoliqarpPlusTree("Baum");
732 map = ppt.getRequestMap().get("query").toString();
733 assertEquals(simple1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel16da4e12013-12-17 09:48:12 +0000734
Joachim Bingela67e6a32014-01-02 18:35:24 +0000735 // Der Baum
736 String simple2 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000737 "{@type=korap:sequence, @operands=[" +
738 "{@type=korap:token, @value={@type=korap:term, @value=Der, @attr=orth, @relation==}}, " +
739 "{@type=korap:token, @value={@type=korap:term, @value=Baum, @attr=orth, @relation==}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000740 "]}";
741 ppt = new PoliqarpPlusTree("Der Baum");
742 map = ppt.getRequestMap().get("query").toString();
743 assertEquals(simple2.replaceAll(" ", ""), map.replaceAll(" ", ""));
744
745 // Der große Baum
746 String simple3 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000747 "{@type=korap:sequence, @operands=[" +
748 "{@type=korap:token, @value={@type=korap:term, @value=Der, @attr=orth, @relation==}}, " +
749 "{@type=korap:token, @value={@type=korap:term, @value=große, @attr=orth, @relation==}}, " +
750 "{@type=korap:token, @value={@type=korap:term, @value=Baum, @attr=orth, @relation==}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000751 "]}";
752 ppt = new PoliqarpPlusTree("Der große Baum");
753 map = ppt.getRequestMap().get("query").toString();
754 assertEquals(simple3.replaceAll(" ", ""), map.replaceAll(" ", ""));
755
756 // Baum | Stein
757 String simple4 =
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000758 "{@type=korap:group, @relation=or, @operands=[" +
759 "{@type=korap:token, @value={@type=korap:term, @value=Baum, @attr=orth, @relation==}}, " +
760 "{@type=korap:token, @value={@type=korap:term, @value=Stein, @attr=orth, @relation==}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000761 "]}";
762 ppt = new PoliqarpPlusTree("Baum | Stein");
763 map = ppt.getRequestMap().get("query").toString();
764 assertEquals(simple4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel84e33df2014-01-31 14:02:46 +0000765
766 // Baum | Stein Haus
767 String query = "(Baum | Stein) Haus";
768 String simple5 =
769 "{@type=korap:sequence, @operands=[" +
770 "{@type=korap:group, @relation=or, @operands=[" +
771 "{@type=korap:token, @value={@type=korap:term, @value=Baum, @attr=orth, @relation==}}, " +
772 "{@type=korap:token, @value={@type=korap:term, @value=Stein, @attr=orth, @relation==}}" +
773 "]}," +
774 "{@type=korap:token, @value={@type=korap:term, @value=Haus, @attr=orth, @relation==}} " +
775 "]}";
776 ppt = new PoliqarpPlusTree(query);
777 map = ppt.getRequestMap().get("query").toString();
778 assertEquals(simple5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel16da4e12013-12-17 09:48:12 +0000779 }
Joachim Bingel53333e62013-12-09 19:25:52 +0000780}
781