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