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 | } |
| 439 | |
| 440 | @Test |
Joachim Bingel | 7503879 | 2014-05-19 15:12:23 +0000 | [diff] [blame] | 441 | public void testPositions() throws QueryException { |
| 442 | query = "node & node & #2 _=_ #1"; |
| 443 | String pos1 = |
| 444 | "{@type=korap:group, operation=operation:position, operands=[" + |
| 445 | "{@type=korap:span}," + |
| 446 | "{@type=korap:span}" + |
| 447 | "], frame=frame:matches" + |
| 448 | "}"; |
| 449 | aqlt = new AqlTree(query); |
| 450 | map = aqlt.getRequestMap().get("query").toString(); |
| 451 | assertEquals(pos1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 452 | |
Joachim Bingel | ca4944e | 2014-06-13 13:55:10 +0000 | [diff] [blame] | 453 | query = "node & node & #2 _i_ #1"; |
| 454 | String pos2 = |
| 455 | "{@type=korap:group, operation=operation:position, operands=[" + |
| 456 | "{@type=korap:span}," + |
| 457 | "{@type=korap:span}" + |
| 458 | "], frame=frame:contains" + |
| 459 | "}"; |
| 460 | aqlt = new AqlTree(query); |
| 461 | map = aqlt.getRequestMap().get("query").toString(); |
| 462 | assertEquals(pos2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 7503879 | 2014-05-19 15:12:23 +0000 | [diff] [blame] | 463 | |
Joachim Bingel | ca4944e | 2014-06-13 13:55:10 +0000 | [diff] [blame] | 464 | query = "node & node & #2 _l_ #1"; |
| 465 | String pos3 = |
| 466 | "{@type=korap:group, operation=operation:position, operands=[" + |
| 467 | "{@type=korap:span}," + |
| 468 | "{@type=korap:span}" + |
| 469 | "], inOrder=false, frame=frame:startswith" + |
| 470 | "}"; |
| 471 | aqlt = new AqlTree(query); |
| 472 | map = aqlt.getRequestMap().get("query").toString(); |
| 473 | assertEquals(pos3.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 474 | |
| 475 | query = "node & \"Mann\" & #1 _r_ #2"; |
Joachim Bingel | 7503879 | 2014-05-19 15:12:23 +0000 | [diff] [blame] | 476 | String pos4 = |
Joachim Bingel | 7503879 | 2014-05-19 15:12:23 +0000 | [diff] [blame] | 477 | "{@type=korap:group, operation=operation:position, operands=[" + |
| 478 | "{@type=korap:span}," + |
Joachim Bingel | b6d6781 | 2014-08-13 11:37:09 +0000 | [diff] [blame] | 479 | "{@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] | 480 | "], inOrder=false, frame=frame:endswith" + |
| 481 | "}"; |
Joachim Bingel | 7503879 | 2014-05-19 15:12:23 +0000 | [diff] [blame] | 482 | aqlt = new AqlTree(query); |
| 483 | map = aqlt.getRequestMap().get("query").toString(); |
| 484 | assertEquals(pos4.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 13421ef | 2014-05-07 16:22:58 +0000 | [diff] [blame] | 485 | |
Joachim Bingel | ca4944e | 2014-06-13 13:55:10 +0000 | [diff] [blame] | 486 | query = "node & \"Mann\" & #2 _r_ #1"; |
| 487 | String pos5 = |
| 488 | "{@type=korap:group, operation=operation:position, operands=[" + |
Joachim Bingel | b6d6781 | 2014-08-13 11:37:09 +0000 | [diff] [blame] | 489 | "{@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] | 490 | "{@type=korap:span}" + |
| 491 | "], inOrder=false, frame=frame:endswith" + |
| 492 | "}"; |
| 493 | aqlt = new AqlTree(query); |
| 494 | map = aqlt.getRequestMap().get("query").toString(); |
| 495 | assertEquals(pos5.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 13421ef | 2014-05-07 16:22:58 +0000 | [diff] [blame] | 496 | } |
| 497 | |
Joachim Bingel | ca4944e | 2014-06-13 13:55:10 +0000 | [diff] [blame] | 498 | @Test |
| 499 | public void testMultiplePredications() throws QueryException { |
Joachim Bingel | 9c3ddb9 | 2014-06-23 13:49:58 +0000 | [diff] [blame] | 500 | // a noun before a verb before a preposition |
Joachim Bingel | fc42881 | 2014-06-18 14:50:14 +0000 | [diff] [blame] | 501 | query = "pos=\"N\" & pos=\"V\" & pos=\"P\" & #1 . #2 & #2 . #3"; |
Joachim Bingel | ca4944e | 2014-06-13 13:55:10 +0000 | [diff] [blame] | 502 | String mult1 = |
Joachim Bingel | 9c3ddb9 | 2014-06-23 13:49:58 +0000 | [diff] [blame] | 503 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 1846c8c | 2014-07-08 14:13:31 +0000 | [diff] [blame] | 504 | "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" + |
Joachim Bingel | ca4944e | 2014-06-13 13:55:10 +0000 | [diff] [blame] | 505 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 9c3ddb9 | 2014-06-23 13:49:58 +0000 | [diff] [blame] | 506 | "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=N, match=match:eq}}," + |
| 507 | "{@type=korap:group, operation=operation:class, class=0, operands=[" + |
| 508 | "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=V, match=match:eq}}" + |
| 509 | "]}" + |
| 510 | "], inOrder=true}" + |
Joachim Bingel | aee38ae | 2014-06-25 09:32:56 +0000 | [diff] [blame] | 511 | "]}," + |
Joachim Bingel | 9c3ddb9 | 2014-06-23 13:49:58 +0000 | [diff] [blame] | 512 | "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=P, match=match:eq}}" + |
| 513 | "], inOrder=true}"; |
Joachim Bingel | ca4944e | 2014-06-13 13:55:10 +0000 | [diff] [blame] | 514 | aqlt = new AqlTree(query); |
| 515 | map = aqlt.getRequestMap().get("query").toString(); |
| 516 | assertEquals(mult1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 9c3ddb9 | 2014-06-23 13:49:58 +0000 | [diff] [blame] | 517 | |
| 518 | // a noun before a verb before a preposition |
| 519 | query = "pos=\"N\" & pos=\"V\" & #1 . #2 & #2 . pos=\"P\""; |
| 520 | String mult2 = |
| 521 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 1846c8c | 2014-07-08 14:13:31 +0000 | [diff] [blame] | 522 | "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" + |
Joachim Bingel | 9c3ddb9 | 2014-06-23 13:49:58 +0000 | [diff] [blame] | 523 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 524 | "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=N, match=match:eq}}," + |
| 525 | "{@type=korap:group, operation=operation:class, class=0, operands=[" + |
| 526 | "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=V, match=match:eq}}" + |
| 527 | "]}" + |
| 528 | "], inOrder=true}" + |
Joachim Bingel | aee38ae | 2014-06-25 09:32:56 +0000 | [diff] [blame] | 529 | "]}," + |
Joachim Bingel | 9c3ddb9 | 2014-06-23 13:49:58 +0000 | [diff] [blame] | 530 | "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=P, match=match:eq}}" + |
| 531 | "], inOrder=true}"; |
| 532 | aqlt = new AqlTree(query); |
| 533 | map = aqlt.getRequestMap().get("query").toString(); |
| 534 | assertEquals(mult2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | aee38ae | 2014-06-25 09:32:56 +0000 | [diff] [blame] | 535 | |
| 536 | query = "pos=\"N\" & pos=\"V\" & pos=\"P\" & #1 > #2 & #1 > #3"; |
| 537 | String mult3 = |
| 538 | "{@type=korap:group, operation=operation:relation, operands=[" + |
Joachim Bingel | 1846c8c | 2014-07-08 14:13:31 +0000 | [diff] [blame] | 539 | "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" + |
Joachim Bingel | aee38ae | 2014-06-25 09:32:56 +0000 | [diff] [blame] | 540 | "{@type=korap:group, operation=operation:relation, operands=[" + |
| 541 | "{@type=korap:group, operation=operation:class, class=0, operands=[" + |
| 542 | "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=N, match=match:eq}}" + |
| 543 | "]}," + |
| 544 | "{@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] | 545 | "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" + |
Joachim Bingel | aee38ae | 2014-06-25 09:32:56 +0000 | [diff] [blame] | 546 | "]}," + |
| 547 | "{@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] | 548 | "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}"; |
Joachim Bingel | aee38ae | 2014-06-25 09:32:56 +0000 | [diff] [blame] | 549 | aqlt = new AqlTree(query); |
| 550 | map = aqlt.getRequestMap().get("query").toString(); |
| 551 | assertEquals(mult3.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 552 | |
| 553 | query = "cat=\"NP\" & pos=\"V\" & pos=\"P\" & #1 > #2 & #1 > #3 & #2 . #3"; |
| 554 | String mult4 = |
| 555 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 556 | // 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] | 557 | "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" + |
Joachim Bingel | aee38ae | 2014-06-25 09:32:56 +0000 | [diff] [blame] | 558 | "{@type=korap:group, operation=operation:relation, operands=[" + |
| 559 | // dominance relation #1 > #2 is reduced to #1, for expressing #1 > #3 |
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:span, layer=cat, key=NP, match=match:eq}" + |
| 564 | "]}," + |
| 565 | "{@type=korap:group, operation=operation:class, class=1, operands=[" + |
| 566 | "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=V, match=match:eq}}" + |
| 567 | "]}" + |
Joachim Bingel | 6289241 | 2014-08-06 15:18:59 +0000 | [diff] [blame] | 568 | "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" + |
Joachim Bingel | aee38ae | 2014-06-25 09:32:56 +0000 | [diff] [blame] | 569 | "]}," + |
| 570 | // establish class 2 around P for later reference |
| 571 | "{@type=korap:group, operation=operation:class, class=2, operands=[" + |
| 572 | "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=P, match=match:eq}}" + |
| 573 | "]}" + |
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 | "]}," + |
| 576 | // refer back to class 2 as second operand |
Joachim Bingel | 1846c8c | 2014-07-08 14:13:31 +0000 | [diff] [blame] | 577 | "{@type=korap:reference, operation=operation:focus, classRef=[2]}" + |
Joachim Bingel | aee38ae | 2014-06-25 09:32:56 +0000 | [diff] [blame] | 578 | "], inOrder=true}"; |
| 579 | aqlt = new AqlTree(query); |
| 580 | map = aqlt.getRequestMap().get("query").toString(); |
| 581 | assertEquals(mult4.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | ca4944e | 2014-06-13 13:55:10 +0000 | [diff] [blame] | 582 | } |
Joachim Bingel | eee549e | 2014-04-29 11:15:37 +0000 | [diff] [blame] | 583 | |
Joachim Bingel | ca4944e | 2014-06-13 13:55:10 +0000 | [diff] [blame] | 584 | @Test |
| 585 | public void testUnaryRelations() throws QueryException { |
| 586 | query = "node & #1:tokenarity=2"; |
| 587 | String unary1 = |
| 588 | "{@type=korap:span, attr={@type=korap:term, tokenarity={@type=korap:boundary,min=2,max=2}}}"; |
| 589 | aqlt = new AqlTree(query); |
| 590 | map = aqlt.getRequestMap().get("query").toString(); |
| 591 | assertEquals(unary1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 592 | |
| 593 | query = "cnx/cat=\"NP\" & #1:tokenarity=2"; |
| 594 | String unary2 = |
| 595 | "{@type=korap:span, foundry=cnx, layer=cat, key=NP, match=match:eq, attr={@type=korap:term, tokenarity={@type=korap:boundary,min=2,max=2}}}"; |
| 596 | aqlt = new AqlTree(query); |
| 597 | map = aqlt.getRequestMap().get("query").toString(); |
| 598 | assertEquals(unary2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 599 | |
| 600 | query = "cnx/cat=\"NP\" & #1:root"; |
| 601 | String unary3 = |
| 602 | "{@type=korap:span, foundry=cnx, layer=cat, key=NP, match=match:eq, attr={@type=korap:term, root=true}}"; |
| 603 | aqlt = new AqlTree(query); |
| 604 | map = aqlt.getRequestMap().get("query").toString(); |
| 605 | assertEquals(unary3.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 606 | |
| 607 | query = "cnx/cat=\"NP\" & node & #1>#2 & #1:tokenarity=2"; |
| 608 | String unary4 = |
| 609 | "{@type=korap:group, operation=operation:relation, operands=[" + |
| 610 | "{@type=korap:span, foundry=cnx, layer=cat, key=NP, match=match:eq, attr={@type=korap:term, tokenarity={@type=korap:boundary,min=2,max=2}}}," + |
| 611 | "{@type=korap:span}" + |
Joachim Bingel | 6289241 | 2014-08-06 15:18:59 +0000 | [diff] [blame] | 612 | "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" + |
Joachim Bingel | ca4944e | 2014-06-13 13:55:10 +0000 | [diff] [blame] | 613 | "}"; |
| 614 | aqlt = new AqlTree(query); |
| 615 | map = aqlt.getRequestMap().get("query").toString(); |
| 616 | assertEquals(unary4.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 617 | } |
| 618 | |
Joachim Bingel | 1846c8c | 2014-07-08 14:13:31 +0000 | [diff] [blame] | 619 | @Test |
| 620 | public void testCommonParent() throws QueryException { |
| 621 | query = "cat=\"NP\" & cat=\"VP\" & #1 $ #2"; |
| 622 | String cp1 = |
| 623 | "{@type=korap:group, operation=operation:relation, operands=[" + |
| 624 | "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" + |
| 625 | "{@type=korap:group, operation=operation:relation, operands=[" + |
| 626 | "{@type=korap:group, operation=operation:class, class=0, operands=[" + |
| 627 | "{@type=korap:span}" + |
| 628 | "]}," + |
| 629 | "{@type=korap:span, layer=cat, key=NP, match=match:eq}" + |
Joachim Bingel | 6289241 | 2014-08-06 15:18:59 +0000 | [diff] [blame] | 630 | "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" + |
Joachim Bingel | 1846c8c | 2014-07-08 14:13:31 +0000 | [diff] [blame] | 631 | "]}," + |
| 632 | "{@type=korap:span, layer=cat, key=VP, match=match:eq}" + |
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 | 1846c8c | 2014-07-08 14:13:31 +0000 | [diff] [blame] | 634 | ""; |
| 635 | aqlt = new AqlTree(query); |
| 636 | map = aqlt.getRequestMap().get("query").toString(); |
| 637 | assertEquals(cp1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 638 | |
| 639 | query = "cat=\"NP\" & cat=\"VP\" & cat=\"PP\" & #1 $ #2 $ #3"; |
| 640 | String cp2 = |
| 641 | "{@type=korap:group, operation=operation:relation, operands=[" + |
| 642 | "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" + |
| 643 | "{@type=korap:group, operation=operation:relation, operands=[" + |
| 644 | "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" + |
| 645 | "{@type=korap:group, operation=operation:relation, operands=[" + |
| 646 | "{@type=korap:group, operation=operation:class, class=0, operands=[" + |
| 647 | "{@type=korap:span}" + |
| 648 | "]}," + |
| 649 | "{@type=korap:span, layer=cat, key=NP, match=match:eq}" + |
Joachim Bingel | 6289241 | 2014-08-06 15:18:59 +0000 | [diff] [blame] | 650 | "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" + |
Joachim Bingel | 1846c8c | 2014-07-08 14:13:31 +0000 | [diff] [blame] | 651 | "]}," + |
| 652 | "{@type=korap:span, layer=cat, key=VP, match=match:eq}" + |
Joachim Bingel | 6289241 | 2014-08-06 15:18:59 +0000 | [diff] [blame] | 653 | "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" + |
Joachim Bingel | 1846c8c | 2014-07-08 14:13:31 +0000 | [diff] [blame] | 654 | "}" + |
| 655 | "]}," + |
| 656 | "{@type=korap:span, layer=cat, key=PP, match=match:eq}" + |
Joachim Bingel | 6289241 | 2014-08-06 15:18:59 +0000 | [diff] [blame] | 657 | "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" + |
Joachim Bingel | 1846c8c | 2014-07-08 14:13:31 +0000 | [diff] [blame] | 658 | "}"; |
| 659 | aqlt = new AqlTree(query); |
| 660 | map = aqlt.getRequestMap().get("query").toString(); |
| 661 | assertEquals(cp2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 662 | |
| 663 | query = "cat=\"NP\" & cat=\"VP\" & cat=\"PP\" & cat=\"CP\" & #1 $ #2 $ #3 $ #4"; |
| 664 | String cp3 = |
| 665 | "{@type=korap:group, operation=operation:relation, operands=[" + |
| 666 | "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" + |
| 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 | "{@type=korap:span, layer=cat, key=PP, match=match:eq}" + |
Joachim Bingel | 6289241 | 2014-08-06 15:18:59 +0000 | [diff] [blame] | 682 | "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}}" + |
Joachim Bingel | 1846c8c | 2014-07-08 14:13:31 +0000 | [diff] [blame] | 683 | "]}," + |
| 684 | "{@type=korap:span, layer=cat, key=CP, match=match:eq}" + |
Joachim Bingel | 6289241 | 2014-08-06 15:18:59 +0000 | [diff] [blame] | 685 | "], relation={@type=korap:relation, wrap={@type=korap:term, layer=c}}" + |
Joachim Bingel | 1846c8c | 2014-07-08 14:13:31 +0000 | [diff] [blame] | 686 | "}" + |
| 687 | ""; |
| 688 | aqlt = new AqlTree(query); |
| 689 | map = aqlt.getRequestMap().get("query").toString(); |
| 690 | assertEquals(cp3.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 691 | } |
| 692 | |
Joachim Bingel | ca4944e | 2014-06-13 13:55:10 +0000 | [diff] [blame] | 693 | } |