Joachim Bingel | 4eacdd3 | 2014-10-22 15:49:47 +0000 | [diff] [blame] | 1 | import static org.junit.Assert.*; |
| 2 | |
| 3 | import java.io.IOException; |
| 4 | import java.util.ArrayList; |
Joachim Bingel | 4eacdd3 | 2014-10-22 15:49:47 +0000 | [diff] [blame] | 5 | |
| 6 | import org.junit.Test; |
| 7 | |
Joachim Bingel | 4eacdd3 | 2014-10-22 15:49:47 +0000 | [diff] [blame] | 8 | import com.fasterxml.jackson.core.JsonProcessingException; |
| 9 | import com.fasterxml.jackson.databind.JsonNode; |
| 10 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 11 | import com.google.common.collect.Lists; |
| 12 | |
| 13 | |
| 14 | import de.ids_mannheim.korap.query.serialize.QuerySerializer; |
| 15 | import de.ids_mannheim.korap.util.QueryException; |
| 16 | |
| 17 | public class PoliqarpPlusTreeJSONTest { |
| 18 | |
| 19 | String map; |
| 20 | String expected; |
| 21 | String metaExpected; |
| 22 | String metaMap; |
| 23 | String query; |
| 24 | ArrayList<JsonNode> operands; |
| 25 | |
| 26 | QuerySerializer qs = new QuerySerializer(); |
| 27 | ObjectMapper mapper = new ObjectMapper(); |
| 28 | JsonNode res; |
| 29 | |
| 30 | @Test |
| 31 | public void testContext() throws QueryException, JsonProcessingException, IOException { |
| 32 | query = "foo"; |
| 33 | String contextString = "http://ids-mannheim.de/ns/KorAP/json-ld/v0.2/context.jsonld"; |
| 34 | qs.setQuery(query, "poliqarpplus"); |
| 35 | res = mapper.readTree(qs.toJSON()); |
| 36 | assertEquals(contextString, res.get("@context").asText()); |
| 37 | } |
| 38 | |
| 39 | |
| 40 | |
| 41 | @Test |
| 42 | public void testSingleTokens() throws QueryException, JsonProcessingException, IOException { |
| 43 | query = "[base=Mann]"; |
| 44 | qs.setQuery(query, "poliqarpplus"); |
| 45 | res = mapper.readTree(qs.toJSON()); |
| 46 | assertEquals("korap:token", res.at("/query/@type").asText()); |
| 47 | assertEquals("Mann", res.at("/query/wrap/key").asText()); |
| 48 | assertEquals("lemma", res.at("/query/wrap/layer").asText()); |
| 49 | assertEquals("match:eq", res.at("/query/wrap/match").asText()); |
| 50 | |
| 51 | query = "[orth!=Frau]"; |
| 52 | qs.setQuery(query, "poliqarpplus"); |
| 53 | res = mapper.readTree(qs.toJSON()); |
| 54 | assertEquals("korap:token", res.at("/query/@type").asText()); |
| 55 | assertEquals("Frau", res.at("/query/wrap/key").asText()); |
| 56 | assertEquals("orth", res.at("/query/wrap/layer").asText()); |
| 57 | assertEquals("match:ne", res.at("/query/wrap/match").asText()); |
| 58 | |
| 59 | query = "[p!=NN]"; |
| 60 | qs.setQuery(query, "poliqarpplus"); |
| 61 | res = mapper.readTree(qs.toJSON()); |
| 62 | assertEquals("korap:token", res.at("/query/@type").asText()); |
| 63 | assertEquals("NN", res.at("/query/wrap/key").asText()); |
| 64 | assertEquals("p", res.at("/query/wrap/layer").asText()); |
| 65 | assertEquals("match:ne", res.at("/query/wrap/match").asText()); |
| 66 | |
| 67 | query = "[!p!=NN]"; |
| 68 | qs.setQuery(query, "poliqarpplus"); |
| 69 | res = mapper.readTree(qs.toJSON()); |
| 70 | assertEquals("korap:token", res.at("/query/@type").asText()); |
| 71 | assertEquals("NN", res.at("/query/wrap/key").asText()); |
| 72 | assertEquals("p", res.at("/query/wrap/layer").asText()); |
| 73 | assertEquals("match:eq", res.at("/query/wrap/match").asText()); |
| 74 | |
| 75 | query = "[base=schland/x]"; |
| 76 | qs.setQuery(query, "poliqarpplus"); |
| 77 | res = mapper.readTree(qs.toJSON()); |
| 78 | assertEquals("korap:token", res.at("/query/@type").asText()); |
| 79 | assertEquals(".*?schland.*?", res.at("/query/wrap/key").asText()); |
| 80 | assertEquals("lemma", res.at("/query/wrap/layer").asText()); |
| 81 | assertEquals("type:regex", res.at("/query/wrap/type").asText()); |
| 82 | assertEquals("match:eq", res.at("/query/wrap/match").asText()); |
| 83 | } |
| 84 | |
| 85 | @Test |
| 86 | public void testValue() throws QueryException, JsonProcessingException, IOException { |
| 87 | query = "[mate/m=temp:pres]"; |
| 88 | qs.setQuery(query, "poliqarpplus"); |
| 89 | res = mapper.readTree(qs.toJSON()); |
| 90 | assertEquals("korap:token", res.at("/query/@type").asText()); |
| 91 | assertEquals("korap:term", res.at("/query/wrap/@type").asText()); |
| 92 | assertEquals("temp", res.at("/query/wrap/key").asText()); |
| 93 | assertEquals("pres", res.at("/query/wrap/value").asText()); |
| 94 | assertEquals("m", res.at("/query/wrap/layer").asText()); |
| 95 | assertEquals("mate", res.at("/query/wrap/foundry").asText()); |
| 96 | assertEquals("match:eq", res.at("/query/wrap/match").asText()); |
| 97 | } |
| 98 | |
| 99 | @Test |
| 100 | public void testRegex() throws QueryException, JsonProcessingException, IOException { |
| 101 | query = "[orth=\"M(a|ä)nn(er)?\"]"; |
| 102 | qs.setQuery(query, "poliqarpplus"); |
| 103 | res = mapper.readTree(qs.toJSON()); |
| 104 | assertEquals("korap:token", res.at("/query/@type").asText()); |
| 105 | assertEquals("korap:term", res.at("/query/wrap/@type").asText()); |
| 106 | assertEquals("M(a|ä)nn(er)?", res.at("/query/wrap/key").asText()); |
| 107 | assertEquals("type:regex", res.at("/query/wrap/type").asText()); |
| 108 | assertEquals("orth", res.at("/query/wrap/layer").asText()); |
| 109 | assertEquals("match:eq", res.at("/query/wrap/match").asText()); |
| 110 | |
| 111 | query = "[orth=\"M(a|ä)nn(er)?\"/x]"; |
| 112 | qs.setQuery(query, "poliqarpplus"); |
| 113 | res = mapper.readTree(qs.toJSON()); |
| 114 | assertEquals("korap:token", res.at("/query/@type").asText()); |
| 115 | assertEquals("korap:term", res.at("/query/wrap/@type").asText()); |
| 116 | assertEquals(".*?M(a|ä)nn(er)?.*?", res.at("/query/wrap/key").asText()); |
| 117 | assertEquals("type:regex", res.at("/query/wrap/type").asText()); |
| 118 | assertEquals("orth", res.at("/query/wrap/layer").asText()); |
| 119 | assertEquals("match:eq", res.at("/query/wrap/match").asText()); |
| 120 | |
| 121 | query = "\".*?Mann.*?\""; |
| 122 | qs.setQuery(query, "poliqarpplus"); |
| 123 | res = mapper.readTree(qs.toJSON()); |
| 124 | assertEquals("korap:token", res.at("/query/@type").asText()); |
| 125 | assertEquals("korap:term", res.at("/query/wrap/@type").asText()); |
| 126 | assertEquals(".*?Mann.*?", res.at("/query/wrap/key").asText()); |
| 127 | assertEquals("type:regex", res.at("/query/wrap/type").asText()); |
| 128 | assertEquals("orth", res.at("/query/wrap/layer").asText()); |
| 129 | assertEquals("match:eq", res.at("/query/wrap/match").asText()); |
| 130 | |
| 131 | query = "z.B./x"; |
| 132 | qs.setQuery(query, "poliqarpplus"); |
| 133 | res = mapper.readTree(qs.toJSON()); |
| 134 | assertEquals("korap:token", res.at("/query/@type").asText()); |
| 135 | assertEquals("korap:term", res.at("/query/wrap/@type").asText()); |
| 136 | assertEquals(".*?z\\.B\\..*?", res.at("/query/wrap/key").asText()); |
| 137 | assertEquals("type:regex", res.at("/query/wrap/type").asText()); |
| 138 | assertEquals("orth", res.at("/query/wrap/layer").asText()); |
| 139 | assertEquals("match:eq", res.at("/query/wrap/match").asText()); |
| 140 | |
| 141 | } |
| 142 | |
| 143 | @Test |
| 144 | public void testCaseSensitivityFlag() throws QueryException, JsonProcessingException, IOException { |
| 145 | query = "[orth=deutscher/i]"; |
| 146 | qs.setQuery(query, "poliqarpplus"); |
| 147 | res = mapper.readTree(qs.toJSON()); |
| 148 | assertEquals("korap:token", res.at("/query/@type").asText()); |
| 149 | assertEquals("korap:term", res.at("/query/wrap/@type").asText()); |
| 150 | assertEquals("deutscher", res.at("/query/wrap/key").asText()); |
| 151 | assertEquals("true", res.at("/query/wrap/caseInsensitive").asText()); |
| 152 | assertEquals("orth", res.at("/query/wrap/layer").asText()); |
| 153 | assertEquals("match:eq", res.at("/query/wrap/match").asText()); |
| 154 | |
| 155 | query = "deutscher/i"; |
| 156 | qs.setQuery(query, "poliqarpplus"); |
| 157 | res = mapper.readTree(qs.toJSON()); |
| 158 | assertEquals("korap:token", res.at("/query/@type").asText()); |
| 159 | assertEquals("korap:term", res.at("/query/wrap/@type").asText()); |
| 160 | assertEquals("deutscher", res.at("/query/wrap/key").asText()); |
| 161 | assertEquals("true", res.at("/query/wrap/caseInsensitive").asText()); |
| 162 | assertEquals("orth", res.at("/query/wrap/layer").asText()); |
| 163 | assertEquals("match:eq", res.at("/query/wrap/match").asText()); |
| 164 | |
| 165 | query = "deutscher/I"; |
| 166 | qs.setQuery(query, "poliqarpplus"); |
| 167 | res = mapper.readTree(qs.toJSON()); |
| 168 | assertEquals("korap:token", res.at("/query/@type").asText()); |
| 169 | assertEquals("korap:term", res.at("/query/wrap/@type").asText()); |
| 170 | assertEquals("deutscher", res.at("/query/wrap/key").asText()); |
| 171 | assertEquals("false", res.at("/query/wrap/caseInsensitive").asText()); |
| 172 | assertEquals("orth", res.at("/query/wrap/layer").asText()); |
| 173 | assertEquals("match:eq", res.at("/query/wrap/match").asText()); |
| 174 | |
| 175 | query = "[orth=deutscher/i][orth=Bundestag]"; |
| 176 | qs.setQuery(query, "poliqarpplus"); |
| 177 | res = mapper.readTree(qs.toJSON()); |
| 178 | assertEquals("korap:group", res.at("/query/@type").asText()); |
| 179 | assertEquals("operation:sequence", res.at("/query/operation").asText()); |
| 180 | operands = Lists.newArrayList(res.at("/query/operands").elements()); |
| 181 | assertEquals("korap:token", operands.get(0).at("/@type").asText()); |
| 182 | assertEquals("deutscher", operands.get(0).at("/wrap/key").asText()); |
| 183 | assertEquals("orth", operands.get(0).at("/wrap/layer").asText()); |
| 184 | assertEquals("match:eq", operands.get(0).at("/wrap/match").asText()); |
Joachim Bingel | 3376363 | 2014-10-23 13:31:05 +0000 | [diff] [blame] | 185 | assertEquals(true, operands.get(0).at("/wrap/caseInsensitive").asBoolean()); |
Joachim Bingel | 4eacdd3 | 2014-10-22 15:49:47 +0000 | [diff] [blame] | 186 | assertEquals("korap:token", operands.get(1).at("/@type").asText()); |
| 187 | assertEquals("Bundestag", operands.get(1).at("/wrap/key").asText()); |
| 188 | assertEquals("orth", operands.get(1).at("/wrap/layer").asText()); |
| 189 | assertEquals("match:eq", operands.get(1).at("/wrap/match").asText()); |
| 190 | assertEquals(true, operands.get(1).at("/wrap/caseInsensitive").isMissingNode()); |
| 191 | |
| 192 | query = "deutscher/i Bundestag"; |
| 193 | qs.setQuery(query, "poliqarpplus"); |
| 194 | res = mapper.readTree(qs.toJSON()); |
| 195 | assertEquals("korap:group", res.at("/query/@type").asText()); |
| 196 | assertEquals("operation:sequence", res.at("/query/operation").asText()); |
| 197 | operands = Lists.newArrayList(res.at("/query/operands").elements()); |
| 198 | assertEquals("korap:token", operands.get(0).at("/@type").asText()); |
| 199 | assertEquals("deutscher", operands.get(0).at("/wrap/key").asText()); |
| 200 | assertEquals("orth", operands.get(0).at("/wrap/layer").asText()); |
| 201 | assertEquals("match:eq", operands.get(0).at("/wrap/match").asText()); |
Joachim Bingel | 3376363 | 2014-10-23 13:31:05 +0000 | [diff] [blame] | 202 | assertEquals(true, operands.get(0).at("/wrap/caseInsensitive").asBoolean()); |
Joachim Bingel | 4eacdd3 | 2014-10-22 15:49:47 +0000 | [diff] [blame] | 203 | assertEquals("korap:token", operands.get(1).at("/@type").asText()); |
| 204 | assertEquals("Bundestag", operands.get(1).at("/wrap/key").asText()); |
| 205 | assertEquals("orth", operands.get(1).at("/wrap/layer").asText()); |
| 206 | assertEquals("match:eq", operands.get(1).at("/wrap/match").asText()); |
| 207 | assertEquals(true, operands.get(1).at("/wrap/caseInsensitive").isMissingNode()); |
| 208 | } |
| 209 | |
| 210 | @Test |
| 211 | public void testSpans() throws QueryException, JsonProcessingException, IOException { |
| 212 | query = "<s>"; |
| 213 | qs.setQuery(query, "poliqarpplus"); |
| 214 | res = mapper.readTree(qs.toJSON()); |
| 215 | assertEquals("korap:span", res.at("/query/@type").asText()); |
| 216 | assertEquals("s", res.at("/query/key").asText()); |
| 217 | |
| 218 | query = "<vp>"; |
| 219 | qs.setQuery(query, "poliqarpplus"); |
| 220 | res = mapper.readTree(qs.toJSON()); |
| 221 | assertEquals("korap:span", res.at("/query/@type").asText()); |
| 222 | assertEquals("vp", res.at("/query/key").asText()); |
| 223 | |
| 224 | query = "<cnx/c=vp>"; |
| 225 | qs.setQuery(query, "poliqarpplus"); |
| 226 | res = mapper.readTree(qs.toJSON()); |
| 227 | assertEquals("korap:span", res.at("/query/@type").asText()); |
| 228 | assertEquals("vp", res.at("/query/key").asText()); |
| 229 | assertEquals("cnx", res.at("/query/foundry").asText()); |
| 230 | assertEquals("c", res.at("/query/layer").asText()); |
| 231 | |
| 232 | query = "<cnx/c!=vp>"; |
| 233 | qs.setQuery(query, "poliqarpplus"); |
| 234 | res = mapper.readTree(qs.toJSON()); |
| 235 | assertEquals("korap:span", res.at("/query/@type").asText()); |
| 236 | assertEquals("vp", res.at("/query/key").asText()); |
| 237 | assertEquals("cnx", res.at("/query/foundry").asText()); |
| 238 | assertEquals("c", res.at("/query/layer").asText()); |
| 239 | assertEquals("match:ne", res.at("/query/match").asText()); |
| 240 | |
| 241 | query = "<cnx/c!=vp class!=header>"; |
| 242 | qs.setQuery(query, "poliqarpplus"); |
| 243 | res = mapper.readTree(qs.toJSON()); |
| 244 | assertEquals("korap:span", res.at("/query/@type").asText()); |
| 245 | assertEquals("vp", res.at("/query/key").asText()); |
| 246 | assertEquals("cnx", res.at("/query/foundry").asText()); |
| 247 | assertEquals("c", res.at("/query/layer").asText()); |
| 248 | assertEquals("match:ne", res.at("/query/match").asText()); |
| 249 | assertEquals("class", res.at("/query/attr/key").asText()); |
| 250 | assertEquals("header", res.at("/query/attr/value").asText()); |
| 251 | assertEquals("match:ne", res.at("/query/attr/match").asText()); |
| 252 | |
| 253 | query = "<cnx/c!=vp !(class!=header)>"; |
| 254 | qs.setQuery(query, "poliqarpplus"); |
| 255 | res = mapper.readTree(qs.toJSON()); |
| 256 | assertEquals("korap:span", res.at("/query/@type").asText()); |
| 257 | assertEquals("vp", res.at("/query/key").asText()); |
| 258 | assertEquals("cnx", res.at("/query/foundry").asText()); |
| 259 | assertEquals("c", res.at("/query/layer").asText()); |
| 260 | assertEquals("match:ne", res.at("/query/match").asText()); |
| 261 | assertEquals("class", res.at("/query/attr/key").asText()); |
| 262 | assertEquals("header", res.at("/query/attr/value").asText()); |
| 263 | assertEquals("match:eq", res.at("/query/attr/match").asText()); |
| 264 | |
| 265 | query = "<cnx/c!=vp !(class=header & id=7)>"; |
| 266 | qs.setQuery(query, "poliqarpplus"); |
| 267 | res = mapper.readTree(qs.toJSON()); |
| 268 | assertEquals("korap:span", res.at("/query/@type").asText()); |
| 269 | assertEquals("vp", res.at("/query/key").asText()); |
| 270 | assertEquals("cnx", res.at("/query/foundry").asText()); |
| 271 | assertEquals("c", res.at("/query/layer").asText()); |
| 272 | assertEquals("match:ne", res.at("/query/match").asText()); |
| 273 | assertEquals("korap:termGroup", res.at("/query/attr/@type").asText()); |
| 274 | assertEquals("relation:and", res.at("/query/attr/relation").asText()); |
| 275 | operands = Lists.newArrayList( res.at("/query/attr/operands").elements()); |
| 276 | assertEquals("korap:term", operands.get(0).at("/@type").asText()); |
| 277 | assertEquals("class", operands.get(0).at("/key").asText()); |
| 278 | assertEquals("header", operands.get(0).at("/value").asText()); |
| 279 | assertEquals("match:ne", operands.get(0).at("/match").asText()); |
| 280 | assertEquals("korap:term", operands.get(1).at("/@type").asText()); |
| 281 | assertEquals("id", operands.get(1).at("/key").asText()); |
Joachim Bingel | 3376363 | 2014-10-23 13:31:05 +0000 | [diff] [blame] | 282 | assertEquals(7, operands.get(1).at("/value").asInt()); |
Joachim Bingel | 4eacdd3 | 2014-10-22 15:49:47 +0000 | [diff] [blame] | 283 | assertEquals("match:ne", operands.get(1).at("/match").asText()); |
| 284 | } |
| 285 | |
| 286 | @Test |
| 287 | public void testDistances() throws QueryException, JsonProcessingException, IOException { |
| 288 | query = "[base=der][][base=Mann]"; |
| 289 | qs.setQuery(query, "poliqarpplus"); |
| 290 | res = mapper.readTree(qs.toJSON()); |
Joachim Bingel | 4eacdd3 | 2014-10-22 15:49:47 +0000 | [diff] [blame] | 291 | assertEquals("korap:group", res.at("/query/@type").asText()); |
| 292 | assertEquals("operation:sequence", res.at("/query/operation").asText()); |
| 293 | assertEquals("true", res.at("/query/inOrder").asText()); |
| 294 | assertEquals("korap:distance", res.at("/query/distances").elements().next().at("/@type").asText()); |
| 295 | assertEquals("w", res.at("/query/distances").elements().next().at("/key").asText()); |
| 296 | assertEquals("korap:boundary", res.at("/query/distances").elements().next().at("/boundary/@type").asText()); |
Joachim Bingel | 3376363 | 2014-10-23 13:31:05 +0000 | [diff] [blame] | 297 | assertEquals(2, res.at("/query/distances").elements().next().at("/boundary/min").asInt()); |
| 298 | assertEquals(2, res.at("/query/distances").elements().next().at("/boundary/max").asInt()); |
Joachim Bingel | 4eacdd3 | 2014-10-22 15:49:47 +0000 | [diff] [blame] | 299 | operands = Lists.newArrayList(res.at("/query/operands").elements()); |
| 300 | assertEquals("korap:token", operands.get(0).at("/@type").asText()); |
| 301 | assertEquals("der", operands.get(0).at("/wrap/key").asText()); |
| 302 | assertEquals("lemma", operands.get(0).at("/wrap/layer").asText()); |
| 303 | assertEquals("match:eq", operands.get(0).at("/wrap/match").asText()); |
| 304 | assertEquals("korap:token", operands.get(1).at("/@type").asText()); |
| 305 | assertEquals("Mann", operands.get(1).at("/wrap/key").asText()); |
| 306 | assertEquals("lemma", operands.get(1).at("/wrap/layer").asText()); |
| 307 | assertEquals("match:eq", operands.get(1).at("/wrap/match").asText()); |
| 308 | |
| 309 | query = "[base=der][][][base=Mann]"; |
| 310 | qs.setQuery(query, "poliqarpplus"); |
| 311 | res = mapper.readTree(qs.toJSON()); |
Joachim Bingel | 4eacdd3 | 2014-10-22 15:49:47 +0000 | [diff] [blame] | 312 | assertEquals("korap:group", res.at("/query/@type").asText()); |
| 313 | assertEquals("operation:sequence", res.at("/query/operation").asText()); |
| 314 | assertEquals("true", res.at("/query/inOrder").asText()); |
| 315 | assertEquals("korap:distance", res.at("/query/distances").elements().next().at("/@type").asText()); |
| 316 | assertEquals("w", res.at("/query/distances").elements().next().at("/key").asText()); |
| 317 | assertEquals("korap:boundary", res.at("/query/distances").elements().next().at("/boundary/@type").asText()); |
Joachim Bingel | 3376363 | 2014-10-23 13:31:05 +0000 | [diff] [blame] | 318 | assertEquals(3, res.at("/query/distances").elements().next().at("/boundary/min").asInt()); |
| 319 | assertEquals(3, res.at("/query/distances").elements().next().at("/boundary/max").asInt()); |
Joachim Bingel | 4eacdd3 | 2014-10-22 15:49:47 +0000 | [diff] [blame] | 320 | operands = Lists.newArrayList(res.at("/query/operands").elements()); |
| 321 | assertEquals("korap:token", operands.get(0).at("/@type").asText()); |
| 322 | assertEquals("der", operands.get(0).at("/wrap/key").asText()); |
| 323 | assertEquals("lemma", operands.get(0).at("/wrap/layer").asText()); |
| 324 | assertEquals("match:eq", operands.get(0).at("/wrap/match").asText()); |
| 325 | assertEquals("korap:token", operands.get(1).at("/@type").asText()); |
| 326 | assertEquals("Mann", operands.get(1).at("/wrap/key").asText()); |
| 327 | assertEquals("lemma", operands.get(1).at("/wrap/layer").asText()); |
| 328 | assertEquals("match:eq", operands.get(1).at("/wrap/match").asText()); |
| 329 | |
| 330 | query = "[base=der][][]?[base=Mann]"; |
| 331 | qs.setQuery(query, "poliqarpplus"); |
| 332 | res = mapper.readTree(qs.toJSON()); |
Joachim Bingel | 4eacdd3 | 2014-10-22 15:49:47 +0000 | [diff] [blame] | 333 | assertEquals("korap:group", res.at("/query/@type").asText()); |
| 334 | assertEquals("operation:sequence", res.at("/query/operation").asText()); |
| 335 | assertEquals("true", res.at("/query/inOrder").asText()); |
| 336 | assertEquals("korap:distance", res.at("/query/distances").elements().next().at("/@type").asText()); |
| 337 | assertEquals("w", res.at("/query/distances").elements().next().at("/key").asText()); |
| 338 | assertEquals("korap:boundary", res.at("/query/distances").elements().next().at("/boundary/@type").asText()); |
Joachim Bingel | 3376363 | 2014-10-23 13:31:05 +0000 | [diff] [blame] | 339 | assertEquals(2, res.at("/query/distances").elements().next().at("/boundary/min").asInt()); |
| 340 | assertEquals(3, res.at("/query/distances").elements().next().at("/boundary/max").asInt()); |
Joachim Bingel | 4eacdd3 | 2014-10-22 15:49:47 +0000 | [diff] [blame] | 341 | operands = Lists.newArrayList(res.at("/query/operands").elements()); |
| 342 | assertEquals("korap:token", operands.get(0).at("/@type").asText()); |
| 343 | assertEquals("der", operands.get(0).at("/wrap/key").asText()); |
| 344 | assertEquals("lemma", operands.get(0).at("/wrap/layer").asText()); |
| 345 | assertEquals("match:eq", operands.get(0).at("/wrap/match").asText()); |
| 346 | assertEquals("korap:token", operands.get(1).at("/@type").asText()); |
| 347 | assertEquals("Mann", operands.get(1).at("/wrap/key").asText()); |
| 348 | assertEquals("lemma", operands.get(1).at("/wrap/layer").asText()); |
| 349 | assertEquals("match:eq", operands.get(1).at("/wrap/match").asText()); |
Joachim Bingel | 3376363 | 2014-10-23 13:31:05 +0000 | [diff] [blame] | 350 | |
| 351 | query = "[base=der][]+[base=Mann]"; |
| 352 | qs.setQuery(query, "poliqarpplus"); |
| 353 | res = mapper.readTree(qs.toJSON()); |
| 354 | assertEquals("korap:group", res.at("/query/@type").asText()); |
| 355 | assertEquals("operation:sequence", res.at("/query/operation").asText()); |
| 356 | assertEquals("true", res.at("/query/inOrder").asText()); |
| 357 | assertEquals("korap:distance", res.at("/query/distances").elements().next().at("/@type").asText()); |
| 358 | assertEquals("w", res.at("/query/distances").elements().next().at("/key").asText()); |
| 359 | assertEquals("korap:boundary", res.at("/query/distances").elements().next().at("/boundary/@type").asText()); |
| 360 | assertEquals(2, res.at("/query/distances").elements().next().at("/boundary/min").asInt()); |
| 361 | assertEquals(true, res.at("/query/distances").elements().next().at("/boundary/max").isMissingNode()); |
| 362 | operands = Lists.newArrayList(res.at("/query/operands").elements()); |
| 363 | assertEquals("korap:token", operands.get(0).at("/@type").asText()); |
| 364 | assertEquals("der", operands.get(0).at("/wrap/key").asText()); |
| 365 | assertEquals("lemma", operands.get(0).at("/wrap/layer").asText()); |
| 366 | assertEquals("match:eq", operands.get(0).at("/wrap/match").asText()); |
| 367 | assertEquals("korap:token", operands.get(1).at("/@type").asText()); |
| 368 | assertEquals("Mann", operands.get(1).at("/wrap/key").asText()); |
| 369 | assertEquals("lemma", operands.get(1).at("/wrap/layer").asText()); |
| 370 | assertEquals("match:eq", operands.get(1).at("/wrap/match").asText()); |
| 371 | |
| 372 | query = "[base=der][]*[base=Mann]"; |
| 373 | qs.setQuery(query, "poliqarpplus"); |
| 374 | res = mapper.readTree(qs.toJSON()); |
| 375 | assertEquals("korap:group", res.at("/query/@type").asText()); |
| 376 | assertEquals("operation:sequence", res.at("/query/operation").asText()); |
| 377 | assertEquals("true", res.at("/query/inOrder").asText()); |
| 378 | assertEquals("korap:distance", res.at("/query/distances").elements().next().at("/@type").asText()); |
| 379 | assertEquals("w", res.at("/query/distances").elements().next().at("/key").asText()); |
| 380 | assertEquals("korap:boundary", res.at("/query/distances").elements().next().at("/boundary/@type").asText()); |
| 381 | assertEquals(1, res.at("/query/distances").elements().next().at("/boundary/min").asInt()); |
| 382 | assertEquals(true, res.at("/query/distances").elements().next().at("/boundary/max").isMissingNode()); |
| 383 | |
| 384 | query = "[base=der][]{2,5}[base=Mann][]?[][base=Frau]"; |
| 385 | qs.setQuery(query, "poliqarpplus"); |
| 386 | res = mapper.readTree(qs.toJSON()); |
| 387 | assertEquals("korap:group", res.at("/query/@type").asText()); |
| 388 | assertEquals("operation:sequence", res.at("/query/operation").asText()); |
| 389 | assertEquals("true", res.at("/query/inOrder").asText()); |
| 390 | assertEquals("korap:distance", res.at("/query/distances").elements().next().at("/@type").asText()); |
| 391 | assertEquals("w", res.at("/query/distances").elements().next().at("/key").asText()); |
| 392 | assertEquals("korap:boundary", res.at("/query/distances").elements().next().at("/boundary/@type").asText()); |
| 393 | assertEquals(3, res.at("/query/distances").elements().next().at("/boundary/min").asInt()); |
| 394 | assertEquals(6, res.at("/query/distances").elements().next().at("/boundary/max").asInt()); |
| 395 | operands = Lists.newArrayList(res.at("/query/operands").elements()); |
| 396 | assertEquals("korap:token", operands.get(0).at("/@type").asText()); |
| 397 | assertEquals("der", operands.get(0).at("/wrap/key").asText()); |
| 398 | assertEquals("lemma", operands.get(0).at("/wrap/layer").asText()); |
| 399 | assertEquals("match:eq", operands.get(0).at("/wrap/match").asText()); |
| 400 | assertEquals("korap:group", operands.get(1).at("/@type").asText()); |
| 401 | assertEquals("operation:sequence", operands.get(1).at("/operation").asText()); |
| 402 | assertEquals("korap:distance", operands.get(1).get("distances").elements().next().at("/@type").asText()); |
| 403 | assertEquals("w", operands.get(1).get("distances").elements().next().at("/key").asText()); |
| 404 | assertEquals("korap:boundary", operands.get(1).get("distances").elements().next().at("/boundary/@type").asText()); |
| 405 | assertEquals(2, operands.get(1).get("distances").elements().next().at("/boundary/min").asInt()); |
| 406 | assertEquals(3, operands.get(1).get("distances").elements().next().at("/boundary/max").asInt()); |
| 407 | operands = Lists.newArrayList(operands.get(1).get("operands").elements()); |
| 408 | assertEquals("Mann", operands.get(0).at("/wrap/key").asText()); |
| 409 | assertEquals("lemma", operands.get(0).at("/wrap/layer").asText()); |
| 410 | assertEquals("match:eq", operands.get(0).at("/wrap/match").asText()); |
| 411 | assertEquals("Frau", operands.get(1).at("/wrap/key").asText()); |
| 412 | assertEquals("lemma", operands.get(1).at("/wrap/layer").asText()); |
| 413 | assertEquals("match:eq", operands.get(1).at("/wrap/match").asText()); |
| 414 | |
| 415 | query = "[base=geht][base=der][]*contains(<s>,<np>)"; |
| 416 | qs.setQuery(query, "poliqarpplus"); |
| 417 | res = mapper.readTree(qs.toJSON()); |
| 418 | assertEquals("korap:group", res.at("/query/@type").asText()); |
| 419 | assertEquals("operation:sequence", res.at("/query/operation").asText()); |
| 420 | assertEquals(true, res.at("/query/inOrder").isMissingNode()); |
| 421 | assertEquals(true, res.at("/query/distances").isMissingNode()); |
| 422 | operands = Lists.newArrayList(res.at("/query/operands").elements()); |
| 423 | assertEquals("korap:token", operands.get(0).at("/@type").asText()); |
| 424 | assertEquals("geht", operands.get(0).at("/wrap/key").asText()); |
| 425 | assertEquals("lemma", operands.get(0).at("/wrap/layer").asText()); |
| 426 | assertEquals("match:eq", operands.get(0).at("/wrap/match").asText()); |
| 427 | assertEquals("korap:group", operands.get(1).at("/@type").asText()); |
| 428 | assertEquals("operation:sequence", operands.get(1).at("/operation").asText()); |
| 429 | assertEquals("korap:distance", operands.get(1).get("distances").elements().next().at("/@type").asText()); |
| 430 | assertEquals("w", operands.get(1).get("distances").elements().next().at("/key").asText()); |
| 431 | assertEquals("korap:boundary", operands.get(1).get("distances").elements().next().at("/boundary/@type").asText()); |
| 432 | assertEquals(1, operands.get(1).get("distances").elements().next().at("/boundary/min").asInt()); |
| 433 | assertEquals(true, operands.get(1).get("distances").elements().next().at("/boundary/max").isMissingNode()); |
| 434 | operands = Lists.newArrayList(operands.get(1).get("operands").elements()); |
| 435 | assertEquals("der", operands.get(0).at("/wrap/key").asText()); |
| 436 | assertEquals("lemma", operands.get(0).at("/wrap/layer").asText()); |
| 437 | assertEquals("match:eq", operands.get(0).at("/wrap/match").asText()); |
| 438 | assertEquals("korap:group", operands.get(1).at("/@type").asText()); |
| 439 | assertEquals("operation:position", operands.get(1).at("/operation").asText()); |
Joachim Bingel | 4eacdd3 | 2014-10-22 15:49:47 +0000 | [diff] [blame] | 440 | } |
Joachim Bingel | 3376363 | 2014-10-23 13:31:05 +0000 | [diff] [blame] | 441 | |
| 442 | @Test |
| 443 | public void testDistancesWithClass() throws QueryException, JsonProcessingException, IOException { |
| 444 | query = "[base=der]{[]}[base=Mann]"; |
| 445 | qs.setQuery(query, "poliqarpplus"); |
| 446 | res = mapper.readTree(qs.toJSON()); |
| 447 | assertEquals("korap:group", res.at("/query/@type").asText()); |
| 448 | assertEquals("operation:sequence", res.at("/query/operation").asText()); |
| 449 | assertEquals(true, res.at("/query/inOrder").isMissingNode()); |
| 450 | assertEquals(true, res.at("/query/distances").isMissingNode()); |
| 451 | operands = Lists.newArrayList(res.at("/query/operands").elements()); |
| 452 | assertEquals("der", operands.get(0).at("/wrap/key").asText()); |
| 453 | assertEquals("Mann", operands.get(2).at("/wrap/key").asText()); |
| 454 | assertEquals("korap:group", operands.get(1).at("/@type").asText()); |
| 455 | assertEquals("operation:class", operands.get(1).at("/operation").asText()); |
| 456 | assertEquals(1, operands.get(1).at("/classOut").asInt()); |
| 457 | operands = Lists.newArrayList(operands.get(1).at("/operands").elements()); |
| 458 | assertEquals("korap:token", operands.get(0).at("/@type").asText()); |
| 459 | assertEquals(true, operands.get(0).at("/wrap").isMissingNode()); |
| 460 | |
| 461 | query = "[base=der]{2:[]}[base=Mann]"; |
| 462 | qs.setQuery(query, "poliqarpplus"); |
| 463 | res = mapper.readTree(qs.toJSON()); |
| 464 | operands = Lists.newArrayList(res.at("/query/operands").elements()); |
| 465 | assertEquals("operation:class", operands.get(1).at("/operation").asText()); |
| 466 | assertEquals(2, operands.get(1).at("/classOut").asInt()); |
| 467 | |
| 468 | query = "{1:[]}[base=der][base=Mann]"; |
| 469 | qs.setQuery(query, "poliqarpplus"); |
| 470 | res = mapper.readTree(qs.toJSON()); |
| 471 | operands = Lists.newArrayList(res.at("/query/operands").elements()); |
| 472 | assertEquals("operation:class", operands.get(0).at("/operation").asText()); |
| 473 | assertEquals(1, operands.get(0).at("/classOut").asInt()); |
Joachim Bingel | 1eef403 | 2014-11-07 13:11:01 +0000 | [diff] [blame] | 474 | |
| 475 | query = "{1:{2:der} {3:[]} Mann}"; |
| 476 | qs.setQuery(query, "poliqarpplus"); |
| 477 | res = mapper.readTree(qs.toJSON()); |
| 478 | operands = Lists.newArrayList(res.at("/query/operands").elements()); |
| 479 | assertEquals(1, operands.size()); // class operation may only have one operand (the sequence) |
| 480 | operands = Lists.newArrayList(operands.get(0).at("/operands").elements()); |
| 481 | assertEquals(3, operands.size()); // the sequence has three operands ("der", "[]" and "Mann") |
| 482 | |
Joachim Bingel | 3376363 | 2014-10-23 13:31:05 +0000 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | @Test |
| 486 | public void testLeadingTrailingEmptyTokens() throws QueryException, JsonProcessingException, IOException { |
| 487 | query = "[][base=Mann]"; |
| 488 | qs.setQuery(query, "poliqarpplus"); |
| 489 | res = mapper.readTree(qs.toJSON()); |
| 490 | operands = Lists.newArrayList(res.at("/query/operands").elements()); |
| 491 | assertEquals("korap:token", operands.get(0).at("/@type").asText()); |
| 492 | assertEquals(true, operands.get(0).at("/key").isMissingNode()); |
| 493 | |
| 494 | query = "[][][base=Mann]"; |
| 495 | qs.setQuery(query, "poliqarpplus"); |
| 496 | res = mapper.readTree(qs.toJSON()); |
| 497 | operands = Lists.newArrayList(res.at("/query/operands").elements()); |
| 498 | assertEquals("korap:group", operands.get(0).at("/@type").asText()); |
| 499 | assertEquals("operation:repetition",operands.get(0).at("/operation").asText()); |
| 500 | assertEquals(2, operands.get(0).at("/boundary/min").asInt()); |
| 501 | assertEquals(2, operands.get(0).at("/boundary/max").asInt()); |
| 502 | operands = Lists.newArrayList(operands.get(0).at("/operands").elements()); |
| 503 | assertEquals("korap:token", operands.get(0).at("/@type").asText()); |
| 504 | assertEquals(true, operands.get(0).at("/key").isMissingNode()); |
| 505 | |
| 506 | query = "startswith(<s>, [][base=Mann])"; |
| 507 | qs.setQuery(query, "poliqarpplus"); |
| 508 | res = mapper.readTree(qs.toJSON()); |
| 509 | operands = Lists.newArrayList(res.at("/query/operands")); |
| 510 | operands = Lists.newArrayList(operands.get(1).at("/operands")); |
| 511 | assertEquals("korap:token", operands.get(0).at("/@type").asText()); |
| 512 | assertEquals(true, operands.get(0).at("/key").isMissingNode()); |
| 513 | } |
Joachim Bingel | 1eef403 | 2014-11-07 13:11:01 +0000 | [diff] [blame] | 514 | |
| 515 | |
| 516 | |
Joachim Bingel | 4eacdd3 | 2014-10-22 15:49:47 +0000 | [diff] [blame] | 517 | // } |
| 518 | // |
| 519 | // @Test |
| 520 | // public void testCoordinatedFields() throws QueryException { |
| 521 | // // [base=Mann&(cas=N|cas=A)] |
| 522 | // String cof1 = |
| 523 | // "{@type=korap:token, wrap=" + |
| 524 | // "{@type=korap:termGroup, relation=relation:and, operands=[" + |
| 525 | // "{@type=korap:term, layer=lemma, key=Mann, match=match:eq}," + |
| 526 | // "{@type=korap:termGroup, relation=relation:or, operands=[" + |
| 527 | // "{@type=korap:term, layer=cas, key=N, match=match:eq}," + |
| 528 | // "{@type=korap:term, layer=cas, key=A, match=match:eq}" + |
| 529 | // "]}" + |
| 530 | // "]}" + |
| 531 | // "}"; |
| 532 | // ppt = new PoliqarpPlusTree("[base=Mann&(cas=N|cas=A)]"); |
| 533 | // map = ppt.getRequestMap().get("query").toString(); |
| 534 | // assertEquals(cof1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 535 | // |
| 536 | // |
| 537 | // assertEquals( |
| 538 | // new PoliqarpPlusTree(" [ base=Mann & ( cas=N | cas=A)] ").getRequestMap().get("query").toString(), |
| 539 | // new PoliqarpPlusTree("[base=Mann &(cas=N|cas=A)]").getRequestMap().get("query").toString() |
| 540 | // ); |
| 541 | // |
| 542 | // // [base=Mann&cas=N&gen=m] |
| 543 | // String cof2 = |
| 544 | // "{@type=korap:token, wrap=" + |
| 545 | // "{@type=korap:termGroup, relation=relation:and, operands=[" + |
| 546 | // "{@type=korap:term, layer=lemma, key=Mann, match=match:eq}," + |
| 547 | // "{@type=korap:termGroup, relation=relation:and, operands=[" + |
| 548 | // "{@type=korap:term, layer=cas, key=N, match=match:eq}," + |
| 549 | // "{@type=korap:term, layer=gen, key=m, match=match:eq}" + |
| 550 | // "]}" + |
| 551 | // "]}" + |
| 552 | // "}"; |
| 553 | // ppt = new PoliqarpPlusTree("[base=Mann&cas=N&gen=m]"); |
| 554 | // map = ppt.getRequestMap().get("query").toString(); |
| 555 | // assertEquals(cof2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 556 | // } |
| 557 | // |
| 558 | // @Test |
| 559 | // public void testOccurrence() throws QueryException { |
| 560 | // // [base=foo]* |
| 561 | // String occ1 = "{@type=korap:group, operation=operation:repetition, operands=[" + |
| 562 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" + |
| 563 | // "], boundary={@type=korap:boundary, min=0}, min=0}"; |
| 564 | // ppt = new PoliqarpPlusTree("[base=foo]*"); |
| 565 | // map = ppt.getRequestMap().get("query").toString(); |
| 566 | // assertEquals(occ1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 567 | // |
| 568 | // // [base=foo]*[base=bar] |
| 569 | // String occ2 = |
| 570 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 571 | // "{@type=korap:group, operation=operation:repetition, operands=[" + |
| 572 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" + |
| 573 | // "], boundary={@type=korap:boundary, min=0}, min=0 }," + |
| 574 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}" + |
| 575 | // "]}"; |
| 576 | // ppt = new PoliqarpPlusTree("[base=foo]*[base=bar]"); |
| 577 | // map = ppt.getRequestMap().get("query").toString(); |
| 578 | // assertEquals(occ2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 579 | // |
| 580 | // // [base=bar][base=foo]* |
| 581 | // String occ3 = |
| 582 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 583 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," + |
| 584 | // "{@type=korap:group, operation=operation:repetition, operands=[" + |
| 585 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" + |
| 586 | // "], boundary={@type=korap:boundary, min=0}, min=0 }" + |
| 587 | // "]}"; |
| 588 | // ppt = new PoliqarpPlusTree("[base=bar][base=foo]*"); |
| 589 | // map = ppt.getRequestMap().get("query").toString(); |
| 590 | // assertEquals(occ3.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 591 | // |
| 592 | // // ([base=bar][base=foo])* |
| 593 | // String occ4 = |
| 594 | // "{@type=korap:group, operation=operation:repetition, operands=[" + |
| 595 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 596 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," + |
| 597 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" + |
| 598 | // "]}" + |
| 599 | // "], boundary={@type=korap:boundary, min=0}, min=0}" ; |
| 600 | // ppt = new PoliqarpPlusTree("([base=bar][base=foo])*"); |
| 601 | // map = ppt.getRequestMap().get("query").toString(); |
| 602 | // assertEquals(occ4.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 603 | // |
| 604 | // // <s>([base=bar][base=foo])* |
| 605 | // String occ5 = |
| 606 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 607 | // "{@type=korap:span, key=s}," + |
| 608 | // "{@type=korap:group, operation=operation:repetition, operands=[" + |
| 609 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 610 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," + |
| 611 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" + |
| 612 | // "]}" + |
| 613 | // "], boundary={@type=korap:boundary, min=0}, min=0 }" + |
| 614 | // "]}" ; |
| 615 | // ppt = new PoliqarpPlusTree("<s>([base=bar][base=foo])*"); |
| 616 | // map = ppt.getRequestMap().get("query").toString(); |
| 617 | // assertEquals(occ5.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 618 | // |
| 619 | // // <s><np>([base=bar][base=foo])* |
| 620 | // String occ6 = |
| 621 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 622 | // "{@type=korap:span, key=s}," + |
| 623 | // "{@type=korap:span, key=np}," + |
| 624 | // "{@type=korap:group, operation=operation:repetition, operands=[" + |
| 625 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 626 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," + |
| 627 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" + |
| 628 | // "]}" + |
| 629 | // "], boundary={@type=korap:boundary, min=0}, min=0 }" + |
| 630 | // "]}" ; |
| 631 | // ppt = new PoliqarpPlusTree("<s><np>([base=bar][base=foo])*"); |
| 632 | // map = ppt.getRequestMap().get("query").toString(); |
| 633 | // assertEquals(occ6.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 634 | // |
| 635 | // // <s><np>([base=bar][base=foo])*[p=NN] |
| 636 | // // comment: embedded sequence shouldn't really be here, but does not really hurt, either. (?) |
| 637 | // // really hard to get this behaviour out of the PQPlus grammar... |
| 638 | // String occ7 = |
| 639 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 640 | // "{@type=korap:span, key=s}," + |
| 641 | // "{@type=korap:span, key=np}," + |
| 642 | // "{@type=korap:group, operation=operation:repetition, operands=[" + |
| 643 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 644 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," + |
| 645 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" + |
| 646 | // "]}" + |
| 647 | // "], boundary={@type=korap:boundary, min=0}, min=0 }," + |
| 648 | // "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}" + |
| 649 | // "]}" ; |
| 650 | // ppt = new PoliqarpPlusTree("<s><np>([base=bar][base=foo])*[p=NN]"); |
| 651 | // map = ppt.getRequestMap().get("query").toString(); |
| 652 | // assertEquals(occ7.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 653 | // |
| 654 | // // ([base=bar][base=foo])*[p=NN] |
| 655 | // String occ8 = |
| 656 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 657 | // "{@type=korap:group, operation=operation:repetition, operands=[" + |
| 658 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 659 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," + |
| 660 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" + |
| 661 | // "]}" + |
| 662 | // "], boundary={@type=korap:boundary, min=0}, min=0 }," + |
| 663 | // "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}" + |
| 664 | // "]}" ; |
| 665 | // ppt = new PoliqarpPlusTree("([base=bar][base=foo])*[p=NN]"); |
| 666 | // map = ppt.getRequestMap().get("query").toString(); |
| 667 | // assertEquals(occ8.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 668 | // |
| 669 | // // [base=foo]+ |
| 670 | // String occ9 = "{@type=korap:group, operation=operation:repetition, operands=[" + |
| 671 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" + |
| 672 | // "], boundary={@type=korap:boundary, min=1}, min=1}"; |
| 673 | // ppt = new PoliqarpPlusTree("[base=foo]+"); |
| 674 | // map = ppt.getRequestMap().get("query").toString(); |
| 675 | // assertEquals(occ9.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 676 | // |
| 677 | // // [base=foo]? |
| 678 | // String occ10 = "{@type=korap:group, operation=operation:repetition, operands=[" + |
| 679 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" + |
| 680 | // "], boundary={@type=korap:boundary, min=0, max=1}, min=0, max=1}"; |
| 681 | // ppt = new PoliqarpPlusTree("[base=foo]?"); |
| 682 | // map = ppt.getRequestMap().get("query").toString(); |
| 683 | // assertEquals(occ10.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 684 | // |
| 685 | // // [base=foo]{2,5} |
| 686 | // String occ11 = "{@type=korap:group, operation=operation:repetition, operands=[" + |
| 687 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" + |
| 688 | // "], boundary={@type=korap:boundary, min=2, max=5}, min=2, max=5}"; |
| 689 | // ppt = new PoliqarpPlusTree("[base=foo]{2,5}"); |
| 690 | // map = ppt.getRequestMap().get("query").toString(); |
| 691 | // assertEquals(occ11.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 692 | // |
| 693 | // // [base=foo]{2} |
| 694 | // String occ12 = "{@type=korap:group, operation=operation:repetition, operands=[" + |
| 695 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" + |
| 696 | // "], boundary={@type=korap:boundary, min=2, max=2}, min=2, max=2}"; |
| 697 | // ppt = new PoliqarpPlusTree("[base=foo]{2}"); |
| 698 | // map = ppt.getRequestMap().get("query").toString(); |
| 699 | // assertEquals(occ12.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 700 | // |
| 701 | // // [base=foo]{2} |
| 702 | // String occ13 = "{@type=korap:group, operation=operation:repetition, operands=[" + |
| 703 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" + |
| 704 | // "], boundary={@type=korap:boundary, min=2}, min=2}"; |
| 705 | // ppt = new PoliqarpPlusTree("[base=foo]{2,}"); |
| 706 | // map = ppt.getRequestMap().get("query").toString(); |
| 707 | // assertEquals(occ13.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 708 | // |
| 709 | // // [base=foo]{2} |
| 710 | // String occ14 = "{@type=korap:group, operation=operation:repetition, operands=[" + |
| 711 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" + |
| 712 | // "], boundary={@type=korap:boundary, min=0, max=2}, min=0, max=2}"; |
| 713 | // ppt = new PoliqarpPlusTree("[base=foo]{,2}"); |
| 714 | // map = ppt.getRequestMap().get("query").toString(); |
| 715 | // assertEquals(occ14.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 716 | // } |
| 717 | // |
| 718 | // @Test |
| 719 | // public void testTokenSequence() throws QueryException { |
| 720 | // // [base=Mann][orth=Frau] |
| 721 | // String seq1 = "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 722 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}, " + |
| 723 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}" + |
| 724 | // "]}"; |
| 725 | // assertTrue(equalsQueryContent(seq1, "[base=Mann][orth=Frau]")); |
| 726 | // |
| 727 | // // [base=Mann][orth=Frau][p=NN] |
| 728 | // String seq2 = "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 729 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}, " + |
| 730 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}, " + |
| 731 | // "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}" + |
| 732 | // "]}"; |
| 733 | // assertTrue(equalsQueryContent(seq2, "[base=Mann][orth=Frau][p=NN]")); |
| 734 | // } |
| 735 | // |
| 736 | // @Test |
| 737 | // public void testDisjSegments() throws QueryException { |
| 738 | // // ([base=der]|[base=das])[base=Schild] |
| 739 | // String disj1 = |
| 740 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 741 | // "{@type=korap:group, operation=operation:or, operands=[" + |
| 742 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," + |
| 743 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=das, match=match:eq}}" + |
| 744 | // "]}," + |
| 745 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Schild, match=match:eq}}" + |
| 746 | // "]}"; |
| 747 | // ppt = new PoliqarpPlusTree("([base=der]|[base=das])[base=Schild]"); |
| 748 | // map = ppt.getRequestMap().get("query").toString(); |
| 749 | // assertEquals(disj1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 750 | // |
| 751 | // // [base=Schild]([base=der]|[base=das]) |
| 752 | // String disj2 = |
| 753 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 754 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Schild, match=match:eq}}," + |
| 755 | // "{@type=korap:group, operation=operation:or, operands=[" + |
| 756 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," + |
| 757 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=das, match=match:eq}}" + |
| 758 | // "]}" + |
| 759 | // "]}"; |
| 760 | // ppt = new PoliqarpPlusTree("[base=Schild]([base=der]|[base=das])"); |
| 761 | // map = ppt.getRequestMap().get("query").toString(); |
| 762 | // assertEquals(disj2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 763 | // |
| 764 | // // "([orth=der][base=katze])|([orth=eine][base=baum])" |
| 765 | // String disj3 = |
| 766 | // "{@type=korap:group, operation=operation:or, operands=[" + |
| 767 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 768 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," + |
| 769 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=katze, match=match:eq}}" + |
| 770 | // "]}," + |
| 771 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 772 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=eine, match=match:eq}}," + |
| 773 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=baum, match=match:eq}}" + |
| 774 | // "]}" + |
| 775 | // "]}"; |
| 776 | // ppt = new PoliqarpPlusTree("([orth=der][base=katze])|([orth=eine][base=baum])"); |
| 777 | // map = ppt.getRequestMap().get("query").toString(); |
| 778 | // assertEquals(disj3.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 779 | // |
| 780 | // // "[orth=der][base=katze]|[orth=eine][base=baum]" |
| 781 | // String disj4 = |
| 782 | // "{@type=korap:group, operation=operation:or, operands=[" + |
| 783 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 784 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," + |
| 785 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=katze, match=match:eq}}" + |
| 786 | // "]}," + |
| 787 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 788 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=eine, match=match:eq}}," + |
| 789 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=baum, match=match:eq}}" + |
| 790 | // "]}" + |
| 791 | // "]}"; |
| 792 | // ppt = new PoliqarpPlusTree("[orth=der][base=katze]|[orth=eine][base=baum]"); |
| 793 | // map = ppt.getRequestMap().get("query").toString(); |
| 794 | // assertEquals(disj4.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 795 | // |
| 796 | // PoliqarpPlusTree ppt1 = new PoliqarpPlusTree("[orth=der][base=katze]|[orth=eine][base=baum]"); |
| 797 | // PoliqarpPlusTree ppt2 = new PoliqarpPlusTree("([orth=der][base=katze])|([orth=eine][base=baum])"); |
| 798 | // assertEquals(ppt1.getRequestMap().toString(), ppt2.getRequestMap().toString()); |
| 799 | // |
| 800 | // // "[orth=der][base=katze]|[orth=der][base=hund]|[orth=der][base=baum]" |
| 801 | // String disj5 = |
| 802 | // "{@type=korap:group, operation=operation:or, operands=[" + |
| 803 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 804 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," + |
| 805 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=katze, match=match:eq}}" + |
| 806 | // "]}," + |
| 807 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 808 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," + |
| 809 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=hund, match=match:eq}}" + |
| 810 | // "]}," + |
| 811 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 812 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," + |
| 813 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=baum, match=match:eq}}" + |
| 814 | // "]}" + |
| 815 | // "]}"; |
| 816 | // ppt = new PoliqarpPlusTree("[orth=der][base=katze]|[orth=der][base=hund]|[orth=der][base=baum]"); |
| 817 | // map = ppt.getRequestMap().get("query").toString(); |
| 818 | // assertEquals(disj5.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 819 | // |
| 820 | // // [orth=der]([base=katze]|[base=hund]|[base=baum]) |
| 821 | // String disj6 = |
| 822 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 823 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," + |
| 824 | // "{@type=korap:group, operation=operation:or, operands=[" + |
| 825 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=katze, match=match:eq}}," + |
| 826 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=hund, match=match:eq}}," + |
| 827 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=baum, match=match:eq}}" + |
| 828 | // "]}" + |
| 829 | // "]}"; |
| 830 | // ppt = new PoliqarpPlusTree("[orth=der]([base=katze]|[base=hund]|[base=baum])"); |
| 831 | // map = ppt.getRequestMap().get("query").toString(); |
| 832 | // assertEquals(disj6.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 833 | // } |
| 834 | // |
| 835 | // @Test |
| 836 | // public void testTokenElemSequence() throws QueryException { |
| 837 | // // [base=Mann]<vp> |
| 838 | // String seq1 = "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 839 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}, " + |
| 840 | // "{@type=korap:span, key=vp}" + |
| 841 | // "]}"; |
| 842 | // assertTrue(equalsQueryContent(seq1, "[base=Mann]<vp>")); |
| 843 | // |
| 844 | // // <vp>[base=Mann] |
| 845 | // String seq2 = "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 846 | // "{@type=korap:span, key=vp}, "+ |
| 847 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}} " + |
| 848 | // "]}"; |
| 849 | // assertTrue(equalsQueryContent(seq2, "<vp>[base=Mann]")); |
| 850 | // |
| 851 | // // <vp>[base=Mann]<pp> |
| 852 | // String seq3 = "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 853 | // "{@type=korap:span, key=vp}, "+ |
| 854 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}, " + |
| 855 | // "{@type=korap:span, key=pp} "+ |
| 856 | // "]}"; |
| 857 | // assertTrue(equalsQueryContent(seq3, "<vp>[base=Mann]<pp>")); |
| 858 | // } |
| 859 | // |
| 860 | // @Test |
| 861 | // public void testElemSequence() throws QueryException { |
| 862 | // // <np><vp> |
| 863 | // String seq1 = "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 864 | // "{@type=korap:span, key=np}," + |
| 865 | // "{@type=korap:span, key=vp}" + |
| 866 | // "]}"; |
| 867 | // assertTrue(equalsQueryContent(seq1, "<np><vp>")); |
| 868 | // |
| 869 | // // <np><vp><pp> |
| 870 | // String seq2 = "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 871 | // "{@type=korap:span, key=np}," + |
| 872 | // "{@type=korap:span, key=vp}," + |
| 873 | // "{@type=korap:span, key=pp}" + |
| 874 | // "]}"; |
| 875 | // assertTrue(equalsQueryContent(seq2, "<np><vp><pp>")); |
| 876 | // } |
| 877 | // |
| 878 | // @Test |
| 879 | // public void testClasses() throws QueryException { |
| 880 | // String query; |
| 881 | // // {[base=Mann]} |
| 882 | // String cls1 = "{@type=korap:group, operation=operation:class, class=0, classOut=0, operands=[" + |
| 883 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" + |
| 884 | // "]}"; |
| 885 | // ppt = new PoliqarpPlusTree("{[base=Mann]}"); |
| 886 | // map = ppt.getRequestMap().get("query").toString(); |
| 887 | // assertEquals(cls1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 888 | // |
| 889 | // // {[base=Mann][orth=Frau]} |
| 890 | // query = "{[base=Mann][orth=Frau]}"; |
| 891 | // String cls2 = "{@type=korap:group, operation=operation:class, class=0, classOut=0, operands=[" + |
| 892 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 893 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}," + |
| 894 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}" + |
| 895 | // "]}" + |
| 896 | // "]}"; |
| 897 | // ppt = new PoliqarpPlusTree(query); |
| 898 | // map = ppt.getRequestMap().get("query").toString(); |
| 899 | // assertEquals(cls2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 900 | // |
| 901 | // // [p=NN]{[base=Mann][orth=Frau]} |
| 902 | // String cls3 = "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 903 | // "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}," + |
| 904 | // "{@type=korap:group, operation=operation:class, class=0, classOut=0, operands=[" + |
| 905 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 906 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}," + |
| 907 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}" + |
| 908 | // "]}" + |
| 909 | // "]}" + |
| 910 | // "]}"; |
| 911 | // ppt = new PoliqarpPlusTree("[p=NN]{[base=Mann][orth=Frau]}"); |
| 912 | // map = ppt.getRequestMap().get("query").toString(); |
| 913 | // assertEquals(cls3.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 914 | // |
| 915 | // // {[base=Mann][orth=Frau]}[p=NN] |
| 916 | // String cls4 = "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 917 | // "{@type=korap:group, operation=operation:class, class=0, classOut=0, operands=[" + |
| 918 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 919 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}," + |
| 920 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}" + |
| 921 | // "]}" + |
| 922 | // "]}," + |
| 923 | // "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}" + |
| 924 | // "]}"; |
| 925 | // ppt = new PoliqarpPlusTree("{[base=Mann][orth=Frau]}[p=NN]"); |
| 926 | // map = ppt.getRequestMap().get("query").toString(); |
| 927 | // assertEquals(cls4.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 928 | // |
| 929 | // // {2:{1:[tt/p=ADJA]}[mate/p=NN]}" |
| 930 | // String cls5 = "{@type=korap:group, operation=operation:class, class=2, classOut=2, operands=[" + |
| 931 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 932 | // "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" + |
| 933 | // "{@type=korap:token, wrap={@type=korap:term, foundry=tt, layer=p, key=ADJA, match=match:eq}}" + |
| 934 | // "]}," + |
| 935 | // "{@type=korap:token, wrap={@type=korap:term, foundry=mate, layer=p, key=NN, match=match:eq}}" + |
| 936 | // "]}" + |
| 937 | // "]}"; |
| 938 | // ppt = new PoliqarpPlusTree("{2: {1:[tt/p=ADJA]}[mate/p=NN]}"); |
| 939 | // map = ppt.getRequestMap().get("query").toString(); |
| 940 | // assertEquals(cls5.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 941 | // } |
| 942 | // |
| 943 | // @Test |
| 944 | // public void testPositions() throws QueryException { |
| 945 | // // contains(<s>,<np>) |
| 946 | // String pos1 = "{@type=korap:group, operation=operation:position, frames=[frames:contains], operands=[" + |
| 947 | // "{@type=korap:span, key=s}," + |
| 948 | // "{@type=korap:span, key=np}" + |
| 949 | // "], frame=frame:contains}"; |
| 950 | // assertTrue(equalsQueryContent(pos1, "contains(<s>,<np>)")); |
| 951 | // |
| 952 | // // contains(<s>,[base=Mann]) |
| 953 | // String pos2 = "{@type=korap:group, operation=operation:position, frames=[frames:contains], operands=[" + |
| 954 | // "{@type=korap:span, key=s}," + |
| 955 | // "{@type=korap:token, wrap= {@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" + |
| 956 | // "], frame=frame:contains}"; |
| 957 | // assertTrue(equalsQueryContent(pos2, "contains(<s>,[base=Mann])")); |
| 958 | // |
| 959 | // // contains(<s>,[orth=der][orth=Mann]) |
| 960 | // String pos3 = "{@type=korap:group, operation=operation:position, frames=[frames:contains], operands=[" + |
| 961 | // "{@type=korap:span, key=s}," + |
| 962 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 963 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," + |
| 964 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" + |
| 965 | // "]}" + |
| 966 | // "], frame=frame:contains}"; |
| 967 | // ppt = new PoliqarpPlusTree("contains(<s>,[orth=der][orth=Mann])"); |
| 968 | // map = ppt.getRequestMap().get("query").toString(); |
| 969 | // assertEquals(pos3.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 970 | // |
| 971 | // // [base=Auto]contains(<s>,[base=Mann]) |
| 972 | // String pos4 = |
| 973 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 974 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Auto, match=match:eq}}," + |
| 975 | // "{@type=korap:group, operation=operation:position, frames=[frames:contains], operands=[" + |
| 976 | // "{@type=korap:span, key=s}," + |
| 977 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" + |
| 978 | // "], frame=frame:contains}" + |
| 979 | // "]}"; |
| 980 | // ppt = new PoliqarpPlusTree("[base=Auto]contains(<s>,[base=Mann])"); |
| 981 | // map = ppt.getRequestMap().get("query").toString(); |
| 982 | // assertEquals(pos4.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 983 | // |
| 984 | // // contains(<s>,[pos=N]*) |
| 985 | // String pos5 = |
| 986 | // "{@type=korap:group, operation=operation:position, frames=[frames:contains], operands=[" + |
| 987 | // "{@type=korap:span, key=s}," + |
| 988 | // "{@type=korap:group, operation=operation:repetition, " + |
| 989 | // "operands=[{@type=korap:token, wrap={@type=korap:term, layer=pos, key=N, match=match:eq}}" + |
| 990 | // "], boundary={@type=korap:boundary, min=0}, min=0" + |
| 991 | // "}" + |
| 992 | // "], frame=frame:contains}"; |
| 993 | // ppt = new PoliqarpPlusTree("contains(<s>,[pos=N]*)"); |
| 994 | // map = ppt.getRequestMap().get("query").toString(); |
| 995 | // assertEquals(pos5.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 996 | // |
| 997 | // // [base=Auto]contains(<s>,[pos=N]*) |
| 998 | // String pos6 = |
| 999 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 1000 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Auto, match=match:eq}}," + |
| 1001 | // "{@type=korap:group, operation=operation:position, frames=[frames:contains], operands=[" + |
| 1002 | // "{@type=korap:span, key=s}," + |
| 1003 | // "{@type=korap:group, operation=operation:repetition, " + |
| 1004 | // "operands=[{@type=korap:token, wrap={@type=korap:term, layer=pos, key=N, match=match:eq}}" + |
| 1005 | // "], boundary={@type=korap:boundary, min=0}, min=0" + |
| 1006 | // "}" + |
| 1007 | // "], frame=frame:contains}" + |
| 1008 | // "]}"; |
| 1009 | // ppt = new PoliqarpPlusTree("[base=Auto]contains(<s>,[pos=N]*)"); |
| 1010 | // map = ppt.getRequestMap().get("query").toString(); |
| 1011 | // assertEquals(pos6.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 1012 | // } |
| 1013 | // |
| 1014 | // @Test |
| 1015 | // public void testNestedPositions() throws QueryException { |
| 1016 | // // contains(<s>,startswith(<np>,[orth=Der])) |
| 1017 | // String npos1 = |
| 1018 | // "{@type=korap:group, operation=operation:position, frames=[frames:contains], operands=[" + |
| 1019 | // "{@type=korap:span, key=s}," + |
| 1020 | // "{@type=korap:group, operation=operation:position, frames=[frames:startswith], operands=[" + |
| 1021 | // "{@type=korap:span, key=np}," + |
| 1022 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}" + |
| 1023 | // "], frame=frame:startswith}" + |
| 1024 | // "], frame=frame:contains}"; |
| 1025 | // ppt = new PoliqarpPlusTree("contains(<s>, startswith(<np>,[orth=Der]))"); |
| 1026 | // map = ppt.getRequestMap().get("query").toString(); |
| 1027 | // assertEquals(npos1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 1028 | // } |
| 1029 | // |
| 1030 | // @Test |
| 1031 | // public void testFocusSplit() throws QueryException { |
| 1032 | // // focus([orth=Der]{[orth=Mann]}) |
| 1033 | // String shr1 = |
| 1034 | // "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" + |
| 1035 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 1036 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}," + |
| 1037 | // "{@type=korap:group, operation=operation:class, class=0, classOut=0, operands=[" + |
| 1038 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" + |
| 1039 | // "]}" + |
| 1040 | // "]}" + |
| 1041 | // "]}"; |
| 1042 | // ppt = new PoliqarpPlusTree("focus([orth=Der]{[orth=Mann]})"); |
| 1043 | // map = ppt.getRequestMap().get("query").toString(); |
| 1044 | // assertEquals(shr1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 1045 | // |
| 1046 | // // focus([orth=Der]{[orth=Mann][orth=geht]}) |
| 1047 | // String shr2 = |
| 1048 | // "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" + |
| 1049 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 1050 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}," + |
| 1051 | // "{@type=korap:group, operation=operation:class, class=0, classOut=0, operands=[" + |
| 1052 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 1053 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}," + |
| 1054 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=geht, match=match:eq}}" + |
| 1055 | // "]}" + |
| 1056 | // "]}" + |
| 1057 | // "]}" + |
| 1058 | // "]}"; |
| 1059 | // ppt = new PoliqarpPlusTree("focus([orth=Der]{[orth=Mann][orth=geht]})"); |
| 1060 | // map = ppt.getRequestMap().get("query").toString(); |
| 1061 | // assertEquals(shr2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 1062 | // |
| 1063 | // // focus(1:[orth=Der]{1:[orth=Mann][orth=geht]}) |
| 1064 | // String shr3 = |
| 1065 | // "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" + |
| 1066 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 1067 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}," + |
| 1068 | // "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" + |
| 1069 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 1070 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}," + |
| 1071 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=geht, match=match:eq}}" + |
| 1072 | // "]}" + |
| 1073 | // "]}" + |
| 1074 | // "]}" + |
| 1075 | // "]}"; |
| 1076 | // ppt = new PoliqarpPlusTree("focus(1:[orth=Der]{1:[orth=Mann][orth=geht]})"); |
| 1077 | // map = ppt.getRequestMap().get("query").toString(); |
| 1078 | // assertEquals(shr3.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 1079 | // |
| 1080 | // // focus(1:startswith(<s>,{1:<np>})) |
| 1081 | // String shr4 = |
| 1082 | // "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" + |
| 1083 | // "{@type=korap:group, operation=operation:position, frames=[frames:startswith], operands=[" + |
| 1084 | // "{@type=korap:span, key=s}," + |
| 1085 | // "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" + |
| 1086 | // "{@type=korap:span, key=np}" + |
| 1087 | // "]}" + |
| 1088 | // "], frame=frame:startswith}" + |
| 1089 | // "]}"; |
| 1090 | // ppt = new PoliqarpPlusTree("focus(1:startswith(<s>,{1:<np>}))"); |
| 1091 | // map = ppt.getRequestMap().get("query").toString(); |
| 1092 | // assertEquals(shr4.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 1093 | // |
| 1094 | // // focus(3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) |
| 1095 | // String shr5 = |
| 1096 | // "{@type=korap:reference, operation=operation:focus, classRef=[3], operands=[" + |
| 1097 | // "{@type=korap:group, operation=operation:position, frames=[frames:startswith], operands=[" + |
| 1098 | // "{@type=korap:span, key=s}," + |
| 1099 | // "{@type=korap:group, operation=operation:class, class=3, classOut=3, operands=[" + |
| 1100 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 1101 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," + |
| 1102 | // "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" + |
| 1103 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 1104 | // "{@type=korap:token, wrap={@type=korap:term, foundry=mate, layer=p, key=ADJA, match=match:eq}}," + |
| 1105 | // "{@type=korap:group, operation=operation:class, class=2, classOut=2, operands=[" + |
| 1106 | // "{@type=korap:token, wrap={@type=korap:term, foundry=tt, layer=p, key=NN, match=match:eq}}" + |
| 1107 | // "]}" + |
| 1108 | // "]}" + |
| 1109 | // "]}" + |
| 1110 | // "]}" + |
| 1111 | // "]}" + |
| 1112 | // "], frame=frame:startswith}" + |
| 1113 | // "]}"; |
| 1114 | // ppt = new PoliqarpPlusTree("focus(3:startswith(<s>,{3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) "); |
| 1115 | // map = ppt.getRequestMap().get("query").toString(); |
| 1116 | // assertEquals(shr5.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 1117 | // |
| 1118 | // // split(3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) |
| 1119 | // String shr6 = |
| 1120 | // "{@type=korap:reference, operation=operation:split, classRef=[3], operands=[" + |
| 1121 | // "{@type=korap:group, operation=operation:position, frames=[frames:startswith], operands=[" + |
| 1122 | // "{@type=korap:span, key=s}," + |
| 1123 | // "{@type=korap:group, operation=operation:class, class=3, classOut=3, operands=[" + |
| 1124 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 1125 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," + |
| 1126 | // "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" + |
| 1127 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 1128 | // "{@type=korap:token, wrap={@type=korap:term, foundry=mate, layer=p, key=ADJA, match=match:eq}}," + |
| 1129 | // "{@type=korap:group, operation=operation:class, class=2, classOut=2, operands=[" + |
| 1130 | // "{@type=korap:token, wrap={@type=korap:term, foundry=tt, layer=p, key=NN, match=match:eq}}" + |
| 1131 | // "]}" + |
| 1132 | // "]}" + |
| 1133 | // "]}" + |
| 1134 | // "]}" + |
| 1135 | // "]}" + |
| 1136 | // "], frame=frame:startswith}" + |
| 1137 | // "]}"; |
| 1138 | // ppt = new PoliqarpPlusTree("split(3:startswith(<s>,{3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) "); |
| 1139 | // map = ppt.getRequestMap().get("query").toString(); |
| 1140 | // assertEquals(shr6.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 1141 | // |
| 1142 | // // split(2|3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) |
| 1143 | // String shr7 = |
| 1144 | // "{@type=korap:reference, operation=operation:split, classRef=[2, 3], classRefOp=classRefOp:intersection, operands=[" + |
| 1145 | // "{@type=korap:group, operation=operation:position, frames=[frames:startswith], operands=[" + |
| 1146 | // "{@type=korap:span, key=s}," + |
| 1147 | // "{@type=korap:group, operation=operation:class, class=3, classOut=3, operands=[" + |
| 1148 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 1149 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," + |
| 1150 | // "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" + |
| 1151 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 1152 | // "{@type=korap:token, wrap={@type=korap:term, foundry=mate, layer=p, key=ADJA, match=match:eq}}," + |
| 1153 | // "{@type=korap:group, operation=operation:class, class=2, classOut=2, operands=[" + |
| 1154 | // "{@type=korap:token, wrap={@type=korap:term, foundry=tt, layer=p, key=NN, match=match:eq}}" + |
| 1155 | // "]}" + |
| 1156 | // "]}" + |
| 1157 | // "]}" + |
| 1158 | // "]}" + |
| 1159 | // "]}" + |
| 1160 | // "], frame=frame:startswith}" + |
| 1161 | // "]}"; |
| 1162 | // ppt = new PoliqarpPlusTree("split(2|3:startswith(<s>,{3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) "); |
| 1163 | // map = ppt.getRequestMap().get("query").toString(); |
| 1164 | // assertEquals(shr7.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 1165 | // |
| 1166 | // |
| 1167 | // String shr8 = |
| 1168 | // "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" + |
| 1169 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 1170 | // "{@type=korap:group, operation=operation:class, class=0, classOut=0, operands=[" + |
| 1171 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}" + |
| 1172 | // "]}," + |
| 1173 | // "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" + |
| 1174 | // "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=ADJA, match=match:eq}}" + |
| 1175 | // "]}" + |
| 1176 | // "]}" + |
| 1177 | // "]}"; |
| 1178 | // ppt = new PoliqarpPlusTree("focus(1:{[base=der]}{1:[pos=ADJA]})"); |
| 1179 | // map = ppt.getRequestMap().get("query").toString(); |
| 1180 | // assertEquals(shr8.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 1181 | // |
| 1182 | // } |
| 1183 | // |
| 1184 | // @Test |
| 1185 | // public void testSubspan() throws QueryException { |
| 1186 | // query = "submatch(1,:<s>)"; |
| 1187 | // expected = |
| 1188 | // "{@type=korap:reference, operation=operation:focus, operands=[" + |
| 1189 | // "{@type=korap:span, key=s}" + |
| 1190 | // "], spanRef=[1]" + |
| 1191 | // "}"; |
| 1192 | // ppt = new PoliqarpPlusTree(query); |
| 1193 | // map = ppt.getRequestMap().get("query").toString(); |
| 1194 | // assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 1195 | // |
| 1196 | // query = "submatch(1,4:<s>)"; |
| 1197 | // expected = |
| 1198 | // "{@type=korap:reference, operation=operation:focus, operands=[" + |
| 1199 | // "{@type=korap:span, key=s}" + |
| 1200 | // "], spanRef=[1,4]" + |
| 1201 | // "}"; |
| 1202 | // ppt = new PoliqarpPlusTree(query); |
| 1203 | // map = ppt.getRequestMap().get("query").toString(); |
| 1204 | // assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 1205 | // |
| 1206 | // query = "submatch(1,4:contains(<s>,[base=Haus]))"; |
| 1207 | // expected = |
| 1208 | // "{@type=korap:reference, operation=operation:focus, operands=[" + |
| 1209 | // "{@type=korap:group, operation=operation:position, frames=[frames:contains], operands=[" + |
| 1210 | // "{@type=korap:span, key=s}," + |
| 1211 | // "{@type=korap:token, wrap= {@type=korap:term, layer=lemma, key=Haus, match=match:eq}}" + |
| 1212 | // "], frame=frame:contains}" + |
| 1213 | // "], spanRef=[1,4]" + |
| 1214 | // "}"; |
| 1215 | // ppt = new PoliqarpPlusTree(query); |
| 1216 | // map = ppt.getRequestMap().get("query").toString(); |
| 1217 | // assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 1218 | // } |
| 1219 | // |
| 1220 | // @Test |
| 1221 | // public void testRelations() throws QueryException { |
| 1222 | // query = "relatesTo(<s>,<np>)"; |
| 1223 | // expected = |
| 1224 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 1225 | // "{@type=korap:span, key=s}," + |
| 1226 | // "{@type=korap:span, key=np}" + |
| 1227 | // "], relation={@type=korap:relation}" + |
| 1228 | // "}"; |
| 1229 | // ppt = new PoliqarpPlusTree(query); |
| 1230 | // map = ppt.getRequestMap().get("query").toString(); |
| 1231 | // assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 1232 | // |
| 1233 | // query = "relatesTo([base=Baum],<np>)"; |
| 1234 | // expected = |
| 1235 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 1236 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Baum, match=match:eq}}," + |
| 1237 | // "{@type=korap:span, key=np}" + |
| 1238 | // "], relation={@type=korap:relation}" + |
| 1239 | // "}"; |
| 1240 | // ppt = new PoliqarpPlusTree(query); |
| 1241 | // map = ppt.getRequestMap().get("query").toString(); |
| 1242 | // assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 1243 | // |
| 1244 | // query = "dominates(<np>,[base=Baum])"; |
| 1245 | // expected = |
| 1246 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 1247 | // "{@type=korap:span, key=np}," + |
| 1248 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Baum, match=match:eq}}" + |
| 1249 | // "], relation={@type=korap:relation, layer=c}" + |
| 1250 | // "}"; |
| 1251 | // ppt = new PoliqarpPlusTree(query); |
| 1252 | // map = ppt.getRequestMap().get("query").toString(); |
| 1253 | // assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 1254 | // |
| 1255 | // query = "dominates(cnx/c:<np>,[base=Baum])"; |
| 1256 | // expected = |
| 1257 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 1258 | // "{@type=korap:span, key=np}," + |
| 1259 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Baum, match=match:eq}}" + |
| 1260 | // "], relation={@type=korap:relation, layer=c, foundry=cnx}" + |
| 1261 | // "}"; |
| 1262 | // ppt = new PoliqarpPlusTree(query); |
| 1263 | // map = ppt.getRequestMap().get("query").toString(); |
| 1264 | // assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 1265 | // |
| 1266 | // query = "dominates(cnx/c*:<np>,[base=Baum])"; |
| 1267 | // expected = |
| 1268 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 1269 | // "{@type=korap:span, key=np}," + |
| 1270 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Baum, match=match:eq}}" + |
| 1271 | // "], relation={@type=korap:relation, layer=c, foundry=cnx, boundary={@type=korap:boundary, min=0}}" + |
| 1272 | // "}"; |
| 1273 | // ppt = new PoliqarpPlusTree(query); |
| 1274 | // map = ppt.getRequestMap().get("query").toString(); |
| 1275 | // assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 1276 | // |
| 1277 | // query = "dominates(cnx/c{1,5}:<np>,[base=Baum])"; |
| 1278 | // expected = |
| 1279 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 1280 | // "{@type=korap:span, key=np}," + |
| 1281 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Baum, match=match:eq}}" + |
| 1282 | // "], relation={@type=korap:relation, layer=c, foundry=cnx, boundary={@type=korap:boundary, min=1, max=5}}" + |
| 1283 | // "}"; |
| 1284 | // ppt = new PoliqarpPlusTree(query); |
| 1285 | // map = ppt.getRequestMap().get("query").toString(); |
| 1286 | // assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 1287 | // |
| 1288 | // query = "relatesTo(mate/d=HEAD:<np>,[base=Baum])"; |
| 1289 | // expected = |
| 1290 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 1291 | // "{@type=korap:span, key=np}," + |
| 1292 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Baum, match=match:eq}}" + |
| 1293 | // "], relation={@type=korap:relation, foundry=mate, layer=d, key=HEAD}" + |
| 1294 | // "}"; |
| 1295 | // ppt = new PoliqarpPlusTree(query); |
| 1296 | // map = ppt.getRequestMap().get("query").toString(); |
| 1297 | // assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 1298 | // |
| 1299 | // } |
| 1300 | // |
| 1301 | // |
| 1302 | // |
| 1303 | // @Test |
| 1304 | // public void testFoundries() throws QueryException { |
| 1305 | // // [tt/base=Mann] |
| 1306 | // String layer1 = "{@type=korap:token, wrap={@type=korap:term, foundry=tt, layer=lemma, key=Mann, match=match:eq}}"; |
| 1307 | // ppt = new PoliqarpPlusTree("[tt/base=Mann]"); |
| 1308 | // map = ppt.getRequestMap().get("query").toString(); |
| 1309 | // assertEquals(layer1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 1310 | // |
| 1311 | // } |
| 1312 | // |
| 1313 | // @Test |
| 1314 | // public void testAlign() throws QueryException { |
| 1315 | // // [orth=der]^[orth=Mann] |
| 1316 | // query = "[orth=der]^[orth=Mann]"; |
| 1317 | // expected = |
| 1318 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 1319 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," + |
| 1320 | // "{@type=korap:group, operation=operation:class, class=1025, classOut=1025, operands=[" + |
| 1321 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" + |
| 1322 | // "]}" + |
| 1323 | // "]}"; |
| 1324 | // metaExpected = |
| 1325 | // "{alignment=1025}"; |
| 1326 | // ppt = new PoliqarpPlusTree(query); |
| 1327 | // map = ppt.getRequestMap().get("query").toString(); |
| 1328 | // metaMap = ppt.getRequestMap().get("meta").toString(); |
| 1329 | // assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 1330 | // assertEquals(metaExpected.replaceAll(" ", ""), metaMap.replaceAll(" ", "")); |
| 1331 | // |
| 1332 | // // [orth=der]^[orth=große][orth=Mann] |
| 1333 | // query = "[orth=der]^[orth=große][orth=Mann]"; |
| 1334 | // String expected = |
| 1335 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 1336 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," + |
| 1337 | // "{@type=korap:group, operation=operation:class, class=1025, classOut=1025, operands=[" + |
| 1338 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 1339 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=große, match=match:eq}}," + |
| 1340 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" + |
| 1341 | // "]}" + |
| 1342 | // "]}" + |
| 1343 | // "]}"; |
| 1344 | // metaExpected = |
| 1345 | // "{alignment=1025}"; |
| 1346 | // ppt = new PoliqarpPlusTree(query); |
| 1347 | // map = ppt.getRequestMap().get("query").toString(); |
| 1348 | // metaMap = ppt.getRequestMap().get("meta").toString(); |
| 1349 | // assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 1350 | // assertEquals(metaExpected.replaceAll(" ", ""), metaMap.replaceAll(" ", "")); |
| 1351 | // |
| 1352 | // query = "([base=a]^[base=b])|[base=c]"; |
| 1353 | // expected = |
| 1354 | // "{@type=korap:group, operation=operation:or, operands=[" + |
| 1355 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 1356 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=a, match=match:eq}}," + |
| 1357 | // "{@type=korap:group, operation=operation:class, class=1025, classOut=1025, operands=[" + |
| 1358 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=b, match=match:eq}}" + |
| 1359 | // "]}" + |
| 1360 | // "]}," + |
| 1361 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=c, match=match:eq}}" + |
| 1362 | // "]}"; |
| 1363 | // metaExpected = |
| 1364 | // "{alignment=1025}"; |
| 1365 | // ppt = new PoliqarpPlusTree(query); |
| 1366 | // map = ppt.getRequestMap().get("query").toString(); |
| 1367 | // metaMap = ppt.getRequestMap().get("meta").toString(); |
| 1368 | // assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 1369 | // assertEquals(metaExpected.replaceAll(" ", ""), metaMap.replaceAll(" ", "")); |
| 1370 | // |
| 1371 | // query = "([base=a]^[base=b][base=c])|[base=d]"; |
| 1372 | // expected = |
| 1373 | // "{@type=korap:group, operation=operation:or, operands=[" + |
| 1374 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 1375 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=a, match=match:eq}}," + |
| 1376 | // "{@type=korap:group, operation=operation:class, class=1025, classOut=1025, operands=[" + |
| 1377 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 1378 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=b, match=match:eq}}," + |
| 1379 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=c, match=match:eq}}" + |
| 1380 | // "]}" + |
| 1381 | // "]}" + |
| 1382 | // "]}," + |
| 1383 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=d, match=match:eq}}" + |
| 1384 | // "]}"; |
| 1385 | // metaExpected = |
| 1386 | // "{alignment=1025}"; |
| 1387 | // ppt = new PoliqarpPlusTree(query); |
| 1388 | // map = ppt.getRequestMap().get("query").toString(); |
| 1389 | // metaMap = ppt.getRequestMap().get("meta").toString(); |
| 1390 | // assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 1391 | // assertEquals(metaExpected.replaceAll(" ", ""), metaMap.replaceAll(" ", "")); |
| 1392 | // |
| 1393 | // query = "([base=a]^[base=b]^[base=c])|[base=d]"; |
| 1394 | // expected = |
| 1395 | // "{@type=korap:group, operation=operation:or, operands=[" + |
| 1396 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 1397 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=a, match=match:eq}}," + |
| 1398 | // "{@type=korap:group, operation=operation:class, class=1025, classOut=1025, operands=[" + |
| 1399 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 1400 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=b, match=match:eq}}," + |
| 1401 | // "{@type=korap:group, operation=operation:class, class=1026, classOut=1026, operands=[" + |
| 1402 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=c, match=match:eq}}" + |
| 1403 | // "]}" + |
| 1404 | // "]}" + |
| 1405 | // "]}" + |
| 1406 | // "]}," + |
| 1407 | // "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=d, match=match:eq}}" + |
| 1408 | // "]}"; |
| 1409 | // metaExpected = |
| 1410 | // "{alignment=[1025,1026]}"; |
| 1411 | // ppt = new PoliqarpPlusTree(query); |
| 1412 | // map = ppt.getRequestMap().get("query").toString(); |
| 1413 | // metaMap = ppt.getRequestMap().get("meta").toString(); |
| 1414 | // assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 1415 | // assertEquals(metaExpected.replaceAll(" ", ""), metaMap.replaceAll(" ", "")); |
| 1416 | // |
| 1417 | // |
| 1418 | // } |
| 1419 | // |
| 1420 | // @Test |
| 1421 | // public void testSimpleQueries() throws QueryException { |
| 1422 | // // Baum |
| 1423 | // String simple1 = |
| 1424 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq}}"; |
| 1425 | // ppt = new PoliqarpPlusTree("Baum"); |
| 1426 | // map = ppt.getRequestMap().get("query").toString(); |
| 1427 | // assertEquals(simple1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 1428 | // |
| 1429 | // // Baum/i |
| 1430 | // String simple1b = |
| 1431 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq, caseInsensitive=true}}"; |
| 1432 | // ppt = new PoliqarpPlusTree("Baum/i"); |
| 1433 | // map = ppt.getRequestMap().get("query").toString(); |
| 1434 | // assertEquals(simple1b.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 1435 | // |
| 1436 | // // Der Baum |
| 1437 | // String simple2 = |
| 1438 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 1439 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}, " + |
| 1440 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq}}" + |
| 1441 | // "]}"; |
| 1442 | // ppt = new PoliqarpPlusTree("Der Baum"); |
| 1443 | // map = ppt.getRequestMap().get("query").toString(); |
| 1444 | // assertEquals(simple2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 1445 | // |
| 1446 | // // Der Baum/i |
| 1447 | // String simple2b = |
| 1448 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 1449 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}, " + |
| 1450 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq, caseInsensitive=true}}" + |
| 1451 | // "]}"; |
| 1452 | // ppt = new PoliqarpPlusTree("Der Baum/i"); |
| 1453 | // map = ppt.getRequestMap().get("query").toString(); |
| 1454 | // assertEquals(simple2b.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 1455 | // |
| 1456 | // // Der große Baum |
| 1457 | // String simple3 = |
| 1458 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 1459 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}, " + |
| 1460 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=große, match=match:eq}}, " + |
| 1461 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq}}" + |
| 1462 | // "]}"; |
| 1463 | // ppt = new PoliqarpPlusTree("Der große Baum"); |
| 1464 | // map = ppt.getRequestMap().get("query").toString(); |
| 1465 | // assertEquals(simple3.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 1466 | // |
| 1467 | // // Baum | Stein |
| 1468 | // String simple4 = |
| 1469 | // "{@type=korap:group, operation=operation:or, operands=[" + |
| 1470 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq}}, " + |
| 1471 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Stein, match=match:eq}}" + |
| 1472 | // "]}"; |
| 1473 | // ppt = new PoliqarpPlusTree("Baum | Stein"); |
| 1474 | // map = ppt.getRequestMap().get("query").toString(); |
| 1475 | // assertEquals(simple4.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 1476 | // |
| 1477 | // // Baum | Stein Haus |
| 1478 | // String query = "(Baum | Stein) Haus"; |
| 1479 | // String simple5 = |
| 1480 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 1481 | // "{@type=korap:group, operation=operation:or, operands=[" + |
| 1482 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq}}, " + |
| 1483 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Stein, match=match:eq}}" + |
| 1484 | // "]}," + |
| 1485 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Haus, match=match:eq}} " + |
| 1486 | // "]}"; |
| 1487 | // ppt = new PoliqarpPlusTree(query); |
| 1488 | // map = ppt.getRequestMap().get("query").toString(); |
| 1489 | // assertEquals(simple5.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 1490 | // } |
| 1491 | } |