Joachim Bingel | b5f7bf0 | 2014-01-07 16:36:54 +0000 | [diff] [blame] | 1 | import static org.junit.Assert.*; |
| 2 | |
| 3 | import org.junit.Test; |
| 4 | |
| 5 | import de.ids_mannheim.korap.query.serialize.CosmasTree; |
Joachim Bingel | b5f7bf0 | 2014-01-07 16:36:54 +0000 | [diff] [blame] | 6 | import de.ids_mannheim.korap.util.QueryException; |
| 7 | |
| 8 | public class CosmasTreeTest { |
| 9 | |
| 10 | CosmasTree ppt; |
| 11 | String map; |
| 12 | String query; |
| 13 | |
| 14 | private boolean equalsContent(String str, Object map) { |
| 15 | str = str.replaceAll(" ", ""); |
| 16 | String mapStr = map.toString().replaceAll(" ", ""); |
| 17 | return str.equals(mapStr); |
| 18 | } |
| 19 | |
| 20 | private boolean equalsQueryContent(String res, String query) throws QueryException { |
| 21 | res = res.replaceAll(" ", ""); |
| 22 | ppt = new CosmasTree(query); |
| 23 | String queryMap = ppt.getRequestMap().get("query").toString().replaceAll(" ", ""); |
| 24 | return res.equals(queryMap); |
| 25 | } |
| 26 | |
| 27 | @Test |
| 28 | public void testContext() throws QueryException { |
| 29 | 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}"; |
| 30 | ppt = new CosmasTree("Test"); |
| 31 | assertTrue(equalsContent(contextString, ppt.getRequestMap().get("@context"))); |
| 32 | } |
| 33 | |
| 34 | |
| 35 | @Test |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame^] | 36 | public void testSingleToken() throws QueryException { |
Joachim Bingel | b5f7bf0 | 2014-01-07 16:36:54 +0000 | [diff] [blame] | 37 | query="der"; |
| 38 | String single1 = |
| 39 | "{@type=korap:token, @value={@type=korap:term, @value=orth:der, relation==}}"; |
| 40 | ppt = new CosmasTree(query); |
| 41 | map = ppt.getRequestMap().get("query").toString(); |
| 42 | assertEquals(single1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 43 | |
| 44 | query="Mann"; |
| 45 | String single2 = |
| 46 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Mann, relation==}}"; |
| 47 | ppt = new CosmasTree(query); |
| 48 | map = ppt.getRequestMap().get("query").toString(); |
| 49 | assertEquals(single2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 50 | |
| 51 | query="&Mann"; |
| 52 | String single3 = |
| 53 | "{@type=korap:token, @value={@type=korap:term, @value=base:Mann, relation==}}"; |
| 54 | ppt = new CosmasTree(query); |
| 55 | map = ppt.getRequestMap().get("query").toString(); |
| 56 | assertEquals(single3.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 57 | } |
| 58 | |
| 59 | @Test |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame^] | 60 | public void testSequence() throws QueryException { |
Joachim Bingel | b5f7bf0 | 2014-01-07 16:36:54 +0000 | [diff] [blame] | 61 | query="der Mann"; |
| 62 | String seq1 = |
| 63 | "{@type=korap:sequence, operands=[" + |
| 64 | "{@type=korap:token, @value={@type=korap:term, @value=orth:der, relation==}}," + |
| 65 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Mann, relation==}}" + |
| 66 | "]}"; |
| 67 | ppt = new CosmasTree(query); |
| 68 | map = ppt.getRequestMap().get("query").toString(); |
| 69 | assertEquals(seq1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 70 | |
Joachim Bingel | d5161a1 | 2014-01-08 11:15:49 +0000 | [diff] [blame] | 71 | query="der Mann schläft"; |
| 72 | String seq2 = |
| 73 | "{@type=korap:sequence, operands=[" + |
| 74 | "{@type=korap:token, @value={@type=korap:term, @value=orth:der, relation==}}," + |
| 75 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Mann, relation==}}," + |
| 76 | "{@type=korap:token, @value={@type=korap:term, @value=orth:schläft, relation==}}" + |
| 77 | "]}"; |
| 78 | ppt = new CosmasTree(query); |
| 79 | map = ppt.getRequestMap().get("query").toString(); |
| 80 | assertEquals(seq2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 81 | |
| 82 | query="der Mann schläft lang"; |
| 83 | String seq3 = |
| 84 | "{@type=korap:sequence, operands=[" + |
| 85 | "{@type=korap:token, @value={@type=korap:term, @value=orth:der, relation==}}," + |
| 86 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Mann, relation==}}," + |
| 87 | "{@type=korap:token, @value={@type=korap:term, @value=orth:schläft, relation==}}," + |
| 88 | "{@type=korap:token, @value={@type=korap:term, @value=orth:lang, relation==}}" + |
| 89 | "]}"; |
| 90 | ppt = new CosmasTree(query); |
| 91 | map = ppt.getRequestMap().get("query").toString(); |
| 92 | assertEquals(seq3.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | b5f7bf0 | 2014-01-07 16:36:54 +0000 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | @Test |
| 96 | public void testOPOR() throws QueryException { |
| 97 | query="Sonne oder Mond"; |
| 98 | String disj1 = |
| 99 | "{@type=korap:group, relation=or, operands=[" + |
| 100 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Sonne, relation==}}," + |
| 101 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Mond, relation==}}" + |
| 102 | "]}"; |
| 103 | ppt = new CosmasTree(query); |
| 104 | map = ppt.getRequestMap().get("query").toString(); |
| 105 | assertEquals(disj1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 106 | |
Joachim Bingel | d5161a1 | 2014-01-08 11:15:49 +0000 | [diff] [blame] | 107 | query="(Sonne scheint) oder Mond"; |
| 108 | String disj2 = |
| 109 | "{@type=korap:group, relation=or, operands=[" + |
| 110 | "{@type=korap:sequence, operands=[" + |
| 111 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Sonne, relation==}}," + |
| 112 | "{@type=korap:token, @value={@type=korap:term, @value=orth:scheint, relation==}}" + |
| 113 | "]}," + |
| 114 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Mond, relation==}}" + |
| 115 | "]}"; |
| 116 | ppt = new CosmasTree(query); |
| 117 | map = ppt.getRequestMap().get("query").toString(); |
| 118 | assertEquals(disj2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 119 | |
| 120 | query="(Sonne scheint) oder (Mond scheint)"; |
| 121 | String disj3 = |
| 122 | "{@type=korap:group, relation=or, operands=[" + |
| 123 | "{@type=korap:sequence, operands=[" + |
| 124 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Sonne, relation==}}," + |
| 125 | "{@type=korap:token, @value={@type=korap:term, @value=orth:scheint, relation==}}" + |
| 126 | "]}," + |
| 127 | "{@type=korap:sequence, operands=[" + |
| 128 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Mond, relation==}}," + |
| 129 | "{@type=korap:token, @value={@type=korap:term, @value=orth:scheint, relation==}}" + |
| 130 | "]}" + |
| 131 | "]}"; |
| 132 | ppt = new CosmasTree(query); |
| 133 | map = ppt.getRequestMap().get("query").toString(); |
| 134 | assertEquals(disj3.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 135 | |
| 136 | } |
| 137 | |
| 138 | @Test |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame^] | 139 | public void testOPORAND() throws QueryException { |
Joachim Bingel | d5161a1 | 2014-01-08 11:15:49 +0000 | [diff] [blame] | 140 | query="(Sonne oder Mond) und scheint"; |
| 141 | String orand1 = |
| 142 | "{@type=korap:group, relation=and, operands=[" + |
| 143 | "{@type=korap:group, relation=or, operands=[" + |
| 144 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Sonne, relation==}}," + |
| 145 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Mond, relation==}}" + |
| 146 | "]}," + |
| 147 | "{@type=korap:token, @value={@type=korap:term, @value=orth:scheint, relation==}}" + |
| 148 | "]}"; |
| 149 | ppt = new CosmasTree(query); |
| 150 | map = ppt.getRequestMap().get("query").toString(); |
| 151 | assertEquals(orand1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 152 | |
| 153 | query="scheint und (Sonne oder Mond)"; |
| 154 | String orand2 = |
| 155 | "{@type=korap:group, relation=and, operands=[" + |
| 156 | "{@type=korap:token, @value={@type=korap:term, @value=orth:scheint, relation==}}," + |
| 157 | "{@type=korap:group, relation=or, operands=[" + |
| 158 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Sonne, relation==}}," + |
| 159 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Mond, relation==}}" + |
| 160 | "]}" + |
| 161 | "]}"; |
| 162 | ppt = new CosmasTree(query); |
| 163 | map = ppt.getRequestMap().get("query").toString(); |
| 164 | assertEquals(orand2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | b5f7bf0 | 2014-01-07 16:36:54 +0000 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | @Test |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame^] | 168 | public void testOPPROX() throws QueryException { |
Joachim Bingel | b5f7bf0 | 2014-01-07 16:36:54 +0000 | [diff] [blame] | 169 | query="Sonne /+w1:4 Mond"; |
| 170 | String prox1 = |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame^] | 171 | "{@type=korap:group, relation=distance, match=operands, @subtype=incl, " + |
Joachim Bingel | 89cceac | 2014-01-08 15:51:08 +0000 | [diff] [blame] | 172 | "constraint=[" + |
| 173 | "{@type=korap:distance, measure=w, direction=plus, min=1, max=4}" + |
| 174 | "], " + |
| 175 | "operands=[" + |
| 176 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Sonne, relation==}}," + |
| 177 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Mond, relation==}}" + |
| 178 | "]" + |
| 179 | "}"; |
Joachim Bingel | b5f7bf0 | 2014-01-07 16:36:54 +0000 | [diff] [blame] | 180 | ppt = new CosmasTree(query); |
| 181 | map = ppt.getRequestMap().get("query").toString(); |
| 182 | assertEquals(prox1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 89cceac | 2014-01-08 15:51:08 +0000 | [diff] [blame] | 183 | |
| 184 | query="Sonne /+w1:4,s0,p1:3 Mond"; |
| 185 | String prox2 = |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame^] | 186 | "{@type=korap:group, relation=distance, match=operands, @subtype=incl, " + |
Joachim Bingel | 89cceac | 2014-01-08 15:51:08 +0000 | [diff] [blame] | 187 | "constraint=[" + |
| 188 | "{@type=korap:group, relation=and, operands=[" + |
| 189 | "{@type=korap:distance, measure=w, direction=plus, min=1, max=4}," + |
| 190 | "{@type=korap:distance, measure=s, direction=both, min=0, max=0}," + |
| 191 | "{@type=korap:distance, measure=p, direction=both, min=1, max=3}" + |
| 192 | "]}" + |
| 193 | "], " + |
| 194 | "operands=[" + |
| 195 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Sonne, relation==}}," + |
| 196 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Mond, relation==}}" + |
| 197 | "]" + |
| 198 | "}"; |
| 199 | ppt = new CosmasTree(query); |
| 200 | map = ppt.getRequestMap().get("query").toString(); |
| 201 | assertEquals(prox2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame^] | 202 | |
| 203 | query="Sonne %+w1:4,s0,p1:3 Mond"; |
| 204 | String prox3 = |
| 205 | "{@type=korap:group, relation=distance, match=operands, @subtype=excl, " + |
| 206 | "constraint=[" + |
| 207 | "{@type=korap:group, relation=and, operands=[" + |
| 208 | "{@type=korap:distance, measure=w, direction=plus, min=1, max=4}," + |
| 209 | "{@type=korap:distance, measure=s, direction=both, min=0, max=0}," + |
| 210 | "{@type=korap:distance, measure=p, direction=both, min=1, max=3}" + |
| 211 | "]}" + |
| 212 | "], " + |
| 213 | "operands=[" + |
| 214 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Sonne, relation==}}," + |
| 215 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Mond, relation==}}" + |
| 216 | "]" + |
| 217 | "}"; |
| 218 | ppt = new CosmasTree(query); |
| 219 | map = ppt.getRequestMap().get("query").toString(); |
| 220 | assertEquals(prox3.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 221 | |
| 222 | query="Sonne /+w4 Mond"; |
| 223 | String prox4 = |
| 224 | "{@type=korap:group, relation=distance, match=operands, @subtype=incl, " + |
| 225 | "constraint=[" + |
| 226 | "{@type=korap:distance, measure=w, direction=plus, min=0, max=4}" + |
| 227 | "], " + |
| 228 | "operands=[" + |
| 229 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Sonne, relation==}}," + |
| 230 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Mond, relation==}}" + |
| 231 | "]" + |
| 232 | "}"; |
| 233 | ppt = new CosmasTree(query); |
| 234 | map = ppt.getRequestMap().get("query").toString(); |
| 235 | assertEquals(prox4.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | b5f7bf0 | 2014-01-07 16:36:54 +0000 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | @Test |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame^] | 239 | public void testOPIN() throws QueryException { |
Joachim Bingel | cc1dc24 | 2014-01-15 09:32:38 +0000 | [diff] [blame] | 240 | query="wegen #IN <s>"; |
Joachim Bingel | 3a9f793 | 2014-01-07 17:11:31 +0000 | [diff] [blame] | 241 | String opin1 = |
Joachim Bingel | eecc765 | 2014-01-11 17:21:07 +0000 | [diff] [blame] | 242 | "{@type=korap:group, relation=shrink, shrink=1, operands=[" + |
Joachim Bingel | cc1dc24 | 2014-01-15 09:32:38 +0000 | [diff] [blame] | 243 | "{@type=korap:group, relation=position, position=contains, operands=[" + |
Joachim Bingel | eecc765 | 2014-01-11 17:21:07 +0000 | [diff] [blame] | 244 | "{@type=korap:elem, @value=s}," + |
| 245 | "{@type=korap:group, class=1, operands=[" + |
Joachim Bingel | cc1dc24 | 2014-01-15 09:32:38 +0000 | [diff] [blame] | 246 | "{@type=korap:token, @value={@type=korap:term, @value=orth:wegen, relation==}}" + |
Joachim Bingel | eecc765 | 2014-01-11 17:21:07 +0000 | [diff] [blame] | 247 | "]}" + |
| 248 | "]}" + |
Joachim Bingel | d5161a1 | 2014-01-08 11:15:49 +0000 | [diff] [blame] | 249 | "]}"; |
| 250 | ppt = new CosmasTree(query); |
| 251 | map = ppt.getRequestMap().get("query").toString(); |
| 252 | assertEquals(opin1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 253 | |
Joachim Bingel | cc1dc24 | 2014-01-15 09:32:38 +0000 | [diff] [blame] | 254 | query="wegen #IN(L) <s>"; |
| 255 | String opin2 = |
| 256 | "{@type=korap:group, relation=shrink, shrink=1, operands=[" + |
| 257 | "{@type=korap:group, relation=position, position=startswith, operands=[" + |
| 258 | "{@type=korap:elem, @value=s}," + |
| 259 | "{@type=korap:group, class=1, operands=[" + |
| 260 | "{@type=korap:token, @value={@type=korap:term, @value=orth:wegen, relation==}}" + |
| 261 | "]}" + |
| 262 | "]}" + |
| 263 | "]}"; |
| 264 | ppt = new CosmasTree(query); |
| 265 | map = ppt.getRequestMap().get("query").toString(); |
| 266 | assertEquals(opin2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 267 | |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame^] | 268 | query="wegen #IN(%, L) <s>"; |
| 269 | String opin3 = |
| 270 | "{@type=korap:group, relation=shrink, shrink=1, operands=[" + |
| 271 | "{@type=korap:group, relation=position, position=startswith, @subtype=excl, operands=[" + |
| 272 | "{@type=korap:elem, @value=s}," + |
| 273 | "{@type=korap:group, class=1, operands=[" + |
| 274 | "{@type=korap:token, @value={@type=korap:term, @value=orth:wegen, relation==}}" + |
| 275 | "]}" + |
| 276 | "]}" + |
| 277 | "]}"; |
| 278 | ppt = new CosmasTree(query); |
| 279 | map = ppt.getRequestMap().get("query").toString(); |
| 280 | assertEquals(opin3.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 281 | |
| 282 | query="wegen #IN('FE,ALL,%,MIN') <s>"; |
| 283 | String opin4 = |
| 284 | "{@type=korap:group, relation=shrink, shrink=1, operands=[" + |
| 285 | "{@type=korap:group, relation=position, position=ident, range=all, @subtype=excl, grouping=false, operands=[" + |
| 286 | "{@type=korap:elem, @value=s}," + |
| 287 | "{@type=korap:group, class=1, operands=[" + |
| 288 | "{@type=korap:token, @value={@type=korap:term, @value=orth:wegen, relation==}}" + |
| 289 | "]}" + |
| 290 | "]}" + |
| 291 | "]}"; |
| 292 | ppt = new CosmasTree(query); |
| 293 | map = ppt.getRequestMap().get("query").toString(); |
| 294 | assertEquals(opin4.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 295 | |
Joachim Bingel | eecc765 | 2014-01-11 17:21:07 +0000 | [diff] [blame] | 296 | // // position argument is optional |
| 297 | // query="wegen #IN <s>"; |
| 298 | // String opin2 = |
| 299 | // "{@type=korap:group, relation=include, operands=[" + |
| 300 | // "{@type=korap:token, @value={@type=korap:term, @value=orth:wegen, relation==}}," + |
| 301 | // "{@type=korap:elem, @value=s}" + |
| 302 | // "]}"; |
| 303 | // ppt = new CosmasTree(query); |
| 304 | // map = ppt.getRequestMap().get("query").toString(); |
| 305 | // assertEquals(opin2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 306 | // |
| 307 | // // parentheses around 'wegen mir' are optional |
| 308 | // query="wegen #IN (wegen mir)"; |
| 309 | // String opin3 = |
| 310 | // "{@type=korap:group, relation=include, operands=[" + |
| 311 | // "{@type=korap:token, @value={@type=korap:term, @value=orth:wegen, relation==}}," + |
| 312 | // "{@type=korap:sequence, operands=[" + |
| 313 | // "{@type=korap:token, @value={@type=korap:term, @value=orth:wegen, relation==}}," + |
| 314 | // "{@type=korap:token, @value={@type=korap:term, @value=orth:mir, relation==}}" + |
| 315 | // "]}" + |
| 316 | // "]}"; |
| 317 | // ppt = new CosmasTree(query); |
| 318 | // map = ppt.getRequestMap().get("query").toString(); |
| 319 | // assertEquals(opin3.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | d5161a1 | 2014-01-08 11:15:49 +0000 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | @Test |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame^] | 323 | public void testOPOV() throws QueryException { |
Joachim Bingel | d5161a1 | 2014-01-08 11:15:49 +0000 | [diff] [blame] | 324 | query="wegen #OV <s>"; |
Joachim Bingel | cc1dc24 | 2014-01-15 09:32:38 +0000 | [diff] [blame] | 325 | String opov1 = |
| 326 | "{@type=korap:group, relation=shrink, shrink=1, operands=[" + |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame^] | 327 | "{@type=korap:group, relation=overlap, position=any, operands=[" + |
Joachim Bingel | cc1dc24 | 2014-01-15 09:32:38 +0000 | [diff] [blame] | 328 | "{@type=korap:elem, @value=s}," + |
| 329 | "{@type=korap:group, class=1, operands=[" + |
| 330 | "{@type=korap:token, @value={@type=korap:term, @value=orth:wegen, relation==}}" + |
| 331 | "]}" + |
| 332 | "]}" + |
Joachim Bingel | b5f7bf0 | 2014-01-07 16:36:54 +0000 | [diff] [blame] | 333 | "]}"; |
| 334 | ppt = new CosmasTree(query); |
| 335 | map = ppt.getRequestMap().get("query").toString(); |
Joachim Bingel | cc1dc24 | 2014-01-15 09:32:38 +0000 | [diff] [blame] | 336 | assertEquals(opov1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 337 | |
| 338 | query="wegen #OV(L) <s>"; |
| 339 | String opov2 = |
| 340 | "{@type=korap:group, relation=shrink, shrink=1, operands=[" + |
| 341 | "{@type=korap:group, relation=overlap, position=startswith, operands=[" + |
| 342 | "{@type=korap:elem, @value=s}," + |
| 343 | "{@type=korap:group, class=1, operands=[" + |
| 344 | "{@type=korap:token, @value={@type=korap:term, @value=orth:wegen, relation==}}" + |
| 345 | "]}" + |
| 346 | "]}" + |
| 347 | "]}"; |
| 348 | ppt = new CosmasTree(query); |
| 349 | map = ppt.getRequestMap().get("query").toString(); |
| 350 | assertEquals(opov2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | b5f7bf0 | 2014-01-07 16:36:54 +0000 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | @Test |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame^] | 354 | public void testOPNOT() throws QueryException { |
Joachim Bingel | 3a9f793 | 2014-01-07 17:11:31 +0000 | [diff] [blame] | 355 | query="Sonne nicht Mond"; |
| 356 | String opnot1 = |
| 357 | "{@type=korap:group, relation=not, operands=[" + |
| 358 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Sonne, relation==}}," + |
| 359 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Mond, relation==}}" + |
| 360 | "]}"; |
| 361 | ppt = new CosmasTree(query); |
| 362 | map = ppt.getRequestMap().get("query").toString(); |
| 363 | assertEquals(opnot1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 364 | } |
| 365 | |
| 366 | @Test |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame^] | 367 | public void testBEG_END() throws QueryException { |
Joachim Bingel | 3a9f793 | 2014-01-07 17:11:31 +0000 | [diff] [blame] | 368 | // BEG and END operators |
| 369 | // http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/syntax/links.html |
| 370 | // http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/syntax/rechts.html |
| 371 | // http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/thematische-bsp/bsp-satzlaenge.html |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame^] | 372 | query="#BEG(der /w3:5 Mann)"; |
| 373 | String beg1 = |
| 374 | "{@type=korap:group, relation=shrink, shrink=first, operands=[" + |
| 375 | "{@type=korap:group, relation=distance, match=operands, @subtype=incl, constraint=[" + |
| 376 | "{@type=korap:distance, measure=w, direction=both, min=3, max=5}" + |
| 377 | "]," + |
| 378 | "operands = [" + |
| 379 | "{@type=korap:token, @value={@type=korap:term, @value=orth:der, relation==}}," + |
| 380 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Mann, relation==}}" + |
| 381 | "]}" + |
| 382 | "]}"; |
| 383 | ppt = new CosmasTree(query); |
| 384 | map = ppt.getRequestMap().get("query").toString(); |
| 385 | assertEquals(beg1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 386 | |
| 387 | query="#BEG(der /w3:5 Mann) /+w10 kommt"; // nesting #BEG() in a distance group |
| 388 | String beg2 = |
| 389 | "{@type=korap:group, relation=distance, match=operands, @subtype=incl, constraint=[" + |
| 390 | "{@type=korap:distance, measure=w, direction=plus, min=0, max=10}" + |
| 391 | "], operands=[" + |
| 392 | "{@type=korap:group, relation=shrink, shrink=first, operands=[" + |
| 393 | "{@type=korap:group, relation=distance, match=operands, @subtype=incl, constraint=[" + |
| 394 | "{@type=korap:distance, measure=w, direction=both, min=3, max=5}" + |
| 395 | "]," + |
| 396 | "operands = [" + |
| 397 | "{@type=korap:token, @value={@type=korap:term, @value=orth:der, relation==}}," + |
| 398 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Mann, relation==}}" + |
| 399 | "]}" + |
| 400 | "]}," + |
| 401 | "{@type=korap:token, @value={@type=korap:term, @value=orth:kommt, relation==}}" + |
| 402 | "]}"; |
| 403 | ppt = new CosmasTree(query); |
| 404 | map = ppt.getRequestMap().get("query").toString(); |
| 405 | assertEquals(beg2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 406 | |
| 407 | query="#END(der /w3:5 Mann)"; |
| 408 | String end1 = |
| 409 | "{@type=korap:group, relation=shrink, shrink=last, operands=[" + |
| 410 | "{@type=korap:group, relation=distance, match=operands, @subtype=incl, constraint=[" + |
| 411 | "{@type=korap:distance, measure=w, direction=both, min=3, max=5}" + |
| 412 | "]," + |
| 413 | "operands = [" + |
| 414 | "{@type=korap:token, @value={@type=korap:term, @value=orth:der, relation==}}," + |
| 415 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Mann, relation==}}" + |
| 416 | "]}" + |
| 417 | "]}"; |
| 418 | ppt = new CosmasTree(query); |
| 419 | map = ppt.getRequestMap().get("query").toString(); |
| 420 | assertEquals(end1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | b5f7bf0 | 2014-01-07 16:36:54 +0000 | [diff] [blame] | 421 | } |
Joachim Bingel | d5161a1 | 2014-01-08 11:15:49 +0000 | [diff] [blame] | 422 | |
| 423 | |
| 424 | @Test |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame^] | 425 | public void testELEM() throws QueryException { |
Joachim Bingel | d5161a1 | 2014-01-08 11:15:49 +0000 | [diff] [blame] | 426 | // http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/syntax/elem.html |
Joachim Bingel | eecc765 | 2014-01-11 17:21:07 +0000 | [diff] [blame] | 427 | query="#ELEM(S)"; |
| 428 | String elem1 = "{@type=korap:elem, @value=s}"; |
| 429 | ppt = new CosmasTree(query); |
| 430 | map = ppt.getRequestMap().get("query").toString(); |
| 431 | assertEquals(elem1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | d5161a1 | 2014-01-08 11:15:49 +0000 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | @Test |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame^] | 435 | public void testOPALL() throws QueryException { |
Joachim Bingel | 89cceac | 2014-01-08 15:51:08 +0000 | [diff] [blame] | 436 | query="#ALL(gehen /w1:10 voran)"; |
| 437 | String all1 = |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame^] | 438 | // "{@type=korap:group, relation=all, operands=[" + |
| 439 | "{@type=korap:group, relation=distance, match=all, @subtype=incl, " + |
Joachim Bingel | 89cceac | 2014-01-08 15:51:08 +0000 | [diff] [blame] | 440 | "constraint=[" + |
| 441 | "{@type=korap:distance, measure=w, direction=both, min=1, max=10}" + |
| 442 | "], " + |
| 443 | "operands=[" + |
| 444 | "{@type=korap:token, @value={@type=korap:term, @value=orth:gehen, relation==}}," + |
| 445 | "{@type=korap:token, @value={@type=korap:term, @value=orth:voran, relation==}}" + |
| 446 | "]" + |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame^] | 447 | "}" //+ |
| 448 | // "]}" |
| 449 | ; |
Joachim Bingel | 89cceac | 2014-01-08 15:51:08 +0000 | [diff] [blame] | 450 | ppt = new CosmasTree(query); |
| 451 | map = ppt.getRequestMap().get("query").toString(); |
| 452 | assertEquals(all1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | d5161a1 | 2014-01-08 11:15:49 +0000 | [diff] [blame] | 453 | } |
| 454 | |
| 455 | @Test |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame^] | 456 | public void testOPNHIT() throws QueryException { |
Joachim Bingel | 89cceac | 2014-01-08 15:51:08 +0000 | [diff] [blame] | 457 | query="#NHIT(gehen /w1:10 voran)"; |
| 458 | String nhit1 = |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame^] | 459 | // "{@type=korap:group, relation=nhit, operands=[" + |
| 460 | "{@type=korap:group, relation=distance, match=between, @subtype=incl, " + |
Joachim Bingel | eecc765 | 2014-01-11 17:21:07 +0000 | [diff] [blame] | 461 | "constraint=[" + |
| 462 | "{@type=korap:distance, measure=w, direction=both, min=1, max=10}" + |
| 463 | "], " + |
| 464 | "operands=[" + |
| 465 | "{@type=korap:token, @value={@type=korap:term, @value=orth:gehen, relation==}}," + |
| 466 | "{@type=korap:token, @value={@type=korap:term, @value=orth:voran, relation==}}" + |
| 467 | "]" + |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame^] | 468 | "}" //+ |
| 469 | // "]}" |
| 470 | ; |
Joachim Bingel | 89cceac | 2014-01-08 15:51:08 +0000 | [diff] [blame] | 471 | ppt = new CosmasTree(query); |
| 472 | map = ppt.getRequestMap().get("query").toString(); |
| 473 | assertEquals(nhit1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | d5161a1 | 2014-01-08 11:15:49 +0000 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | @Test |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame^] | 477 | public void testOPBED() throws QueryException { |
Joachim Bingel | eecc765 | 2014-01-11 17:21:07 +0000 | [diff] [blame] | 478 | query = "#BED(der , sa)"; |
| 479 | String bed1 = |
| 480 | "{@type=korap:group, relation=position, position=startswith, operands=[" + |
| 481 | "{@type=korap:token, @value={@type=korap:term, @value=orth:der, relation==}}," + |
| 482 | "{@type=korap:elem, @value=s}" + |
| 483 | "]}"; |
| 484 | ppt = new CosmasTree(query); |
| 485 | map = ppt.getRequestMap().get("query").toString(); |
| 486 | assertEquals(bed1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 487 | |
| 488 | query = "#BED(der Mann , +pe)"; |
| 489 | String bed2 = |
| 490 | "{@type=korap:group, relation=position, position=endswith, operands=[" + |
| 491 | "{@type=korap:sequence, operands=[" + |
| 492 | "{@type=korap:token, @value={@type=korap:term, @value=orth:der, relation==}}," + |
| 493 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Mann, relation==}}" + |
| 494 | "]}," + |
| 495 | "{@type=korap:elem, @value=p}" + |
| 496 | "]}"; |
| 497 | ppt = new CosmasTree(query); |
| 498 | map = ppt.getRequestMap().get("query").toString(); |
| 499 | assertEquals(bed2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | d5161a1 | 2014-01-08 11:15:49 +0000 | [diff] [blame] | 500 | } |
| 501 | |
Joachim Bingel | b5f7bf0 | 2014-01-07 16:36:54 +0000 | [diff] [blame] | 502 | } |
| 503 | |