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