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])* |
| 142 | // comment: embedded sequence shouldn't really be here, but does not really hurt, either. (?) |
| 143 | // really hard to get this behaviour out of the PQPlus grammar... |
| 144 | String occ6 = |
| 145 | "{@type=korap:sequence, operands=[" + |
| 146 | "{@type=korap:sequence, operands=[" + |
| 147 | "{@type=korap:element, @value=s}," + |
| 148 | "{@type=korap:element, @value=np}" + |
| 149 | "]}," + |
| 150 | "{@type=korap:group, operands=[" + |
| 151 | "{@type=korap:sequence, operands=[" + |
| 152 | "{@type=korap:token, @value={@type=korap:term, @value=base:bar, relation==}}," + |
| 153 | "{@type=korap:token, @value={@type=korap:term, @value=base:foo, relation==}}" + |
| 154 | "]}" + |
| 155 | "], relation=repetition, quantifier=* }" + |
| 156 | "]}" ; |
| 157 | ppt = new PoliqarpPlusTree("<s><np>([base=bar][base=foo])*"); |
| 158 | map = ppt.getRequestMap().get("query").toString(); |
| 159 | assertEquals(occ6.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 160 | |
| 161 | // <s><np>([base=bar][base=foo])*[p=NN] |
| 162 | // comment: embedded sequence shouldn't really be here, but does not really hurt, either. (?) |
| 163 | // really hard to get this behaviour out of the PQPlus grammar... |
| 164 | String occ7 = |
| 165 | "{@type=korap:sequence, operands=[" + |
| 166 | "{@type=korap:sequence, operands=[" + |
| 167 | "{@type=korap:element, @value=s}," + |
| 168 | "{@type=korap:element, @value=np}" + |
| 169 | "]}," + |
| 170 | "{@type=korap:group, operands=[" + |
| 171 | "{@type=korap:sequence, operands=[" + |
| 172 | "{@type=korap:token, @value={@type=korap:term, @value=base:bar, relation==}}," + |
| 173 | "{@type=korap:token, @value={@type=korap:term, @value=base:foo, relation==}}" + |
| 174 | "]}" + |
| 175 | "], relation=repetition, quantifier=* }," + |
| 176 | "{@type=korap:token, @value={@type=korap:term, @value=p:NN, relation==}}" + |
| 177 | "]}" ; |
| 178 | ppt = new PoliqarpPlusTree("<s><np>([base=bar][base=foo])*[p=NN]"); |
| 179 | map = ppt.getRequestMap().get("query").toString(); |
| 180 | assertEquals(occ7.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 181 | |
| 182 | // ([base=bar][base=foo])*[p=NN] |
| 183 | // comment: embedded sequence shouldn't really be here, but does not really hurt, either. (?) |
| 184 | // really hard to get this behaviour out of the PQPlus grammar... |
| 185 | String occ8 = |
| 186 | "{@type=korap:sequence, operands=[" + |
| 187 | "{@type=korap:group, operands=[" + |
| 188 | "{@type=korap:sequence, operands=[" + |
| 189 | "{@type=korap:token, @value={@type=korap:term, @value=base:bar, relation==}}," + |
| 190 | "{@type=korap:token, @value={@type=korap:term, @value=base:foo, relation==}}" + |
| 191 | "]}" + |
| 192 | "], relation=repetition, quantifier=* }," + |
| 193 | "{@type=korap:token, @value={@type=korap:term, @value=p:NN, relation==}}" + |
| 194 | "]}" ; |
| 195 | ppt = new PoliqarpPlusTree("([base=bar][base=foo])*[p=NN]"); |
| 196 | map = ppt.getRequestMap().get("query").toString(); |
| 197 | assertEquals(occ8.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | @Test |
| 201 | public void testTokenSequence() { |
| 202 | // [base=Mann][orth=Frau] |
| 203 | String seq1 = "{@type=korap:sequence, operands=[" + |
| 204 | "{@type=korap:token, @value={@type=korap:term, @value=base:Mann, relation==}}, " + |
| 205 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Frau, relation==}}" + |
| 206 | "]}"; |
| 207 | assertTrue(equalsQueryContent(seq1, "[base=Mann][orth=Frau]")); |
| 208 | |
| 209 | // [base=Mann][orth=Frau][p=NN] |
| 210 | String seq2 = "{@type=korap:sequence, operands=[" + |
| 211 | "{@type=korap:token, @value={@type=korap:term, @value=base:Mann, relation==}}, " + |
| 212 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Frau, relation==}}, " + |
| 213 | "{@type=korap:token, @value={@type=korap:term, @value=p:NN, relation==}}" + |
| 214 | "]}"; |
| 215 | assertTrue(equalsQueryContent(seq2, "[base=Mann][orth=Frau][p=NN]")); |
| 216 | } |
| 217 | |
| 218 | @Test |
| 219 | public void testTokenElemSequence() { |
| 220 | // [base=Mann]<vp> |
| 221 | String seq1 = "{@type=korap:sequence, operands=[" + |
| 222 | "{@type=korap:token, @value={@type=korap:term, @value=base:Mann, relation==}}, " + |
| 223 | "{@type=korap:element, @value=vp}" + |
| 224 | "]}"; |
| 225 | assertTrue(equalsQueryContent(seq1, "[base=Mann]<vp>")); |
| 226 | |
| 227 | // <vp>[base=Mann] |
| 228 | String seq2 = "{@type=korap:sequence, operands=[" + |
| 229 | "{@type=korap:element, @value=vp}, "+ |
| 230 | "{@type=korap:token, @value={@type=korap:term, @value=base:Mann, relation==}} " + |
| 231 | "]}"; |
| 232 | assertTrue(equalsQueryContent(seq2, "<vp>[base=Mann]")); |
| 233 | |
| 234 | // <vp>[base=Mann]<pp> |
| 235 | String seq3 = "{@type=korap:sequence, operands=[" + |
| 236 | "{@type=korap:element, @value=vp}, "+ |
| 237 | "{@type=korap:token, @value={@type=korap:term, @value=base:Mann, relation==}}, " + |
| 238 | "{@type=korap:element, @value=pp} "+ |
| 239 | "]}"; |
| 240 | assertTrue(equalsQueryContent(seq3, "<vp>[base=Mann]<pp>")); |
| 241 | } |
| 242 | |
| 243 | @Test |
| 244 | public void testElemSequence() { |
| 245 | // <np><vp> |
| 246 | String seq1 = "{@type=korap:sequence, operands=[" + |
| 247 | "{@type=korap:element, @value=np}," + |
| 248 | "{@type=korap:element, @value=vp}" + |
| 249 | "]}"; |
| 250 | assertTrue(equalsQueryContent(seq1, "<np><vp>")); |
| 251 | |
| 252 | // <np><vp><pp> |
| 253 | String seq2 = "{@type=korap:sequence, operands=[" + |
| 254 | "{@type=korap:element, @value=np}," + |
| 255 | "{@type=korap:element, @value=vp}," + |
| 256 | "{@type=korap:element, @value=pp}" + |
| 257 | "]}"; |
| 258 | assertTrue(equalsQueryContent(seq2, "<np><vp><pp>")); |
| 259 | } |
| 260 | |
| 261 | @Test |
| 262 | public void testClasses() { |
| 263 | // {[base=Mann]} |
| 264 | String cls1 = "{@type=korap:group, class=0, operands=[" + |
| 265 | "{@type=korap:token, @value={@type=korap:term, @value=base:Mann, relation==}}" + |
| 266 | "]}"; |
| 267 | assertTrue(equalsQueryContent(cls1, "{[base=Mann]}")); |
| 268 | |
| 269 | // {[base=Mann][orth=Frau]} |
| 270 | String cls2 = "{@type=korap:group, class=0, operands=[" + |
| 271 | "{@type=korap:sequence, operands=[" + |
| 272 | "{@type=korap:token, @value={@type=korap:term, @value=base:Mann, relation==}}," + |
| 273 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Frau, relation==}}" + |
| 274 | "]}" + |
| 275 | "]}"; |
| 276 | assertTrue(equalsQueryContent(cls2, "{[base=Mann][orth=Frau]}")); |
| 277 | |
| 278 | // [p=NN]{[base=Mann][orth=Frau]} |
| 279 | String cls3 = "{@type=korap:sequence, operands=[" + |
| 280 | "{@type=korap:token, @value={@type=korap:term, @value=p:NN, relation==}}," + |
| 281 | "{@type=korap:group, class=0, operands=[" + |
| 282 | "{@type=korap:sequence, operands=[" + |
| 283 | "{@type=korap:token, @value={@type=korap:term, @value=base:Mann, relation==}}," + |
| 284 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Frau, relation==}}" + |
| 285 | "]}" + |
| 286 | "]}" + |
| 287 | "]}"; |
| 288 | assertTrue(equalsQueryContent(cls3, "[p=NN]{[base=Mann][orth=Frau]}")); |
| 289 | |
| 290 | // {[base=Mann][orth=Frau]}[p=NN] |
| 291 | String cls4 = "{@type=korap:sequence, operands=[" + |
| 292 | "{@type=korap:group, class=0, operands=[" + |
| 293 | "{@type=korap:sequence, operands=[" + |
| 294 | "{@type=korap:token, @value={@type=korap:term, @value=base:Mann, relation==}}," + |
| 295 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Frau, relation==}}" + |
| 296 | "]}" + |
| 297 | "]}," + |
| 298 | "{@type=korap:token, @value={@type=korap:term, @value=p:NN, relation==}}" + |
| 299 | "]}"; |
| 300 | assertTrue(equalsQueryContent(cls4, "{[base=Mann][orth=Frau]}[p=NN]")); |
Joachim Bingel | cd9ed33 | 2013-12-09 21:01:35 +0000 | [diff] [blame] | 301 | |
| 302 | // {2:{1:[tt/p=ADJA]}[mate/p=NN]}" |
| 303 | String cls5 = "{@type=korap:group, class=2, operands=[" + |
| 304 | "{@type=korap:sequence, operands=[" + |
| 305 | "{@type=korap:group, class=1, operands=[" + |
| 306 | "{@type=korap:token, @value={@type=korap:term, @value=tt/p:ADJA, relation==}}" + |
| 307 | "]}," + |
| 308 | "{@type=korap:token, @value={@type=korap:term, @value=mate/p:NN, relation==}}" + |
| 309 | "]}" + |
| 310 | "]}"; |
| 311 | ppt = new PoliqarpPlusTree("{2: {1:[tt/p=ADJA]}[mate/p=NN]}"); |
| 312 | map = ppt.getRequestMap().get("query").toString(); |
| 313 | assertEquals(cls5.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 314 | } |
| 315 | |
| 316 | @Test |
| 317 | public void testPositions() { |
| 318 | // contains(<s>,<np>) |
| 319 | String pos1 = "{@type=korap:group, relation=position, position=contains, operands=[" + |
| 320 | "{@type=korap:element, @value=s}," + |
| 321 | "{@type=korap:element, @value=np}" + |
| 322 | "]}"; |
| 323 | assertTrue(equalsQueryContent(pos1, "contains(<s>,<np>)")); |
| 324 | |
| 325 | // contains(<s>,[base=Mann]) |
| 326 | String pos2 = "{@type=korap:group, relation=position, position=contains, operands=[" + |
| 327 | "{@type=korap:element, @value=s}," + |
| 328 | "{@type=korap:token, @value= {@type=korap:term, @value=base:Mann, relation==}}" + |
| 329 | "]}"; |
| 330 | assertTrue(equalsQueryContent(pos2, "contains(<s>,[base=Mann])")); |
| 331 | |
| 332 | // contains(<s>,[orth=der][orth=Mann]) |
| 333 | String pos3 = "{@type=korap:group, relation=position, position=contains, operands=[" + |
| 334 | "{@type=korap:element, @value=s}," + |
| 335 | "{@type=korap:sequence, operands=[" + |
| 336 | "{@type=korap:token, @value={@type=korap:term, @value=orth:der, relation==}}," + |
| 337 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Mann, relation==}}" + |
| 338 | "]}" + |
| 339 | "]}"; |
| 340 | ppt = new PoliqarpPlusTree("contains(<s>,[orth=der][orth=Mann])"); |
| 341 | map = ppt.getRequestMap().get("query").toString(); |
| 342 | assertEquals(pos3.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 343 | |
| 344 | // [base=Auto]contains(<s>,[base=Mann]) |
| 345 | String pos4 = |
| 346 | "{@type=korap:sequence, operands=[" + |
| 347 | "{@type=korap:token, @value={@type=korap:term, @value=base:Auto, relation==}}," + |
| 348 | "{@type=korap:group, relation=position, position=contains, operands=[" + |
| 349 | "{@type=korap:element, @value=s}," + |
| 350 | "{@type=korap:token, @value={@type=korap:term, @value=base:Mann, relation==}}" + |
| 351 | "]}" + |
| 352 | "]}"; |
| 353 | ppt = new PoliqarpPlusTree("[base=Auto]contains(<s>,[base=Mann])"); |
| 354 | map = ppt.getRequestMap().get("query").toString(); |
| 355 | assertEquals(pos4.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 356 | } |
| 357 | |
| 358 | @Test |
| 359 | public void testNestedPositions() { |
| 360 | // contains(<s>,startswith(<np>,[orth=Der])) |
| 361 | String npos1 = |
| 362 | "{@type=korap:group, relation=position, position=contains, operands=[" + |
| 363 | "{@type=korap:element, @value=s}," + |
| 364 | "{@type=korap:group, relation=position, position=startswith, operands=[" + |
| 365 | "{@type=korap:element, @value=np}," + |
| 366 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Der, relation==}}" + |
| 367 | "]}" + |
| 368 | "]}"; |
Joachim Bingel | cd9ed33 | 2013-12-09 21:01:35 +0000 | [diff] [blame] | 369 | ppt = new PoliqarpPlusTree("contains(<s>, startswith(<np>,[orth=Der]))"); |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 370 | map = ppt.getRequestMap().get("query").toString(); |
| 371 | assertEquals(npos1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 372 | } |
| 373 | |
| 374 | @Test |
| 375 | public void testShrinkSplit() { |
| 376 | // shrink([orth=Der]{[orth=Mann]}) |
| 377 | String shr1 = |
| 378 | "{@type=korap:group, relation=shrink, shrink=0, operands=[" + |
| 379 | "{@type=korap:sequence, operands=[" + |
| 380 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Der, relation==}}," + |
| 381 | "{@type=korap:group, class=0, operands=[" + |
| 382 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Mann, relation==}}" + |
| 383 | "]}" + |
| 384 | "]}" + |
| 385 | "]}"; |
| 386 | ppt = new PoliqarpPlusTree("shrink([orth=Der]{[orth=Mann]})"); |
| 387 | map = ppt.getRequestMap().get("query").toString(); |
| 388 | assertEquals(shr1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 389 | |
| 390 | // shrink([orth=Der]{[orth=Mann][orth=geht]}) |
| 391 | String shr2 = |
| 392 | "{@type=korap:group, relation=shrink, shrink=0, operands=[" + |
| 393 | "{@type=korap:sequence, operands=[" + |
| 394 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Der, relation==}}," + |
| 395 | "{@type=korap:group, class=0, operands=[" + |
| 396 | "{@type=korap:sequence, operands=[" + |
| 397 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Mann, relation==}}," + |
| 398 | "{@type=korap:token, @value={@type=korap:term, @value=orth:geht, relation==}}" + |
| 399 | "]}" + |
| 400 | "]}" + |
| 401 | "]}" + |
| 402 | "]}"; |
| 403 | ppt = new PoliqarpPlusTree("shrink([orth=Der]{[orth=Mann][orth=geht]})"); |
| 404 | map = ppt.getRequestMap().get("query").toString(); |
| 405 | assertEquals(shr2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 406 | |
| 407 | // shrink(1:[orth=Der]{1:[orth=Mann][orth=geht]}) |
| 408 | String shr3 = |
| 409 | "{@type=korap:group, relation=shrink, shrink=1, operands=[" + |
| 410 | "{@type=korap:sequence, operands=[" + |
| 411 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Der, relation==}}," + |
| 412 | "{@type=korap:group, class=1, operands=[" + |
| 413 | "{@type=korap:sequence, operands=[" + |
| 414 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Mann, relation==}}," + |
| 415 | "{@type=korap:token, @value={@type=korap:term, @value=orth:geht, relation==}}" + |
| 416 | "]}" + |
| 417 | "]}" + |
| 418 | "]}" + |
| 419 | "]}"; |
| 420 | ppt = new PoliqarpPlusTree("shrink(1:[orth=Der]{1:[orth=Mann][orth=geht]})"); |
| 421 | map = ppt.getRequestMap().get("query").toString(); |
| 422 | assertEquals(shr3.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 423 | |
| 424 | // shrink(1:startswith(<s>,{1:<np>})) |
| 425 | String shr4 = |
| 426 | "{@type=korap:group, relation=shrink, shrink=1, operands=[" + |
| 427 | "{@type=korap:group, relation=position, position=startswith, operands=[" + |
| 428 | "{@type=korap:element, @value=s}," + |
| 429 | "{@type=korap:group, class=1, operands=[" + |
| 430 | "{@type=korap:element, @value=np}" + |
| 431 | "]}" + |
| 432 | "]}" + |
| 433 | "]}"; |
Joachim Bingel | cd9ed33 | 2013-12-09 21:01:35 +0000 | [diff] [blame] | 434 | ppt = new PoliqarpPlusTree("shrink(1: startswith(<s>,{1:<np>}))"); |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 435 | map = ppt.getRequestMap().get("query").toString(); |
| 436 | assertEquals(shr4.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | cd9ed33 | 2013-12-09 21:01:35 +0000 | [diff] [blame] | 437 | |
| 438 | // shrink(3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) |
| 439 | String shr5 = |
| 440 | "{@type=korap:group, relation=shrink, shrink=3, operands=[" + |
| 441 | "{@type=korap:group, relation=position, position=startswith, operands=[" + |
| 442 | "{@type=korap:element, @value=s}," + |
| 443 | "{@type=korap:group, class=3, operands=[" + |
| 444 | "{@type=korap:sequence, operands=[" + |
| 445 | "{@type=korap:token, @value={@type=korap:term, @value=base:der, relation==}}," + |
| 446 | "{@type=korap:group, class=1, operands=[" + |
| 447 | "{@type=korap:sequence, operands=[" + |
| 448 | "{@type=korap:token, @value={@type=korap:term, @value=mate/p:ADJA, relation==}}," + |
| 449 | "{@type=korap:group, class=2, operands=[" + |
| 450 | "{@type=korap:token, @value={@type=korap:term, @value=tt/p:NN, relation==}}" + |
| 451 | "]}" + |
| 452 | "]}" + |
| 453 | "]}" + |
| 454 | "]}" + |
| 455 | "]}" + |
| 456 | "]}" + |
| 457 | "]}"; |
| 458 | ppt = new PoliqarpPlusTree("shrink(3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) "); |
| 459 | map = ppt.getRequestMap().get("query").toString(); |
| 460 | assertEquals(shr5.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | @Test |
| 464 | public void testLayers() { |
Joachim Bingel | cd9ed33 | 2013-12-09 21:01:35 +0000 | [diff] [blame] | 465 | // [base=Mann] |
| 466 | String layer1 = "{@type=korap:token, @value={@type=korap:term, @value=tt/base:Mann, relation==}}"; |
| 467 | assertTrue(equalsQueryContent(layer1, "[tt/base=Mann]")); |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 468 | |
| 469 | } |
| 470 | } |
| 471 | |