blob: 430b2711c444f2417ff505230affec775906276d [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
Joachim Bingel53333e62013-12-09 19:25:52 +000013
Joachim Bingel16da4e12013-12-17 09:48:12 +000014 private boolean equalsQueryContent(String res, String query) throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +000015 res = res.replaceAll(" ", "");
16 ppt = new PoliqarpPlusTree(query);
17 String queryMap = ppt.getRequestMap().get("query").toString().replaceAll(" ", "");
18 return res.equals(queryMap);
19 }
20
Joachim Bingel81812632014-02-18 08:55:22 +000021 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +000022 public void testContext() throws QueryException {
Joachim Bingel81812632014-02-18 08:55:22 +000023 String contextString = "http://ids-mannheim.de/ns/KorAP/json-ld/v0.1/context.jsonld";
Joachim Bingel2daf9862014-02-12 10:18:54 +000024 ppt = new PoliqarpPlusTree("Test");
25 assertEquals(contextString.replaceAll(" ", ""), ppt.getRequestMap().get("@context").toString().replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +000026 }
27
28 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +000029 public void testSingleTokens() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +000030 // [base=Mann]
Joachim Bingelee3b21d2014-02-12 12:34:59 +000031 String token1 = "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}";
Joachim Bingel53333e62013-12-09 19:25:52 +000032 assertTrue(equalsQueryContent(token1, "[base=Mann]"));
33
34 // [orth!=Frau]
Joachim Bingelee3b21d2014-02-12 12:34:59 +000035 String token2 = "{@type=korap:token, wrap={@type=korap:term, key=Frau, layer=orth, match=match:ne}}";
Joachim Bingel53333e62013-12-09 19:25:52 +000036 assertTrue(equalsQueryContent(token2, "[orth!=Frau]"));
37
38 // [!p=NN]
Joachim Bingelee3b21d2014-02-12 12:34:59 +000039 String token3 = "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, match=match:ne}}";
Joachim Bingel53333e62013-12-09 19:25:52 +000040 assertTrue(equalsQueryContent(token3, "[!p=NN]"));
41
42 // [!p!=NN]
Joachim Bingelee3b21d2014-02-12 12:34:59 +000043 String token4 = "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, match=match:eq}}";
Joachim Bingel53333e62013-12-09 19:25:52 +000044 assertTrue(equalsQueryContent(token4, "[!p!=NN]"));
45 }
46
47 @Test
Joachim Bingel41e112e2014-02-12 10:46:18 +000048 public void testRegex() throws QueryException {
49 String query = "[orth=\"M(a|ä)nn(er)?\"]";
Joachim Bingelbc537b62014-02-12 12:47:45 +000050 String re1 = "{@type=korap:token, wrap={@type=korap:term, type=type:regex, key=M(a|ä)nn(er)?, layer=orth, match=match:eq}}";
Joachim Bingel41e112e2014-02-12 10:46:18 +000051 ppt = new PoliqarpPlusTree(query);
52 map = ppt.getRequestMap().get("query").toString();
53 assertEquals(re1.replaceAll(" ", ""), map.replaceAll(" ", ""));
54 }
55
56 @Test
Joachim Bingel0207d5e2014-02-12 14:18:41 +000057 public void testCaseSensitivityFlag() throws QueryException {
58 String query="[orth=deutscher/i]";
59 String cs1 =
60 "{@type=korap:token, wrap={@type=korap:term, key=deutscher, layer=orth, match=match:eq, caseInsensitive=true}}";
61 ppt = new PoliqarpPlusTree(query);
62 map = ppt.getRequestMap().get("query").toString();
63 assertEquals(cs1.replaceAll(" ", ""), map.replaceAll(" ", ""));
64
65 query="[orth=deutscher/i][orth=Bundestag]";
66 String cs2 =
67 "{@type=korap:group, operation=operation:sequence, operands=[" +
68 "{@type=korap:token, wrap={@type=korap:term, key=deutscher, layer=orth, match=match:eq, caseInsensitive=true}}," +
69 "{@type=korap:token, wrap={@type=korap:term, key=Bundestag, layer=orth, match=match:eq}}" +
70 "]}";
71 ppt = new PoliqarpPlusTree(query);
72 map = ppt.getRequestMap().get("query").toString();
73 assertEquals(cs2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeladd0fb12014-06-24 08:54:14 +000074
75 query="deutscher/i";
76 String cs3 =
77 "{@type=korap:token, wrap={@type=korap:term, key=deutscher, layer=orth, match=match:eq, caseInsensitive=true}}";
78 ppt = new PoliqarpPlusTree(query);
79 map = ppt.getRequestMap().get("query").toString();
80 assertEquals(cs3.replaceAll(" ", ""), map.replaceAll(" ", ""));
81
82 query="deutscher/i Bundestag";
83 String cs4 =
84 "{@type=korap:group, operation=operation:sequence, operands=[" +
85 "{@type=korap:token, wrap={@type=korap:term, key=deutscher, layer=orth, match=match:eq, caseInsensitive=true}}," +
86 "{@type=korap:token, wrap={@type=korap:term, key=Bundestag, layer=orth, match=match:eq}}" +
87 "]}";
88 ppt = new PoliqarpPlusTree(query);
89 map = ppt.getRequestMap().get("query").toString();
90 assertEquals(cs4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelf8dfcf82014-06-25 09:57:44 +000091
92 query="deutscher Bundestag/i";
93 String cs5 =
94 "{@type=korap:group, operation=operation:sequence, operands=[" +
95 "{@type=korap:token, wrap={@type=korap:term, key=deutscher, layer=orth, match=match:eq}}," +
96 "{@type=korap:token, wrap={@type=korap:term, key=Bundestag, layer=orth, match=match:eq, caseInsensitive=true}}" +
97 "]}";
98 ppt = new PoliqarpPlusTree(query);
99 map = ppt.getRequestMap().get("query").toString();
100 assertEquals(cs5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel0207d5e2014-02-12 14:18:41 +0000101 }
102
103 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000104 public void testElements() throws QueryException {
Joachim Bingelfc1fb352014-02-26 14:40:27 +0000105 String query;
Joachim Bingel53333e62013-12-09 19:25:52 +0000106 // <s>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000107 String elem1 = "{@type=korap:span, key=s}";
Joachim Bingel53333e62013-12-09 19:25:52 +0000108 assertTrue(equalsQueryContent(elem1, "<s>"));
109
110 // <vp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000111 String elem2 = "{@type=korap:span, key=vp}";
Joachim Bingel53333e62013-12-09 19:25:52 +0000112 assertTrue(equalsQueryContent(elem2, "<vp>"));
Joachim Bingelfc1fb352014-02-26 14:40:27 +0000113
114 // <cnx/c=vp>
115 query = "<c=vp>";
116 String span3 = "{@type=korap:span, layer=c, key=vp}";
117 ppt = new PoliqarpPlusTree(query);
118 map = ppt.getRequestMap().get("query").toString();
119 assertEquals(span3.replaceAll(" ", ""), map.replaceAll(" ", ""));
120
121 // <cnx/c=vp>
122 query = "<cnx/c=vp>";
123 String span4 = "{@type=korap:span, foundry=cnx, layer=c, key=vp}";
124 ppt = new PoliqarpPlusTree(query);
125 map = ppt.getRequestMap().get("query").toString();
126 assertEquals(span4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000127 }
Joachim Bingel87480d02014-01-17 14:07:46 +0000128
129 @Test
130 public void testEmptyTokens() throws QueryException {
131 // [base=der][][base=Mann]
132 String et1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000133 "{@type=korap:group, operation=operation:sequence, inOrder=true, distances=[" +
Joachim Bingelb8a44a12014-04-17 09:35:30 +0000134 "{@type=korap:distance, key=w, min=2, max=2}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000135 "], " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000136 "operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000137 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=match:eq}}," +
138 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000139 "]}";
140 ppt = new PoliqarpPlusTree("[base=der][][base=Mann]");
141 map = ppt.getRequestMap().get("query").toString();
142 assertEquals(et1.replaceAll(" ", ""), map.replaceAll(" ", ""));
143
144 // [base=der][][][base=Mann]
145 String et2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000146 "{@type=korap:group, operation=operation:sequence, inOrder=true, distances=[" +
Joachim Bingelb8a44a12014-04-17 09:35:30 +0000147 "{@type=korap:distance, key=w, min=3, max=3}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000148 "], " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000149 "operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000150 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=match:eq}}," +
151 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000152 "]}";
Joachim Bingelffd65e32014-01-22 14:22:57 +0000153 ppt = new PoliqarpPlusTree("[base=der][][][base=Mann]");
Joachim Bingel87480d02014-01-17 14:07:46 +0000154 map = ppt.getRequestMap().get("query").toString();
155 assertEquals(et2.replaceAll(" ", ""), map.replaceAll(" ", ""));
156
157 // [base=der][][]?[base=Mann]
158 String et3 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000159 "{@type=korap:group, operation=operation:sequence, inOrder=true, distances=[" +
Joachim Bingelb8a44a12014-04-17 09:35:30 +0000160 "{@type=korap:distance, key=w, min=2, max=3}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000161 "], " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000162 "operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000163 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=match:eq}}," +
164 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000165 "]}";
166 ppt = new PoliqarpPlusTree("[base=der][][]?[base=Mann]");
167 map = ppt.getRequestMap().get("query").toString();
168 assertEquals(et3.replaceAll(" ", ""), map.replaceAll(" ", ""));
169
Joachim Bingel87480d02014-01-17 14:07:46 +0000170
171 // startswith(<s>, [][base=Mann]
Joachim Bingelffd65e32014-01-22 14:22:57 +0000172 String et4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000173 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
174 "{@type=korap:span, key=s}," +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000175 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000176 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}" +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000177 "], offset-min=1, offset-max=1}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000178 "]}";
Joachim Bingelffd65e32014-01-22 14:22:57 +0000179 ppt = new PoliqarpPlusTree("startswith(<s>, [][base=Mann])");
180 map = ppt.getRequestMap().get("query").toString();
181 assertEquals(et4.replaceAll(" ", ""), map.replaceAll(" ", ""));
182
Joachim Bingel11d5b152014-02-11 21:33:47 +0000183 // [base=der][]{2,5}[base=Mann][]?[][base=Frau] nested distances=
Joachim Bingelffd65e32014-01-22 14:22:57 +0000184 String et5 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000185 "{@type=korap:group, operation=operation:sequence, inOrder=true, distances=[" +
Joachim Bingelb8a44a12014-04-17 09:35:30 +0000186 "{@type=korap:distance, key=w, min=3, max=6}" +
Joachim Bingelffd65e32014-01-22 14:22:57 +0000187 "], " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000188 "operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000189 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000190 "{@type=korap:group, operation=operation:sequence, inOrder=true, distances=[" +
Joachim Bingelb8a44a12014-04-17 09:35:30 +0000191 "{@type=korap:distance, key=w, min=2, max=3}" +
Joachim Bingelffd65e32014-01-22 14:22:57 +0000192 "], " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000193 "operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000194 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}," +
195 "{@type=korap:token, wrap={@type=korap:term, key=Frau, layer=lemma, match=match:eq}}" +
Joachim Bingelffd65e32014-01-22 14:22:57 +0000196 "]}" +
197 "]}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000198 ppt = new PoliqarpPlusTree("[base=der][]{2,5}[base=Mann][]?[][base=Frau]");
Joachim Bingel87480d02014-01-17 14:07:46 +0000199 map = ppt.getRequestMap().get("query").toString();
200 assertEquals(et5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel87480d02014-01-17 14:07:46 +0000201
Joachim Bingelc15720f2014-05-07 14:37:23 +0000202 // [base=der][]*[base=Mann]
203 String et6 =
204 "{@type=korap:group, operation=operation:sequence, inOrder=true, distances=[" +
205 "{@type=korap:distance, key=w, min=1, max=100}" +
206 "], " +
207 "operands=[" +
208 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=match:eq}}," +
209 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}" +
210 "]}";
211 ppt = new PoliqarpPlusTree("[base=der][]*[base=Mann]");
212 map = ppt.getRequestMap().get("query").toString();
213 assertEquals(et6.replaceAll(" ", ""), map.replaceAll(" ", ""));
214
215 // [base=der][]*[base=Mann]
216 String et7 =
217 "{@type=korap:group, operation=operation:sequence, inOrder=true, distances=[" +
218 "{@type=korap:distance, key=w, min=2, max=100}" +
219 "], " +
220 "operands=[" +
221 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=match:eq}}," +
222 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}" +
223 "]}";
224 ppt = new PoliqarpPlusTree("[base=der][]+[base=Mann]");
225 map = ppt.getRequestMap().get("query").toString();
226 assertEquals(et7.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel87480d02014-01-17 14:07:46 +0000227 }
Joachim Bingel53333e62013-12-09 19:25:52 +0000228
229 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000230 public void testCoordinatedFields() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000231 // [base=Mann&(cas=N|cas=A)]
232 String cof1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000233 "{@type=korap:token, wrap=" +
Joachim Bingel2980bda2014-04-04 12:09:46 +0000234 "{@type=korap:termGroup, relation=relation:and, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000235 "{@type=korap:term, key=Mann, layer=lemma, match=match:eq}," +
Joachim Bingel2980bda2014-04-04 12:09:46 +0000236 "{@type=korap:termGroup, relation=relation:or, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000237 "{@type=korap:term, key=N, layer=cas, match=match:eq}," +
238 "{@type=korap:term, key=A, layer=cas, match=match:eq}" +
239 "]}" +
240 "]}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000241 "}";
242 ppt = new PoliqarpPlusTree("[base=Mann&(cas=N|cas=A)]");
243 map = ppt.getRequestMap().get("query").toString();
244 assertEquals(cof1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Nils Diewald7d486c22013-12-13 16:32:18 +0000245
246
247 assertEquals(
248 new PoliqarpPlusTree(" [ base=Mann & ( cas=N | cas=A)] ").getRequestMap().get("query").toString(),
249 new PoliqarpPlusTree("[base=Mann &(cas=N|cas=A)]").getRequestMap().get("query").toString()
250 );
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000251
252 // [base=Mann&cas=N&gen=m]
253 String cof2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000254 "{@type=korap:token, wrap=" +
Joachim Bingel2980bda2014-04-04 12:09:46 +0000255 "{@type=korap:termGroup, relation=relation:and, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000256 "{@type=korap:term, key=Mann, layer=lemma, match=match:eq}," +
257 "{@type=korap:term, key=N, layer=cas, match=match:eq}," +
258 "{@type=korap:term, key=m, layer=gen, match=match:eq}" +
259 "]}" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000260 "}";
261 ppt = new PoliqarpPlusTree("[base=Mann&cas=N&gen=m]");
262 map = ppt.getRequestMap().get("query").toString();
263 assertEquals(cof2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000264 }
265
266 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000267 public void testOccurrence() throws QueryException {
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000268 // [base=foo]*
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000269 String occ1 = "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000270 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000271 "], min=0, max=100}";
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000272 ppt = new PoliqarpPlusTree("[base=foo]*");
273 map = ppt.getRequestMap().get("query").toString();
274 assertEquals(occ1.replaceAll(" ", ""), map.replaceAll(" ", ""));
275
276 // [base=foo]*[base=bar]
277 String occ2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000278 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000279 "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000280 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000281 "], min=0, max=100 }," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000282 "{@type=korap:token, wrap={@type=korap:term, key=bar, layer=lemma, match=match:eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000283 "]}";
284 ppt = new PoliqarpPlusTree("[base=foo]*[base=bar]");
285 map = ppt.getRequestMap().get("query").toString();
286 assertEquals(occ2.replaceAll(" ", ""), map.replaceAll(" ", ""));
287
288 // [base=bar][base=foo]*
289 String occ3 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000290 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000291 "{@type=korap:token, wrap={@type=korap:term, key=bar, layer=lemma, match=match:eq}}," +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000292 "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000293 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000294 "], min=0, max=100 }" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000295 "]}";
296 ppt = new PoliqarpPlusTree("[base=bar][base=foo]*");
297 map = ppt.getRequestMap().get("query").toString();
298 assertEquals(occ3.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb4da7022013-12-09 23:17:24 +0000299
300 // ([base=bar][base=foo])*
301 String occ4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000302 "{@type=korap:group, operands=[" +
303 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000304 "{@type=korap:token, wrap={@type=korap:term, key=bar, layer=lemma, match=match:eq}}," +
305 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000306 "]}" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000307 "], operation=operation:repetition, min=0, max=100 }" ;
Joachim Bingelb4da7022013-12-09 23:17:24 +0000308 ppt = new PoliqarpPlusTree("([base=bar][base=foo])*");
309 map = ppt.getRequestMap().get("query").toString();
310 assertEquals(occ4.replaceAll(" ", ""), map.replaceAll(" ", ""));
311
312 // <s>([base=bar][base=foo])*
313 String occ5 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000314 "{@type=korap:group, operation=operation:sequence, operands=[" +
315 "{@type=korap:span, key=s}," +
316 "{@type=korap:group, operands=[" +
317 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000318 "{@type=korap:token, wrap={@type=korap:term, key=bar, layer=lemma, match=match:eq}}," +
319 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000320 "]}" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000321 "], operation=operation:repetition, min=0, max=100 }" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000322 "]}" ;
323 ppt = new PoliqarpPlusTree("<s>([base=bar][base=foo])*");
324 map = ppt.getRequestMap().get("query").toString();
325 assertEquals(occ5.replaceAll(" ", ""), map.replaceAll(" ", ""));
326
327 // <s><np>([base=bar][base=foo])*
Joachim Bingelb4da7022013-12-09 23:17:24 +0000328 String occ6 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000329 "{@type=korap:group, operation=operation:sequence, operands=[" +
330 "{@type=korap:span, key=s}," +
331 "{@type=korap:span, key=np}," +
332 "{@type=korap:group, operands=[" +
333 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000334 "{@type=korap:token, wrap={@type=korap:term, key=bar, layer=lemma, match=match:eq}}," +
335 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000336 "]}" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000337 "], operation=operation:repetition, min=0, max=100 }" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000338 "]}" ;
339 ppt = new PoliqarpPlusTree("<s><np>([base=bar][base=foo])*");
340 map = ppt.getRequestMap().get("query").toString();
341 assertEquals(occ6.replaceAll(" ", ""), map.replaceAll(" ", ""));
342
343 // <s><np>([base=bar][base=foo])*[p=NN]
344 // comment: embedded sequence shouldn't really be here, but does not really hurt, either. (?)
345 // really hard to get this behaviour out of the PQPlus grammar...
346 String occ7 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000347 "{@type=korap:group, operation=operation:sequence, operands=[" +
348 "{@type=korap:span, key=s}," +
349 "{@type=korap:span, key=np}," +
350 "{@type=korap:group, operands=[" +
351 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000352 "{@type=korap:token, wrap={@type=korap:term, key=bar, layer=lemma, match=match:eq}}," +
353 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000354 "]}" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000355 "], operation=operation:repetition, min=0, max=100 }," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000356 "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000357 "]}" ;
358 ppt = new PoliqarpPlusTree("<s><np>([base=bar][base=foo])*[p=NN]");
359 map = ppt.getRequestMap().get("query").toString();
360 assertEquals(occ7.replaceAll(" ", ""), map.replaceAll(" ", ""));
361
362 // ([base=bar][base=foo])*[p=NN]
Joachim Bingelb4da7022013-12-09 23:17:24 +0000363 String occ8 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000364 "{@type=korap:group, operation=operation:sequence, operands=[" +
365 "{@type=korap:group, operands=[" +
366 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000367 "{@type=korap:token, wrap={@type=korap:term, key=bar, layer=lemma, match=match:eq}}," +
368 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000369 "]}" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000370 "], operation=operation:repetition, min=0, max=100 }," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000371 "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, match=match:eq}}" +
Joachim Bingelb4da7022013-12-09 23:17:24 +0000372 "]}" ;
373 ppt = new PoliqarpPlusTree("([base=bar][base=foo])*[p=NN]");
374 map = ppt.getRequestMap().get("query").toString();
375 assertEquals(occ8.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000376
377 // [base=foo]+
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000378 String occ9 = "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000379 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000380 "], min=1, max=100}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000381 ppt = new PoliqarpPlusTree("[base=foo]+");
382 map = ppt.getRequestMap().get("query").toString();
383 assertEquals(occ9.replaceAll(" ", ""), map.replaceAll(" ", ""));
384
385 // [base=foo]?
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000386 String occ10 = "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000387 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000388 "], min=0, max=1}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000389 ppt = new PoliqarpPlusTree("[base=foo]?");
390 map = ppt.getRequestMap().get("query").toString();
391 assertEquals(occ10.replaceAll(" ", ""), map.replaceAll(" ", ""));
392
393 // [base=foo]{2,5}
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000394 String occ11 = "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000395 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000396 "], min=2, max=5}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000397 ppt = new PoliqarpPlusTree("[base=foo]{2,5}");
398 map = ppt.getRequestMap().get("query").toString();
399 assertEquals(occ11.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel2980bda2014-04-04 12:09:46 +0000400
401 // [base=foo]{2}
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000402 String occ12 = "{@type=korap:group, operation=operation:repetition, operands=[" +
Joachim Bingel2980bda2014-04-04 12:09:46 +0000403 "{@type=korap:token, wrap={@type=korap:term, key=foo, layer=lemma, match=match:eq}}" +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000404 "], min=2, max=2}";
Joachim Bingel2980bda2014-04-04 12:09:46 +0000405 ppt = new PoliqarpPlusTree("[base=foo]{2}");
406 map = ppt.getRequestMap().get("query").toString();
407 assertEquals(occ12.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000408 }
409
410 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000411 public void testTokenSequence() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000412 // [base=Mann][orth=Frau]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000413 String seq1 = "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000414 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}, " +
415 "{@type=korap:token, wrap={@type=korap:term, key=Frau, layer=orth, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000416 "]}";
417 assertTrue(equalsQueryContent(seq1, "[base=Mann][orth=Frau]"));
418
419 // [base=Mann][orth=Frau][p=NN]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000420 String seq2 = "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000421 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}, " +
422 "{@type=korap:token, wrap={@type=korap:term, key=Frau, layer=orth, match=match:eq}}, " +
423 "{@type=korap:token, wrap={@type=korap:term, key=NN,layer=p, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000424 "]}";
425 assertTrue(equalsQueryContent(seq2, "[base=Mann][orth=Frau][p=NN]"));
426 }
427
428 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000429 public void testDisjSegments() throws QueryException {
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000430 // ([base=der]|[base=das])[base=Schild]
431 String disj1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000432 "{@type=korap:group, operation=operation:sequence, operands=[" +
433 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000434 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=match:eq}}," +
435 "{@type=korap:token, wrap={@type=korap:term, key=das, layer=lemma, match=match:eq}}" +
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000436 "]}," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000437 "{@type=korap:token, wrap={@type=korap:term, key=Schild, layer=lemma, match=match:eq}}" +
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000438 "]}";
439 ppt = new PoliqarpPlusTree("([base=der]|[base=das])[base=Schild]");
440 map = ppt.getRequestMap().get("query").toString();
441 assertEquals(disj1.replaceAll(" ", ""), map.replaceAll(" ", ""));
442
443 // [base=Schild]([base=der]|[base=das])
444 String disj2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000445 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000446 "{@type=korap:token, wrap={@type=korap:term, key=Schild, layer=lemma, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000447 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000448 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=match:eq}}," +
449 "{@type=korap:token, wrap={@type=korap:term, key=das, layer=lemma, match=match:eq}}" +
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000450 "]}" +
451 "]}";
452 ppt = new PoliqarpPlusTree("[base=Schild]([base=der]|[base=das])");
453 map = ppt.getRequestMap().get("query").toString();
454 assertEquals(disj2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel76b498d2014-06-06 12:06:46 +0000455
456 // "([orth=der][base=katze])|([orth=eine][base=baum])"
457 String disj3 =
458 "{@type=korap:group, operation=operation:or, operands=[" +
459 "{@type=korap:group, operation=operation:sequence, operands=[" +
460 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
461 "{@type=korap:token, wrap={@type=korap:term, key=katze, layer=lemma, match=match:eq}}" +
462 "]}," +
463 "{@type=korap:group, operation=operation:sequence, operands=[" +
464 "{@type=korap:token, wrap={@type=korap:term, key=eine, layer=orth, match=match:eq}}," +
465 "{@type=korap:token, wrap={@type=korap:term, key=baum, layer=lemma, match=match:eq}}" +
466 "]}" +
467 "]}";
468 ppt = new PoliqarpPlusTree("([orth=der][base=katze])|([orth=eine][base=baum])");
469 map = ppt.getRequestMap().get("query").toString();
470 assertEquals(disj3.replaceAll(" ", ""), map.replaceAll(" ", ""));
471
472 // "[orth=der][base=katze]|[orth=eine][base=baum]"
473 String disj4 =
474 "{@type=korap:group, operation=operation:or, operands=[" +
475 "{@type=korap:group, operation=operation:sequence, operands=[" +
476 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
477 "{@type=korap:token, wrap={@type=korap:term, key=katze, layer=lemma, match=match:eq}}" +
478 "]}," +
479 "{@type=korap:group, operation=operation:sequence, operands=[" +
480 "{@type=korap:token, wrap={@type=korap:term, key=eine, layer=orth, match=match:eq}}," +
481 "{@type=korap:token, wrap={@type=korap:term, key=baum, layer=lemma, match=match:eq}}" +
482 "]}" +
483 "]}";
484 ppt = new PoliqarpPlusTree("[orth=der][base=katze]|[orth=eine][base=baum]");
485 map = ppt.getRequestMap().get("query").toString();
486 assertEquals(disj4.replaceAll(" ", ""), map.replaceAll(" ", ""));
487
488 PoliqarpPlusTree ppt1 = new PoliqarpPlusTree("[orth=der][base=katze]|[orth=eine][base=baum]");
489 PoliqarpPlusTree ppt2 = new PoliqarpPlusTree("([orth=der][base=katze])|([orth=eine][base=baum])");
490 assertEquals(ppt1.getRequestMap().toString(), ppt2.getRequestMap().toString());
491
492 // "[orth=der][base=katze]|[orth=der][base=hund]|[orth=der][base=baum]"
493 String disj5 =
494 "{@type=korap:group, operation=operation:or, operands=[" +
495 "{@type=korap:group, operation=operation:sequence, operands=[" +
496 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
497 "{@type=korap:token, wrap={@type=korap:term, key=katze, layer=lemma, match=match:eq}}" +
498 "]}," +
499 "{@type=korap:group, operation=operation:sequence, operands=[" +
500 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
501 "{@type=korap:token, wrap={@type=korap:term, key=hund, layer=lemma, match=match:eq}}" +
502 "]}," +
503 "{@type=korap:group, operation=operation:sequence, operands=[" +
504 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
505 "{@type=korap:token, wrap={@type=korap:term, key=baum, layer=lemma, match=match:eq}}" +
506 "]}" +
507 "]}";
508 ppt = new PoliqarpPlusTree("[orth=der][base=katze]|[orth=der][base=hund]|[orth=der][base=baum]");
509 map = ppt.getRequestMap().get("query").toString();
510 assertEquals(disj5.replaceAll(" ", ""), map.replaceAll(" ", ""));
511
512 // [orth=der]([base=katze]|[base=hund]|[base=baum])
513 String disj6 =
514 "{@type=korap:group, operation=operation:sequence, operands=[" +
515 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
516 "{@type=korap:group, operation=operation:or, operands=[" +
517 "{@type=korap:token, wrap={@type=korap:term, key=katze, layer=lemma, match=match:eq}}," +
518 "{@type=korap:token, wrap={@type=korap:term, key=hund, layer=lemma, match=match:eq}}," +
519 "{@type=korap:token, wrap={@type=korap:term, key=baum, layer=lemma, match=match:eq}}" +
520 "]}" +
521 "]}";
522 ppt = new PoliqarpPlusTree("[orth=der]([base=katze]|[base=hund]|[base=baum])");
523 map = ppt.getRequestMap().get("query").toString();
524 assertEquals(disj6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel94a1ccd2013-12-10 10:37:29 +0000525 }
526
527 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000528 public void testTokenElemSequence() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000529 // [base=Mann]<vp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000530 String seq1 = "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000531 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}, " +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000532 "{@type=korap:span, key=vp}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000533 "]}";
534 assertTrue(equalsQueryContent(seq1, "[base=Mann]<vp>"));
535
536 // <vp>[base=Mann]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000537 String seq2 = "{@type=korap:group, operation=operation:sequence, operands=[" +
538 "{@type=korap:span, key=vp}, "+
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000539 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}} " +
Joachim Bingel53333e62013-12-09 19:25:52 +0000540 "]}";
541 assertTrue(equalsQueryContent(seq2, "<vp>[base=Mann]"));
542
543 // <vp>[base=Mann]<pp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000544 String seq3 = "{@type=korap:group, operation=operation:sequence, operands=[" +
545 "{@type=korap:span, key=vp}, "+
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000546 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}, " +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000547 "{@type=korap:span, key=pp} "+
Joachim Bingel53333e62013-12-09 19:25:52 +0000548 "]}";
549 assertTrue(equalsQueryContent(seq3, "<vp>[base=Mann]<pp>"));
550 }
551
552 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000553 public void testElemSequence() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000554 // <np><vp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000555 String seq1 = "{@type=korap:group, operation=operation:sequence, operands=[" +
556 "{@type=korap:span, key=np}," +
557 "{@type=korap:span, key=vp}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000558 "]}";
559 assertTrue(equalsQueryContent(seq1, "<np><vp>"));
560
561 // <np><vp><pp>
Joachim Bingel2daf9862014-02-12 10:18:54 +0000562 String seq2 = "{@type=korap:group, operation=operation:sequence, operands=[" +
563 "{@type=korap:span, key=np}," +
564 "{@type=korap:span, key=vp}," +
565 "{@type=korap:span, key=pp}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000566 "]}";
567 assertTrue(equalsQueryContent(seq2, "<np><vp><pp>"));
568 }
569
570 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000571 public void testClasses() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000572 // {[base=Mann]}
Joachim Bingel2daf9862014-02-12 10:18:54 +0000573 String cls1 = "{@type=korap:group, operation=operation:class, class=0, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000574 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000575 "]}";
Joachim Bingel8c640e42014-02-07 16:20:47 +0000576 ppt = new PoliqarpPlusTree("{[base=Mann]}");
577 map = ppt.getRequestMap().get("query").toString();
578 assertEquals(cls1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000579
580 // {[base=Mann][orth=Frau]}
Joachim Bingel2daf9862014-02-12 10:18:54 +0000581 String cls2 = "{@type=korap:group, operation=operation:class, class=0, operands=[" +
582 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000583 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}," +
584 "{@type=korap:token, wrap={@type=korap:term, key=Frau, layer=orth, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000585 "]}" +
586 "]}";
587 assertTrue(equalsQueryContent(cls2, "{[base=Mann][orth=Frau]}"));
588
589 // [p=NN]{[base=Mann][orth=Frau]}
Joachim Bingel2daf9862014-02-12 10:18:54 +0000590 String cls3 = "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000591 "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000592 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
593 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000594 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}," +
595 "{@type=korap:token, wrap={@type=korap:term, key=Frau, layer=orth, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000596 "]}" +
597 "]}" +
598 "]}";
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000599 ppt = new PoliqarpPlusTree("[p=NN]{[base=Mann][orth=Frau]}");
600 map = ppt.getRequestMap().get("query").toString();
601 assertEquals(cls3.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000602
603 // {[base=Mann][orth=Frau]}[p=NN]
Joachim Bingel2daf9862014-02-12 10:18:54 +0000604 String cls4 = "{@type=korap:group, operation=operation:sequence, operands=[" +
605 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
606 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000607 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}," +
608 "{@type=korap:token, wrap={@type=korap:term, key=Frau, layer=orth, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000609 "]}" +
610 "]}," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000611 "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000612 "]}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000613 ppt = new PoliqarpPlusTree("{[base=Mann][orth=Frau]}[p=NN]");
614 map = ppt.getRequestMap().get("query").toString();
615 assertEquals(cls4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000616
617 // {2:{1:[tt/p=ADJA]}[mate/p=NN]}"
Joachim Bingel2daf9862014-02-12 10:18:54 +0000618 String cls5 = "{@type=korap:group, operation=operation:class, class=2, operands=[" +
619 "{@type=korap:group, operation=operation:sequence, operands=[" +
620 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000621 "{@type=korap:token, wrap={@type=korap:term, key=ADJA, layer=p, foundry=tt, match=match:eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000622 "]}," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000623 "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, foundry=mate, match=match:eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000624 "]}" +
625 "]}";
626 ppt = new PoliqarpPlusTree("{2: {1:[tt/p=ADJA]}[mate/p=NN]}");
627 map = ppt.getRequestMap().get("query").toString();
628 assertEquals(cls5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000629 }
630
631 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000632 public void testPositions() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000633 // contains(<s>,<np>)
Joachim Bingel2daf9862014-02-12 10:18:54 +0000634 String pos1 = "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
635 "{@type=korap:span, key=s}," +
636 "{@type=korap:span, key=np}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000637 "]}";
638 assertTrue(equalsQueryContent(pos1, "contains(<s>,<np>)"));
639
640 // contains(<s>,[base=Mann])
Joachim Bingel2daf9862014-02-12 10:18:54 +0000641 String pos2 = "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
642 "{@type=korap:span, key=s}," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000643 "{@type=korap:token, wrap= {@type=korap:term, key=Mann, layer=lemma, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000644 "]}";
645 assertTrue(equalsQueryContent(pos2, "contains(<s>,[base=Mann])"));
646
647 // contains(<s>,[orth=der][orth=Mann])
Joachim Bingel2daf9862014-02-12 10:18:54 +0000648 String pos3 = "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
649 "{@type=korap:span, key=s}," +
650 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000651 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
652 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000653 "]}" +
654 "]}";
655 ppt = new PoliqarpPlusTree("contains(<s>,[orth=der][orth=Mann])");
656 map = ppt.getRequestMap().get("query").toString();
657 assertEquals(pos3.replaceAll(" ", ""), map.replaceAll(" ", ""));
658
659 // [base=Auto]contains(<s>,[base=Mann])
660 String pos4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000661 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000662 "{@type=korap:token, wrap={@type=korap:term, key=Auto, layer=lemma, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000663 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
664 "{@type=korap:span, key=s}," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000665 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000666 "]}" +
667 "]}";
668 ppt = new PoliqarpPlusTree("[base=Auto]contains(<s>,[base=Mann])");
669 map = ppt.getRequestMap().get("query").toString();
670 assertEquals(pos4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelef7059b2014-04-22 13:44:19 +0000671
672 // contains(<s>,[pos=N]*)
673 String pos5 =
674 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
675 "{@type=korap:span, key=s}," +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000676 "{@type=korap:group, operation=operation:repetition, " +
Joachim Bingelef7059b2014-04-22 13:44:19 +0000677 "operands=[{@type=korap:token, wrap={@type=korap:term, key=N, layer=pos, match=match:eq}}" +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000678 "], min=0, max=100" +
Joachim Bingelef7059b2014-04-22 13:44:19 +0000679 "}" +
680 "]}";
681 ppt = new PoliqarpPlusTree("contains(<s>,[pos=N]*)");
682 map = ppt.getRequestMap().get("query").toString();
683 assertEquals(pos5.replaceAll(" ", ""), map.replaceAll(" ", ""));
684
685 // [base=Auto]contains(<s>,[pos=N]*)
686 String pos6 =
687 "{@type=korap:group, operation=operation:sequence, operands=[" +
688 "{@type=korap:token, wrap={@type=korap:term, key=Auto, layer=lemma, match=match:eq}}," +
689 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
690 "{@type=korap:span, key=s}," +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000691 "{@type=korap:group, operation=operation:repetition, " +
Joachim Bingelef7059b2014-04-22 13:44:19 +0000692 "operands=[{@type=korap:token, wrap={@type=korap:term, key=N, layer=pos, match=match:eq}}" +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000693 "], min=0, max=100" +
Joachim Bingelef7059b2014-04-22 13:44:19 +0000694 "}" +
695 "]}" +
696 "]}";
697 ppt = new PoliqarpPlusTree("[base=Auto]contains(<s>,[pos=N]*)");
698 map = ppt.getRequestMap().get("query").toString();
699 assertEquals(pos6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000700 }
701
702 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000703 public void testNestedPositions() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000704 // contains(<s>,startswith(<np>,[orth=Der]))
705 String npos1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000706 "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" +
707 "{@type=korap:span, key=s}," +
708 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
709 "{@type=korap:span, key=np}," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000710 "{@type=korap:token, wrap={@type=korap:term, key=Der, layer=orth, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000711 "]}" +
712 "]}";
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000713 ppt = new PoliqarpPlusTree("contains(<s>, startswith(<np>,[orth=Der]))");
Joachim Bingel53333e62013-12-09 19:25:52 +0000714 map = ppt.getRequestMap().get("query").toString();
715 assertEquals(npos1.replaceAll(" ", ""), map.replaceAll(" ", ""));
716 }
717
718 @Test
Joachim Bingel16da4e12013-12-17 09:48:12 +0000719 public void testShrinkSplit() throws QueryException {
Joachim Bingel53333e62013-12-09 19:25:52 +0000720 // shrink([orth=Der]{[orth=Mann]})
721 String shr1 =
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000722 "{@type=korap:reference, classRef=[0], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000723 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000724 "{@type=korap:token, wrap={@type=korap:term, key=Der, layer=orth, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000725 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000726 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000727 "]}" +
728 "]}" +
729 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000730 ppt = new PoliqarpPlusTree("focus([orth=Der]{[orth=Mann]})");
Joachim Bingel53333e62013-12-09 19:25:52 +0000731 map = ppt.getRequestMap().get("query").toString();
732 assertEquals(shr1.replaceAll(" ", ""), map.replaceAll(" ", ""));
733
734 // shrink([orth=Der]{[orth=Mann][orth=geht]})
735 String shr2 =
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000736 "{@type=korap:reference, classRef=[0], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000737 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000738 "{@type=korap:token, wrap={@type=korap:term, key=Der, layer=orth, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000739 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
740 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000741 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}," +
742 "{@type=korap:token, wrap={@type=korap:term, key=geht, layer=orth, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000743 "]}" +
744 "]}" +
745 "]}" +
746 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000747 ppt = new PoliqarpPlusTree("focus([orth=Der]{[orth=Mann][orth=geht]})");
Joachim Bingel53333e62013-12-09 19:25:52 +0000748 map = ppt.getRequestMap().get("query").toString();
749 assertEquals(shr2.replaceAll(" ", ""), map.replaceAll(" ", ""));
750
751 // shrink(1:[orth=Der]{1:[orth=Mann][orth=geht]})
752 String shr3 =
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000753 "{@type=korap:reference, classRef=[1], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000754 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000755 "{@type=korap:token, wrap={@type=korap:term, key=Der, layer=orth, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000756 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
757 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000758 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}," +
759 "{@type=korap:token, wrap={@type=korap:term, key=geht, layer=orth, match=match:eq}}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000760 "]}" +
761 "]}" +
762 "]}" +
763 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000764 ppt = new PoliqarpPlusTree("focus(1:[orth=Der]{1:[orth=Mann][orth=geht]})");
Joachim Bingel53333e62013-12-09 19:25:52 +0000765 map = ppt.getRequestMap().get("query").toString();
766 assertEquals(shr3.replaceAll(" ", ""), map.replaceAll(" ", ""));
767
768 // shrink(1:startswith(<s>,{1:<np>}))
769 String shr4 =
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000770 "{@type=korap:reference, classRef=[1], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000771 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
772 "{@type=korap:span, key=s}," +
773 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
774 "{@type=korap:span, key=np}" +
Joachim Bingel53333e62013-12-09 19:25:52 +0000775 "]}" +
776 "]}" +
777 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000778 ppt = new PoliqarpPlusTree("focus(1:startswith(<s>,{1:<np>}))");
Joachim Bingel53333e62013-12-09 19:25:52 +0000779 map = ppt.getRequestMap().get("query").toString();
780 assertEquals(shr4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000781
782 // shrink(3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))
783 String shr5 =
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000784 "{@type=korap:reference, classRef=[3], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000785 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
786 "{@type=korap:span, key=s}," +
787 "{@type=korap:group, operation=operation:class, class=3, operands=[" +
788 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000789 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000790 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
791 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000792 "{@type=korap:token, wrap={@type=korap:term, key=ADJA, layer=p, foundry=mate, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000793 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000794 "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, foundry=tt, match=match:eq}}" +
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000795 "]}" +
796 "]}" +
797 "]}" +
798 "]}" +
799 "]}" +
800 "]}" +
801 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000802 ppt = new PoliqarpPlusTree("focus(3:startswith(<s>,{3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) ");
Joachim Bingelcd9ed332013-12-09 21:01:35 +0000803 map = ppt.getRequestMap().get("query").toString();
804 assertEquals(shr5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000805
806 // split(3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))
807 String shr6 =
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000808 "{@type=korap:reference, classRef=[3], operation=operation:split, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000809 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
810 "{@type=korap:span, key=s}," +
811 "{@type=korap:group, operation=operation:class, class=3, operands=[" +
812 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000813 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000814 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
815 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000816 "{@type=korap:token, wrap={@type=korap:term, key=ADJA, layer=p, foundry=mate, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000817 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000818 "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, foundry=tt, match=match:eq}}" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000819 "]}" +
820 "]}" +
821 "]}" +
822 "]}" +
823 "]}" +
824 "]}" +
825 "]}";
826 ppt = new PoliqarpPlusTree("split(3:startswith(<s>,{3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) ");
827 map = ppt.getRequestMap().get("query").toString();
828 assertEquals(shr6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel8c640e42014-02-07 16:20:47 +0000829
830 // split(2|3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))
831 String shr7 =
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000832 "{@type=korap:reference, classRef=[2, 3], operation=operation:split, classRefOp=classRefOp:intersection, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000833 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
834 "{@type=korap:span, key=s}," +
835 "{@type=korap:group, operation=operation:class, class=3, operands=[" +
836 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000837 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000838 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
839 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000840 "{@type=korap:token, wrap={@type=korap:term, key=ADJA, layer=p, foundry=mate, match=match:eq}}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000841 "{@type=korap:group, operation=operation:class, class=2, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000842 "{@type=korap:token, wrap={@type=korap:term, key=NN, layer=p, foundry=tt, match=match:eq}}" +
Joachim Bingel8c640e42014-02-07 16:20:47 +0000843 "]}" +
844 "]}" +
845 "]}" +
846 "]}" +
847 "]}" +
848 "]}" +
849 "]}";
850 ppt = new PoliqarpPlusTree("split(2|3:startswith(<s>,{3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) ");
851 map = ppt.getRequestMap().get("query").toString();
852 assertEquals(shr7.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel5146ebe2014-06-12 08:49:21 +0000853
854
855 String shr8 =
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000856 "{@type=korap:reference, classRef=[1], operands=[" +
Joachim Bingeladd0fb12014-06-24 08:54:14 +0000857 "{@type=korap:group, operation=operation:sequence, operands=[" +
858 "{@type=korap:group, operation=operation:class, class=0, operands=[" +
859 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=lemma, match=match:eq}}" +
860 "]}," +
861 "{@type=korap:group, operation=operation:class, class=1, operands=[" +
862 "{@type=korap:token, wrap={@type=korap:term, key=ADJA, layer=pos, match=match:eq}}" +
Joachim Bingel5146ebe2014-06-12 08:49:21 +0000863 "]}" +
Joachim Bingeladd0fb12014-06-24 08:54:14 +0000864 "]}" +
865 "]}";
Joachim Bingelf8dfcf82014-06-25 09:57:44 +0000866 ppt = new PoliqarpPlusTree("focus(1:{[base=der]}{1:[pos=ADJA]})");
Joachim Bingeladd0fb12014-06-24 08:54:14 +0000867 map = ppt.getRequestMap().get("query").toString();
868 assertEquals(shr8.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel5146ebe2014-06-12 08:49:21 +0000869
Joachim Bingel53333e62013-12-09 19:25:52 +0000870 }
871
Joachim Bingel03882702013-12-31 19:53:05 +0000872
Joachim Bingel53333e62013-12-09 19:25:52 +0000873 @Test
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000874 public void testFoundries() throws QueryException {
875 // [tt/base=Mann]
Joachim Bingelac13a472014-02-14 21:18:52 +0000876 String layer1 = "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, foundry=tt, match=match:eq}}";
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000877 ppt = new PoliqarpPlusTree("[tt/base=Mann]");
878 map = ppt.getRequestMap().get("query").toString();
879 assertEquals(layer1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel53333e62013-12-09 19:25:52 +0000880
881 }
Joachim Bingel16da4e12013-12-17 09:48:12 +0000882
883 @Test
Joachim Bingel8c640e42014-02-07 16:20:47 +0000884 public void testAlign() throws QueryException {
Joachim Bingel16da4e12013-12-17 09:48:12 +0000885 // [orth=der]^[orth=Mann]
886 String align1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000887 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000888 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000889 "{@type=korap:group, align=left, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000890 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
Joachim Bingel03882702013-12-31 19:53:05 +0000891 "]}" +
Joachim Bingel16da4e12013-12-17 09:48:12 +0000892 "]}";
893 ppt = new PoliqarpPlusTree("[orth=der]^[orth=Mann]");
894 map = ppt.getRequestMap().get("query").toString();
895 assertEquals(align1.replaceAll(" ", ""), map.replaceAll(" ", ""));
896
Joachim Bingel84e33df2014-01-31 14:02:46 +0000897 // [orth=der]^[orth=große][orth=Mann]
898 String query = "[orth=der]^[orth=große][orth=Mann]";
899 String align1b =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000900 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000901 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000902 "{@type=korap:group, align=left, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000903 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000904 "{@type=korap:token, wrap={@type=korap:term, key=große, layer=orth, match=match:eq}}," +
905 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +0000906 "]}" +
907 "]}" +
908 "]}";
909 ppt = new PoliqarpPlusTree(query);
910 map = ppt.getRequestMap().get("query").toString();
911 assertEquals(align1b.replaceAll(" ", ""), map.replaceAll(" ", ""));
912
Joachim Bingel16da4e12013-12-17 09:48:12 +0000913 // "([base=a]^[base=b])|[base=c]",
914 String align2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000915 "{@type=korap:group, operation=operation:or, operands=[" +
916 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000917 "{@type=korap:token, wrap={@type=korap:term, key=a, layer=lemma, match=match:eq}}," +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000918 "{@type=korap:group, align=left, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000919 "{@type=korap:token, wrap={@type=korap:term, key=b, layer=lemma, match=match:eq}}" +
Joachim Bingel03882702013-12-31 19:53:05 +0000920 "]}" +
Joachim Bingel16da4e12013-12-17 09:48:12 +0000921 "]}," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000922 "{@type=korap:token, wrap={@type=korap:term, key=c, layer=lemma, match=match:eq}}" +
Joachim Bingel16da4e12013-12-17 09:48:12 +0000923 "]}";
924 ppt = new PoliqarpPlusTree("([base=a]^[base=b])|[base=c]");
925 map = ppt.getRequestMap().get("query").toString();
926 assertEquals(align2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingela67e6a32014-01-02 18:35:24 +0000927
928 // "([base=a]^[base=b][base=c])|[base=d]",
929 String align3 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000930 "{@type=korap:group, operation=operation:or, operands=[" +
931 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000932 "{@type=korap:token, wrap={@type=korap:term, key=a, layer=lemma, match=match:eq}}," +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000933 "{@type=korap:group, align=left, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000934 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000935 "{@type=korap:token, wrap={@type=korap:term, key=b, layer=lemma, match=match:eq}}," +
936 "{@type=korap:token, wrap={@type=korap:term, key=c, layer=lemma, match=match:eq}}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +0000937 "]}" +
938 "]}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000939 "]}," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000940 "{@type=korap:token, wrap={@type=korap:term, key=d, layer=lemma, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000941 "]}";
942 ppt = new PoliqarpPlusTree("([base=a]^[base=b][base=c])|[base=d]");
943 map = ppt.getRequestMap().get("query").toString();
944 assertEquals(align3.replaceAll(" ", ""), map.replaceAll(" ", ""));
945
946 // "([base=a]^[base=b]^[base=c])|[base=d]",
947 String align4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000948 "{@type=korap:group, operation=operation:or, operands=[" +
949 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000950 "{@type=korap:token, wrap={@type=korap:term, key=a, layer=lemma, match=match:eq}}," +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000951 "{@type=korap:group, align=left, operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000952 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000953 "{@type=korap:token, wrap={@type=korap:term, key=b, layer=lemma, match=match:eq}}," +
Joachim Bingel33bd45f2014-06-25 15:00:54 +0000954 "{@type=korap:group, align=left, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000955 "{@type=korap:token, wrap={@type=korap:term, key=c, layer=lemma, match=match:eq}}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +0000956 "]}" +
957 "]}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000958 "]}" +
959 "]}," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000960 "{@type=korap:token, wrap={@type=korap:term, key=d, layer=lemma, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000961 "]}";
962 ppt = new PoliqarpPlusTree("([base=a]^[base=b]^[base=c])|[base=d]");
963 map = ppt.getRequestMap().get("query").toString();
964 assertEquals(align4.replaceAll(" ", ""), map.replaceAll(" ", ""));
965
966
Joachim Bingel16da4e12013-12-17 09:48:12 +0000967 }
968
969 @Test
Joachim Bingel8c640e42014-02-07 16:20:47 +0000970 public void testSimpleQueries() throws QueryException {
Joachim Bingela67e6a32014-01-02 18:35:24 +0000971 // Baum
972 String simple1 =
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000973 "{@type=korap:token, wrap={@type=korap:term, key=Baum, layer=orth, match=match:eq}}";
Joachim Bingela67e6a32014-01-02 18:35:24 +0000974 ppt = new PoliqarpPlusTree("Baum");
975 map = ppt.getRequestMap().get("query").toString();
976 assertEquals(simple1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel16da4e12013-12-17 09:48:12 +0000977
Joachim Bingela67e6a32014-01-02 18:35:24 +0000978 // Der Baum
979 String simple2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000980 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000981 "{@type=korap:token, wrap={@type=korap:term, key=Der, layer=orth, match=match:eq}}, " +
982 "{@type=korap:token, wrap={@type=korap:term, key=Baum, layer=orth, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000983 "]}";
984 ppt = new PoliqarpPlusTree("Der Baum");
985 map = ppt.getRequestMap().get("query").toString();
986 assertEquals(simple2.replaceAll(" ", ""), map.replaceAll(" ", ""));
987
988 // Der große Baum
989 String simple3 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000990 "{@type=korap:group, operation=operation:sequence, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +0000991 "{@type=korap:token, wrap={@type=korap:term, key=Der, layer=orth, match=match:eq}}, " +
992 "{@type=korap:token, wrap={@type=korap:term, key=große, layer=orth, match=match:eq}}, " +
993 "{@type=korap:token, wrap={@type=korap:term, key=Baum, layer=orth, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +0000994 "]}";
995 ppt = new PoliqarpPlusTree("Der große Baum");
996 map = ppt.getRequestMap().get("query").toString();
997 assertEquals(simple3.replaceAll(" ", ""), map.replaceAll(" ", ""));
998
999 // Baum | Stein
1000 String simple4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001001 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +00001002 "{@type=korap:token, wrap={@type=korap:term, key=Baum, layer=orth, match=match:eq}}, " +
1003 "{@type=korap:token, wrap={@type=korap:term, key=Stein, layer=orth, match=match:eq}}" +
Joachim Bingela67e6a32014-01-02 18:35:24 +00001004 "]}";
1005 ppt = new PoliqarpPlusTree("Baum | Stein");
1006 map = ppt.getRequestMap().get("query").toString();
1007 assertEquals(simple4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel84e33df2014-01-31 14:02:46 +00001008
1009 // Baum | Stein Haus
1010 String query = "(Baum | Stein) Haus";
1011 String simple5 =
Joachim Bingel2daf9862014-02-12 10:18:54 +00001012 "{@type=korap:group, operation=operation:sequence, operands=[" +
1013 "{@type=korap:group, operation=operation:or, operands=[" +
Joachim Bingelee3b21d2014-02-12 12:34:59 +00001014 "{@type=korap:token, wrap={@type=korap:term, key=Baum, layer=orth, match=match:eq}}, " +
1015 "{@type=korap:token, wrap={@type=korap:term, key=Stein, layer=orth, match=match:eq}}" +
Joachim Bingel84e33df2014-01-31 14:02:46 +00001016 "]}," +
Joachim Bingelee3b21d2014-02-12 12:34:59 +00001017 "{@type=korap:token, wrap={@type=korap:term, key=Haus, layer=orth, match=match:eq}} " +
Joachim Bingel84e33df2014-01-31 14:02:46 +00001018 "]}";
1019 ppt = new PoliqarpPlusTree(query);
1020 map = ppt.getRequestMap().get("query").toString();
1021 assertEquals(simple5.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel16da4e12013-12-17 09:48:12 +00001022 }
Joachim Bingel53333e62013-12-09 19:25:52 +00001023}
1024