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 | 3f0850c | 2014-01-17 16:50:10 +0000 | [diff] [blame^] | 236 | |
| 237 | query="Sonne /-w4 Mond"; |
| 238 | String prox5 = |
| 239 | "{@type=korap:group, relation=distance, match=operands, @subtype=incl, " + |
| 240 | "constraint=[" + |
| 241 | "{@type=korap:distance, measure=w, direction=plus, min=0, max=4}" + |
| 242 | "], " + |
| 243 | "operands=[" + |
| 244 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Mond, relation==}}," + |
| 245 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Sonne, relation==}}" + |
| 246 | "]" + |
| 247 | "}"; |
| 248 | ppt = new CosmasTree(query); |
| 249 | map = ppt.getRequestMap().get("query").toString(); |
| 250 | assertEquals(prox5.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 251 | } |
| 252 | |
| 253 | @Test |
| 254 | public void testNestedOPPROX() throws QueryException { |
| 255 | query="Sonne /-w4 Mond /+w2 Sterne"; |
| 256 | String prox6 = |
| 257 | "{@type=korap:group, relation=distance, match=operands, @subtype=incl, " + |
| 258 | "constraint=[" + |
| 259 | "{@type=korap:distance, measure=w, direction=plus, min=0, max=4}" + |
| 260 | "], " + |
| 261 | "operands=[" + |
| 262 | "{@type=korap:group, relation=distance, match=operands, @subtype=incl, " + |
| 263 | "constraint=[" + |
| 264 | "{@type=korap:distance, measure=w, direction=plus, min=0, max=2}" + |
| 265 | "], " + |
| 266 | "operands=[" + |
| 267 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Mond, relation==}}," + |
| 268 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Sterne, relation==}}" + |
| 269 | "]}," + |
| 270 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Sonne, relation==}}" + |
| 271 | "]" + |
| 272 | "}"; |
| 273 | ppt = new CosmasTree(query); |
| 274 | map = ppt.getRequestMap().get("query").toString(); |
| 275 | assertEquals(prox6.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | b5f7bf0 | 2014-01-07 16:36:54 +0000 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | @Test |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame] | 279 | public void testOPIN() throws QueryException { |
Joachim Bingel | cc1dc24 | 2014-01-15 09:32:38 +0000 | [diff] [blame] | 280 | query="wegen #IN <s>"; |
Joachim Bingel | 3a9f793 | 2014-01-07 17:11:31 +0000 | [diff] [blame] | 281 | String opin1 = |
Joachim Bingel | eecc765 | 2014-01-11 17:21:07 +0000 | [diff] [blame] | 282 | "{@type=korap:group, relation=shrink, shrink=1, operands=[" + |
Joachim Bingel | cc1dc24 | 2014-01-15 09:32:38 +0000 | [diff] [blame] | 283 | "{@type=korap:group, relation=position, position=contains, operands=[" + |
Joachim Bingel | eecc765 | 2014-01-11 17:21:07 +0000 | [diff] [blame] | 284 | "{@type=korap:elem, @value=s}," + |
| 285 | "{@type=korap:group, class=1, operands=[" + |
Joachim Bingel | cc1dc24 | 2014-01-15 09:32:38 +0000 | [diff] [blame] | 286 | "{@type=korap:token, @value={@type=korap:term, @value=orth:wegen, relation==}}" + |
Joachim Bingel | eecc765 | 2014-01-11 17:21:07 +0000 | [diff] [blame] | 287 | "]}" + |
| 288 | "]}" + |
Joachim Bingel | d5161a1 | 2014-01-08 11:15:49 +0000 | [diff] [blame] | 289 | "]}"; |
| 290 | ppt = new CosmasTree(query); |
| 291 | map = ppt.getRequestMap().get("query").toString(); |
| 292 | assertEquals(opin1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 293 | |
Joachim Bingel | cc1dc24 | 2014-01-15 09:32:38 +0000 | [diff] [blame] | 294 | query="wegen #IN(L) <s>"; |
| 295 | String opin2 = |
| 296 | "{@type=korap:group, relation=shrink, shrink=1, operands=[" + |
| 297 | "{@type=korap:group, relation=position, position=startswith, operands=[" + |
| 298 | "{@type=korap:elem, @value=s}," + |
| 299 | "{@type=korap:group, class=1, operands=[" + |
| 300 | "{@type=korap:token, @value={@type=korap:term, @value=orth:wegen, relation==}}" + |
| 301 | "]}" + |
| 302 | "]}" + |
| 303 | "]}"; |
| 304 | ppt = new CosmasTree(query); |
| 305 | map = ppt.getRequestMap().get("query").toString(); |
| 306 | assertEquals(opin2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 307 | |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame] | 308 | query="wegen #IN(%, L) <s>"; |
| 309 | String opin3 = |
| 310 | "{@type=korap:group, relation=shrink, shrink=1, operands=[" + |
| 311 | "{@type=korap:group, relation=position, position=startswith, @subtype=excl, operands=[" + |
| 312 | "{@type=korap:elem, @value=s}," + |
| 313 | "{@type=korap:group, class=1, operands=[" + |
| 314 | "{@type=korap:token, @value={@type=korap:term, @value=orth:wegen, relation==}}" + |
| 315 | "]}" + |
| 316 | "]}" + |
| 317 | "]}"; |
| 318 | ppt = new CosmasTree(query); |
| 319 | map = ppt.getRequestMap().get("query").toString(); |
| 320 | assertEquals(opin3.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 321 | |
| 322 | query="wegen #IN('FE,ALL,%,MIN') <s>"; |
| 323 | String opin4 = |
| 324 | "{@type=korap:group, relation=shrink, shrink=1, operands=[" + |
| 325 | "{@type=korap:group, relation=position, position=ident, range=all, @subtype=excl, grouping=false, operands=[" + |
| 326 | "{@type=korap:elem, @value=s}," + |
| 327 | "{@type=korap:group, class=1, operands=[" + |
| 328 | "{@type=korap:token, @value={@type=korap:term, @value=orth:wegen, relation==}}" + |
| 329 | "]}" + |
| 330 | "]}" + |
| 331 | "]}"; |
| 332 | ppt = new CosmasTree(query); |
| 333 | map = ppt.getRequestMap().get("query").toString(); |
| 334 | assertEquals(opin4.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | d5161a1 | 2014-01-08 11:15:49 +0000 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | @Test |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame] | 338 | public void testOPOV() throws QueryException { |
Joachim Bingel | d5161a1 | 2014-01-08 11:15:49 +0000 | [diff] [blame] | 339 | query="wegen #OV <s>"; |
Joachim Bingel | cc1dc24 | 2014-01-15 09:32:38 +0000 | [diff] [blame] | 340 | String opov1 = |
| 341 | "{@type=korap:group, relation=shrink, shrink=1, operands=[" + |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame] | 342 | "{@type=korap:group, relation=overlap, position=any, operands=[" + |
Joachim Bingel | cc1dc24 | 2014-01-15 09:32:38 +0000 | [diff] [blame] | 343 | "{@type=korap:elem, @value=s}," + |
| 344 | "{@type=korap:group, class=1, operands=[" + |
| 345 | "{@type=korap:token, @value={@type=korap:term, @value=orth:wegen, relation==}}" + |
| 346 | "]}" + |
| 347 | "]}" + |
Joachim Bingel | b5f7bf0 | 2014-01-07 16:36:54 +0000 | [diff] [blame] | 348 | "]}"; |
| 349 | ppt = new CosmasTree(query); |
| 350 | map = ppt.getRequestMap().get("query").toString(); |
Joachim Bingel | cc1dc24 | 2014-01-15 09:32:38 +0000 | [diff] [blame] | 351 | assertEquals(opov1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 352 | |
| 353 | query="wegen #OV(L) <s>"; |
| 354 | String opov2 = |
| 355 | "{@type=korap:group, relation=shrink, shrink=1, operands=[" + |
| 356 | "{@type=korap:group, relation=overlap, position=startswith, operands=[" + |
| 357 | "{@type=korap:elem, @value=s}," + |
| 358 | "{@type=korap:group, class=1, operands=[" + |
| 359 | "{@type=korap:token, @value={@type=korap:term, @value=orth:wegen, relation==}}" + |
| 360 | "]}" + |
| 361 | "]}" + |
| 362 | "]}"; |
| 363 | ppt = new CosmasTree(query); |
| 364 | map = ppt.getRequestMap().get("query").toString(); |
| 365 | assertEquals(opov2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | b5f7bf0 | 2014-01-07 16:36:54 +0000 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | @Test |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame] | 369 | public void testOPNOT() throws QueryException { |
Joachim Bingel | 3a9f793 | 2014-01-07 17:11:31 +0000 | [diff] [blame] | 370 | query="Sonne nicht Mond"; |
| 371 | String opnot1 = |
| 372 | "{@type=korap:group, relation=not, operands=[" + |
| 373 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Sonne, relation==}}," + |
| 374 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Mond, relation==}}" + |
| 375 | "]}"; |
| 376 | ppt = new CosmasTree(query); |
| 377 | map = ppt.getRequestMap().get("query").toString(); |
| 378 | assertEquals(opnot1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 379 | } |
| 380 | |
| 381 | @Test |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame] | 382 | public void testBEG_END() throws QueryException { |
Joachim Bingel | 3a9f793 | 2014-01-07 17:11:31 +0000 | [diff] [blame] | 383 | // BEG and END operators |
| 384 | // http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/syntax/links.html |
| 385 | // http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/syntax/rechts.html |
| 386 | // 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] | 387 | query="#BEG(der /w3:5 Mann)"; |
| 388 | String beg1 = |
| 389 | "{@type=korap:group, relation=shrink, shrink=first, operands=[" + |
| 390 | "{@type=korap:group, relation=distance, match=operands, @subtype=incl, constraint=[" + |
| 391 | "{@type=korap:distance, measure=w, direction=both, min=3, max=5}" + |
| 392 | "]," + |
| 393 | "operands = [" + |
| 394 | "{@type=korap:token, @value={@type=korap:term, @value=orth:der, relation==}}," + |
| 395 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Mann, relation==}}" + |
| 396 | "]}" + |
| 397 | "]}"; |
| 398 | ppt = new CosmasTree(query); |
| 399 | map = ppt.getRequestMap().get("query").toString(); |
| 400 | assertEquals(beg1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 401 | |
| 402 | query="#BEG(der /w3:5 Mann) /+w10 kommt"; // nesting #BEG() in a distance group |
| 403 | String beg2 = |
| 404 | "{@type=korap:group, relation=distance, match=operands, @subtype=incl, constraint=[" + |
| 405 | "{@type=korap:distance, measure=w, direction=plus, min=0, max=10}" + |
| 406 | "], operands=[" + |
| 407 | "{@type=korap:group, relation=shrink, shrink=first, operands=[" + |
| 408 | "{@type=korap:group, relation=distance, match=operands, @subtype=incl, constraint=[" + |
| 409 | "{@type=korap:distance, measure=w, direction=both, min=3, max=5}" + |
| 410 | "]," + |
| 411 | "operands = [" + |
| 412 | "{@type=korap:token, @value={@type=korap:term, @value=orth:der, relation==}}," + |
| 413 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Mann, relation==}}" + |
| 414 | "]}" + |
| 415 | "]}," + |
| 416 | "{@type=korap:token, @value={@type=korap:term, @value=orth:kommt, relation==}}" + |
| 417 | "]}"; |
| 418 | ppt = new CosmasTree(query); |
| 419 | map = ppt.getRequestMap().get("query").toString(); |
| 420 | assertEquals(beg2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 421 | |
| 422 | query="#END(der /w3:5 Mann)"; |
| 423 | String end1 = |
| 424 | "{@type=korap:group, relation=shrink, shrink=last, operands=[" + |
| 425 | "{@type=korap:group, relation=distance, match=operands, @subtype=incl, constraint=[" + |
| 426 | "{@type=korap:distance, measure=w, direction=both, min=3, max=5}" + |
| 427 | "]," + |
| 428 | "operands = [" + |
| 429 | "{@type=korap:token, @value={@type=korap:term, @value=orth:der, relation==}}," + |
| 430 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Mann, relation==}}" + |
| 431 | "]}" + |
| 432 | "]}"; |
| 433 | ppt = new CosmasTree(query); |
| 434 | map = ppt.getRequestMap().get("query").toString(); |
| 435 | assertEquals(end1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | b5f7bf0 | 2014-01-07 16:36:54 +0000 | [diff] [blame] | 436 | } |
Joachim Bingel | d5161a1 | 2014-01-08 11:15:49 +0000 | [diff] [blame] | 437 | |
| 438 | |
| 439 | @Test |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame] | 440 | public void testELEM() throws QueryException { |
Joachim Bingel | d5161a1 | 2014-01-08 11:15:49 +0000 | [diff] [blame] | 441 | // 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] | 442 | query="#ELEM(S)"; |
| 443 | String elem1 = "{@type=korap:elem, @value=s}"; |
| 444 | ppt = new CosmasTree(query); |
| 445 | map = ppt.getRequestMap().get("query").toString(); |
| 446 | assertEquals(elem1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | d5161a1 | 2014-01-08 11:15:49 +0000 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | @Test |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame] | 450 | public void testOPALL() throws QueryException { |
Joachim Bingel | 89cceac | 2014-01-08 15:51:08 +0000 | [diff] [blame] | 451 | query="#ALL(gehen /w1:10 voran)"; |
| 452 | String all1 = |
Joachim Bingel | 3f0850c | 2014-01-17 16:50:10 +0000 | [diff] [blame^] | 453 | "{@type=korap:group, relation=distance, match=all, @subtype=incl, " + |
| 454 | "constraint=[" + |
| 455 | "{@type=korap:distance, measure=w, direction=both, min=1, max=10}" + |
| 456 | "], " + |
| 457 | "operands=[" + |
| 458 | "{@type=korap:token, @value={@type=korap:term, @value=orth:gehen, relation==}}," + |
| 459 | "{@type=korap:token, @value={@type=korap:term, @value=orth:voran, relation==}}" + |
| 460 | "]" + |
| 461 | "}"; |
Joachim Bingel | 89cceac | 2014-01-08 15:51:08 +0000 | [diff] [blame] | 462 | ppt = new CosmasTree(query); |
| 463 | map = ppt.getRequestMap().get("query").toString(); |
| 464 | assertEquals(all1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | d5161a1 | 2014-01-08 11:15:49 +0000 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | @Test |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame] | 468 | public void testOPNHIT() throws QueryException { |
Joachim Bingel | 89cceac | 2014-01-08 15:51:08 +0000 | [diff] [blame] | 469 | query="#NHIT(gehen /w1:10 voran)"; |
| 470 | String nhit1 = |
Joachim Bingel | 3f0850c | 2014-01-17 16:50:10 +0000 | [diff] [blame^] | 471 | "{@type=korap:group, relation=distance, match=between, @subtype=incl, " + |
| 472 | "constraint=[" + |
| 473 | "{@type=korap:distance, measure=w, direction=both, min=1, max=10}" + |
| 474 | "], " + |
| 475 | "operands=[" + |
| 476 | "{@type=korap:token, @value={@type=korap:term, @value=orth:gehen, relation==}}," + |
| 477 | "{@type=korap:token, @value={@type=korap:term, @value=orth:voran, relation==}}" + |
| 478 | "]" + |
| 479 | "}"; |
Joachim Bingel | 89cceac | 2014-01-08 15:51:08 +0000 | [diff] [blame] | 480 | ppt = new CosmasTree(query); |
| 481 | map = ppt.getRequestMap().get("query").toString(); |
| 482 | assertEquals(nhit1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | d5161a1 | 2014-01-08 11:15:49 +0000 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | @Test |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame] | 486 | public void testOPBED() throws QueryException { |
Joachim Bingel | eecc765 | 2014-01-11 17:21:07 +0000 | [diff] [blame] | 487 | query = "#BED(der , sa)"; |
| 488 | String bed1 = |
| 489 | "{@type=korap:group, relation=position, position=startswith, operands=[" + |
Joachim Bingel | 3f0850c | 2014-01-17 16:50:10 +0000 | [diff] [blame^] | 490 | "{@type=korap:elem, @value=s}," + |
| 491 | "{@type=korap:token, @value={@type=korap:term, @value=orth:der, relation==}}" + |
Joachim Bingel | eecc765 | 2014-01-11 17:21:07 +0000 | [diff] [blame] | 492 | "]}"; |
| 493 | ppt = new CosmasTree(query); |
| 494 | map = ppt.getRequestMap().get("query").toString(); |
| 495 | assertEquals(bed1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 496 | |
| 497 | query = "#BED(der Mann , +pe)"; |
| 498 | String bed2 = |
| 499 | "{@type=korap:group, relation=position, position=endswith, operands=[" + |
Joachim Bingel | 3f0850c | 2014-01-17 16:50:10 +0000 | [diff] [blame^] | 500 | "{@type=korap:elem, @value=p}," + |
Joachim Bingel | eecc765 | 2014-01-11 17:21:07 +0000 | [diff] [blame] | 501 | "{@type=korap:sequence, operands=[" + |
| 502 | "{@type=korap:token, @value={@type=korap:term, @value=orth:der, relation==}}," + |
| 503 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Mann, relation==}}" + |
Joachim Bingel | 3f0850c | 2014-01-17 16:50:10 +0000 | [diff] [blame^] | 504 | "]}" + |
Joachim Bingel | eecc765 | 2014-01-11 17:21:07 +0000 | [diff] [blame] | 505 | "]}"; |
| 506 | ppt = new CosmasTree(query); |
| 507 | map = ppt.getRequestMap().get("query").toString(); |
| 508 | assertEquals(bed2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 3f0850c | 2014-01-17 16:50:10 +0000 | [diff] [blame^] | 509 | |
| 510 | query = "#BED(der Mann , sa,-pa)"; |
| 511 | String bed3 = |
| 512 | "{@type=korap:group, relation=and, operands=[" + |
| 513 | "{@type=korap:group, relation=position, position=startswith, operands=[" + |
| 514 | "{@type=korap:elem, @value=s}," + |
| 515 | "{@type=korap:sequence, operands=[" + |
| 516 | "{@type=korap:token, @value={@type=korap:term, @value=orth:der, relation==}}," + |
| 517 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Mann, relation==}}" + |
| 518 | "]}" + |
| 519 | "]}," + |
| 520 | "{@type=korap:group, relation=position, position=startswith, @subtype=excl, operands=[" + |
| 521 | "{@type=korap:elem, @value=p}," + |
| 522 | "{@type=korap:sequence, operands=[" + |
| 523 | "{@type=korap:token, @value={@type=korap:term, @value=orth:der, relation==}}," + |
| 524 | "{@type=korap:token, @value={@type=korap:term, @value=orth:Mann, relation==}}" + |
| 525 | "]}" + |
| 526 | "]}" + |
| 527 | "]}"; |
| 528 | ppt = new CosmasTree(query); |
| 529 | map = ppt.getRequestMap().get("query").toString(); |
| 530 | assertEquals(bed3.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | d5161a1 | 2014-01-08 11:15:49 +0000 | [diff] [blame] | 531 | } |
| 532 | |
Joachim Bingel | b5f7bf0 | 2014-01-07 16:36:54 +0000 | [diff] [blame] | 533 | } |
| 534 | |