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 | |
Joachim Bingel | 755ada9 | 2014-12-16 13:55:37 +0000 | [diff] [blame^] | 240 | query = "cat=\"S\" & cat=\"NP\" & #1 >@l #2"; // all sentences starting with NP -> wrap relation in startswith and retrieve 2nd operand with focus |
Joachim Bingel | 66472b8 | 2014-12-04 16:00:05 +0000 | [diff] [blame] | 241 | qs.setQuery(query, "annis"); |
| 242 | res = mapper.readTree(qs.toJSON()); |
Joachim Bingel | 755ada9 | 2014-12-16 13:55:37 +0000 | [diff] [blame^] | 243 | assertEquals("operation:position", res.at("/query/operation").asText()); |
| 244 | assertEquals("operation:relation", res.at("/query/operands/0/operation").asText()); |
| 245 | assertEquals("frames:startswith", res.at("/query/frames/0").asText()); |
Joachim Bingel | 66472b8 | 2014-12-04 16:00:05 +0000 | [diff] [blame] | 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()); |
Joachim Bingel | 755ada9 | 2014-12-16 13:55:37 +0000 | [diff] [blame^] | 250 | assertEquals(129, res.at("/query/operands/0/operands/1/classOut").asInt()); |
Joachim Bingel | 66472b8 | 2014-12-04 16:00:05 +0000 | [diff] [blame] | 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()); |
Joachim Bingel | 755ada9 | 2014-12-16 13:55:37 +0000 | [diff] [blame^] | 255 | assertEquals(129, res.at("/query/operands/1/classRef/0").asInt()); |
| 256 | |
| 257 | query = "cat=\"S\" & cat=\"NP\" & #1 >@r #2"; |
| 258 | qs.setQuery(query, "annis"); |
| 259 | res = mapper.readTree(qs.toJSON()); |
| 260 | assertEquals("operation:position", res.at("/query/operation").asText()); |
| 261 | assertEquals("operation:relation", res.at("/query/operands/0/operation").asText()); |
| 262 | assertEquals("frames:endswith", res.at("/query/frames/0").asText()); |
| 263 | assertEquals("korap:span", res.at("/query/operands/0/operands/0/@type").asText()); |
| 264 | assertEquals("S", res.at("/query/operands/0/operands/0/key").asText()); |
| 265 | assertEquals("korap:group", res.at("/query/operands/0/operands/1/@type").asText()); |
| 266 | assertEquals("operation:class", res.at("/query/operands/0/operands/1/operation").asText()); |
| 267 | assertEquals(129, res.at("/query/operands/0/operands/1/classOut").asInt()); |
| 268 | assertEquals("korap:span", res.at("/query/operands/0/operands/1/operands/0/@type").asText()); |
| 269 | assertEquals("NP", res.at("/query/operands/0/operands/1/operands/0/key").asText()); |
| 270 | assertEquals("korap:reference", res.at("/query/operands/1/@type").asText()); |
| 271 | assertEquals("operation:focus", res.at("/query/operands/1/operation").asText()); |
| 272 | assertEquals(129, res.at("/query/operands/1/classRef/0").asInt()); |
Joachim Bingel | 66472b8 | 2014-12-04 16:00:05 +0000 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | @Test |
| 276 | public void testIndirectDominance() throws QueryException, JsonProcessingException, IOException { |
| 277 | query = "node & node & #1 >2,4 #2"; |
| 278 | qs.setQuery(query, "annis"); |
| 279 | res = mapper.readTree(qs.toJSON()); |
| 280 | assertEquals("korap:group", res.at("/query/@type").asText()); |
| 281 | assertEquals("operation:relation", res.at("/query/operation").asText()); |
| 282 | assertEquals("korap:span", res.at("/query/operands/0/@type").asText()); |
| 283 | assertEquals("korap:span", res.at("/query/operands/1/@type").asText()); |
| 284 | assertEquals("korap:relation", res.at("/query/relation/@type").asText()); |
| 285 | assertEquals(2, res.at("/query/relation/boundary/min").asInt()); |
| 286 | assertEquals(4, res.at("/query/relation/boundary/max").asInt()); |
| 287 | assertEquals("korap:term", res.at("/query/relation/wrap/@type").asText()); |
| 288 | assertEquals("c", res.at("/query/relation/wrap/layer").asText()); |
| 289 | |
| 290 | query = "node & node & #1 >* #2"; |
| 291 | qs.setQuery(query, "annis"); |
| 292 | res = mapper.readTree(qs.toJSON()); |
| 293 | assertEquals(0, res.at("/query/relation/boundary/min").asInt()); |
| 294 | assertEquals(true, res.at("/query/relation/boundary/max").isMissingNode()); |
| 295 | } |
| 296 | |
| 297 | // |
| 298 | // @Test |
| 299 | // public void testMultipleDominance() throws QueryException { |
| 300 | // query = "cat=\"CP\" & cat=\"VP\" & cat=\"NP\" & #1 > #2 > #3"; |
| 301 | // String dom1 = |
| 302 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 303 | // "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" + |
| 304 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 305 | // "{@type=korap:span, layer=cat, key=CP, match=match:eq}," + |
| 306 | // "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" + |
| 307 | // "{@type=korap:span, layer=cat, key=VP, match=match:eq}" + |
| 308 | // "]}" + |
| 309 | // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" + |
| 310 | // "]}," + |
| 311 | // "{@type=korap:span, layer=cat, key=NP, match=match:eq}" + |
| 312 | // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" + |
| 313 | // "}"; |
| 314 | // aqlt = new AqlTree(query); |
| 315 | // map = aqlt.getRequestMap().get("query").toString(); |
| 316 | // assertEquals(dom1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 317 | // |
| 318 | // query = "cat=\"CP\" & cat=\"VP\" & cat=\"NP\" & cat=\"DP\" & #1 > #2 > #3 > #4"; |
| 319 | // String dom2 = |
| 320 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 321 | // "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" + |
| 322 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 323 | // "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" + |
| 324 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 325 | // "{@type=korap:span, layer=cat, key=CP, match=match:eq}," + |
| 326 | // "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" + |
| 327 | // "{@type=korap:span, layer=cat, key=VP, match=match:eq}" + |
| 328 | // "]}" + |
| 329 | // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" + |
| 330 | // "]}," + |
| 331 | // "{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" + |
| 332 | // "{@type=korap:span, layer=cat, key=NP, match=match:eq}" + |
| 333 | // "]}" + |
| 334 | // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" + |
| 335 | // "]}," + |
| 336 | // "{@type=korap:span, layer=cat, key=DP, match=match:eq}" + |
| 337 | // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" + |
| 338 | // "}"; |
| 339 | // aqlt = new AqlTree(query); |
| 340 | // map = aqlt.getRequestMap().get("query").toString(); |
| 341 | // assertEquals(dom2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 342 | // } |
| 343 | // |
| 344 | // @Test |
| 345 | // public void testPointingRelations() throws QueryException { |
| 346 | // query = "node & node & #2 ->coref[val=\"true\"] #1"; |
| 347 | // String dom1 = |
| 348 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 349 | // "{@type=korap:span}," + |
| 350 | // "{@type=korap:span}" + |
| 351 | // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=coref, key=true, match=match:eq}}" + |
| 352 | // "}"; |
| 353 | // aqlt = new AqlTree(query); |
| 354 | // map = aqlt.getRequestMap().get("query").toString(); |
| 355 | // assertEquals(dom1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 356 | // |
| 357 | // query = "node & node & #2 ->mate/coref[val=\"true\"] #1"; |
| 358 | // String dom2 = |
| 359 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 360 | // "{@type=korap:span}," + |
| 361 | // "{@type=korap:span}" + |
| 362 | // "], relation={@type=korap:relation, wrap={@type=korap:term, foundry=mate, layer=coref, key=true, match=match:eq}}" + |
| 363 | // "}"; |
| 364 | // aqlt = new AqlTree(query); |
| 365 | // map = aqlt.getRequestMap().get("query").toString(); |
| 366 | // assertEquals(dom2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 367 | // } |
| 368 | // |
| 369 | // @Test |
| 370 | // public void testSequence() throws QueryException { |
| 371 | // query = "node & node & #1 . #2"; |
| 372 | // String seq1 = |
| 373 | // "{@type=korap:group, operation=operation:sequence, " + |
| 374 | // "operands=[" + |
| 375 | // "{@type=korap:span}," + |
| 376 | // "{@type=korap:span}" + |
| 377 | // "], inOrder=true" + |
| 378 | // "}"; |
| 379 | // aqlt = new AqlTree(query); |
| 380 | // map = aqlt.getRequestMap().get("query").toString(); |
| 381 | // assertEquals(seq1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 382 | // |
| 383 | // query = "node & node & #1 .* #2"; |
| 384 | // String seq2 = |
| 385 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 386 | // "{@type=korap:span}," + |
| 387 | // "{@type=korap:span}" + |
| 388 | // "], distances=[" + |
| 389 | // "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0}, min=0}" + |
| 390 | // "], inOrder=true" + |
| 391 | // "}"; |
| 392 | // aqlt = new AqlTree(query); |
| 393 | // map = aqlt.getRequestMap().get("query").toString(); |
| 394 | // assertEquals(seq2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 395 | // |
| 396 | // query = "node & node & #1 .2,3 #2"; |
| 397 | // String seq3 = |
| 398 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 399 | // "{@type=korap:span}," + |
| 400 | // "{@type=korap:span}" + |
| 401 | // "], distances=[" + |
| 402 | // "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=2, max=3}, min=2, max=3}" + |
| 403 | // "], inOrder=true" + |
| 404 | // "}"; |
| 405 | // aqlt = new AqlTree(query); |
| 406 | // map = aqlt.getRequestMap().get("query").toString(); |
| 407 | // assertEquals(seq3.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 408 | // |
| 409 | // } |
| 410 | // |
| 411 | // @Test |
| 412 | // public void testMultipleSequence() throws QueryException { |
| 413 | // query = "tok=\"Sonne\" & tok=\"Mond\" & tok=\"Sterne\" & #1 .0,2 #2 .0,4 #3"; |
| 414 | // String seq4 = |
| 415 | // "{@type=korap:group, operation=operation:sequence," + |
| 416 | // "operands=[" + |
| 417 | // "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" + |
| 418 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 419 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sonne, match=match:eq}}," + |
| 420 | // "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" + |
| 421 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mond, match=match:eq}}" + |
| 422 | // "]}" + |
| 423 | // "], distances=[" + |
| 424 | // "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0, max=2}, min=0, max=2}" + |
| 425 | // "], inOrder=true}" + |
| 426 | // "]}," + |
| 427 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sterne, match=match:eq}}" + |
| 428 | // "],distances=[" + |
| 429 | // "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0, max=4}, min=0, max=4}" + |
| 430 | // "], inOrder=true" + |
| 431 | // "}"; |
| 432 | // aqlt = new AqlTree(query); |
| 433 | // map = aqlt.getRequestMap().get("query").toString(); |
| 434 | // assertEquals(seq4.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 435 | // |
| 436 | // query = "node & node & node & #1 . #2 .1,3 #3"; |
| 437 | // String seq5 = |
| 438 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 439 | // "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" + |
| 440 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 441 | // "{@type=korap:span}," + |
| 442 | // "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" + |
| 443 | // "{@type=korap:span}" + |
| 444 | // "]} "+ |
| 445 | // "], inOrder=true}" + |
| 446 | // "]}," + |
| 447 | // "{@type=korap:span}" + |
| 448 | // "], distances=[" + |
| 449 | // "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1, max=3}, min=1, max=3}" + |
| 450 | // "], inOrder=true" + |
| 451 | // "}"; |
| 452 | // aqlt = new AqlTree(query); |
| 453 | // map = aqlt.getRequestMap().get("query").toString(); |
| 454 | // assertEquals(seq5.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 455 | // |
| 456 | // query = "tok=\"Sonne\" & tok=\"Mond\" & tok=\"Sterne\" & tok=\"Himmel\" & #1 .0,2 #2 .0,4 #3 . #4"; |
| 457 | // String seq6 = |
| 458 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 459 | // "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" + |
| 460 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 461 | // "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" + |
| 462 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 463 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sonne, match=match:eq}}," + |
| 464 | // "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" + |
| 465 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mond, match=match:eq}}" + |
| 466 | // "]}" + |
| 467 | // "], distances=[" + |
| 468 | // "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0, max=2}, min=0, max=2}" + |
| 469 | // "], inOrder=true}" + |
| 470 | // "]}," + |
| 471 | // "{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" + |
| 472 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sterne, match=match:eq}}" + |
| 473 | // "]}" + |
| 474 | // "],distances=[" + |
| 475 | // "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0, max=4}, min=0, max=4}" + |
| 476 | // "], inOrder=true}" + |
| 477 | // "]}," + |
| 478 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Himmel, match=match:eq}}" + |
| 479 | // "], inOrder=true}" ; |
| 480 | // aqlt = new AqlTree(query); |
| 481 | // map = aqlt.getRequestMap().get("query").toString(); |
| 482 | // assertEquals(seq6.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 483 | // } |
| 484 | // |
| 485 | // @Test |
| 486 | // public void testMultipleMixedOperators() throws QueryException { |
| 487 | // query = "tok=\"Sonne\" & tok=\"Mond\" & tok=\"Sterne\" & #1 > #2 .0,4 #3"; |
| 488 | // String seq4 = |
| 489 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 490 | // "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" + |
| 491 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 492 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sonne, match=match:eq}}," + |
| 493 | // "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" + |
| 494 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mond, match=match:eq}}" + |
| 495 | // "]}" + |
| 496 | // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" + |
| 497 | // "]}," + |
| 498 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sterne, match=match:eq}}" + |
| 499 | // "], distances=[" + |
| 500 | // "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0, max=4}, min=0, max=4}" + |
| 501 | // "], inOrder=true" + |
| 502 | // "}"; |
| 503 | // aqlt = new AqlTree(query); |
| 504 | // map = aqlt.getRequestMap().get("query").toString(); |
| 505 | // assertEquals(seq4.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 506 | // |
| 507 | // query = "tok=\"Sonne\" & tok=\"Mond\" & #1 > #2 .0,4 tok=\"Sterne\""; |
| 508 | // String seq5 = |
| 509 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 510 | // "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" + |
| 511 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 512 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sonne, match=match:eq}}," + |
| 513 | // "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" + |
| 514 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mond, match=match:eq}}" + |
| 515 | // "]}" + |
| 516 | // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" + |
| 517 | // "]}," + |
| 518 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sterne, match=match:eq}}" + |
| 519 | // "], distances=[" + |
| 520 | // "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=0, max=4}, min=0, max=4}" + |
| 521 | // "], inOrder=true" + |
| 522 | // "}"; |
| 523 | // aqlt = new AqlTree(query); |
| 524 | // map = aqlt.getRequestMap().get("query").toString(); |
| 525 | // assertEquals(seq5.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 526 | // |
| 527 | // query = "cat=\"NP\" & cat=\"VP\" & cat=\"PP\" & #1 $ #2 > #3"; |
| 528 | // String cp2 = |
| 529 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 530 | // "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" + |
| 531 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 532 | // "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" + |
| 533 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 534 | // "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" + |
| 535 | // "{@type=korap:span}" + |
| 536 | // "]}," + |
| 537 | // "{@type=korap:span, layer=cat, key=NP, match=match:eq}" + |
| 538 | // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" + |
| 539 | // "]}," + |
| 540 | // "{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" + |
| 541 | // "{@type=korap:span, layer=cat, key=VP, match=match:eq}" + |
| 542 | // "]}" + |
| 543 | // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" + |
| 544 | // "}" + |
| 545 | // "]}," + |
| 546 | // "{@type=korap:span, layer=cat, key=PP, match=match:eq}" + |
| 547 | // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" + |
| 548 | // "}"; |
| 549 | // aqlt = new AqlTree(query); |
| 550 | // map = aqlt.getRequestMap().get("query").toString(); |
| 551 | // assertEquals(cp2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 552 | // } |
| 553 | // /* |
| 554 | // @Test |
| 555 | // public void testMultipleOperatorsWithSameOperands() throws QueryException { |
| 556 | // |
| 557 | // query = "cat=\"NP\" > cat=\"VP\" & #1 _l_ #2"; |
| 558 | // String eq2 = |
| 559 | // "{@type=korap:group, operation=operation:position, frames=[frame:startswith], sharedClasses=[sharedClasses:includes], operands=[" + |
| 560 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 561 | // "{@type=korap:group, operation=operation:class, class=, classOut=129, operands=[" + |
| 562 | // "{@type=korap:span, layer=cat, key=NP, match=match:eq}" + |
| 563 | // "]}," + |
| 564 | // "{@type=korap:group, operation=operation:class, class=, classOut=129, operands=[" + |
| 565 | // "{@type=korap:span, layer=cat, key=VP, match=match:eq}" + |
| 566 | // "]}" + |
| 567 | // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}," + |
| 568 | // "{@type=korap:reference, operation=operation:focus, classRef=[2]}" + |
| 569 | // "]" + |
| 570 | // "}"; // ??? |
| 571 | // aqlt = new AqlTree(query); |
| 572 | // map = aqlt.getRequestMap().get("query").toString(); |
| 573 | // assertEquals(eq2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 574 | // } |
| 575 | // */ |
| 576 | // @Test |
| 577 | // public void testPositions() throws QueryException { |
| 578 | // query = "node & node & #2 _=_ #1"; |
| 579 | // String pos1 = |
| 580 | // "{@type=korap:group, operation=operation:position, frames=[frames:matches], operands=[" + |
| 581 | // "{@type=korap:span}," + |
| 582 | // "{@type=korap:span}" + |
| 583 | // "], frame=frame:matches}"; |
| 584 | // aqlt = new AqlTree(query); |
| 585 | // map = aqlt.getRequestMap().get("query").toString(); |
| 586 | // assertEquals(pos1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 587 | // |
| 588 | // query = "node & node & #2 _i_ #1"; |
| 589 | // String pos2 = |
| 590 | // "{@type=korap:group, operation=operation:position, frames=[frames:contains], operands=[" + |
| 591 | // "{@type=korap:span}," + |
| 592 | // "{@type=korap:span}" + |
| 593 | // "], frame=frame:contains" + |
| 594 | // "}"; |
| 595 | // aqlt = new AqlTree(query); |
| 596 | // map = aqlt.getRequestMap().get("query").toString(); |
| 597 | // assertEquals(pos2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 598 | // |
| 599 | // query = "node & node & #2 _l_ #1"; |
| 600 | // String pos3 = |
| 601 | // "{@type=korap:group, operation=operation:position, frames=[frames:startswith], operands=[" + |
| 602 | // "{@type=korap:span}," + |
| 603 | // "{@type=korap:span}" + |
| 604 | // "], frame=frame:startswith" + |
| 605 | // "}"; |
| 606 | // aqlt = new AqlTree(query); |
| 607 | // map = aqlt.getRequestMap().get("query").toString(); |
| 608 | // assertEquals(pos3.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 609 | // |
| 610 | // query = "node & \"Mann\" & #1 _r_ #2"; |
| 611 | // String pos4 = |
| 612 | // "{@type=korap:group, operation=operation:position, frames=[frames:endswith], operands=[" + |
| 613 | // "{@type=korap:span}," + |
| 614 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" + |
| 615 | // "], frame=frame:endswith" + |
| 616 | // "}"; |
| 617 | // aqlt = new AqlTree(query); |
| 618 | // map = aqlt.getRequestMap().get("query").toString(); |
| 619 | // assertEquals(pos4.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 620 | // |
| 621 | // query = "node & \"Mann\" & #2 _r_ #1"; |
| 622 | // String pos5 = |
| 623 | // "{@type=korap:group, operation=operation:position, frames=[frames:endswith], operands=[" + |
| 624 | // "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}," + |
| 625 | // "{@type=korap:span}" + |
| 626 | // "], frame=frame:endswith" + |
| 627 | // "}"; |
| 628 | // aqlt = new AqlTree(query); |
| 629 | // map = aqlt.getRequestMap().get("query").toString(); |
| 630 | // assertEquals(pos5.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 631 | // } |
| 632 | // |
| 633 | // @Test |
| 634 | // public void testMultiplePredications() throws QueryException { |
| 635 | // // a noun before a verb before a preposition |
| 636 | // query = "pos=\"N\" & pos=\"V\" & pos=\"P\" & #1 . #2 & #2 . #3"; |
| 637 | // String mult1 = |
| 638 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 639 | // "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" + |
| 640 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 641 | // "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=N, match=match:eq}}," + |
| 642 | // "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" + |
| 643 | // "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=V, match=match:eq}}" + |
| 644 | // "]}" + |
| 645 | // "], inOrder=true}" + |
| 646 | // "]}," + |
| 647 | // "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=P, match=match:eq}}" + |
| 648 | // "], inOrder=true}"; |
| 649 | // aqlt = new AqlTree(query); |
| 650 | // map = aqlt.getRequestMap().get("query").toString(); |
| 651 | // assertEquals(mult1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 652 | // |
| 653 | // // a noun before a verb before a preposition |
| 654 | // query = "pos=\"N\" & pos=\"V\" & #1 . #2 & #2 . pos=\"P\""; |
| 655 | // String mult2 = |
| 656 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 657 | // "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" + |
| 658 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 659 | // "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=N, match=match:eq}}," + |
| 660 | // "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" + |
| 661 | // "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=V, match=match:eq}}" + |
| 662 | // "]}" + |
| 663 | // "], inOrder=true}" + |
| 664 | // "]}," + |
| 665 | // "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=P, match=match:eq}}" + |
| 666 | // "], inOrder=true}"; |
| 667 | // aqlt = new AqlTree(query); |
| 668 | // map = aqlt.getRequestMap().get("query").toString(); |
| 669 | // assertEquals(mult2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 670 | // |
| 671 | // query = "pos=\"N\" & pos=\"V\" & pos=\"P\" & #1 > #2 & #1 > #3"; |
| 672 | // String mult3 = |
| 673 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 674 | // "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" + |
| 675 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 676 | // "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" + |
| 677 | // "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=N, match=match:eq}}" + |
| 678 | // "]}," + |
| 679 | // "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=V, match=match:eq}}" + |
| 680 | // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" + |
| 681 | // "]}," + |
| 682 | // "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=P, match=match:eq}}" + |
| 683 | // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}"; |
| 684 | // aqlt = new AqlTree(query); |
| 685 | // map = aqlt.getRequestMap().get("query").toString(); |
| 686 | // assertEquals(mult3.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 687 | // |
| 688 | // query = "cat=\"NP\" & pos=\"V\" & pos=\"P\" & #1 > #2 & #1 > #3 & #2 . #3"; |
| 689 | // String mult4 = |
| 690 | // "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 691 | // // reduce dominance relations "#1 > #2 & #1 > #3" to operand #2 in order to make it accessible for #2 . #3 (the last/outermost relation) |
| 692 | // "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" + |
| 693 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 694 | // // dominance relation #1 > #2 is reduced to #1, for expressing #1 > #3 |
| 695 | // "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" + |
| 696 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 697 | // "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" + |
| 698 | // "{@type=korap:span, layer=cat, key=NP, match=match:eq}" + |
| 699 | // "]}," + |
| 700 | // "{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" + |
| 701 | // "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=V, match=match:eq}}" + |
| 702 | // "]}" + |
| 703 | // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" + |
| 704 | // "]}," + |
| 705 | // // establish class 2 around P for later reference |
| 706 | // "{@type=korap:group, operation=operation:class, class=130, classOut=130, operands=[" + |
| 707 | // "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=P, match=match:eq}}" + |
| 708 | // "]}" + |
| 709 | // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" + |
| 710 | // "]}," + |
| 711 | // // refer back to class 2 as second operand |
| 712 | // "{@type=korap:reference, operation=operation:focus, classRef=[2]}" + |
| 713 | // "], inOrder=true}"; |
| 714 | // aqlt = new AqlTree(query); |
| 715 | // map = aqlt.getRequestMap().get("query").toString(); |
| 716 | // assertEquals(mult4.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 717 | // } |
| 718 | // |
| 719 | // @Test |
| 720 | // public void testUnaryRelations() throws QueryException { |
| 721 | // query = "node & #1:tokenarity=2"; |
| 722 | // String unary1 = |
| 723 | // "{@type=korap:span, attr={@type=korap:term, tokenarity={@type=korap:boundary,min=2,max=2}}}"; |
| 724 | // aqlt = new AqlTree(query); |
| 725 | // map = aqlt.getRequestMap().get("query").toString(); |
| 726 | // assertEquals(unary1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 727 | // |
| 728 | // query = "cnx/cat=\"NP\" & #1:tokenarity=2"; |
| 729 | // String unary2 = |
| 730 | // "{@type=korap:span, foundry=cnx, layer=cat, key=NP, match=match:eq, attr={@type=korap:term, tokenarity={@type=korap:boundary,min=2,max=2}}}"; |
| 731 | // aqlt = new AqlTree(query); |
| 732 | // map = aqlt.getRequestMap().get("query").toString(); |
| 733 | // assertEquals(unary2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 734 | // |
| 735 | // query = "cnx/cat=\"NP\" & #1:root"; |
| 736 | // String unary3 = |
| 737 | // "{@type=korap:span, foundry=cnx, layer=cat, key=NP, match=match:eq, attr={@type=korap:term, root=true}}"; |
| 738 | // aqlt = new AqlTree(query); |
| 739 | // map = aqlt.getRequestMap().get("query").toString(); |
| 740 | // assertEquals(unary3.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 741 | // |
| 742 | // query = "cnx/cat=\"NP\" & node & #1>#2 & #1:tokenarity=2"; |
| 743 | // String unary4 = |
| 744 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 745 | // "{@type=korap:span, foundry=cnx, layer=cat, key=NP, match=match:eq, attr={@type=korap:term, tokenarity={@type=korap:boundary,min=2,max=2}}}," + |
| 746 | // "{@type=korap:span}" + |
| 747 | // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" + |
| 748 | // "}"; |
| 749 | // aqlt = new AqlTree(query); |
| 750 | // map = aqlt.getRequestMap().get("query").toString(); |
| 751 | // assertEquals(unary4.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 752 | // } |
| 753 | // |
| 754 | // @Test |
| 755 | // public void testCommonParent() throws QueryException { |
| 756 | // query = "cat=\"NP\" & cat=\"VP\" & #1 $ #2"; |
| 757 | // String cp1 = |
| 758 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 759 | // "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" + |
| 760 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 761 | // "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" + |
| 762 | // "{@type=korap:span}" + |
| 763 | // "]}," + |
| 764 | // "{@type=korap:span, layer=cat, key=NP, match=match:eq}" + |
| 765 | // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" + |
| 766 | // "]}," + |
| 767 | // "{@type=korap:span, layer=cat, key=VP, match=match:eq}" + |
| 768 | // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" + |
| 769 | // ""; |
| 770 | // aqlt = new AqlTree(query); |
| 771 | // map = aqlt.getRequestMap().get("query").toString(); |
| 772 | // assertEquals(cp1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 773 | // |
| 774 | // query = "cat=\"NP\" & cat=\"VP\" & cat=\"PP\" & #1 $ #2 $ #3"; |
| 775 | // String cp2 = |
| 776 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 777 | // "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" + |
| 778 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 779 | // "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" + |
| 780 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 781 | // "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" + |
| 782 | // "{@type=korap:span}" + |
| 783 | // "]}," + |
| 784 | // "{@type=korap:span, layer=cat, key=NP, match=match:eq}" + |
| 785 | // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" + |
| 786 | // "]}," + |
| 787 | // "{@type=korap:span, layer=cat, key=VP, match=match:eq}" + |
| 788 | // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" + |
| 789 | // "}" + |
| 790 | // "]}," + |
| 791 | // "{@type=korap:span, layer=cat, key=PP, match=match:eq}" + |
| 792 | // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" + |
| 793 | // "}"; |
| 794 | // aqlt = new AqlTree(query); |
| 795 | // map = aqlt.getRequestMap().get("query").toString(); |
| 796 | // assertEquals(cp2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 797 | // |
| 798 | // query = "cat=\"NP\" & cat=\"VP\" & cat=\"PP\" & cat=\"CP\" & #1 $ #2 $ #3 $ #4"; |
| 799 | // String cp3 = |
| 800 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 801 | // "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" + |
| 802 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 803 | // "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" + |
| 804 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 805 | // "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" + |
| 806 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 807 | // "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" + |
| 808 | // "{@type=korap:span}" + |
| 809 | // "]}," + |
| 810 | // "{@type=korap:span, layer=cat, key=NP, match=match:eq}" + |
| 811 | // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" + |
| 812 | // "]}," + |
| 813 | // "{@type=korap:span, layer=cat, key=VP, match=match:eq}" + |
| 814 | // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" + |
| 815 | // "]}," + |
| 816 | // "{@type=korap:span, layer=cat, key=PP, match=match:eq}" + |
| 817 | // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" + |
| 818 | // "]}," + |
| 819 | // "{@type=korap:span, layer=cat, key=CP, match=match:eq}" + |
| 820 | // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" + |
| 821 | // "}" + |
| 822 | // ""; |
| 823 | // aqlt = new AqlTree(query); |
| 824 | // map = aqlt.getRequestMap().get("query").toString(); |
| 825 | // assertEquals(cp3.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 826 | // |
| 827 | // query = "cat=\"NP\" & cat=\"VP\" & #1 $* #2"; |
| 828 | // String cp4 = |
| 829 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 830 | // "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" + |
| 831 | // "{@type=korap:group, operation=operation:relation, operands=[" + |
| 832 | // "{@type=korap:group, operation=operation:class, class=128, classOut=128, operands=[" + |
| 833 | // "{@type=korap:span}" + |
| 834 | // "]}," + |
| 835 | // "{@type=korap:span, layer=cat, key=NP, match=match:eq}" + |
| 836 | // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c},boundary={@type=korap:boundary,min=1}}}" + |
| 837 | // "]}," + |
| 838 | // "{@type=korap:span, layer=cat, key=VP, match=match:eq}" + |
| 839 | // "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c},boundary={@type=korap:boundary,min=1}}}" + |
| 840 | // ""; |
| 841 | // aqlt = new AqlTree(query); |
| 842 | // map = aqlt.getRequestMap().get("query").toString(); |
| 843 | // assertEquals(cp4.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 844 | // } |
| 845 | |
Joachim Bingel | e6d73b1 | 2014-09-30 15:34:59 +0000 | [diff] [blame] | 846 | /* |
| 847 | @Test |
| 848 | public void testEqualNotequalValue() throws QueryException { |
| 849 | query = "cat=\"NP\" & cat=\"VP\" & #1 == #2"; |
| 850 | String eq1 = |
| 851 | "{}"; // ??? |
| 852 | aqlt = new AqlTree(query); |
| 853 | map = aqlt.getRequestMap().get("query").toString(); |
| 854 | assertEquals(eq1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 855 | } |
| 856 | */ |
| 857 | |
Joachim Bingel | 66472b8 | 2014-12-04 16:00:05 +0000 | [diff] [blame] | 858 | } |