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