Joachim Bingel | 019ba5c | 2014-04-28 14:59:04 +0000 | [diff] [blame] | 1 | import static org.junit.Assert.*; |
| 2 | |
Joachim Bingel | 66472b8 | 2014-12-04 16:00:05 +0000 | [diff] [blame] | 3 | import java.io.IOException; |
| 4 | import java.util.ArrayList; |
| 5 | |
Joachim Bingel | 019ba5c | 2014-04-28 14:59:04 +0000 | [diff] [blame] | 6 | import org.junit.Test; |
| 7 | |
Joachim Bingel | 66472b8 | 2014-12-04 16:00:05 +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 | |
| 12 | import de.ids_mannheim.korap.query.serialize.QuerySerializer; |
Joachim Bingel | 019ba5c | 2014-04-28 14:59:04 +0000 | [diff] [blame] | 13 | import de.ids_mannheim.korap.util.QueryException; |
| 14 | |
Joachim Bingel | 66472b8 | 2014-12-04 16:00:05 +0000 | [diff] [blame] | 15 | /** |
| 16 | * Tests for JSON-LD serialization of ANNIS QL queries. |
| 17 | * @author Joachim Bingel (bingel@ids-mannheim.de) |
| 18 | * @version 1.0 |
| 19 | */ |
Joachim Bingel | 019ba5c | 2014-04-28 14:59:04 +0000 | [diff] [blame] | 20 | public class AqlTreeTest { |
| 21 | |
Joachim Bingel | 66472b8 | 2014-12-04 16:00:05 +0000 | [diff] [blame] | 22 | String query; |
| 23 | ArrayList<JsonNode> operands; |
Joachim Bingel | 019ba5c | 2014-04-28 14:59:04 +0000 | [diff] [blame] | 24 | |
Joachim Bingel | 66472b8 | 2014-12-04 16:00:05 +0000 | [diff] [blame] | 25 | QuerySerializer qs = new QuerySerializer(); |
| 26 | ObjectMapper mapper = new ObjectMapper(); |
| 27 | JsonNode res; |
| 28 | |
| 29 | @Test |
| 30 | public void testContext() throws QueryException, JsonProcessingException, IOException { |
| 31 | String contextUrl = "http://ids-mannheim.de/ns/KorAP/json-ld/v0.2/context.jsonld"; |
| 32 | query = "foo"; |
| 33 | qs.setQuery(query, "annis"); |
| 34 | res = mapper.readTree(qs.toJSON()); |
| 35 | assertEquals(contextUrl, res.get("@context").asText()); |
Joachim Bingel | 019ba5c | 2014-04-28 14:59:04 +0000 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | @Test |
Joachim Bingel | 66472b8 | 2014-12-04 16:00:05 +0000 | [diff] [blame] | 39 | public void testSingleTokens() throws QueryException, JsonProcessingException, IOException { |
Joachim Bingel | 019ba5c | 2014-04-28 14:59:04 +0000 | [diff] [blame] | 40 | query = "\"Mann\""; |
Joachim Bingel | 66472b8 | 2014-12-04 16:00:05 +0000 | [diff] [blame] | 41 | qs.setQuery(query, "annis"); |
| 42 | res = mapper.readTree(qs.toJSON()); |
| 43 | assertEquals("korap:token", res.at("/query/@type").asText()); |
| 44 | assertEquals("korap:term", res.at("/query/wrap/@type").asText()); |
| 45 | assertEquals("orth", res.at("/query/wrap/layer").asText()); |
| 46 | assertEquals("Mann", res.at("/query/wrap/key").asText()); |
| 47 | assertEquals("match:eq", res.at("/query/wrap/match").asText()); |
Joachim Bingel | 019ba5c | 2014-04-28 14:59:04 +0000 | [diff] [blame] | 48 | |
Joachim Bingel | 019ba5c | 2014-04-28 14:59:04 +0000 | [diff] [blame] | 49 | query = "tok!=\"Frau\""; |
Joachim Bingel | 66472b8 | 2014-12-04 16:00:05 +0000 | [diff] [blame] | 50 | qs.setQuery(query, "annis"); |
| 51 | res = mapper.readTree(qs.toJSON()); |
| 52 | assertEquals("korap:token", res.at("/query/@type").asText()); |
| 53 | assertEquals("korap:term", res.at("/query/wrap/@type").asText()); |
| 54 | assertEquals("orth", res.at("/query/wrap/layer").asText()); |
| 55 | assertEquals("Frau", res.at("/query/wrap/key").asText()); |
| 56 | assertEquals("match:ne", res.at("/query/wrap/match").asText()); |
Joachim Bingel | 019ba5c | 2014-04-28 14:59:04 +0000 | [diff] [blame] | 57 | |
Joachim Bingel | 66472b8 | 2014-12-04 16:00:05 +0000 | [diff] [blame] | 58 | query = "tok"; // special keyword for token |
| 59 | qs.setQuery(query, "annis"); |
| 60 | res = mapper.readTree(qs.toJSON()); |
| 61 | assertEquals("korap:token", res.at("/query/@type").asText()); |
Joachim Bingel | c9c0cf9 | 2014-10-02 12:03:59 +0000 | [diff] [blame] | 62 | |
Joachim Bingel | 66472b8 | 2014-12-04 16:00:05 +0000 | [diff] [blame] | 63 | query = "Mann"; // no special keyword -> defaults to layer name |
| 64 | qs.setQuery(query, "annis"); |
| 65 | res = mapper.readTree(qs.toJSON()); |
| 66 | assertEquals("korap:span", res.at("/query/@type").asText()); |
| 67 | assertEquals("Mann", res.at("/query/layer").asText()); |
Joachim Bingel | 019ba5c | 2014-04-28 14:59:04 +0000 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | @Test |
Joachim Bingel | 66472b8 | 2014-12-04 16:00:05 +0000 | [diff] [blame] | 71 | public void testSpans() throws QueryException, JsonProcessingException, IOException { |
| 72 | query = "node"; // special keyword for general span |
| 73 | qs.setQuery(query, "annis"); |
| 74 | res = mapper.readTree(qs.toJSON()); |
| 75 | assertEquals("korap:span", res.at("/query/@type").asText()); |
| 76 | |
| 77 | query = "cat=\"np\""; // cat is special keyword for spans |
| 78 | qs.setQuery(query, "annis"); |
| 79 | res = mapper.readTree(qs.toJSON()); |
| 80 | assertEquals("korap:span", res.at("/query/@type").asText()); |
| 81 | assertEquals("np", res.at("/query/key").asText()); |
| 82 | assertEquals("c", res.at("/query/layer").asText()); |
| 83 | |
| 84 | query = "cat=\"NP\""; |
| 85 | qs.setQuery(query, "annis"); |
| 86 | res = mapper.readTree(qs.toJSON()); |
| 87 | assertEquals("korap:span", res.at("/query/@type").asText()); |
| 88 | assertEquals("NP", res.at("/query/key").asText()); |
| 89 | assertEquals("c", res.at("/query/layer").asText()); |
Joachim Bingel | 019ba5c | 2014-04-28 14:59:04 +0000 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | @Test |
Joachim Bingel | 66472b8 | 2014-12-04 16:00:05 +0000 | [diff] [blame] | 93 | public void testRegex() throws QueryException, JsonProcessingException, IOException { |
| 94 | query = "/Mann/"; |
| 95 | qs.setQuery(query, "annis"); |
| 96 | res = mapper.readTree(qs.toJSON()); |
| 97 | assertEquals("korap:token", res.at("/query/@type").asText()); |
| 98 | assertEquals("korap:term", res.at("/query/wrap/@type").asText()); |
| 99 | assertEquals("type:regex", res.at("/query/wrap/type").asText()); |
| 100 | assertEquals("orth", res.at("/query/wrap/layer").asText()); |
| 101 | assertEquals("Mann", res.at("/query/wrap/key").asText()); |
| 102 | assertEquals("match:eq", res.at("/query/wrap/match").asText()); |
Joachim Bingel | e49b467 | 2014-07-16 08:06:56 +0000 | [diff] [blame] | 103 | |
Joachim Bingel | 66472b8 | 2014-12-04 16:00:05 +0000 | [diff] [blame] | 104 | query = "/.*?Mann.*?/"; |
| 105 | qs.setQuery(query, "annis"); |
| 106 | res = mapper.readTree(qs.toJSON()); |
| 107 | assertEquals("type:regex", res.at("/query/wrap/type").asText()); |
| 108 | assertEquals(".*?Mann.*?", res.at("/query/wrap/key").asText()); |
Joachim Bingel | 019ba5c | 2014-04-28 14:59:04 +0000 | [diff] [blame] | 109 | } |
Joachim Bingel | aee38ae | 2014-06-25 09:32:56 +0000 | [diff] [blame] | 110 | |
Joachim Bingel | ca4944e | 2014-06-13 13:55:10 +0000 | [diff] [blame] | 111 | @Test |
Joachim Bingel | 66472b8 | 2014-12-04 16:00:05 +0000 | [diff] [blame] | 112 | public void testFoundriesLayers() throws QueryException, JsonProcessingException, IOException { |
| 113 | query = "c=\"np\""; |
| 114 | qs.setQuery(query, "annis"); |
| 115 | res = mapper.readTree(qs.toJSON()); |
| 116 | assertEquals("korap:span", res.at("/query/@type").asText()); |
| 117 | assertEquals("np", res.at("/query/key").asText()); |
| 118 | assertEquals("c", res.at("/query/layer").asText()); |
Joachim Bingel | ca4944e | 2014-06-13 13:55:10 +0000 | [diff] [blame] | 119 | |
Joachim Bingel | 66472b8 | 2014-12-04 16:00:05 +0000 | [diff] [blame] | 120 | query = "cnx/c=\"np\""; |
| 121 | qs.setQuery(query, "annis"); |
| 122 | res = mapper.readTree(qs.toJSON()); |
| 123 | assertEquals("korap:span", res.at("/query/@type").asText()); |
| 124 | assertEquals("np", res.at("/query/key").asText()); |
| 125 | assertEquals("c", res.at("/query/layer").asText()); |
| 126 | assertEquals("cnx", res.at("/query/foundry").asText()); |
Joachim Bingel | ca4944e | 2014-06-13 13:55:10 +0000 | [diff] [blame] | 127 | |
Joachim Bingel | 66472b8 | 2014-12-04 16:00:05 +0000 | [diff] [blame] | 128 | query = "tt/pos=\"np\""; |
| 129 | qs.setQuery(query, "annis"); |
| 130 | res = mapper.readTree(qs.toJSON()); |
| 131 | assertEquals("korap:token", res.at("/query/@type").asText()); |
| 132 | assertEquals("korap:term", res.at("/query/wrap/@type").asText()); |
| 133 | assertEquals("np", res.at("/query/wrap/key").asText()); |
| 134 | assertEquals("p", res.at("/query/wrap/layer").asText()); |
| 135 | assertEquals("tt", res.at("/query/wrap/foundry").asText()); |
Joachim Bingel | e6d73b1 | 2014-09-30 15:34:59 +0000 | [diff] [blame] | 136 | } |
| 137 | |
Joachim Bingel | 66472b8 | 2014-12-04 16:00:05 +0000 | [diff] [blame] | 138 | @Test |
| 139 | public void testDirectDeclarationRelations() throws QueryException, JsonProcessingException, IOException { |
| 140 | query = "node > node"; |
| 141 | qs.setQuery(query, "annis"); |
| 142 | res = mapper.readTree(qs.toJSON()); |
| 143 | assertEquals("korap:group", res.at("/query/@type").asText()); |
| 144 | assertEquals("operation:relation", res.at("/query/operation").asText()); |
| 145 | assertEquals("korap:span", res.at("/query/operands/0/@type").asText()); |
| 146 | assertEquals("korap:span", res.at("/query/operands/1/@type").asText()); |
| 147 | assertEquals("korap:relation", res.at("/query/relation/@type").asText()); |
| 148 | assertEquals("korap:term", res.at("/query/relation/wrap/@type").asText()); |
| 149 | assertEquals("c", res.at("/query/relation/wrap/layer").asText()); |
| 150 | |
| 151 | query = "node > cnx/c=\"np\""; |
| 152 | qs.setQuery(query, "annis"); |
| 153 | res = mapper.readTree(qs.toJSON()); |
| 154 | assertEquals("korap:group", res.at("/query/@type").asText()); |
| 155 | assertEquals("operation:relation", res.at("/query/operation").asText()); |
| 156 | assertEquals("korap:span", res.at("/query/operands/0/@type").asText()); |
| 157 | assertEquals("korap:span", res.at("/query/operands/1/@type").asText()); |
| 158 | assertEquals("np", res.at("/query/operands/1/key").asText()); |
| 159 | assertEquals("c", res.at("/query/operands/1/layer").asText()); |
| 160 | assertEquals("cnx", res.at("/query/operands/1/foundry").asText()); |
| 161 | assertEquals("korap:relation", res.at("/query/relation/@type").asText()); |
| 162 | assertEquals("korap:term", res.at("/query/relation/wrap/@type").asText()); |
| 163 | assertEquals("c", res.at("/query/relation/wrap/layer").asText()); |
| 164 | |
| 165 | query = "cnx/c=\"np\" > node"; |
| 166 | qs.setQuery(query, "annis"); |
| 167 | res = mapper.readTree(qs.toJSON()); |
| 168 | assertEquals(true, res.at("/query/operands/1/key").isMissingNode()); |
| 169 | assertEquals("np", res.at("/query/operands/0/key").asText()); |
| 170 | } |
| 171 | |
| 172 | @Test |
| 173 | public void testDefPredicationInversion() throws QueryException, JsonProcessingException, IOException { |
| 174 | query = "#1 > #2 & cnx/cat=\"vp\" & cnx/cat=\"np\""; |
| 175 | qs.setQuery(query, "annis"); |
| 176 | res = mapper.readTree(qs.toJSON()); |
| 177 | assertEquals("korap:group", res.at("/query/@type").asText()); |
| 178 | assertEquals("operation:relation", res.at("/query/operation").asText()); |
| 179 | assertEquals("korap:span", res.at("/query/operands/0/@type").asText()); |
| 180 | assertEquals("korap:span", res.at("/query/operands/0/@type").asText()); |
| 181 | assertEquals("vp", res.at("/query/operands/0/key").asText()); |
| 182 | assertEquals("c", res.at("/query/operands/0/layer").asText()); |
| 183 | assertEquals("cnx", res.at("/query/operands/0/foundry").asText()); |
| 184 | assertEquals("korap:span", res.at("/query/operands/1/@type").asText()); |
| 185 | assertEquals("np", res.at("/query/operands/1/key").asText()); |
| 186 | assertEquals("c", res.at("/query/operands/1/layer").asText()); |
| 187 | assertEquals("cnx", res.at("/query/operands/1/foundry").asText()); |
| 188 | assertEquals("korap:relation", res.at("/query/relation/@type").asText()); |
| 189 | assertEquals("korap:term", res.at("/query/relation/wrap/@type").asText()); |
| 190 | assertEquals("c", res.at("/query/relation/wrap/layer").asText()); |
| 191 | } |
| 192 | |
| 193 | @Test |
| 194 | public void testSimpleDominance() throws QueryException, JsonProcessingException, IOException { |
| 195 | query = "node & node & #2 > #1"; |
| 196 | qs.setQuery(query, "annis"); |
| 197 | res = mapper.readTree(qs.toJSON()); |
| 198 | assertEquals("korap:group", res.at("/query/@type").asText()); |
| 199 | assertEquals("operation:relation", res.at("/query/operation").asText()); |
| 200 | assertEquals("korap:span", res.at("/query/operands/0/@type").asText()); |
| 201 | assertEquals("korap:span", res.at("/query/operands/1/@type").asText()); |
| 202 | assertEquals("korap:relation", res.at("/query/relation/@type").asText()); |
| 203 | assertEquals("korap:term", res.at("/query/relation/wrap/@type").asText()); |
| 204 | assertEquals("c", res.at("/query/relation/wrap/layer").asText()); |
| 205 | |
| 206 | query = "\"Mann\" & node & #2 > #1"; |
| 207 | qs.setQuery(query, "annis"); |
| 208 | res = mapper.readTree(qs.toJSON()); |
| 209 | assertEquals("korap:group", res.at("/query/@type").asText()); |
| 210 | assertEquals("operation:relation", res.at("/query/operation").asText()); |
| 211 | assertEquals("korap:span", res.at("/query/operands/0/@type").asText()); |
| 212 | assertEquals("korap:token", res.at("/query/operands/1/@type").asText()); |
| 213 | assertEquals("Mann", res.at("/query/operands/1/wrap/key").asText()); |
| 214 | assertEquals("korap:relation", res.at("/query/relation/@type").asText()); |
| 215 | assertEquals("korap:term", res.at("/query/relation/wrap/@type").asText()); |
| 216 | assertEquals("c", res.at("/query/relation/wrap/layer").asText()); |
| 217 | |
| 218 | query = "\"Mann\" & node & #2 >[func=\"SB\"] #1"; //coordinates the func=SB term and requires a "c"-layer term (consituency relation/dominance) |
| 219 | qs.setQuery(query, "annis"); |
| 220 | res = mapper.readTree(qs.toJSON()); |
| 221 | assertEquals("korap:relation", res.at("/query/relation/@type").asText()); |
| 222 | assertEquals("korap:termGroup", res.at("/query/relation/wrap/@type").asText()); |
| 223 | assertEquals("relation:and", res.at("/query/relation/wrap/relation").asText()); |
| 224 | assertEquals("c", res.at("/query/relation/wrap/operands/1/layer").asText()); |
| 225 | assertEquals("func", res.at("/query/relation/wrap/operands/0/layer").asText()); |
| 226 | assertEquals("SB", res.at("/query/relation/wrap/operands/0/key").asText()); |
| 227 | |
| 228 | query = "cat=\"S\" & node & #1 >[func=\"SB\" func=\"MO\"] #2"; // quite meaningless (function is subject and modifier), but this is allowed by Annis, however its backend only regards the 1st option |
| 229 | qs.setQuery(query, "annis"); |
| 230 | res = mapper.readTree(qs.toJSON()); |
| 231 | assertEquals("korap:relation", res.at("/query/relation/@type").asText()); |
| 232 | assertEquals("korap:termGroup", res.at("/query/relation/wrap/@type").asText()); |
| 233 | assertEquals("relation:and", res.at("/query/relation/wrap/relation").asText()); |
| 234 | assertEquals("func", res.at("/query/relation/wrap/operands/0/layer").asText()); |
| 235 | assertEquals("SB", res.at("/query/relation/wrap/operands/0/key").asText()); |
| 236 | assertEquals("func", res.at("/query/relation/wrap/operands/1/layer").asText()); |
| 237 | assertEquals("MO" , res.at("/query/relation/wrap/operands/1/key").asText()); |
| 238 | assertEquals("c", res.at("/query/relation/wrap/operands/2/layer").asText()); |
| 239 | |
| 240 | query = "cat=\"S\" & cat=\"NP\" & #1 >@l #2"; // all sentences starting with subject -> wrap operands in startswith and retrieve 2nd operand with focus |
| 241 | qs.setQuery(query, "annis"); |
| 242 | res = mapper.readTree(qs.toJSON()); |
| 243 | assertEquals("operation:relation", res.at("/query/operation").asText()); |
| 244 | assertEquals("operation:position", res.at("/query/operands/0/operation").asText()); |
| 245 | assertEquals("frames:startswith", res.at("/query/operands/0/frames/0").asText()); |
| 246 | assertEquals("korap:span", res.at("/query/operands/0/operands/0/@type").asText()); |
| 247 | assertEquals("S", res.at("/query/operands/0/operands/0/key").asText()); |
| 248 | assertEquals("korap:group", res.at("/query/operands/0/operands/1/@type").asText()); |
| 249 | assertEquals("operation:class", res.at("/query/operands/0/operands/1/operation").asText()); |
| 250 | assertEquals(128, res.at("/query/operands/0/operands/1/classOut").asInt()); |
| 251 | assertEquals("korap:span", res.at("/query/operands/0/operands/1/operands/0/@type").asText()); |
| 252 | assertEquals("NP", res.at("/query/operands/0/operands/1/operands/0/key").asText()); |
| 253 | assertEquals("korap:reference", res.at("/query/operands/1/@type").asText()); |
| 254 | assertEquals("operation:focus", res.at("/query/operands/1/operation").asText()); |
| 255 | assertEquals(128, res.at("/query/operands/1/classRef/0").asInt()); |
| 256 | } |
| 257 | |
| 258 | @Test |
| 259 | public void testIndirectDominance() throws QueryException, JsonProcessingException, IOException { |
| 260 | query = "node & node & #1 >2,4 #2"; |
| 261 | qs.setQuery(query, "annis"); |
| 262 | res = mapper.readTree(qs.toJSON()); |
| 263 | assertEquals("korap:group", res.at("/query/@type").asText()); |
| 264 | assertEquals("operation:relation", res.at("/query/operation").asText()); |
| 265 | assertEquals("korap:span", res.at("/query/operands/0/@type").asText()); |
| 266 | assertEquals("korap:span", res.at("/query/operands/1/@type").asText()); |
| 267 | assertEquals("korap:relation", res.at("/query/relation/@type").asText()); |
| 268 | assertEquals(2, res.at("/query/relation/boundary/min").asInt()); |
| 269 | assertEquals(4, res.at("/query/relation/boundary/max").asInt()); |
| 270 | assertEquals("korap:term", res.at("/query/relation/wrap/@type").asText()); |
| 271 | assertEquals("c", res.at("/query/relation/wrap/layer").asText()); |
| 272 | |
| 273 | query = "node & node & #1 >* #2"; |
| 274 | qs.setQuery(query, "annis"); |
| 275 | res = mapper.readTree(qs.toJSON()); |
| 276 | assertEquals(0, res.at("/query/relation/boundary/min").asInt()); |
| 277 | assertEquals(true, res.at("/query/relation/boundary/max").isMissingNode()); |
| 278 | } |
| 279 | |
| 280 | // |
| 281 | // @Test |
| 282 | // public void testMultipleDominance() throws QueryException { |
| 283 | // query = "cat=\"CP\" & cat=\"VP\" & cat=\"NP\" & #1 > #2 > #3"; |
| 284 | // String dom1 = |
| 285 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 286 | // "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" + |
| 287 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 288 | // "{@type=korap:span, layer=cat, key=CP, match=match:eq}," + |
| 289 | // "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" + |
| 290 | // "{@type=korap:span, layer=cat, key=VP, match=match:eq}" + |
| 291 | // "]}" + |
| 292 | // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" + |
| 293 | // "]}," + |
| 294 | // "{@type=korap:span, layer=cat, key=NP, match=match:eq}" + |
| 295 | // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" + |
| 296 | // "}"; |
| 297 | // aqlt = new AqlTree(query); |
| 298 | // map = aqlt.getRequestMap().get("query").toString(); |
| 299 | // assertEquals(dom1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 300 | // |
| 301 | // query = "cat=\"CP\" & cat=\"VP\" & cat=\"NP\" & cat=\"DP\" & #1 > #2 > #3 > #4"; |
| 302 | // String dom2 = |
| 303 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 304 | // "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" + |
| 305 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 306 | // "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" + |
| 307 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 308 | // "{@type=korap:span, layer=cat, key=CP, match=match:eq}," + |
| 309 | // "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" + |
| 310 | // "{@type=korap:span, layer=cat, key=VP, match=match:eq}" + |
| 311 | // "]}" + |
| 312 | // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" + |
| 313 | // "]}," + |
| 314 | // "{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" + |
| 315 | // "{@type=korap:span, layer=cat, key=NP, match=match:eq}" + |
| 316 | // "]}" + |
| 317 | // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" + |
| 318 | // "]}," + |
| 319 | // "{@type=korap:span, layer=cat, key=DP, match=match:eq}" + |
| 320 | // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" + |
| 321 | // "}"; |
| 322 | // aqlt = new AqlTree(query); |
| 323 | // map = aqlt.getRequestMap().get("query").toString(); |
| 324 | // assertEquals(dom2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 325 | // } |
| 326 | // |
| 327 | // @Test |
| 328 | // public void testPointingRelations() throws QueryException { |
| 329 | // query = "node & node & #2 ->coref[val=\"true\"] #1"; |
| 330 | // String dom1 = |
| 331 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 332 | // "{@type=korap:span}," + |
| 333 | // "{@type=korap:span}" + |
| 334 | // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=coref, key=true, match=match:eq}}" + |
| 335 | // "}"; |
| 336 | // aqlt = new AqlTree(query); |
| 337 | // map = aqlt.getRequestMap().get("query").toString(); |
| 338 | // assertEquals(dom1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 339 | // |
| 340 | // query = "node & node & #2 ->mate/coref[val=\"true\"] #1"; |
| 341 | // String dom2 = |
| 342 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 343 | // "{@type=korap:span}," + |
| 344 | // "{@type=korap:span}" + |
| 345 | // "], relation={@type=korap:relation, wrap={@type=korap:term, foundry=mate, layer=coref, key=true, match=match:eq}}" + |
| 346 | // "}"; |
| 347 | // aqlt = new AqlTree(query); |
| 348 | // map = aqlt.getRequestMap().get("query").toString(); |
| 349 | // assertEquals(dom2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 350 | // } |
| 351 | // |
| 352 | // @Test |
| 353 | // public void testSequence() throws QueryException { |
| 354 | // query = "node & node & #1 . #2"; |
| 355 | // String seq1 = |
| 356 | // "{@type=korap:group, operation=operation:sequence, " + |
| 357 | // "operands=[" + |
| 358 | // "{@type=korap:span}," + |
| 359 | // "{@type=korap:span}" + |
| 360 | // "], inOrder=true" + |
| 361 | // "}"; |
| 362 | // aqlt = new AqlTree(query); |
| 363 | // map = aqlt.getRequestMap().get("query").toString(); |
| 364 | // assertEquals(seq1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 365 | // |
| 366 | // query = "node & node & #1 .* #2"; |
| 367 | // String seq2 = |
| 368 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 369 | // "{@type=korap:span}," + |
| 370 | // "{@type=korap:span}" + |
| 371 | // "], distances=[" + |
| 372 | // "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0}, min=0}" + |
| 373 | // "], inOrder=true" + |
| 374 | // "}"; |
| 375 | // aqlt = new AqlTree(query); |
| 376 | // map = aqlt.getRequestMap().get("query").toString(); |
| 377 | // assertEquals(seq2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 378 | // |
| 379 | // query = "node & node & #1 .2,3 #2"; |
| 380 | // String seq3 = |
| 381 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 382 | // "{@type=korap:span}," + |
| 383 | // "{@type=korap:span}" + |
| 384 | // "], distances=[" + |
| 385 | // "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=2, max=3}, min=2, max=3}" + |
| 386 | // "], inOrder=true" + |
| 387 | // "}"; |
| 388 | // aqlt = new AqlTree(query); |
| 389 | // map = aqlt.getRequestMap().get("query").toString(); |
| 390 | // assertEquals(seq3.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 391 | // |
| 392 | // } |
| 393 | // |
| 394 | // @Test |
| 395 | // public void testMultipleSequence() throws QueryException { |
| 396 | // query = "tok=\"Sonne\" & tok=\"Mond\" & tok=\"Sterne\" & #1 .0,2 #2 .0,4 #3"; |
| 397 | // String seq4 = |
| 398 | // "{@type=korap:group, operation=operation:sequence," + |
| 399 | // "operands=[" + |
| 400 | // "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" + |
| 401 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 402 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sonne, match=match:eq}}," + |
| 403 | // "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" + |
| 404 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mond, match=match:eq}}" + |
| 405 | // "]}" + |
| 406 | // "], distances=[" + |
| 407 | // "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0, max=2}, min=0, max=2}" + |
| 408 | // "], inOrder=true}" + |
| 409 | // "]}," + |
| 410 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sterne, match=match:eq}}" + |
| 411 | // "],distances=[" + |
| 412 | // "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0, max=4}, min=0, max=4}" + |
| 413 | // "], inOrder=true" + |
| 414 | // "}"; |
| 415 | // aqlt = new AqlTree(query); |
| 416 | // map = aqlt.getRequestMap().get("query").toString(); |
| 417 | // assertEquals(seq4.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 418 | // |
| 419 | // query = "node & node & node & #1 . #2 .1,3 #3"; |
| 420 | // String seq5 = |
| 421 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 422 | // "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" + |
| 423 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 424 | // "{@type=korap:span}," + |
| 425 | // "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" + |
| 426 | // "{@type=korap:span}" + |
| 427 | // "]} "+ |
| 428 | // "], inOrder=true}" + |
| 429 | // "]}," + |
| 430 | // "{@type=korap:span}" + |
| 431 | // "], distances=[" + |
| 432 | // "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1, max=3}, min=1, max=3}" + |
| 433 | // "], inOrder=true" + |
| 434 | // "}"; |
| 435 | // aqlt = new AqlTree(query); |
| 436 | // map = aqlt.getRequestMap().get("query").toString(); |
| 437 | // assertEquals(seq5.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 438 | // |
| 439 | // query = "tok=\"Sonne\" & tok=\"Mond\" & tok=\"Sterne\" & tok=\"Himmel\" & #1 .0,2 #2 .0,4 #3 . #4"; |
| 440 | // String seq6 = |
| 441 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 442 | // "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" + |
| 443 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 444 | // "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" + |
| 445 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 446 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sonne, match=match:eq}}," + |
| 447 | // "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" + |
| 448 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mond, match=match:eq}}" + |
| 449 | // "]}" + |
| 450 | // "], distances=[" + |
| 451 | // "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0, max=2}, min=0, max=2}" + |
| 452 | // "], inOrder=true}" + |
| 453 | // "]}," + |
| 454 | // "{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" + |
| 455 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sterne, match=match:eq}}" + |
| 456 | // "]}" + |
| 457 | // "],distances=[" + |
| 458 | // "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0, max=4}, min=0, max=4}" + |
| 459 | // "], inOrder=true}" + |
| 460 | // "]}," + |
| 461 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Himmel, match=match:eq}}" + |
| 462 | // "], inOrder=true}" ; |
| 463 | // aqlt = new AqlTree(query); |
| 464 | // map = aqlt.getRequestMap().get("query").toString(); |
| 465 | // assertEquals(seq6.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 466 | // } |
| 467 | // |
| 468 | // @Test |
| 469 | // public void testMultipleMixedOperators() throws QueryException { |
| 470 | // query = "tok=\"Sonne\" & tok=\"Mond\" & tok=\"Sterne\" & #1 > #2 .0,4 #3"; |
| 471 | // String seq4 = |
| 472 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 473 | // "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" + |
| 474 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 475 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sonne, match=match:eq}}," + |
| 476 | // "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" + |
| 477 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mond, match=match:eq}}" + |
| 478 | // "]}" + |
| 479 | // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" + |
| 480 | // "]}," + |
| 481 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sterne, match=match:eq}}" + |
| 482 | // "], distances=[" + |
| 483 | // "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0, max=4}, min=0, max=4}" + |
| 484 | // "], inOrder=true" + |
| 485 | // "}"; |
| 486 | // aqlt = new AqlTree(query); |
| 487 | // map = aqlt.getRequestMap().get("query").toString(); |
| 488 | // assertEquals(seq4.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 489 | // |
| 490 | // query = "tok=\"Sonne\" & tok=\"Mond\" & #1 > #2 .0,4 tok=\"Sterne\""; |
| 491 | // String seq5 = |
| 492 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 493 | // "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" + |
| 494 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 495 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sonne, match=match:eq}}," + |
| 496 | // "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" + |
| 497 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mond, match=match:eq}}" + |
| 498 | // "]}" + |
| 499 | // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" + |
| 500 | // "]}," + |
| 501 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sterne, match=match:eq}}" + |
| 502 | // "], distances=[" + |
| 503 | // "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0, max=4}, min=0, max=4}" + |
| 504 | // "], inOrder=true" + |
| 505 | // "}"; |
| 506 | // aqlt = new AqlTree(query); |
| 507 | // map = aqlt.getRequestMap().get("query").toString(); |
| 508 | // assertEquals(seq5.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 509 | // |
| 510 | // query = "cat=\"NP\" & cat=\"VP\" & cat=\"PP\" & #1 $ #2 > #3"; |
| 511 | // String cp2 = |
| 512 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 513 | // "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" + |
| 514 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 515 | // "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" + |
| 516 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 517 | // "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" + |
| 518 | // "{@type=korap:span}" + |
| 519 | // "]}," + |
| 520 | // "{@type=korap:span, layer=cat, key=NP, match=match:eq}" + |
| 521 | // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" + |
| 522 | // "]}," + |
| 523 | // "{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" + |
| 524 | // "{@type=korap:span, layer=cat, key=VP, match=match:eq}" + |
| 525 | // "]}" + |
| 526 | // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" + |
| 527 | // "}" + |
| 528 | // "]}," + |
| 529 | // "{@type=korap:span, layer=cat, key=PP, match=match:eq}" + |
| 530 | // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" + |
| 531 | // "}"; |
| 532 | // aqlt = new AqlTree(query); |
| 533 | // map = aqlt.getRequestMap().get("query").toString(); |
| 534 | // assertEquals(cp2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 535 | // } |
| 536 | // /* |
| 537 | // @Test |
| 538 | // public void testMultipleOperatorsWithSameOperands() throws QueryException { |
| 539 | // |
| 540 | // query = "cat=\"NP\" > cat=\"VP\" & #1 _l_ #2"; |
| 541 | // String eq2 = |
| 542 | // "{@type=korap:group, operation=operation:position, frames=[frame:startswith], sharedClasses=[sharedClasses:includes], operands=[" + |
| 543 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 544 | // "{@type=korap:group, operation=operation:class, class=, classOut=129, operands=[" + |
| 545 | // "{@type=korap:span, layer=cat, key=NP, match=match:eq}" + |
| 546 | // "]}," + |
| 547 | // "{@type=korap:group, operation=operation:class, class=, classOut=129, operands=[" + |
| 548 | // "{@type=korap:span, layer=cat, key=VP, match=match:eq}" + |
| 549 | // "]}" + |
| 550 | // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}," + |
| 551 | // "{@type=korap:reference, operation=operation:focus, classRef=[2]}" + |
| 552 | // "]" + |
| 553 | // "}"; // ??? |
| 554 | // aqlt = new AqlTree(query); |
| 555 | // map = aqlt.getRequestMap().get("query").toString(); |
| 556 | // assertEquals(eq2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 557 | // } |
| 558 | // */ |
| 559 | // @Test |
| 560 | // public void testPositions() throws QueryException { |
| 561 | // query = "node & node & #2 _=_ #1"; |
| 562 | // String pos1 = |
| 563 | // "{@type=korap:group, operation=operation:position, frames=[frames:matches], operands=[" + |
| 564 | // "{@type=korap:span}," + |
| 565 | // "{@type=korap:span}" + |
| 566 | // "], frame=frame:matches}"; |
| 567 | // aqlt = new AqlTree(query); |
| 568 | // map = aqlt.getRequestMap().get("query").toString(); |
| 569 | // assertEquals(pos1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 570 | // |
| 571 | // query = "node & node & #2 _i_ #1"; |
| 572 | // String pos2 = |
| 573 | // "{@type=korap:group, operation=operation:position, frames=[frames:contains], operands=[" + |
| 574 | // "{@type=korap:span}," + |
| 575 | // "{@type=korap:span}" + |
| 576 | // "], frame=frame:contains" + |
| 577 | // "}"; |
| 578 | // aqlt = new AqlTree(query); |
| 579 | // map = aqlt.getRequestMap().get("query").toString(); |
| 580 | // assertEquals(pos2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 581 | // |
| 582 | // query = "node & node & #2 _l_ #1"; |
| 583 | // String pos3 = |
| 584 | // "{@type=korap:group, operation=operation:position, frames=[frames:startswith], operands=[" + |
| 585 | // "{@type=korap:span}," + |
| 586 | // "{@type=korap:span}" + |
| 587 | // "], frame=frame:startswith" + |
| 588 | // "}"; |
| 589 | // aqlt = new AqlTree(query); |
| 590 | // map = aqlt.getRequestMap().get("query").toString(); |
| 591 | // assertEquals(pos3.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 592 | // |
| 593 | // query = "node & \"Mann\" & #1 _r_ #2"; |
| 594 | // String pos4 = |
| 595 | // "{@type=korap:group, operation=operation:position, frames=[frames:endswith], operands=[" + |
| 596 | // "{@type=korap:span}," + |
| 597 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" + |
| 598 | // "], frame=frame:endswith" + |
| 599 | // "}"; |
| 600 | // aqlt = new AqlTree(query); |
| 601 | // map = aqlt.getRequestMap().get("query").toString(); |
| 602 | // assertEquals(pos4.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 603 | // |
| 604 | // query = "node & \"Mann\" & #2 _r_ #1"; |
| 605 | // String pos5 = |
| 606 | // "{@type=korap:group, operation=operation:position, frames=[frames:endswith], operands=[" + |
| 607 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}," + |
| 608 | // "{@type=korap:span}" + |
| 609 | // "], frame=frame:endswith" + |
| 610 | // "}"; |
| 611 | // aqlt = new AqlTree(query); |
| 612 | // map = aqlt.getRequestMap().get("query").toString(); |
| 613 | // assertEquals(pos5.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 614 | // } |
| 615 | // |
| 616 | // @Test |
| 617 | // public void testMultiplePredications() throws QueryException { |
| 618 | // // a noun before a verb before a preposition |
| 619 | // query = "pos=\"N\" & pos=\"V\" & pos=\"P\" & #1 . #2 & #2 . #3"; |
| 620 | // String mult1 = |
| 621 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 622 | // "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" + |
| 623 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 624 | // "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=N, match=match:eq}}," + |
| 625 | // "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" + |
| 626 | // "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=V, match=match:eq}}" + |
| 627 | // "]}" + |
| 628 | // "], inOrder=true}" + |
| 629 | // "]}," + |
| 630 | // "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=P, match=match:eq}}" + |
| 631 | // "], inOrder=true}"; |
| 632 | // aqlt = new AqlTree(query); |
| 633 | // map = aqlt.getRequestMap().get("query").toString(); |
| 634 | // assertEquals(mult1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 635 | // |
| 636 | // // a noun before a verb before a preposition |
| 637 | // query = "pos=\"N\" & pos=\"V\" & #1 . #2 & #2 . pos=\"P\""; |
| 638 | // String mult2 = |
| 639 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 640 | // "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" + |
| 641 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 642 | // "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=N, match=match:eq}}," + |
| 643 | // "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" + |
| 644 | // "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=V, match=match:eq}}" + |
| 645 | // "]}" + |
| 646 | // "], inOrder=true}" + |
| 647 | // "]}," + |
| 648 | // "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=P, match=match:eq}}" + |
| 649 | // "], inOrder=true}"; |
| 650 | // aqlt = new AqlTree(query); |
| 651 | // map = aqlt.getRequestMap().get("query").toString(); |
| 652 | // assertEquals(mult2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 653 | // |
| 654 | // query = "pos=\"N\" & pos=\"V\" & pos=\"P\" & #1 > #2 & #1 > #3"; |
| 655 | // String mult3 = |
| 656 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 657 | // "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" + |
| 658 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 659 | // "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" + |
| 660 | // "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=N, match=match:eq}}" + |
| 661 | // "]}," + |
| 662 | // "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=V, match=match:eq}}" + |
| 663 | // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" + |
| 664 | // "]}," + |
| 665 | // "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=P, match=match:eq}}" + |
| 666 | // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}"; |
| 667 | // aqlt = new AqlTree(query); |
| 668 | // map = aqlt.getRequestMap().get("query").toString(); |
| 669 | // assertEquals(mult3.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 670 | // |
| 671 | // query = "cat=\"NP\" & pos=\"V\" & pos=\"P\" & #1 > #2 & #1 > #3 & #2 . #3"; |
| 672 | // String mult4 = |
| 673 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 674 | // // reduce dominance relations "#1 > #2 & #1 > #3" to operand #2 in order to make it accessible for #2 . #3 (the last/outermost relation) |
| 675 | // "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" + |
| 676 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 677 | // // dominance relation #1 > #2 is reduced to #1, for expressing #1 > #3 |
| 678 | // "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" + |
| 679 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 680 | // "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" + |
| 681 | // "{@type=korap:span, layer=cat, key=NP, match=match:eq}" + |
| 682 | // "]}," + |
| 683 | // "{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" + |
| 684 | // "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=V, match=match:eq}}" + |
| 685 | // "]}" + |
| 686 | // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" + |
| 687 | // "]}," + |
| 688 | // // establish class 2 around P for later reference |
| 689 | // "{@type=korap:group, operation=operation:class, class=130, classOut=130, operands=[" + |
| 690 | // "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=P, match=match:eq}}" + |
| 691 | // "]}" + |
| 692 | // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" + |
| 693 | // "]}," + |
| 694 | // // refer back to class 2 as second operand |
| 695 | // "{@type=korap:reference, operation=operation:focus, classRef=[2]}" + |
| 696 | // "], inOrder=true}"; |
| 697 | // aqlt = new AqlTree(query); |
| 698 | // map = aqlt.getRequestMap().get("query").toString(); |
| 699 | // assertEquals(mult4.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 700 | // } |
| 701 | // |
| 702 | // @Test |
| 703 | // public void testUnaryRelations() throws QueryException { |
| 704 | // query = "node & #1:tokenarity=2"; |
| 705 | // String unary1 = |
| 706 | // "{@type=korap:span, attr={@type=korap:term, tokenarity={@type=korap:boundary,min=2,max=2}}}"; |
| 707 | // aqlt = new AqlTree(query); |
| 708 | // map = aqlt.getRequestMap().get("query").toString(); |
| 709 | // assertEquals(unary1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 710 | // |
| 711 | // query = "cnx/cat=\"NP\" & #1:tokenarity=2"; |
| 712 | // String unary2 = |
| 713 | // "{@type=korap:span, foundry=cnx, layer=cat, key=NP, match=match:eq, attr={@type=korap:term, tokenarity={@type=korap:boundary,min=2,max=2}}}"; |
| 714 | // aqlt = new AqlTree(query); |
| 715 | // map = aqlt.getRequestMap().get("query").toString(); |
| 716 | // assertEquals(unary2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 717 | // |
| 718 | // query = "cnx/cat=\"NP\" & #1:root"; |
| 719 | // String unary3 = |
| 720 | // "{@type=korap:span, foundry=cnx, layer=cat, key=NP, match=match:eq, attr={@type=korap:term, root=true}}"; |
| 721 | // aqlt = new AqlTree(query); |
| 722 | // map = aqlt.getRequestMap().get("query").toString(); |
| 723 | // assertEquals(unary3.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 724 | // |
| 725 | // query = "cnx/cat=\"NP\" & node & #1>#2 & #1:tokenarity=2"; |
| 726 | // String unary4 = |
| 727 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 728 | // "{@type=korap:span, foundry=cnx, layer=cat, key=NP, match=match:eq, attr={@type=korap:term, tokenarity={@type=korap:boundary,min=2,max=2}}}," + |
| 729 | // "{@type=korap:span}" + |
| 730 | // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" + |
| 731 | // "}"; |
| 732 | // aqlt = new AqlTree(query); |
| 733 | // map = aqlt.getRequestMap().get("query").toString(); |
| 734 | // assertEquals(unary4.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 735 | // } |
| 736 | // |
| 737 | // @Test |
| 738 | // public void testCommonParent() throws QueryException { |
| 739 | // query = "cat=\"NP\" & cat=\"VP\" & #1 $ #2"; |
| 740 | // String cp1 = |
| 741 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 742 | // "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" + |
| 743 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 744 | // "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" + |
| 745 | // "{@type=korap:span}" + |
| 746 | // "]}," + |
| 747 | // "{@type=korap:span, layer=cat, key=NP, match=match:eq}" + |
| 748 | // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" + |
| 749 | // "]}," + |
| 750 | // "{@type=korap:span, layer=cat, key=VP, match=match:eq}" + |
| 751 | // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" + |
| 752 | // ""; |
| 753 | // aqlt = new AqlTree(query); |
| 754 | // map = aqlt.getRequestMap().get("query").toString(); |
| 755 | // assertEquals(cp1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 756 | // |
| 757 | // query = "cat=\"NP\" & cat=\"VP\" & cat=\"PP\" & #1 $ #2 $ #3"; |
| 758 | // String cp2 = |
| 759 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 760 | // "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" + |
| 761 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 762 | // "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" + |
| 763 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 764 | // "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" + |
| 765 | // "{@type=korap:span}" + |
| 766 | // "]}," + |
| 767 | // "{@type=korap:span, layer=cat, key=NP, match=match:eq}" + |
| 768 | // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" + |
| 769 | // "]}," + |
| 770 | // "{@type=korap:span, layer=cat, key=VP, match=match:eq}" + |
| 771 | // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" + |
| 772 | // "}" + |
| 773 | // "]}," + |
| 774 | // "{@type=korap:span, layer=cat, key=PP, match=match:eq}" + |
| 775 | // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" + |
| 776 | // "}"; |
| 777 | // aqlt = new AqlTree(query); |
| 778 | // map = aqlt.getRequestMap().get("query").toString(); |
| 779 | // assertEquals(cp2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 780 | // |
| 781 | // query = "cat=\"NP\" & cat=\"VP\" & cat=\"PP\" & cat=\"CP\" & #1 $ #2 $ #3 $ #4"; |
| 782 | // String cp3 = |
| 783 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 784 | // "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" + |
| 785 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 786 | // "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" + |
| 787 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 788 | // "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" + |
| 789 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 790 | // "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" + |
| 791 | // "{@type=korap:span}" + |
| 792 | // "]}," + |
| 793 | // "{@type=korap:span, layer=cat, key=NP, match=match:eq}" + |
| 794 | // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" + |
| 795 | // "]}," + |
| 796 | // "{@type=korap:span, layer=cat, key=VP, match=match:eq}" + |
| 797 | // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" + |
| 798 | // "]}," + |
| 799 | // "{@type=korap:span, layer=cat, key=PP, match=match:eq}" + |
| 800 | // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" + |
| 801 | // "]}," + |
| 802 | // "{@type=korap:span, layer=cat, key=CP, match=match:eq}" + |
| 803 | // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" + |
| 804 | // "}" + |
| 805 | // ""; |
| 806 | // aqlt = new AqlTree(query); |
| 807 | // map = aqlt.getRequestMap().get("query").toString(); |
| 808 | // assertEquals(cp3.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 809 | // |
| 810 | // query = "cat=\"NP\" & cat=\"VP\" & #1 $* #2"; |
| 811 | // String cp4 = |
| 812 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 813 | // "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" + |
| 814 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 815 | // "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" + |
| 816 | // "{@type=korap:span}" + |
| 817 | // "]}," + |
| 818 | // "{@type=korap:span, layer=cat, key=NP, match=match:eq}" + |
| 819 | // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c},boundary={@type=korap:boundary,min=1}}}" + |
| 820 | // "]}," + |
| 821 | // "{@type=korap:span, layer=cat, key=VP, match=match:eq}" + |
| 822 | // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c},boundary={@type=korap:boundary,min=1}}}" + |
| 823 | // ""; |
| 824 | // aqlt = new AqlTree(query); |
| 825 | // map = aqlt.getRequestMap().get("query").toString(); |
| 826 | // assertEquals(cp4.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 827 | // } |
| 828 | |
Joachim Bingel | e6d73b1 | 2014-09-30 15:34:59 +0000 | [diff] [blame] | 829 | /* |
| 830 | @Test |
| 831 | public void testEqualNotequalValue() throws QueryException { |
| 832 | query = "cat=\"NP\" & cat=\"VP\" & #1 == #2"; |
| 833 | String eq1 = |
| 834 | "{}"; // ??? |
| 835 | aqlt = new AqlTree(query); |
| 836 | map = aqlt.getRequestMap().get("query").toString(); |
| 837 | assertEquals(eq1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 838 | } |
| 839 | */ |
| 840 | |
Joachim Bingel | 66472b8 | 2014-12-04 16:00:05 +0000 | [diff] [blame] | 841 | } |