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 | eee549e | 2014-04-29 11:15:37 +0000 | [diff] [blame] | 32 | String token1 = "{@type=korap:token, wrap={@type=korap:term, 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 | eee549e | 2014-04-29 11:15:37 +0000 | [diff] [blame] | 59 | String regex1 = "{@type=korap:token, wrap={@type=korap:term, 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.*?/"; |
| 65 | String regex2 = "{@type=korap:token, wrap={@type=korap:term, type=type:regex, key=.*?Mann.*?, match=match:eq}}"; |
| 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}" + |
| 93 | "], relation={@type=korap:treeRelation, reltype=dominance}" + |
| 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}" + |
| 104 | "], relation={@type=korap:treeRelation, reltype=dominance}" + |
| 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}" + |
| 119 | "], relation={@type=korap:treeRelation, reltype=dominance}" + |
| 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 | d4ae5fd | 2014-04-29 15:00:16 +0000 | [diff] [blame] | 133 | "], relation={@type=korap:treeRelation, reltype=dominance}" + |
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}," + |
| 143 | "{@type=korap:token, wrap={@type=korap:term, key=Mann, match=match:eq}}" + |
Joachim Bingel | d4ae5fd | 2014-04-29 15:00:16 +0000 | [diff] [blame] | 144 | "], relation={@type=korap:treeRelation, reltype=dominance}" + |
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}," + |
| 154 | "{@type=korap:token, wrap={@type=korap:term, key=Mann, match=match:eq}}" + |
Joachim Bingel | a07b8e7 | 2014-05-09 15:06:07 +0000 | [diff] [blame] | 155 | "], relation={@type=korap:treeRelation, reltype=dominance, wrap=[{@type=korap:term, layer=cat, 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}," + |
| 165 | "{@type=korap:token, wrap={@type=korap:term, key=Mann, match=match:eq}}" + |
Joachim Bingel | a07b8e7 | 2014-05-09 15:06:07 +0000 | [diff] [blame] | 166 | "], relation={@type=korap:treeRelation, reltype=dominance, index=0, wrap=[{@type=korap:term, layer=cat, 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}," + |
| 176 | "{@type=korap:token, wrap={@type=korap:term, key=Mann, match=match:eq}}" + |
| 177 | "], relation={@type=korap:treeRelation, reltype=dominance, " + |
Joachim Bingel | 86195a5 | 2014-07-08 14:29:48 +0000 | [diff] [blame] | 178 | "boundary={@type=korap:boundary, min=2, max=4}}" + |
Joachim Bingel | d4ae5fd | 2014-04-29 15:00:16 +0000 | [diff] [blame] | 179 | "}"; |
| 180 | aqlt = new AqlTree(query); |
| 181 | map = aqlt.getRequestMap().get("query").toString(); |
| 182 | assertEquals(dom5.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 019ba5c | 2014-04-28 14:59:04 +0000 | [diff] [blame] | 183 | } |
| 184 | |
Joachim Bingel | 13421ef | 2014-05-07 16:22:58 +0000 | [diff] [blame] | 185 | @Test |
Joachim Bingel | ca4944e | 2014-06-13 13:55:10 +0000 | [diff] [blame] | 186 | public void testMultipleDominance() throws QueryException { |
Joachim Bingel | 949e3a8 | 2014-06-16 13:20:43 +0000 | [diff] [blame] | 187 | query = "cat=\"CP\" & cat=\"VP\" & cat=\"NP\" & #1 > #2 > #3"; |
Joachim Bingel | ca4944e | 2014-06-13 13:55:10 +0000 | [diff] [blame] | 188 | String dom1 = |
| 189 | "{@type=korap:group, operation=operation:relation, operands=[" + |
Joachim Bingel | 1846c8c | 2014-07-08 14:13:31 +0000 | [diff] [blame] | 190 | "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" + |
Joachim Bingel | fc42881 | 2014-06-18 14:50:14 +0000 | [diff] [blame] | 191 | "{@type=korap:group, operation=operation:relation, operands=[" + |
| 192 | "{@type=korap:span, layer=cat, key=CP, match=match:eq}," + |
| 193 | "{@type=korap:group, operation=operation:class, class=0, operands=[" + |
| 194 | "{@type=korap:span, layer=cat, key=VP, match=match:eq}" + |
| 195 | "]}" + |
| 196 | "], relation={@type=korap:treeRelation, reltype=dominance}}" + |
Joachim Bingel | aee38ae | 2014-06-25 09:32:56 +0000 | [diff] [blame] | 197 | "]}," + |
Joachim Bingel | 949e3a8 | 2014-06-16 13:20:43 +0000 | [diff] [blame] | 198 | "{@type=korap:span, layer=cat, key=NP, match=match:eq}" + |
Joachim Bingel | ca4944e | 2014-06-13 13:55:10 +0000 | [diff] [blame] | 199 | "], relation={@type=korap:treeRelation, reltype=dominance}" + |
| 200 | "}"; |
| 201 | aqlt = new AqlTree(query); |
| 202 | map = aqlt.getRequestMap().get("query").toString(); |
| 203 | assertEquals(dom1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 949e3a8 | 2014-06-16 13:20:43 +0000 | [diff] [blame] | 204 | |
| 205 | query = "cat=\"CP\" & cat=\"VP\" & cat=\"NP\" & cat=\"DP\" & #1 > #2 > #3 > #4"; |
| 206 | String dom2 = |
| 207 | "{@type=korap:group, operation=operation:relation, operands=[" + |
Joachim Bingel | 1846c8c | 2014-07-08 14:13:31 +0000 | [diff] [blame] | 208 | "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" + |
Joachim Bingel | 949e3a8 | 2014-06-16 13:20:43 +0000 | [diff] [blame] | 209 | "{@type=korap:group, operation=operation:relation, operands=[" + |
Joachim Bingel | 1846c8c | 2014-07-08 14:13:31 +0000 | [diff] [blame] | 210 | "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" + |
Joachim Bingel | fc42881 | 2014-06-18 14:50:14 +0000 | [diff] [blame] | 211 | "{@type=korap:group, operation=operation:relation, operands=[" + |
| 212 | "{@type=korap:span, layer=cat, key=CP, match=match:eq}," + |
| 213 | "{@type=korap:group, operation=operation:class, class=0, operands=[" + |
| 214 | "{@type=korap:span, layer=cat, key=VP, match=match:eq}" + |
| 215 | "]}" + |
| 216 | "], relation={@type=korap:treeRelation, reltype=dominance}}" + |
Joachim Bingel | aee38ae | 2014-06-25 09:32:56 +0000 | [diff] [blame] | 217 | "]}," + |
Joachim Bingel | fc42881 | 2014-06-18 14:50:14 +0000 | [diff] [blame] | 218 | "{@type=korap:group, operation=operation:class, class=1, operands=[" + |
| 219 | "{@type=korap:span, layer=cat, key=NP, match=match:eq}" + |
| 220 | "]}" + |
| 221 | "], relation={@type=korap:treeRelation, reltype=dominance}}" + |
Joachim Bingel | aee38ae | 2014-06-25 09:32:56 +0000 | [diff] [blame] | 222 | "]}," + |
Joachim Bingel | 949e3a8 | 2014-06-16 13:20:43 +0000 | [diff] [blame] | 223 | "{@type=korap:span, layer=cat, key=DP, match=match:eq}" + |
| 224 | "], relation={@type=korap:treeRelation, reltype=dominance}" + |
| 225 | "}"; |
| 226 | aqlt = new AqlTree(query); |
| 227 | map = aqlt.getRequestMap().get("query").toString(); |
| 228 | assertEquals(dom2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | ca4944e | 2014-06-13 13:55:10 +0000 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | @Test |
Joachim Bingel | 13421ef | 2014-05-07 16:22:58 +0000 | [diff] [blame] | 232 | public void testPointingRelations() throws QueryException { |
| 233 | query = "node & node & #2 ->label[coref=\"true\"] #1"; |
| 234 | String dom1 = |
| 235 | "{@type=korap:group, operation=operation:relation, operands=[" + |
| 236 | "{@type=korap:span}," + |
| 237 | "{@type=korap:span}" + |
Joachim Bingel | a07b8e7 | 2014-05-09 15:06:07 +0000 | [diff] [blame] | 238 | "], relation={@type=korap:relation, reltype=label, wrap=[{@type=korap:term, layer=coref, key=true, match=match:eq}]}" + |
Joachim Bingel | 13421ef | 2014-05-07 16:22:58 +0000 | [diff] [blame] | 239 | "}"; |
| 240 | aqlt = new AqlTree(query); |
| 241 | map = aqlt.getRequestMap().get("query").toString(); |
| 242 | assertEquals(dom1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 243 | |
Joachim Bingel | 639df9c | 2014-05-12 15:27:00 +0000 | [diff] [blame] | 244 | query = "node & node & #2 ->label[mate/coref=\"true\"] #1"; |
| 245 | String dom2 = |
| 246 | "{@type=korap:group, operation=operation:relation, operands=[" + |
| 247 | "{@type=korap:span}," + |
| 248 | "{@type=korap:span}" + |
| 249 | "], relation={@type=korap:relation, reltype=label, wrap=[{@type=korap:term, foundry=mate, layer=coref, key=true, match=match:eq}]}" + |
| 250 | "}"; |
| 251 | aqlt = new AqlTree(query); |
| 252 | map = aqlt.getRequestMap().get("query").toString(); |
| 253 | assertEquals(dom2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 13421ef | 2014-05-07 16:22:58 +0000 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | @Test |
| 257 | public void testSequence() throws QueryException { |
| 258 | query = "node & node & #1 . #2"; |
Joachim Bingel | ca4944e | 2014-06-13 13:55:10 +0000 | [diff] [blame] | 259 | String seq1 = |
Joachim Bingel | 13421ef | 2014-05-07 16:22:58 +0000 | [diff] [blame] | 260 | "{@type=korap:group, operation=operation:sequence, " + |
| 261 | "operands=[" + |
| 262 | "{@type=korap:span}," + |
| 263 | "{@type=korap:span}" + |
| 264 | "], inOrder=true" + |
| 265 | "}"; |
| 266 | aqlt = new AqlTree(query); |
| 267 | map = aqlt.getRequestMap().get("query").toString(); |
Joachim Bingel | ca4944e | 2014-06-13 13:55:10 +0000 | [diff] [blame] | 268 | assertEquals(seq1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 13421ef | 2014-05-07 16:22:58 +0000 | [diff] [blame] | 269 | |
| 270 | query = "node & node & #1 .* #2"; |
Joachim Bingel | ca4944e | 2014-06-13 13:55:10 +0000 | [diff] [blame] | 271 | String seq2 = |
Joachim Bingel | 7503879 | 2014-05-19 15:12:23 +0000 | [diff] [blame] | 272 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 13421ef | 2014-05-07 16:22:58 +0000 | [diff] [blame] | 273 | "{@type=korap:span}," + |
| 274 | "{@type=korap:span}" + |
| 275 | "], distances=[" + |
| 276 | "{@type=korap:distance, key=w, min=0, max=100}" + |
| 277 | "], inOrder=true" + |
| 278 | "}"; |
| 279 | aqlt = new AqlTree(query); |
| 280 | map = aqlt.getRequestMap().get("query").toString(); |
Joachim Bingel | ca4944e | 2014-06-13 13:55:10 +0000 | [diff] [blame] | 281 | assertEquals(seq2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 282 | |
| 283 | query = "node & node & #1 .2,3 #2"; |
| 284 | String seq3 = |
| 285 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 286 | "{@type=korap:span}," + |
| 287 | "{@type=korap:span}" + |
| 288 | "], distances=[" + |
| 289 | "{@type=korap:distance, key=w, min=2, max=3}" + |
| 290 | "], inOrder=true" + |
| 291 | "}"; |
| 292 | aqlt = new AqlTree(query); |
| 293 | map = aqlt.getRequestMap().get("query").toString(); |
| 294 | assertEquals(seq3.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 295 | |
| 296 | } |
| 297 | |
| 298 | @Test |
| 299 | public void testMultipleSequence() throws QueryException { |
| 300 | query = "tok=\"Sonne\" & tok=\"Mond\" & tok=\"Sterne\" & #1 .0,2 #2 .0,4 #3"; |
| 301 | String seq4 = |
| 302 | "{@type=korap:group, operation=operation:sequence," + |
Joachim Bingel | fc42881 | 2014-06-18 14:50:14 +0000 | [diff] [blame] | 303 | "operands=[" + |
Joachim Bingel | 1846c8c | 2014-07-08 14:13:31 +0000 | [diff] [blame] | 304 | "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" + |
Joachim Bingel | ca4944e | 2014-06-13 13:55:10 +0000 | [diff] [blame] | 305 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 949e3a8 | 2014-06-16 13:20:43 +0000 | [diff] [blame] | 306 | "{@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] | 307 | "{@type=korap:group, operation=operation:class, class=0, operands=[" + |
| 308 | "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mond, match=match:eq}}" + |
| 309 | "]}" + |
Joachim Bingel | 949e3a8 | 2014-06-16 13:20:43 +0000 | [diff] [blame] | 310 | "], distances=[" + |
| 311 | "{@type=korap:distance, key=w, min=0, max=2}" + |
Joachim Bingel | fc42881 | 2014-06-18 14:50:14 +0000 | [diff] [blame] | 312 | "], inOrder=true}" + |
Joachim Bingel | aee38ae | 2014-06-25 09:32:56 +0000 | [diff] [blame] | 313 | "]}," + |
Joachim Bingel | fc42881 | 2014-06-18 14:50:14 +0000 | [diff] [blame] | 314 | "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sterne, match=match:eq}}" + |
| 315 | "],distances=[" + |
| 316 | "{@type=korap:distance, key=w, min=0, max=4}" + |
| 317 | "], inOrder=true" + |
| 318 | "}"; |
Joachim Bingel | ca4944e | 2014-06-13 13:55:10 +0000 | [diff] [blame] | 319 | aqlt = new AqlTree(query); |
| 320 | map = aqlt.getRequestMap().get("query").toString(); |
| 321 | assertEquals(seq4.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 322 | |
| 323 | query = "node & node & node & #1 . #2 .1,3 #3"; |
| 324 | String seq5 = |
| 325 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 1846c8c | 2014-07-08 14:13:31 +0000 | [diff] [blame] | 326 | "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" + |
Joachim Bingel | fc42881 | 2014-06-18 14:50:14 +0000 | [diff] [blame] | 327 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 328 | "{@type=korap:span}," + |
| 329 | "{@type=korap:group, operation=operation:class, class=0, operands=[" + |
| 330 | "{@type=korap:span}" + |
| 331 | "]} "+ |
| 332 | "], inOrder=true}" + |
Joachim Bingel | aee38ae | 2014-06-25 09:32:56 +0000 | [diff] [blame] | 333 | "]}," + |
Joachim Bingel | 949e3a8 | 2014-06-16 13:20:43 +0000 | [diff] [blame] | 334 | "{@type=korap:span}" + |
| 335 | "], distances=[" + |
Joachim Bingel | ca4944e | 2014-06-13 13:55:10 +0000 | [diff] [blame] | 336 | "{@type=korap:distance, key=w, min=1, max=3}" + |
Joachim Bingel | 949e3a8 | 2014-06-16 13:20:43 +0000 | [diff] [blame] | 337 | "], inOrder=true" + |
Joachim Bingel | ca4944e | 2014-06-13 13:55:10 +0000 | [diff] [blame] | 338 | "}"; |
| 339 | aqlt = new AqlTree(query); |
| 340 | map = aqlt.getRequestMap().get("query").toString(); |
| 341 | assertEquals(seq5.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | aee38ae | 2014-06-25 09:32:56 +0000 | [diff] [blame] | 342 | |
| 343 | query = "tok=\"Sonne\" & tok=\"Mond\" & tok=\"Sterne\" & tok=\"Himmel\" & #1 .0,2 #2 .0,4 #3 . #4"; |
| 344 | String seq6 = |
| 345 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 1846c8c | 2014-07-08 14:13:31 +0000 | [diff] [blame] | 346 | "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" + |
Joachim Bingel | aee38ae | 2014-06-25 09:32:56 +0000 | [diff] [blame] | 347 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 1846c8c | 2014-07-08 14:13:31 +0000 | [diff] [blame] | 348 | "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" + |
Joachim Bingel | aee38ae | 2014-06-25 09:32:56 +0000 | [diff] [blame] | 349 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 350 | "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sonne, match=match:eq}}," + |
| 351 | "{@type=korap:group, operation=operation:class, class=0, operands=[" + |
| 352 | "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mond, match=match:eq}}" + |
| 353 | "]}" + |
| 354 | "], distances=[" + |
| 355 | "{@type=korap:distance, key=w, min=0, max=2}" + |
| 356 | "], inOrder=true}" + |
| 357 | "]}," + |
| 358 | "{@type=korap:group, operation=operation:class, class=1, operands=[" + |
| 359 | "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sterne, match=match:eq}}" + |
| 360 | "]}" + |
| 361 | "],distances=[" + |
| 362 | "{@type=korap:distance, key=w, min=0, max=4}" + |
| 363 | "], inOrder=true}" + |
| 364 | "]}," + |
| 365 | "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Himmel, match=match:eq}}" + |
| 366 | "], inOrder=true}" ; |
| 367 | aqlt = new AqlTree(query); |
| 368 | map = aqlt.getRequestMap().get("query").toString(); |
| 369 | assertEquals(seq6.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 7503879 | 2014-05-19 15:12:23 +0000 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | @Test |
Joachim Bingel | 949e3a8 | 2014-06-16 13:20:43 +0000 | [diff] [blame] | 373 | public void testMultipleMixedOperators() throws QueryException { |
| 374 | query = "tok=\"Sonne\" & tok=\"Mond\" & tok=\"Sterne\" & #1 > #2 .0,4 #3"; |
| 375 | String seq4 = |
Joachim Bingel | fc42881 | 2014-06-18 14:50:14 +0000 | [diff] [blame] | 376 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 1846c8c | 2014-07-08 14:13:31 +0000 | [diff] [blame] | 377 | "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" + |
Joachim Bingel | fc42881 | 2014-06-18 14:50:14 +0000 | [diff] [blame] | 378 | "{@type=korap:group, operation=operation:relation, operands=[" + |
| 379 | "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sonne, match=match:eq}}," + |
| 380 | "{@type=korap:group, operation=operation:class, class=0, operands=[" + |
| 381 | "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mond, match=match:eq}}" + |
| 382 | "]}" + |
| 383 | "], relation={@type=korap:treeRelation, reltype=dominance}}" + |
Joachim Bingel | aee38ae | 2014-06-25 09:32:56 +0000 | [diff] [blame] | 384 | "]}," + |
Joachim Bingel | 949e3a8 | 2014-06-16 13:20:43 +0000 | [diff] [blame] | 385 | "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sterne, match=match:eq}}" + |
| 386 | "], distances=[" + |
| 387 | "{@type=korap:distance, key=w, min=0, max=4}" + |
| 388 | "], inOrder=true" + |
| 389 | "}"; |
| 390 | aqlt = new AqlTree(query); |
| 391 | map = aqlt.getRequestMap().get("query").toString(); |
| 392 | assertEquals(seq4.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | fc42881 | 2014-06-18 14:50:14 +0000 | [diff] [blame] | 393 | |
| 394 | query = "tok=\"Sonne\" & tok=\"Mond\" & #1 > #2 .0,4 tok=\"Sterne\""; |
| 395 | String seq5 = |
| 396 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 1846c8c | 2014-07-08 14:13:31 +0000 | [diff] [blame] | 397 | "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" + |
Joachim Bingel | fc42881 | 2014-06-18 14:50:14 +0000 | [diff] [blame] | 398 | "{@type=korap:group, operation=operation:relation, operands=[" + |
| 399 | "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sonne, match=match:eq}}," + |
| 400 | "{@type=korap:group, operation=operation:class, class=0, operands=[" + |
| 401 | "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mond, match=match:eq}}" + |
| 402 | "]}" + |
| 403 | "], relation={@type=korap:treeRelation, reltype=dominance}}" + |
Joachim Bingel | aee38ae | 2014-06-25 09:32:56 +0000 | [diff] [blame] | 404 | "]}," + |
Joachim Bingel | fc42881 | 2014-06-18 14:50:14 +0000 | [diff] [blame] | 405 | "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Sterne, match=match:eq}}" + |
| 406 | "], distances=[" + |
| 407 | "{@type=korap:distance, key=w, min=0, max=4}" + |
| 408 | "], inOrder=true" + |
| 409 | "}"; |
| 410 | aqlt = new AqlTree(query); |
| 411 | map = aqlt.getRequestMap().get("query").toString(); |
| 412 | assertEquals(seq5.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 1846c8c | 2014-07-08 14:13:31 +0000 | [diff] [blame] | 413 | |
| 414 | query = "cat=\"NP\" & cat=\"VP\" & cat=\"PP\" & #1 $ #2 > #3"; |
| 415 | String cp2 = |
| 416 | "{@type=korap:group, operation=operation:relation, operands=[" + |
| 417 | "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" + |
| 418 | "{@type=korap:group, operation=operation:relation, operands=[" + |
| 419 | "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" + |
| 420 | "{@type=korap:group, operation=operation:relation, operands=[" + |
| 421 | "{@type=korap:group, operation=operation:class, class=0, operands=[" + |
| 422 | "{@type=korap:span}" + |
| 423 | "]}," + |
| 424 | "{@type=korap:span, layer=cat, key=NP, match=match:eq}" + |
| 425 | "], relation={@type=korap:treeRelation, reltype=dominance}}" + |
| 426 | "]}," + |
| 427 | "{@type=korap:group, operation=operation:class, class=1, operands=[" + |
| 428 | "{@type=korap:span, layer=cat, key=VP, match=match:eq}" + |
| 429 | "]}" + |
| 430 | "], relation={@type=korap:treeRelation, reltype=dominance}" + |
| 431 | "}" + |
| 432 | "]}," + |
| 433 | "{@type=korap:span, layer=cat, key=PP, match=match:eq}" + |
| 434 | "], relation={@type=korap:treeRelation, reltype=dominance}" + |
| 435 | "}"; |
| 436 | aqlt = new AqlTree(query); |
| 437 | map = aqlt.getRequestMap().get("query").toString(); |
| 438 | assertEquals(cp2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 949e3a8 | 2014-06-16 13:20:43 +0000 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | @Test |
Joachim Bingel | 7503879 | 2014-05-19 15:12:23 +0000 | [diff] [blame] | 442 | public void testPositions() throws QueryException { |
| 443 | query = "node & node & #2 _=_ #1"; |
| 444 | String pos1 = |
| 445 | "{@type=korap:group, operation=operation:position, operands=[" + |
| 446 | "{@type=korap:span}," + |
| 447 | "{@type=korap:span}" + |
| 448 | "], frame=frame:matches" + |
| 449 | "}"; |
| 450 | aqlt = new AqlTree(query); |
| 451 | map = aqlt.getRequestMap().get("query").toString(); |
| 452 | assertEquals(pos1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 453 | |
Joachim Bingel | ca4944e | 2014-06-13 13:55:10 +0000 | [diff] [blame] | 454 | query = "node & node & #2 _i_ #1"; |
| 455 | String pos2 = |
| 456 | "{@type=korap:group, operation=operation:position, operands=[" + |
| 457 | "{@type=korap:span}," + |
| 458 | "{@type=korap:span}" + |
| 459 | "], frame=frame:contains" + |
| 460 | "}"; |
| 461 | aqlt = new AqlTree(query); |
| 462 | map = aqlt.getRequestMap().get("query").toString(); |
| 463 | assertEquals(pos2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 7503879 | 2014-05-19 15:12:23 +0000 | [diff] [blame] | 464 | |
Joachim Bingel | ca4944e | 2014-06-13 13:55:10 +0000 | [diff] [blame] | 465 | query = "node & node & #2 _l_ #1"; |
| 466 | String pos3 = |
| 467 | "{@type=korap:group, operation=operation:position, operands=[" + |
| 468 | "{@type=korap:span}," + |
| 469 | "{@type=korap:span}" + |
| 470 | "], inOrder=false, frame=frame:startswith" + |
| 471 | "}"; |
| 472 | aqlt = new AqlTree(query); |
| 473 | map = aqlt.getRequestMap().get("query").toString(); |
| 474 | assertEquals(pos3.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 475 | |
| 476 | query = "node & \"Mann\" & #1 _r_ #2"; |
Joachim Bingel | 7503879 | 2014-05-19 15:12:23 +0000 | [diff] [blame] | 477 | String pos4 = |
Joachim Bingel | 7503879 | 2014-05-19 15:12:23 +0000 | [diff] [blame] | 478 | "{@type=korap:group, operation=operation:position, operands=[" + |
| 479 | "{@type=korap:span}," + |
Joachim Bingel | ca4944e | 2014-06-13 13:55:10 +0000 | [diff] [blame] | 480 | "{@type=korap:token, wrap={@type=korap:term, key=Mann, match=match:eq}}" + |
| 481 | "], inOrder=false, frame=frame:endswith" + |
| 482 | "}"; |
Joachim Bingel | 7503879 | 2014-05-19 15:12:23 +0000 | [diff] [blame] | 483 | aqlt = new AqlTree(query); |
| 484 | map = aqlt.getRequestMap().get("query").toString(); |
| 485 | assertEquals(pos4.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 13421ef | 2014-05-07 16:22:58 +0000 | [diff] [blame] | 486 | |
Joachim Bingel | ca4944e | 2014-06-13 13:55:10 +0000 | [diff] [blame] | 487 | query = "node & \"Mann\" & #2 _r_ #1"; |
| 488 | String pos5 = |
| 489 | "{@type=korap:group, operation=operation:position, operands=[" + |
| 490 | "{@type=korap:token, wrap={@type=korap:term, key=Mann, match=match:eq}}," + |
| 491 | "{@type=korap:span}" + |
| 492 | "], inOrder=false, frame=frame:endswith" + |
| 493 | "}"; |
| 494 | aqlt = new AqlTree(query); |
| 495 | map = aqlt.getRequestMap().get("query").toString(); |
| 496 | assertEquals(pos5.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 13421ef | 2014-05-07 16:22:58 +0000 | [diff] [blame] | 497 | } |
| 498 | |
Joachim Bingel | ca4944e | 2014-06-13 13:55:10 +0000 | [diff] [blame] | 499 | @Test |
| 500 | public void testMultiplePredications() throws QueryException { |
Joachim Bingel | 9c3ddb9 | 2014-06-23 13:49:58 +0000 | [diff] [blame] | 501 | // a noun before a verb before a preposition |
Joachim Bingel | fc42881 | 2014-06-18 14:50:14 +0000 | [diff] [blame] | 502 | query = "pos=\"N\" & pos=\"V\" & pos=\"P\" & #1 . #2 & #2 . #3"; |
Joachim Bingel | ca4944e | 2014-06-13 13:55:10 +0000 | [diff] [blame] | 503 | String mult1 = |
Joachim Bingel | 9c3ddb9 | 2014-06-23 13:49:58 +0000 | [diff] [blame] | 504 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 1846c8c | 2014-07-08 14:13:31 +0000 | [diff] [blame] | 505 | "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" + |
Joachim Bingel | ca4944e | 2014-06-13 13:55:10 +0000 | [diff] [blame] | 506 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 9c3ddb9 | 2014-06-23 13:49:58 +0000 | [diff] [blame] | 507 | "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=N, match=match:eq}}," + |
| 508 | "{@type=korap:group, operation=operation:class, class=0, operands=[" + |
| 509 | "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=V, match=match:eq}}" + |
| 510 | "]}" + |
| 511 | "], inOrder=true}" + |
Joachim Bingel | aee38ae | 2014-06-25 09:32:56 +0000 | [diff] [blame] | 512 | "]}," + |
Joachim Bingel | 9c3ddb9 | 2014-06-23 13:49:58 +0000 | [diff] [blame] | 513 | "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=P, match=match:eq}}" + |
| 514 | "], inOrder=true}"; |
Joachim Bingel | ca4944e | 2014-06-13 13:55:10 +0000 | [diff] [blame] | 515 | aqlt = new AqlTree(query); |
| 516 | map = aqlt.getRequestMap().get("query").toString(); |
| 517 | assertEquals(mult1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 9c3ddb9 | 2014-06-23 13:49:58 +0000 | [diff] [blame] | 518 | |
| 519 | // a noun before a verb before a preposition |
| 520 | query = "pos=\"N\" & pos=\"V\" & #1 . #2 & #2 . pos=\"P\""; |
| 521 | String mult2 = |
| 522 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 1846c8c | 2014-07-08 14:13:31 +0000 | [diff] [blame] | 523 | "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" + |
Joachim Bingel | 9c3ddb9 | 2014-06-23 13:49:58 +0000 | [diff] [blame] | 524 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 525 | "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=N, match=match:eq}}," + |
| 526 | "{@type=korap:group, operation=operation:class, class=0, operands=[" + |
| 527 | "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=V, match=match:eq}}" + |
| 528 | "]}" + |
| 529 | "], inOrder=true}" + |
Joachim Bingel | aee38ae | 2014-06-25 09:32:56 +0000 | [diff] [blame] | 530 | "]}," + |
Joachim Bingel | 9c3ddb9 | 2014-06-23 13:49:58 +0000 | [diff] [blame] | 531 | "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=P, match=match:eq}}" + |
| 532 | "], inOrder=true}"; |
| 533 | aqlt = new AqlTree(query); |
| 534 | map = aqlt.getRequestMap().get("query").toString(); |
| 535 | assertEquals(mult2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | aee38ae | 2014-06-25 09:32:56 +0000 | [diff] [blame] | 536 | |
| 537 | query = "pos=\"N\" & pos=\"V\" & pos=\"P\" & #1 > #2 & #1 > #3"; |
| 538 | String mult3 = |
| 539 | "{@type=korap:group, operation=operation:relation, operands=[" + |
Joachim Bingel | 1846c8c | 2014-07-08 14:13:31 +0000 | [diff] [blame] | 540 | "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" + |
Joachim Bingel | aee38ae | 2014-06-25 09:32:56 +0000 | [diff] [blame] | 541 | "{@type=korap:group, operation=operation:relation, operands=[" + |
| 542 | "{@type=korap:group, operation=operation:class, class=0, operands=[" + |
| 543 | "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=N, match=match:eq}}" + |
| 544 | "]}," + |
| 545 | "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=V, match=match:eq}}" + |
| 546 | "], relation={@type=korap:treeRelation, reltype=dominance}}" + |
| 547 | "]}," + |
| 548 | "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=P, match=match:eq}}" + |
| 549 | "], relation={@type=korap:treeRelation, reltype=dominance}}"; |
| 550 | aqlt = new AqlTree(query); |
| 551 | map = aqlt.getRequestMap().get("query").toString(); |
| 552 | assertEquals(mult3.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 553 | |
| 554 | query = "cat=\"NP\" & pos=\"V\" & pos=\"P\" & #1 > #2 & #1 > #3 & #2 . #3"; |
| 555 | String mult4 = |
| 556 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 557 | // 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] | 558 | "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" + |
Joachim Bingel | aee38ae | 2014-06-25 09:32:56 +0000 | [diff] [blame] | 559 | "{@type=korap:group, operation=operation:relation, operands=[" + |
| 560 | // dominance relation #1 > #2 is reduced to #1, for expressing #1 > #3 |
Joachim Bingel | 1846c8c | 2014-07-08 14:13:31 +0000 | [diff] [blame] | 561 | "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" + |
Joachim Bingel | aee38ae | 2014-06-25 09:32:56 +0000 | [diff] [blame] | 562 | "{@type=korap:group, operation=operation:relation, operands=[" + |
| 563 | "{@type=korap:group, operation=operation:class, class=0, operands=[" + |
| 564 | "{@type=korap:span, layer=cat, key=NP, match=match:eq}" + |
| 565 | "]}," + |
| 566 | "{@type=korap:group, operation=operation:class, class=1, operands=[" + |
| 567 | "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=V, match=match:eq}}" + |
| 568 | "]}" + |
| 569 | "], relation={@type=korap:treeRelation, reltype=dominance}}" + |
| 570 | "]}," + |
| 571 | // establish class 2 around P for later reference |
| 572 | "{@type=korap:group, operation=operation:class, class=2, operands=[" + |
| 573 | "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=P, match=match:eq}}" + |
| 574 | "]}" + |
| 575 | "], relation={@type=korap:treeRelation, reltype=dominance}}" + |
| 576 | "]}," + |
| 577 | // refer back to class 2 as second operand |
Joachim Bingel | 1846c8c | 2014-07-08 14:13:31 +0000 | [diff] [blame] | 578 | "{@type=korap:reference, operation=operation:focus, classRef=[2]}" + |
Joachim Bingel | aee38ae | 2014-06-25 09:32:56 +0000 | [diff] [blame] | 579 | "], inOrder=true}"; |
| 580 | aqlt = new AqlTree(query); |
| 581 | map = aqlt.getRequestMap().get("query").toString(); |
| 582 | assertEquals(mult4.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | ca4944e | 2014-06-13 13:55:10 +0000 | [diff] [blame] | 583 | } |
Joachim Bingel | eee549e | 2014-04-29 11:15:37 +0000 | [diff] [blame] | 584 | |
Joachim Bingel | ca4944e | 2014-06-13 13:55:10 +0000 | [diff] [blame] | 585 | @Test |
| 586 | public void testUnaryRelations() throws QueryException { |
| 587 | query = "node & #1:tokenarity=2"; |
| 588 | String unary1 = |
| 589 | "{@type=korap:span, attr={@type=korap:term, tokenarity={@type=korap:boundary,min=2,max=2}}}"; |
| 590 | aqlt = new AqlTree(query); |
| 591 | map = aqlt.getRequestMap().get("query").toString(); |
| 592 | assertEquals(unary1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 593 | |
| 594 | query = "cnx/cat=\"NP\" & #1:tokenarity=2"; |
| 595 | String unary2 = |
| 596 | "{@type=korap:span, foundry=cnx, layer=cat, key=NP, match=match:eq, attr={@type=korap:term, tokenarity={@type=korap:boundary,min=2,max=2}}}"; |
| 597 | aqlt = new AqlTree(query); |
| 598 | map = aqlt.getRequestMap().get("query").toString(); |
| 599 | assertEquals(unary2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 600 | |
| 601 | query = "cnx/cat=\"NP\" & #1:root"; |
| 602 | String unary3 = |
| 603 | "{@type=korap:span, foundry=cnx, layer=cat, key=NP, match=match:eq, attr={@type=korap:term, root=true}}"; |
| 604 | aqlt = new AqlTree(query); |
| 605 | map = aqlt.getRequestMap().get("query").toString(); |
| 606 | assertEquals(unary3.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 607 | |
| 608 | query = "cnx/cat=\"NP\" & node & #1>#2 & #1:tokenarity=2"; |
| 609 | String unary4 = |
| 610 | "{@type=korap:group, operation=operation:relation, operands=[" + |
| 611 | "{@type=korap:span, foundry=cnx, layer=cat, key=NP, match=match:eq, attr={@type=korap:term, tokenarity={@type=korap:boundary,min=2,max=2}}}," + |
| 612 | "{@type=korap:span}" + |
| 613 | "], relation={@type=korap:treeRelation, reltype=dominance}" + |
| 614 | "}"; |
| 615 | aqlt = new AqlTree(query); |
| 616 | map = aqlt.getRequestMap().get("query").toString(); |
| 617 | assertEquals(unary4.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 618 | } |
| 619 | |
Joachim Bingel | 1846c8c | 2014-07-08 14:13:31 +0000 | [diff] [blame] | 620 | @Test |
| 621 | public void testCommonParent() throws QueryException { |
| 622 | query = "cat=\"NP\" & cat=\"VP\" & #1 $ #2"; |
| 623 | String cp1 = |
| 624 | "{@type=korap:group, operation=operation:relation, operands=[" + |
| 625 | "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" + |
| 626 | "{@type=korap:group, operation=operation:relation, operands=[" + |
| 627 | "{@type=korap:group, operation=operation:class, class=0, operands=[" + |
| 628 | "{@type=korap:span}" + |
| 629 | "]}," + |
| 630 | "{@type=korap:span, layer=cat, key=NP, match=match:eq}" + |
| 631 | "], relation={@type=korap:treeRelation, reltype=dominance}}" + |
| 632 | "]}," + |
| 633 | "{@type=korap:span, layer=cat, key=VP, match=match:eq}" + |
| 634 | "], relation={@type=korap:treeRelation, reltype=dominance}}" + |
| 635 | ""; |
| 636 | aqlt = new AqlTree(query); |
| 637 | map = aqlt.getRequestMap().get("query").toString(); |
| 638 | assertEquals(cp1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 639 | |
| 640 | query = "cat=\"NP\" & cat=\"VP\" & cat=\"PP\" & #1 $ #2 $ #3"; |
| 641 | String cp2 = |
| 642 | "{@type=korap:group, operation=operation:relation, operands=[" + |
| 643 | "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" + |
| 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}" + |
| 651 | "], relation={@type=korap:treeRelation, reltype=dominance}}" + |
| 652 | "]}," + |
| 653 | "{@type=korap:span, layer=cat, key=VP, match=match:eq}" + |
| 654 | "], relation={@type=korap:treeRelation, reltype=dominance}" + |
| 655 | "}" + |
| 656 | "]}," + |
| 657 | "{@type=korap:span, layer=cat, key=PP, match=match:eq}" + |
| 658 | "], relation={@type=korap:treeRelation, reltype=dominance}" + |
| 659 | "}"; |
| 660 | aqlt = new AqlTree(query); |
| 661 | map = aqlt.getRequestMap().get("query").toString(); |
| 662 | assertEquals(cp2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 663 | |
| 664 | query = "cat=\"NP\" & cat=\"VP\" & cat=\"PP\" & cat=\"CP\" & #1 $ #2 $ #3 $ #4"; |
| 665 | String cp3 = |
| 666 | "{@type=korap:group, operation=operation:relation, operands=[" + |
| 667 | "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" + |
| 668 | "{@type=korap:group, operation=operation:relation, operands=[" + |
| 669 | "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" + |
| 670 | "{@type=korap:group, operation=operation:relation, operands=[" + |
| 671 | "{@type=korap:reference, operation=operation:focus, classRef=[0], operands=[" + |
| 672 | "{@type=korap:group, operation=operation:relation, operands=[" + |
| 673 | "{@type=korap:group, operation=operation:class, class=0, operands=[" + |
| 674 | "{@type=korap:span}" + |
| 675 | "]}," + |
| 676 | "{@type=korap:span, layer=cat, key=NP, match=match:eq}" + |
| 677 | "], relation={@type=korap:treeRelation, reltype=dominance}}" + |
| 678 | "]}," + |
| 679 | "{@type=korap:span, layer=cat, key=VP, match=match:eq}" + |
| 680 | "], relation={@type=korap:treeRelation, reltype=dominance}}" + |
| 681 | "]}," + |
| 682 | "{@type=korap:span, layer=cat, key=PP, match=match:eq}" + |
| 683 | "], relation={@type=korap:treeRelation, reltype=dominance}}" + |
| 684 | "]}," + |
| 685 | "{@type=korap:span, layer=cat, key=CP, match=match:eq}" + |
| 686 | "], relation={@type=korap:treeRelation, reltype=dominance}" + |
| 687 | "}" + |
| 688 | ""; |
| 689 | aqlt = new AqlTree(query); |
| 690 | map = aqlt.getRequestMap().get("query").toString(); |
| 691 | assertEquals(cp3.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 692 | } |
| 693 | |
Joachim Bingel | ca4944e | 2014-06-13 13:55:10 +0000 | [diff] [blame] | 694 | } |