Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 1 | import static org.junit.Assert.*; |
| 2 | |
| 3 | import org.junit.Test; |
| 4 | |
| 5 | import de.ids_mannheim.korap.query.serialize.PoliqarpPlusTree; |
| 6 | |
| 7 | public class PoliqarpPlusTreeTest { |
| 8 | |
| 9 | PoliqarpPlusTree ppt; |
| 10 | String map; |
| 11 | |
| 12 | private boolean equalsContent(String str, Object map) { |
| 13 | str = str.replaceAll(" ", ""); |
| 14 | String mapStr = map.toString().replaceAll(" ", ""); |
| 15 | return str.equals(mapStr); |
| 16 | } |
| 17 | |
| 18 | private boolean equalsQueryContent(String res, String query) { |
| 19 | res = res.replaceAll(" ", ""); |
| 20 | ppt = new PoliqarpPlusTree(query); |
| 21 | String queryMap = ppt.getRequestMap().get("query").toString().replaceAll(" ", ""); |
| 22 | return res.equals(queryMap); |
| 23 | } |
| 24 | |
| 25 | @Test |
| 26 | public void testContext() { |
| 27 | 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}"; |
| 28 | ppt = new PoliqarpPlusTree("[base=test]"); |
| 29 | assertTrue(equalsContent(contextString, ppt.getRequestMap().get("@context"))); |
| 30 | } |
| 31 | |
| 32 | @Test |
| 33 | public void testSingleTokens() { |
| 34 | // [base=Mann] |
| 35 | String token1 = "{@type=korap:token, @value={@type=korap:term, @value=base:Mann, relation==}}"; |
| 36 | assertTrue(equalsQueryContent(token1, "[base=Mann]")); |
| 37 | |
| 38 | // [orth!=Frau] |
| 39 | String token2 = "{@type=korap:token, @value={@type=korap:term, @value=orth:Frau, relation=!=}}"; |
| 40 | assertTrue(equalsQueryContent(token2, "[orth!=Frau]")); |
| 41 | |
| 42 | // [!p=NN] |
| 43 | String token3 = "{@type=korap:token, @value={@type=korap:term, @value=p:NN, relation=!=}}"; |
| 44 | assertTrue(equalsQueryContent(token3, "[!p=NN]")); |
| 45 | |
| 46 | // [!p!=NN] |
| 47 | String token4 = "{@type=korap:token, @value={@type=korap:term, @value=p:NN, relation==}}"; |
| 48 | assertTrue(equalsQueryContent(token4, "[!p!=NN]")); |
| 49 | } |
| 50 | |
| 51 | @Test |
| 52 | public void testElements() { |
| 53 | // <s> |
| 54 | String elem1 = "{@type=korap:element, @value=s}"; |
| 55 | assertTrue(equalsQueryContent(elem1, "<s>")); |
| 56 | |
| 57 | // <vp> |
| 58 | String elem2 = "{@type=korap:element, @value=vp}"; |
| 59 | assertTrue(equalsQueryContent(elem2, "<vp>")); |
| 60 | } |
| 61 | |
| 62 | @Test |
| 63 | public void testCoordinatedFields() { |
| 64 | // [base=Mann&(cas=N|cas=A)] |
| 65 | String cof1 = |
| 66 | "{@type=korap:token, @value=" + |
| 67 | "{@type=korap:group, operands=[" + |
| 68 | "{@type=korap:term, @value=base:Mann, relation==}," + |
| 69 | "{@type=korap:group, operands=[" + |
| 70 | "{@type=korap:term, @value=cas:N, relation==}," + |
| 71 | "{@type=korap:term, @value=cas:A, relation==}" + |
| 72 | "], relation=or}" + |
| 73 | "], relation=and}" + |
| 74 | "}"; |
| 75 | ppt = new PoliqarpPlusTree("[base=Mann&(cas=N|cas=A)]"); |
| 76 | map = ppt.getRequestMap().get("query").toString(); |
| 77 | assertEquals(cof1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 78 | } |
| 79 | |
| 80 | @Test |
| 81 | public void testOccurrence() { |
Joachim Bingel | cd9ed33 | 2013-12-09 21:01:35 +0000 | [diff] [blame] | 82 | // [base=foo]* |
| 83 | String occ1 = "{@type=korap:group, operands=[" + |
| 84 | "{@type=korap:token, @value={@type=korap:term, @value=base:foo, relation==}}" + |
| 85 | "], relation=repetition, quantifier=* }"; |
| 86 | ppt = new PoliqarpPlusTree("[base=foo]*"); |
| 87 | map = ppt.getRequestMap().get("query").toString(); |
| 88 | assertEquals(occ1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 89 | |
| 90 | // [base=foo]*[base=bar] |
| 91 | String occ2 = |
| 92 | "{@type=korap:sequence, operands=[" + |
| 93 | "{@type=korap:group, operands=[" + |
| 94 | "{@type=korap:token, @value={@type=korap:term, @value=base:foo, relation==}}" + |
| 95 | "], relation=repetition, quantifier=* }," + |
| 96 | "{@type=korap:token, @value={@type=korap:term, @value=base:bar, relation==}}" + |
| 97 | "]}"; |
| 98 | ppt = new PoliqarpPlusTree("[base=foo]*[base=bar]"); |
| 99 | map = ppt.getRequestMap().get("query").toString(); |
| 100 | assertEquals(occ2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 101 | |
| 102 | // [base=bar][base=foo]* |
| 103 | String occ3 = |
| 104 | "{@type=korap:sequence, operands=[" + |
| 105 | "{@type=korap:token, @value={@type=korap:term, @value=base:bar, relation==}}," + |
| 106 | "{@type=korap:group, operands=[" + |
| 107 | "{@type=korap:token, @value={@type=korap:term, @value=base:foo, relation==}}" + |
| 108 | "], relation=repetition, quantifier=* }" + |
| 109 | "]}"; |
| 110 | ppt = new PoliqarpPlusTree("[base=bar][base=foo]*"); |
| 111 | map = ppt.getRequestMap().get("query").toString(); |
| 112 | assertEquals(occ3.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | b4da702 | 2013-12-09 23:17:24 +0000 | [diff] [blame] | 113 | |
| 114 | // ([base=bar][base=foo])* |
| 115 | String occ4 = |
| 116 | "{@type=korap:group, operands=[" + |
| 117 | "{@type=korap:sequence, operands=[" + |
| 118 | "{@type=korap:token, @value={@type=korap:term, @value=base:bar, relation==}}," + |
| 119 | "{@type=korap:token, @value={@type=korap:term, @value=base:foo, relation==}}" + |
| 120 | "]}" + |
| 121 | "], relation=repetition, quantifier=* }" ; |
| 122 | ppt = new PoliqarpPlusTree("([base=bar][base=foo])*"); |
| 123 | map = ppt.getRequestMap().get("query").toString(); |
| 124 | assertEquals(occ4.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 125 | |
| 126 | // <s>([base=bar][base=foo])* |
| 127 | String occ5 = |
| 128 | "{@type=korap:sequence, operands=[" + |
| 129 | "{@type=korap:element, @value=s}," + |
| 130 | "{@type=korap:group, operands=[" + |
| 131 | "{@type=korap:sequence, operands=[" + |
| 132 | "{@type=korap:token, @value={@type=korap:term, @value=base:bar, relation==}}," + |
| 133 | "{@type=korap:token, @value={@type=korap:term, @value=base:foo, relation==}}" + |
| 134 | "]}" + |
| 135 | "], relation=repetition, quantifier=* }" + |
| 136 | "]}" ; |
| 137 | ppt = new PoliqarpPlusTree("<s>([base=bar][base=foo])*"); |
| 138 | map = ppt.getRequestMap().get("query").toString(); |
| 139 | assertEquals(occ5.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 140 | |
| 141 | // <s><np>([base=bar][base=foo])* |
Joachim Bingel | b4da702 | 2013-12-09 23:17:24 +0000 | [diff] [blame] | 142 | String occ6 = |
| 143 | "{@type=korap:sequence, operands=[" + |
Joachim Bingel | 94a1ccd | 2013-12-10 10:37:29 +0000 | [diff] [blame] | 144 | "{@type=korap:element, @value=s}," + |
| 145 | "{@type=korap:element, @value=np}," + |
Joachim Bingel | b4da702 | 2013-12-09 23:17:24 +0000 | [diff] [blame] | 146 | "{@type=korap:group, operands=[" + |
| 147 | "{@type=korap:sequence, operands=[" + |
| 148 | "{@type=korap:token, @value={@type=korap:term, @value=base:bar, relation==}}," + |
| 149 | "{@type=korap:token, @value={@type=korap:term, @value=base:foo, relation==}}" + |
| 150 | "]}" + |
| 151 | "], relation=repetition, quantifier=* }" + |
| 152 | "]}" ; |
| 153 | ppt = new PoliqarpPlusTree("<s><np>([base=bar][base=foo])*"); |
| 154 | map = ppt.getRequestMap().get("query").toString(); |
| 155 | assertEquals(occ6.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 156 | |
| 157 | // <s><np>([base=bar][base=foo])*[p=NN] |
| 158 | // comment: embedded sequence shouldn't really be here, but does not really hurt, either. (?) |
| 159 | // really hard to get this behaviour out of the PQPlus grammar... |
| 160 | String occ7 = |
| 161 | "{@type=korap:sequence, operands=[" + |
Joachim Bingel | 94a1ccd | 2013-12-10 10:37:29 +0000 | [diff] [blame] | 162 | "{@type=korap:element, @value=s}," + |
| 163 | "{@type=korap:element, @value=np}," + |
Joachim Bingel | b4da702 | 2013-12-09 23:17:24 +0000 | [diff] [blame] | 164 | "{@type=korap:group, operands=[" + |
| 165 | "{@type=korap:sequence, operands=[" + |
| 166 | "{@type=korap:token, @value={@type=korap:term, @value=base:bar, relation==}}," + |
| 167 | "{@type=korap:token, @value={@type=korap:term, @value=base:foo, relation==}}" + |
| 168 | "]}" + |
| 169 | "], relation=repetition, quantifier=* }," + |
| 170 | "{@type=korap:token, @value={@type=korap:term, @value=p:NN, relation==}}" + |
| 171 | "]}" ; |
| 172 | ppt = new PoliqarpPlusTree("<s><np>([base=bar][base=foo])*[p=NN]"); |
| 173 | map = ppt.getRequestMap().get("query").toString(); |
| 174 | assertEquals(occ7.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 175 | |
| 176 | // ([base=bar][base=foo])*[p=NN] |
Joachim Bingel | b4da702 | 2013-12-09 23:17:24 +0000 | [diff] [blame] | 177 | String occ8 = |
| 178 | "{@type=korap:sequence, operands=[" + |
| 179 | "{@type=korap:group, operands=[" + |
| 180 | "{@type=korap:sequence, operands=[" + |
| 181 | "{@type=korap:token, @value={@type=korap:term, @value=base:bar, relation==}}," + |
| 182 | "{@type=korap:token, @value={@type=korap:term, @value=base:foo, relation==}}" + |
| 183 | "]}" + |
| 184 | "], relation=repetition, quantifier=* }," + |
| 185 | "{@type=korap:token, @value={@type=korap:term, @value=p:NN, relation==}}" + |
| 186 | "]}" ; |
| 187 | ppt = new PoliqarpPlusTree("([base=bar][base=foo])*[p=NN]"); |
| 188 | map = ppt.getRequestMap().get("query").toString(); |
| 189 | assertEquals(occ8.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | @Test |
| 193 | public void testTokenSequence() { |
| 194 | // [base=Mann][orth=Frau] |
| 195 | String seq1 = "{@type=korap:sequence, operands=[" + |
| 196 | "{@type=korap:token, @value={@type=korap:term, @value=base:Mann, relation==}}, " + |
| 197 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Frau, relation==}}" + |
| 198 | "]}"; |
| 199 | assertTrue(equalsQueryContent(seq1, "[base=Mann][orth=Frau]")); |
| 200 | |
| 201 | // [base=Mann][orth=Frau][p=NN] |
| 202 | String seq2 = "{@type=korap:sequence, operands=[" + |
| 203 | "{@type=korap:token, @value={@type=korap:term, @value=base:Mann, relation==}}, " + |
| 204 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Frau, relation==}}, " + |
| 205 | "{@type=korap:token, @value={@type=korap:term, @value=p:NN, relation==}}" + |
| 206 | "]}"; |
| 207 | assertTrue(equalsQueryContent(seq2, "[base=Mann][orth=Frau][p=NN]")); |
| 208 | } |
| 209 | |
| 210 | @Test |
Joachim Bingel | 94a1ccd | 2013-12-10 10:37:29 +0000 | [diff] [blame] | 211 | public void testDisjSegments() { |
| 212 | // ([base=der]|[base=das])[base=Schild] |
| 213 | String disj1 = |
| 214 | "{@type=korap:sequence, operands=[" + |
| 215 | "{@type=korap:group, relation=or, operands=[" + |
| 216 | "{@type=korap:token, @value={@type=korap:term, @value=base:der, relation==}}," + |
| 217 | "{@type=korap:token, @value={@type=korap:term, @value=base:das, relation==}}" + |
| 218 | "]}," + |
| 219 | "{@type=korap:token, @value={@type=korap:term, @value=base:Schild, relation==}}" + |
| 220 | "]}"; |
| 221 | ppt = new PoliqarpPlusTree("([base=der]|[base=das])[base=Schild]"); |
| 222 | map = ppt.getRequestMap().get("query").toString(); |
| 223 | assertEquals(disj1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 224 | |
| 225 | // [base=Schild]([base=der]|[base=das]) |
| 226 | String disj2 = |
| 227 | "{@type=korap:sequence, operands=[" + |
| 228 | "{@type=korap:token, @value={@type=korap:term, @value=base:Schild, relation==}}," + |
| 229 | "{@type=korap:group, relation=or, operands=[" + |
| 230 | "{@type=korap:token, @value={@type=korap:term, @value=base:der, relation==}}," + |
| 231 | "{@type=korap:token, @value={@type=korap:term, @value=base:das, relation==}}" + |
| 232 | "]}" + |
| 233 | "]}"; |
| 234 | ppt = new PoliqarpPlusTree("[base=Schild]([base=der]|[base=das])"); |
| 235 | map = ppt.getRequestMap().get("query").toString(); |
| 236 | assertEquals(disj2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 237 | } |
| 238 | |
| 239 | @Test |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 240 | public void testTokenElemSequence() { |
| 241 | // [base=Mann]<vp> |
| 242 | String seq1 = "{@type=korap:sequence, operands=[" + |
| 243 | "{@type=korap:token, @value={@type=korap:term, @value=base:Mann, relation==}}, " + |
| 244 | "{@type=korap:element, @value=vp}" + |
| 245 | "]}"; |
| 246 | assertTrue(equalsQueryContent(seq1, "[base=Mann]<vp>")); |
| 247 | |
| 248 | // <vp>[base=Mann] |
| 249 | String seq2 = "{@type=korap:sequence, operands=[" + |
| 250 | "{@type=korap:element, @value=vp}, "+ |
| 251 | "{@type=korap:token, @value={@type=korap:term, @value=base:Mann, relation==}} " + |
| 252 | "]}"; |
| 253 | assertTrue(equalsQueryContent(seq2, "<vp>[base=Mann]")); |
| 254 | |
| 255 | // <vp>[base=Mann]<pp> |
| 256 | String seq3 = "{@type=korap:sequence, operands=[" + |
| 257 | "{@type=korap:element, @value=vp}, "+ |
| 258 | "{@type=korap:token, @value={@type=korap:term, @value=base:Mann, relation==}}, " + |
| 259 | "{@type=korap:element, @value=pp} "+ |
| 260 | "]}"; |
| 261 | assertTrue(equalsQueryContent(seq3, "<vp>[base=Mann]<pp>")); |
| 262 | } |
| 263 | |
| 264 | @Test |
| 265 | public void testElemSequence() { |
| 266 | // <np><vp> |
| 267 | String seq1 = "{@type=korap:sequence, operands=[" + |
| 268 | "{@type=korap:element, @value=np}," + |
| 269 | "{@type=korap:element, @value=vp}" + |
| 270 | "]}"; |
| 271 | assertTrue(equalsQueryContent(seq1, "<np><vp>")); |
| 272 | |
| 273 | // <np><vp><pp> |
| 274 | String seq2 = "{@type=korap:sequence, operands=[" + |
| 275 | "{@type=korap:element, @value=np}," + |
| 276 | "{@type=korap:element, @value=vp}," + |
| 277 | "{@type=korap:element, @value=pp}" + |
| 278 | "]}"; |
| 279 | assertTrue(equalsQueryContent(seq2, "<np><vp><pp>")); |
| 280 | } |
| 281 | |
| 282 | @Test |
| 283 | public void testClasses() { |
| 284 | // {[base=Mann]} |
| 285 | String cls1 = "{@type=korap:group, class=0, operands=[" + |
| 286 | "{@type=korap:token, @value={@type=korap:term, @value=base:Mann, relation==}}" + |
| 287 | "]}"; |
| 288 | assertTrue(equalsQueryContent(cls1, "{[base=Mann]}")); |
| 289 | |
| 290 | // {[base=Mann][orth=Frau]} |
| 291 | String cls2 = "{@type=korap:group, class=0, operands=[" + |
| 292 | "{@type=korap:sequence, operands=[" + |
| 293 | "{@type=korap:token, @value={@type=korap:term, @value=base:Mann, relation==}}," + |
| 294 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Frau, relation==}}" + |
| 295 | "]}" + |
| 296 | "]}"; |
| 297 | assertTrue(equalsQueryContent(cls2, "{[base=Mann][orth=Frau]}")); |
| 298 | |
| 299 | // [p=NN]{[base=Mann][orth=Frau]} |
| 300 | String cls3 = "{@type=korap:sequence, operands=[" + |
| 301 | "{@type=korap:token, @value={@type=korap:term, @value=p:NN, relation==}}," + |
| 302 | "{@type=korap:group, class=0, operands=[" + |
| 303 | "{@type=korap:sequence, operands=[" + |
| 304 | "{@type=korap:token, @value={@type=korap:term, @value=base:Mann, relation==}}," + |
| 305 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Frau, relation==}}" + |
| 306 | "]}" + |
| 307 | "]}" + |
| 308 | "]}"; |
| 309 | assertTrue(equalsQueryContent(cls3, "[p=NN]{[base=Mann][orth=Frau]}")); |
| 310 | |
| 311 | // {[base=Mann][orth=Frau]}[p=NN] |
| 312 | String cls4 = "{@type=korap:sequence, operands=[" + |
| 313 | "{@type=korap:group, class=0, operands=[" + |
| 314 | "{@type=korap:sequence, operands=[" + |
| 315 | "{@type=korap:token, @value={@type=korap:term, @value=base:Mann, relation==}}," + |
| 316 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Frau, relation==}}" + |
| 317 | "]}" + |
| 318 | "]}," + |
| 319 | "{@type=korap:token, @value={@type=korap:term, @value=p:NN, relation==}}" + |
| 320 | "]}"; |
| 321 | assertTrue(equalsQueryContent(cls4, "{[base=Mann][orth=Frau]}[p=NN]")); |
Joachim Bingel | cd9ed33 | 2013-12-09 21:01:35 +0000 | [diff] [blame] | 322 | |
| 323 | // {2:{1:[tt/p=ADJA]}[mate/p=NN]}" |
| 324 | String cls5 = "{@type=korap:group, class=2, operands=[" + |
| 325 | "{@type=korap:sequence, operands=[" + |
| 326 | "{@type=korap:group, class=1, operands=[" + |
| 327 | "{@type=korap:token, @value={@type=korap:term, @value=tt/p:ADJA, relation==}}" + |
| 328 | "]}," + |
| 329 | "{@type=korap:token, @value={@type=korap:term, @value=mate/p:NN, relation==}}" + |
| 330 | "]}" + |
| 331 | "]}"; |
| 332 | ppt = new PoliqarpPlusTree("{2: {1:[tt/p=ADJA]}[mate/p=NN]}"); |
| 333 | map = ppt.getRequestMap().get("query").toString(); |
| 334 | assertEquals(cls5.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | @Test |
| 338 | public void testPositions() { |
| 339 | // contains(<s>,<np>) |
| 340 | String pos1 = "{@type=korap:group, relation=position, position=contains, operands=[" + |
| 341 | "{@type=korap:element, @value=s}," + |
| 342 | "{@type=korap:element, @value=np}" + |
| 343 | "]}"; |
| 344 | assertTrue(equalsQueryContent(pos1, "contains(<s>,<np>)")); |
| 345 | |
| 346 | // contains(<s>,[base=Mann]) |
| 347 | String pos2 = "{@type=korap:group, relation=position, position=contains, operands=[" + |
| 348 | "{@type=korap:element, @value=s}," + |
| 349 | "{@type=korap:token, @value= {@type=korap:term, @value=base:Mann, relation==}}" + |
| 350 | "]}"; |
| 351 | assertTrue(equalsQueryContent(pos2, "contains(<s>,[base=Mann])")); |
| 352 | |
| 353 | // contains(<s>,[orth=der][orth=Mann]) |
| 354 | String pos3 = "{@type=korap:group, relation=position, position=contains, operands=[" + |
| 355 | "{@type=korap:element, @value=s}," + |
| 356 | "{@type=korap:sequence, operands=[" + |
| 357 | "{@type=korap:token, @value={@type=korap:term, @value=orth:der, relation==}}," + |
| 358 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Mann, relation==}}" + |
| 359 | "]}" + |
| 360 | "]}"; |
| 361 | ppt = new PoliqarpPlusTree("contains(<s>,[orth=der][orth=Mann])"); |
| 362 | map = ppt.getRequestMap().get("query").toString(); |
| 363 | assertEquals(pos3.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 364 | |
| 365 | // [base=Auto]contains(<s>,[base=Mann]) |
| 366 | String pos4 = |
| 367 | "{@type=korap:sequence, operands=[" + |
| 368 | "{@type=korap:token, @value={@type=korap:term, @value=base:Auto, relation==}}," + |
| 369 | "{@type=korap:group, relation=position, position=contains, operands=[" + |
| 370 | "{@type=korap:element, @value=s}," + |
| 371 | "{@type=korap:token, @value={@type=korap:term, @value=base:Mann, relation==}}" + |
| 372 | "]}" + |
| 373 | "]}"; |
| 374 | ppt = new PoliqarpPlusTree("[base=Auto]contains(<s>,[base=Mann])"); |
| 375 | map = ppt.getRequestMap().get("query").toString(); |
| 376 | assertEquals(pos4.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 377 | } |
| 378 | |
| 379 | @Test |
| 380 | public void testNestedPositions() { |
| 381 | // contains(<s>,startswith(<np>,[orth=Der])) |
| 382 | String npos1 = |
| 383 | "{@type=korap:group, relation=position, position=contains, operands=[" + |
| 384 | "{@type=korap:element, @value=s}," + |
| 385 | "{@type=korap:group, relation=position, position=startswith, operands=[" + |
| 386 | "{@type=korap:element, @value=np}," + |
| 387 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Der, relation==}}" + |
| 388 | "]}" + |
| 389 | "]}"; |
Joachim Bingel | cd9ed33 | 2013-12-09 21:01:35 +0000 | [diff] [blame] | 390 | ppt = new PoliqarpPlusTree("contains(<s>, startswith(<np>,[orth=Der]))"); |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 391 | map = ppt.getRequestMap().get("query").toString(); |
| 392 | assertEquals(npos1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 393 | } |
| 394 | |
| 395 | @Test |
| 396 | public void testShrinkSplit() { |
| 397 | // shrink([orth=Der]{[orth=Mann]}) |
| 398 | String shr1 = |
| 399 | "{@type=korap:group, relation=shrink, shrink=0, operands=[" + |
| 400 | "{@type=korap:sequence, operands=[" + |
| 401 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Der, relation==}}," + |
| 402 | "{@type=korap:group, class=0, operands=[" + |
| 403 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Mann, relation==}}" + |
| 404 | "]}" + |
| 405 | "]}" + |
| 406 | "]}"; |
| 407 | ppt = new PoliqarpPlusTree("shrink([orth=Der]{[orth=Mann]})"); |
| 408 | map = ppt.getRequestMap().get("query").toString(); |
| 409 | assertEquals(shr1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 410 | |
| 411 | // shrink([orth=Der]{[orth=Mann][orth=geht]}) |
| 412 | String shr2 = |
| 413 | "{@type=korap:group, relation=shrink, shrink=0, operands=[" + |
| 414 | "{@type=korap:sequence, operands=[" + |
| 415 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Der, relation==}}," + |
| 416 | "{@type=korap:group, class=0, operands=[" + |
| 417 | "{@type=korap:sequence, operands=[" + |
| 418 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Mann, relation==}}," + |
| 419 | "{@type=korap:token, @value={@type=korap:term, @value=orth:geht, relation==}}" + |
| 420 | "]}" + |
| 421 | "]}" + |
| 422 | "]}" + |
| 423 | "]}"; |
| 424 | ppt = new PoliqarpPlusTree("shrink([orth=Der]{[orth=Mann][orth=geht]})"); |
| 425 | map = ppt.getRequestMap().get("query").toString(); |
| 426 | assertEquals(shr2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 427 | |
| 428 | // shrink(1:[orth=Der]{1:[orth=Mann][orth=geht]}) |
| 429 | String shr3 = |
| 430 | "{@type=korap:group, relation=shrink, shrink=1, operands=[" + |
| 431 | "{@type=korap:sequence, operands=[" + |
| 432 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Der, relation==}}," + |
| 433 | "{@type=korap:group, class=1, operands=[" + |
| 434 | "{@type=korap:sequence, operands=[" + |
| 435 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Mann, relation==}}," + |
| 436 | "{@type=korap:token, @value={@type=korap:term, @value=orth:geht, relation==}}" + |
| 437 | "]}" + |
| 438 | "]}" + |
| 439 | "]}" + |
| 440 | "]}"; |
| 441 | ppt = new PoliqarpPlusTree("shrink(1:[orth=Der]{1:[orth=Mann][orth=geht]})"); |
| 442 | map = ppt.getRequestMap().get("query").toString(); |
| 443 | assertEquals(shr3.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 444 | |
| 445 | // shrink(1:startswith(<s>,{1:<np>})) |
| 446 | String shr4 = |
| 447 | "{@type=korap:group, relation=shrink, shrink=1, operands=[" + |
| 448 | "{@type=korap:group, relation=position, position=startswith, operands=[" + |
| 449 | "{@type=korap:element, @value=s}," + |
| 450 | "{@type=korap:group, class=1, operands=[" + |
| 451 | "{@type=korap:element, @value=np}" + |
| 452 | "]}" + |
| 453 | "]}" + |
| 454 | "]}"; |
Joachim Bingel | adefa62 | 2013-12-13 10:51:48 +0000 | [diff] [blame^] | 455 | ppt = new PoliqarpPlusTree("shrink(1:startswith(<s>,{1:<np>}))"); |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 456 | map = ppt.getRequestMap().get("query").toString(); |
| 457 | assertEquals(shr4.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | cd9ed33 | 2013-12-09 21:01:35 +0000 | [diff] [blame] | 458 | |
| 459 | // shrink(3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) |
| 460 | String shr5 = |
| 461 | "{@type=korap:group, relation=shrink, shrink=3, operands=[" + |
| 462 | "{@type=korap:group, relation=position, position=startswith, operands=[" + |
| 463 | "{@type=korap:element, @value=s}," + |
| 464 | "{@type=korap:group, class=3, operands=[" + |
| 465 | "{@type=korap:sequence, operands=[" + |
| 466 | "{@type=korap:token, @value={@type=korap:term, @value=base:der, relation==}}," + |
| 467 | "{@type=korap:group, class=1, operands=[" + |
| 468 | "{@type=korap:sequence, operands=[" + |
| 469 | "{@type=korap:token, @value={@type=korap:term, @value=mate/p:ADJA, relation==}}," + |
| 470 | "{@type=korap:group, class=2, operands=[" + |
| 471 | "{@type=korap:token, @value={@type=korap:term, @value=tt/p:NN, relation==}}" + |
| 472 | "]}" + |
| 473 | "]}" + |
| 474 | "]}" + |
| 475 | "]}" + |
| 476 | "]}" + |
| 477 | "]}" + |
| 478 | "]}"; |
Joachim Bingel | adefa62 | 2013-12-13 10:51:48 +0000 | [diff] [blame^] | 479 | ppt = new PoliqarpPlusTree("shrink(3:startswith(<s>,{3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) "); |
Joachim Bingel | cd9ed33 | 2013-12-09 21:01:35 +0000 | [diff] [blame] | 480 | map = ppt.getRequestMap().get("query").toString(); |
| 481 | assertEquals(shr5.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | @Test |
| 485 | public void testLayers() { |
Joachim Bingel | cd9ed33 | 2013-12-09 21:01:35 +0000 | [diff] [blame] | 486 | // [base=Mann] |
| 487 | String layer1 = "{@type=korap:token, @value={@type=korap:term, @value=tt/base:Mann, relation==}}"; |
| 488 | assertTrue(equalsQueryContent(layer1, "[tt/base=Mann]")); |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 489 | |
| 490 | } |
| 491 | } |
| 492 | |