Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 1 | import static org.junit.Assert.*; |
| 2 | |
| 3 | import org.junit.Test; |
| 4 | |
| 5 | import de.ids_mannheim.korap.query.serialize.PoliqarpPlusTree; |
Joachim Bingel | 16da4e1 | 2013-12-17 09:48:12 +0000 | [diff] [blame] | 6 | import de.ids_mannheim.korap.util.QueryException; |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 7 | |
| 8 | public class PoliqarpPlusTreeTest { |
| 9 | |
| 10 | PoliqarpPlusTree ppt; |
| 11 | String map; |
Joachim Bingel | 14239d8 | 2014-07-22 09:55:04 +0000 | [diff] [blame] | 12 | String expected; |
Joachim Bingel | 832800e | 2014-10-17 14:46:39 +0000 | [diff] [blame] | 13 | String metaExpected; |
| 14 | String metaMap; |
Joachim Bingel | 14239d8 | 2014-07-22 09:55:04 +0000 | [diff] [blame] | 15 | String query; |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 16 | |
Joachim Bingel | 16da4e1 | 2013-12-17 09:48:12 +0000 | [diff] [blame] | 17 | private boolean equalsQueryContent(String res, String query) throws QueryException { |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 18 | res = res.replaceAll(" ", ""); |
| 19 | ppt = new PoliqarpPlusTree(query); |
| 20 | String queryMap = ppt.getRequestMap().get("query").toString().replaceAll(" ", ""); |
| 21 | return res.equals(queryMap); |
| 22 | } |
| 23 | |
Joachim Bingel | 8181263 | 2014-02-18 08:55:22 +0000 | [diff] [blame] | 24 | @Test |
Joachim Bingel | 16da4e1 | 2013-12-17 09:48:12 +0000 | [diff] [blame] | 25 | public void testContext() throws QueryException { |
Joachim Bingel | 832800e | 2014-10-17 14:46:39 +0000 | [diff] [blame] | 26 | String contextString = "http://ids-mannheim.de/ns/KorAP/json-ld/v0.2/context.jsonld"; |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 27 | ppt = new PoliqarpPlusTree("Test"); |
| 28 | assertEquals(contextString.replaceAll(" ", ""), ppt.getRequestMap().get("@context").toString().replaceAll(" ", "")); |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | @Test |
Joachim Bingel | 16da4e1 | 2013-12-17 09:48:12 +0000 | [diff] [blame] | 32 | public void testSingleTokens() throws QueryException { |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 33 | // [base=Mann] |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 34 | String token1 = "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}"; |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 35 | assertTrue(equalsQueryContent(token1, "[base=Mann]")); |
| 36 | |
| 37 | // [orth!=Frau] |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 38 | String token2 = "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:ne}}"; |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 39 | assertTrue(equalsQueryContent(token2, "[orth!=Frau]")); |
| 40 | |
| 41 | // [!p=NN] |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 42 | query = "[!p=NN]"; |
| 43 | String token3 = "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:ne}}"; |
| 44 | ppt = new PoliqarpPlusTree(query); |
| 45 | map = ppt.getRequestMap().get("query").toString(); |
| 46 | assertEquals(token3.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 47 | |
| 48 | // [!p!=NN] |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 49 | query = "[!p!=NN]"; |
| 50 | String token4 = "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}"; |
| 51 | ppt = new PoliqarpPlusTree(query); |
| 52 | map = ppt.getRequestMap().get("query").toString(); |
| 53 | assertEquals(token4.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 54 | |
Joachim Bingel | d1a3e71 | 2014-07-16 08:02:05 +0000 | [diff] [blame] | 55 | query = "[base=schland/x]"; |
Joachim Bingel | a83f8cc | 2014-08-05 14:12:59 +0000 | [diff] [blame] | 56 | String token5 = "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=.*?schland.*?, match=match:eq, type=type:regex}}"; |
Joachim Bingel | d1a3e71 | 2014-07-16 08:02:05 +0000 | [diff] [blame] | 57 | ppt = new PoliqarpPlusTree(query); |
| 58 | map = ppt.getRequestMap().get("query").toString(); |
| 59 | assertEquals(token5.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 60 | } |
| 61 | |
| 62 | @Test |
| 63 | public void testValue() throws QueryException { |
Joachim Bingel | d1a3e71 | 2014-07-16 08:02:05 +0000 | [diff] [blame] | 64 | query = "[mate/m=temp:pres]"; |
| 65 | String value1 = "{@type=korap:token, wrap={@type=korap:term, foundry=mate, layer=m, key=temp, value=pres, match=match:eq}}"; |
| 66 | ppt = new PoliqarpPlusTree(query); |
| 67 | map = ppt.getRequestMap().get("query").toString(); |
| 68 | assertEquals(value1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | @Test |
Joachim Bingel | 41e112e | 2014-02-12 10:46:18 +0000 | [diff] [blame] | 72 | public void testRegex() throws QueryException { |
Joachim Bingel | 832800e | 2014-10-17 14:46:39 +0000 | [diff] [blame] | 73 | query = "[orth=\"M(a|ä)nn(er)?\"]"; |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 74 | String re1 = "{@type=korap:token, wrap={@type=korap:term, layer=orth, type=type:regex, key=M(a|ä)nn(er)?, match=match:eq}}"; |
Joachim Bingel | 41e112e | 2014-02-12 10:46:18 +0000 | [diff] [blame] | 75 | ppt = new PoliqarpPlusTree(query); |
| 76 | map = ppt.getRequestMap().get("query").toString(); |
| 77 | assertEquals(re1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 78 | |
| 79 | query = "[orth=\"M(a|ä)nn(er)?\"/x]"; |
| 80 | String re2 = "{@type=korap:token, wrap={@type=korap:term, layer=orth, type=type:regex, key=.*?M(a|ä)nn(er)?.*?, match=match:eq}}"; |
| 81 | ppt = new PoliqarpPlusTree(query); |
| 82 | map = ppt.getRequestMap().get("query").toString(); |
| 83 | assertEquals(re2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 84 | |
| 85 | query = "\"M(a|ä)nn(er)?\"/x"; |
| 86 | String re3 = "{@type=korap:token, wrap={@type=korap:term, type=type:regex, layer=orth, key=.*?M(a|ä)nn(er)?.*?, match=match:eq}}"; |
| 87 | ppt = new PoliqarpPlusTree(query); |
| 88 | map = ppt.getRequestMap().get("query").toString(); |
| 89 | assertEquals(re3.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | d1a3e71 | 2014-07-16 08:02:05 +0000 | [diff] [blame] | 90 | |
| 91 | query = "schland/x"; |
Joachim Bingel | a83f8cc | 2014-08-05 14:12:59 +0000 | [diff] [blame] | 92 | String re4 = "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=.*?schland.*?, match=match:eq, type=type:regex}}"; |
Joachim Bingel | d1a3e71 | 2014-07-16 08:02:05 +0000 | [diff] [blame] | 93 | ppt = new PoliqarpPlusTree(query); |
| 94 | map = ppt.getRequestMap().get("query").toString(); |
| 95 | assertEquals(re4.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 96 | |
| 97 | query = "\".*?Mann.*?\""; |
| 98 | String re5 = "{@type=korap:token, wrap={@type=korap:term, type=type:regex, layer=orth, key=.*?Mann.*?, match=match:eq}}"; |
| 99 | ppt = new PoliqarpPlusTree(query); |
| 100 | map = ppt.getRequestMap().get("query").toString(); |
| 101 | assertEquals(re5.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | a83f8cc | 2014-08-05 14:12:59 +0000 | [diff] [blame] | 102 | |
| 103 | query = "z.B./x"; |
| 104 | String re6 = "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=.*?z\\.B\\..*?, match=match:eq, type=type:regex}}"; |
| 105 | ppt = new PoliqarpPlusTree(query); |
| 106 | map = ppt.getRequestMap().get("query").toString(); |
| 107 | assertEquals(re6.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 41e112e | 2014-02-12 10:46:18 +0000 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | @Test |
Joachim Bingel | 0207d5e | 2014-02-12 14:18:41 +0000 | [diff] [blame] | 111 | public void testCaseSensitivityFlag() throws QueryException { |
Joachim Bingel | 832800e | 2014-10-17 14:46:39 +0000 | [diff] [blame] | 112 | query="[orth=deutscher/i]"; |
Joachim Bingel | 0207d5e | 2014-02-12 14:18:41 +0000 | [diff] [blame] | 113 | String cs1 = |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 114 | "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=deutscher, match=match:eq, caseInsensitive=true}}"; |
Joachim Bingel | 0207d5e | 2014-02-12 14:18:41 +0000 | [diff] [blame] | 115 | ppt = new PoliqarpPlusTree(query); |
| 116 | map = ppt.getRequestMap().get("query").toString(); |
| 117 | assertEquals(cs1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 118 | |
| 119 | query="[orth=deutscher/i][orth=Bundestag]"; |
| 120 | String cs2 = |
| 121 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 122 | "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=deutscher, match=match:eq, caseInsensitive=true}}," + |
| 123 | "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Bundestag, match=match:eq}}" + |
Joachim Bingel | 0207d5e | 2014-02-12 14:18:41 +0000 | [diff] [blame] | 124 | "]}"; |
| 125 | ppt = new PoliqarpPlusTree(query); |
| 126 | map = ppt.getRequestMap().get("query").toString(); |
| 127 | assertEquals(cs2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | add0fb1 | 2014-06-24 08:54:14 +0000 | [diff] [blame] | 128 | |
| 129 | query="deutscher/i"; |
| 130 | String cs3 = |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 131 | "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=deutscher, match=match:eq, caseInsensitive=true}}"; |
Joachim Bingel | add0fb1 | 2014-06-24 08:54:14 +0000 | [diff] [blame] | 132 | ppt = new PoliqarpPlusTree(query); |
| 133 | map = ppt.getRequestMap().get("query").toString(); |
| 134 | assertEquals(cs3.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 135 | |
| 136 | query="deutscher/i Bundestag"; |
| 137 | String cs4 = |
| 138 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 139 | "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=deutscher, match=match:eq, caseInsensitive=true}}," + |
| 140 | "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Bundestag, match=match:eq}}" + |
Joachim Bingel | add0fb1 | 2014-06-24 08:54:14 +0000 | [diff] [blame] | 141 | "]}"; |
| 142 | ppt = new PoliqarpPlusTree(query); |
| 143 | map = ppt.getRequestMap().get("query").toString(); |
| 144 | assertEquals(cs4.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | f8dfcf8 | 2014-06-25 09:57:44 +0000 | [diff] [blame] | 145 | |
| 146 | query="deutscher Bundestag/i"; |
| 147 | String cs5 = |
| 148 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 149 | "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=deutscher, match=match:eq}}," + |
| 150 | "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Bundestag, match=match:eq, caseInsensitive=true}}" + |
Joachim Bingel | f8dfcf8 | 2014-06-25 09:57:44 +0000 | [diff] [blame] | 151 | "]}"; |
| 152 | ppt = new PoliqarpPlusTree(query); |
| 153 | map = ppt.getRequestMap().get("query").toString(); |
| 154 | assertEquals(cs5.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 0207d5e | 2014-02-12 14:18:41 +0000 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | @Test |
Joachim Bingel | 3a41a44 | 2014-07-22 12:16:16 +0000 | [diff] [blame] | 158 | public void testSpans() throws QueryException { |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 159 | // <s> |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 160 | String elem1 = "{@type=korap:span, key=s}"; |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 161 | assertTrue(equalsQueryContent(elem1, "<s>")); |
| 162 | |
| 163 | // <vp> |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 164 | String elem2 = "{@type=korap:span, key=vp}"; |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 165 | assertTrue(equalsQueryContent(elem2, "<vp>")); |
Joachim Bingel | fc1fb35 | 2014-02-26 14:40:27 +0000 | [diff] [blame] | 166 | |
| 167 | // <cnx/c=vp> |
| 168 | query = "<c=vp>"; |
| 169 | String span3 = "{@type=korap:span, layer=c, key=vp}"; |
| 170 | ppt = new PoliqarpPlusTree(query); |
| 171 | map = ppt.getRequestMap().get("query").toString(); |
| 172 | assertEquals(span3.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 173 | |
| 174 | // <cnx/c=vp> |
| 175 | query = "<cnx/c=vp>"; |
| 176 | String span4 = "{@type=korap:span, foundry=cnx, layer=c, key=vp}"; |
| 177 | ppt = new PoliqarpPlusTree(query); |
| 178 | map = ppt.getRequestMap().get("query").toString(); |
| 179 | assertEquals(span4.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 3a41a44 | 2014-07-22 12:16:16 +0000 | [diff] [blame] | 180 | |
| 181 | // span negation |
| 182 | query = "<cnx/c!=vp>"; |
| 183 | expected = "{@type=korap:span, foundry=cnx, layer=c, key=vp, match=match:ne}"; |
| 184 | ppt = new PoliqarpPlusTree(query); |
| 185 | map = ppt.getRequestMap().get("query").toString(); |
| 186 | assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 187 | |
| 188 | // span negation |
| 189 | query = "<cnx/c!=vp>"; |
| 190 | expected = "{@type=korap:span, foundry=cnx, layer=c, key=vp, match=match:ne}"; |
| 191 | ppt = new PoliqarpPlusTree(query); |
| 192 | map = ppt.getRequestMap().get("query").toString(); |
| 193 | assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 194 | |
| 195 | query = "<cnx/c=vp class!=header>"; |
| 196 | expected = "{@type=korap:span, foundry=cnx, layer=c, key=vp, attr={@type=korap:term, key=class, value=header, match=match:ne}}"; |
| 197 | ppt = new PoliqarpPlusTree(query); |
| 198 | map = ppt.getRequestMap().get("query").toString(); |
| 199 | assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 200 | |
| 201 | query = "<cnx/c=vp !(class=header&id=7)>"; |
| 202 | expected = |
| 203 | "{@type=korap:span, foundry=cnx, layer=c, key=vp, attr=" + |
| 204 | "{@type=korap:termGroup, relation=relation:and, operands=[" + |
| 205 | "{@type=korap:term, key=class, value=header, match=match:ne}," + |
| 206 | "{@type=korap:term, key=id, value=7, match=match:ne}" + |
| 207 | "]}" + |
| 208 | "}"; |
| 209 | ppt = new PoliqarpPlusTree(query); |
| 210 | map = ppt.getRequestMap().get("query").toString(); |
| 211 | assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 212 | |
| 213 | query = "<cnx/c!=vp (class=header&id=7)>"; |
| 214 | expected = |
| 215 | "{@type=korap:span, foundry=cnx, layer=c, key=vp, match=match:ne, attr=" + |
| 216 | "{@type=korap:termGroup, relation=relation:and, operands=[" + |
| 217 | "{@type=korap:term, key=class, value=header, match=match:eq}," + |
| 218 | "{@type=korap:term, key=id, value=7, match=match:eq}" + |
| 219 | "]}" + |
| 220 | "}"; |
| 221 | ppt = new PoliqarpPlusTree(query); |
| 222 | map = ppt.getRequestMap().get("query").toString(); |
| 223 | assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 224 | |
| 225 | query = "<cnx/c=vp !!class=header>"; |
| 226 | expected = "{@type=korap:span, foundry=cnx, layer=c, key=vp, attr={@type=korap:term, key=class, value=header, match=match:eq}}"; |
| 227 | ppt = new PoliqarpPlusTree(query); |
| 228 | map = ppt.getRequestMap().get("query").toString(); |
| 229 | assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | a0ef08f | 2014-07-24 08:27:57 +0000 | [diff] [blame] | 230 | |
| 231 | query = "<cnx/c!=vp (foundry/class=header&id=7)>"; |
| 232 | expected = |
| 233 | "{@type=korap:span, foundry=cnx, layer=c, key=vp, match=match:ne, attr=" + |
| 234 | "{@type=korap:termGroup, relation=relation:and, operands=[" + |
| 235 | "{@type=korap:term, foundry=foundry, key=class, value=header, match=match:eq}," + |
| 236 | "{@type=korap:term, key=id, value=7, match=match:eq}" + |
| 237 | "]}" + |
| 238 | "}"; |
| 239 | ppt = new PoliqarpPlusTree(query); |
| 240 | map = ppt.getRequestMap().get("query").toString(); |
| 241 | assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 242 | } |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame] | 243 | |
| 244 | @Test |
Joachim Bingel | 14239d8 | 2014-07-22 09:55:04 +0000 | [diff] [blame] | 245 | public void testDistances() throws QueryException { |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame] | 246 | // [base=der][][base=Mann] |
| 247 | String et1 = |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 248 | "{@type=korap:group, operation=operation:sequence, " + |
Joachim Bingel | 11d5b15 | 2014-02-11 21:33:47 +0000 | [diff] [blame] | 249 | "operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 250 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," + |
| 251 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" + |
| 252 | "], inOrder=true, distances=[" + |
Joachim Bingel | 5a146cd | 2014-07-24 14:44:57 +0000 | [diff] [blame] | 253 | "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=2, max=2}, min=2, max=2}" + |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame] | 254 | "]}"; |
| 255 | ppt = new PoliqarpPlusTree("[base=der][][base=Mann]"); |
| 256 | map = ppt.getRequestMap().get("query").toString(); |
| 257 | assertEquals(et1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 258 | |
| 259 | // [base=der][][][base=Mann] |
| 260 | String et2 = |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 261 | "{@type=korap:group, operation=operation:sequence, " + |
Joachim Bingel | 11d5b15 | 2014-02-11 21:33:47 +0000 | [diff] [blame] | 262 | "operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 263 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," + |
| 264 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" + |
| 265 | "], inOrder=true, distances=[" + |
Joachim Bingel | 5a146cd | 2014-07-24 14:44:57 +0000 | [diff] [blame] | 266 | "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=3, max=3}, min=3, max=3}" + |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame] | 267 | "]}"; |
Joachim Bingel | ffd65e3 | 2014-01-22 14:22:57 +0000 | [diff] [blame] | 268 | ppt = new PoliqarpPlusTree("[base=der][][][base=Mann]"); |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame] | 269 | map = ppt.getRequestMap().get("query").toString(); |
| 270 | assertEquals(et2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 271 | |
| 272 | // [base=der][][]?[base=Mann] |
| 273 | String et3 = |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 274 | "{@type=korap:group, operation=operation:sequence, " + |
Joachim Bingel | 11d5b15 | 2014-02-11 21:33:47 +0000 | [diff] [blame] | 275 | "operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 276 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," + |
| 277 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" + |
| 278 | "], inOrder=true, distances=[" + |
Joachim Bingel | 5a146cd | 2014-07-24 14:44:57 +0000 | [diff] [blame] | 279 | "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=2, max=3}, min=2, max=3}" + |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame] | 280 | "]}"; |
| 281 | ppt = new PoliqarpPlusTree("[base=der][][]?[base=Mann]"); |
| 282 | map = ppt.getRequestMap().get("query").toString(); |
| 283 | assertEquals(et3.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 284 | |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame] | 285 | |
Joachim Bingel | 14239d8 | 2014-07-22 09:55:04 +0000 | [diff] [blame] | 286 | |
Joachim Bingel | ffd65e3 | 2014-01-22 14:22:57 +0000 | [diff] [blame] | 287 | |
Joachim Bingel | 11d5b15 | 2014-02-11 21:33:47 +0000 | [diff] [blame] | 288 | // [base=der][]{2,5}[base=Mann][]?[][base=Frau] nested distances= |
Joachim Bingel | ffd65e3 | 2014-01-22 14:22:57 +0000 | [diff] [blame] | 289 | String et5 = |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 290 | "{@type=korap:group, operation=operation:sequence," + |
Joachim Bingel | 11d5b15 | 2014-02-11 21:33:47 +0000 | [diff] [blame] | 291 | "operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 292 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," + |
| 293 | "{@type=korap:group, operation=operation:sequence, " + |
Joachim Bingel | 11d5b15 | 2014-02-11 21:33:47 +0000 | [diff] [blame] | 294 | "operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 295 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}," + |
| 296 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Frau, match=match:eq}}" + |
| 297 | "], inOrder=true, distances=[" + |
Joachim Bingel | 5a146cd | 2014-07-24 14:44:57 +0000 | [diff] [blame] | 298 | "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=2, max=3}, min=2, max=3}" + |
Joachim Bingel | ffd65e3 | 2014-01-22 14:22:57 +0000 | [diff] [blame] | 299 | "]}" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 300 | "], inOrder=true, distances=[" + |
Joachim Bingel | 5a146cd | 2014-07-24 14:44:57 +0000 | [diff] [blame] | 301 | "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=3, max=6}, min=3, max=6}" + |
Joachim Bingel | ffd65e3 | 2014-01-22 14:22:57 +0000 | [diff] [blame] | 302 | "]}"; |
Joachim Bingel | ba9a0ab | 2014-01-29 10:12:25 +0000 | [diff] [blame] | 303 | ppt = new PoliqarpPlusTree("[base=der][]{2,5}[base=Mann][]?[][base=Frau]"); |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame] | 304 | map = ppt.getRequestMap().get("query").toString(); |
| 305 | assertEquals(et5.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame] | 306 | |
Joachim Bingel | c15720f | 2014-05-07 14:37:23 +0000 | [diff] [blame] | 307 | // [base=der][]*[base=Mann] |
| 308 | String et6 = |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 309 | "{@type=korap:group, operation=operation:sequence, " + |
Joachim Bingel | c15720f | 2014-05-07 14:37:23 +0000 | [diff] [blame] | 310 | "operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 311 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," + |
| 312 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" + |
| 313 | "], inOrder=true, distances=[" + |
Joachim Bingel | 687e4d4 | 2014-07-30 09:34:18 +0000 | [diff] [blame] | 314 | "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1}, min=1}" + |
Joachim Bingel | c15720f | 2014-05-07 14:37:23 +0000 | [diff] [blame] | 315 | "]}"; |
| 316 | ppt = new PoliqarpPlusTree("[base=der][]*[base=Mann]"); |
| 317 | map = ppt.getRequestMap().get("query").toString(); |
| 318 | assertEquals(et6.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 319 | |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 320 | // [base=der][]+[base=Mann] |
Joachim Bingel | c15720f | 2014-05-07 14:37:23 +0000 | [diff] [blame] | 321 | String et7 = |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 322 | "{@type=korap:group, operation=operation:sequence, " + |
Joachim Bingel | c15720f | 2014-05-07 14:37:23 +0000 | [diff] [blame] | 323 | "operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 324 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," + |
| 325 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" + |
| 326 | "], inOrder=true, distances=[" + |
Joachim Bingel | 687e4d4 | 2014-07-30 09:34:18 +0000 | [diff] [blame] | 327 | "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=2}, min=2}" + |
Joachim Bingel | c15720f | 2014-05-07 14:37:23 +0000 | [diff] [blame] | 328 | "]}"; |
| 329 | ppt = new PoliqarpPlusTree("[base=der][]+[base=Mann]"); |
| 330 | map = ppt.getRequestMap().get("query").toString(); |
| 331 | assertEquals(et7.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 14239d8 | 2014-07-22 09:55:04 +0000 | [diff] [blame] | 332 | |
| 333 | // [base=der][]+[base=Mann] |
| 334 | String et8 = |
| 335 | "{@type=korap:group, operation=operation:sequence, " + |
| 336 | "operands=[" + |
| 337 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," + |
| 338 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" + |
| 339 | "], inOrder=true, distances=[" + |
Joachim Bingel | 687e4d4 | 2014-07-30 09:34:18 +0000 | [diff] [blame] | 340 | "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=2, max=103}, min=2, max=103}" + |
Joachim Bingel | 14239d8 | 2014-07-22 09:55:04 +0000 | [diff] [blame] | 341 | "]}"; |
| 342 | ppt = new PoliqarpPlusTree("[base=der][]{1,102}[base=Mann]"); |
| 343 | map = ppt.getRequestMap().get("query").toString(); |
| 344 | assertEquals(et8.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 345 | |
| 346 | // [base=geht][base=der][]*[base=Mann] |
| 347 | String et9 = |
| 348 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 349 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=geht, match=match:eq}}," + |
| 350 | "{@type=korap:group, operation=operation:sequence, " + |
| 351 | "operands=[" + |
| 352 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," + |
| 353 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" + |
| 354 | "], inOrder=true, distances=[" + |
Joachim Bingel | 687e4d4 | 2014-07-30 09:34:18 +0000 | [diff] [blame] | 355 | "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1}, min=1}" + |
Joachim Bingel | 14239d8 | 2014-07-22 09:55:04 +0000 | [diff] [blame] | 356 | "]}" + |
| 357 | "]}"; |
| 358 | ppt = new PoliqarpPlusTree("[base=geht][base=der][]*[base=Mann]"); |
| 359 | map = ppt.getRequestMap().get("query").toString(); |
| 360 | assertEquals(et9.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 361 | |
| 362 | query = "[base=geht][base=der][]*[base=Mann][base=da]"; |
| 363 | expected = |
| 364 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 365 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=geht, match=match:eq}}," + |
| 366 | "{@type=korap:group, operation=operation:sequence, " + |
| 367 | "operands=[" + |
| 368 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," + |
| 369 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 370 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}," + |
| 371 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=da, match=match:eq}}" + |
| 372 | "]}" + |
| 373 | "], inOrder=true, distances=[" + |
Joachim Bingel | 687e4d4 | 2014-07-30 09:34:18 +0000 | [diff] [blame] | 374 | "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1}, min=1}" + |
Joachim Bingel | 14239d8 | 2014-07-22 09:55:04 +0000 | [diff] [blame] | 375 | "]}" + |
| 376 | "]}"; |
| 377 | ppt = new PoliqarpPlusTree(query); |
| 378 | map = ppt.getRequestMap().get("query").toString(); |
| 379 | assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 380 | |
| 381 | query = "[base=geht][base=der][]*contains(<s>,<np>)"; |
| 382 | expected = |
| 383 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 384 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=geht, match=match:eq}}," + |
| 385 | "{@type=korap:group, operation=operation:sequence, " + |
| 386 | "operands=[" + |
| 387 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," + |
Joachim Bingel | 832800e | 2014-10-17 14:46:39 +0000 | [diff] [blame] | 388 | "{@type=korap:group, operation=operation:position, frames=[frames:contains], operands=[" + |
Joachim Bingel | 14239d8 | 2014-07-22 09:55:04 +0000 | [diff] [blame] | 389 | "{@type=korap:span, key=s}," + |
| 390 | "{@type=korap:span, key=np}" + |
Joachim Bingel | 6b52d76 | 2014-09-30 15:29:11 +0000 | [diff] [blame] | 391 | "], frame=frame:contains}" + |
Joachim Bingel | 14239d8 | 2014-07-22 09:55:04 +0000 | [diff] [blame] | 392 | "], inOrder=true, distances=[" + |
Joachim Bingel | 687e4d4 | 2014-07-30 09:34:18 +0000 | [diff] [blame] | 393 | "{@type=korap:distance, key=w, boundary={@type=korap:boundary, min=1}, min=1}" + |
Joachim Bingel | 14239d8 | 2014-07-22 09:55:04 +0000 | [diff] [blame] | 394 | "]}" + |
| 395 | "]}"; |
| 396 | ppt = new PoliqarpPlusTree(query); |
| 397 | map = ppt.getRequestMap().get("query").toString(); |
| 398 | assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame] | 399 | } |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 400 | |
| 401 | @Test |
Joachim Bingel | bd38636 | 2014-10-02 12:03:18 +0000 | [diff] [blame] | 402 | public void testDistancesWithClass() throws QueryException { |
| 403 | query = "[base=der]{1:[]}[base=Mann]"; |
| 404 | expected = |
| 405 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 406 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," + |
Joachim Bingel | 832800e | 2014-10-17 14:46:39 +0000 | [diff] [blame] | 407 | "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" + |
Joachim Bingel | bd38636 | 2014-10-02 12:03:18 +0000 | [diff] [blame] | 408 | "{@type=korap:token}" + |
| 409 | "]}," + |
| 410 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" + |
| 411 | "]}"; |
| 412 | ppt = new PoliqarpPlusTree(query); |
| 413 | map = ppt.getRequestMap().get("query").toString(); |
| 414 | assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 415 | |
| 416 | query = "{1:[]}[base=der][base=Mann]"; |
| 417 | expected = |
| 418 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 832800e | 2014-10-17 14:46:39 +0000 | [diff] [blame] | 419 | "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" + |
Joachim Bingel | bd38636 | 2014-10-02 12:03:18 +0000 | [diff] [blame] | 420 | "{@type=korap:token}" + |
| 421 | "]}," + |
| 422 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," + |
| 423 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" + |
| 424 | "]}"; |
| 425 | ppt = new PoliqarpPlusTree(query); |
| 426 | map = ppt.getRequestMap().get("query").toString(); |
| 427 | assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 428 | } |
| 429 | |
| 430 | @Test |
Joachim Bingel | 14239d8 | 2014-07-22 09:55:04 +0000 | [diff] [blame] | 431 | public void testLeadingTrailingEmptyTokens() throws QueryException { |
| 432 | // startswith(<s>, [][base=Mann] |
| 433 | String et1 = |
Joachim Bingel | 832800e | 2014-10-17 14:46:39 +0000 | [diff] [blame] | 434 | "{@type=korap:group, operation=operation:position, frames=[frames:startswith], operands=[" + |
Joachim Bingel | 14239d8 | 2014-07-22 09:55:04 +0000 | [diff] [blame] | 435 | "{@type=korap:span, key=s}," + |
| 436 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 437 | "{@type=korap:token}," + |
| 438 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" + |
| 439 | "]}" + |
Joachim Bingel | 6b52d76 | 2014-09-30 15:29:11 +0000 | [diff] [blame] | 440 | "], frame=frame:startswith}"; |
Joachim Bingel | 14239d8 | 2014-07-22 09:55:04 +0000 | [diff] [blame] | 441 | ppt = new PoliqarpPlusTree("startswith(<s>, [][base=Mann])"); |
| 442 | map = ppt.getRequestMap().get("query").toString(); |
| 443 | assertEquals(et1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 444 | |
| 445 | query = "[][base=Mann]"; |
| 446 | expected = |
| 447 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 448 | "{@type=korap:token}," + |
| 449 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" + |
| 450 | "]}"; |
| 451 | ppt = new PoliqarpPlusTree(query); |
| 452 | map = ppt.getRequestMap().get("query").toString(); |
| 453 | assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 454 | |
Joachim Bingel | f8e8b54 | 2014-10-22 14:58:27 +0000 | [diff] [blame] | 455 | query = "{[]}[base=Mann]"; |
| 456 | expected = |
| 457 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 458 | "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" + |
| 459 | "{@type=korap:token}" + |
| 460 | "]}," + |
| 461 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" + |
| 462 | "]}"; |
| 463 | ppt = new PoliqarpPlusTree(query); |
| 464 | map = ppt.getRequestMap().get("query").toString(); |
| 465 | assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 466 | |
Joachim Bingel | 14239d8 | 2014-07-22 09:55:04 +0000 | [diff] [blame] | 467 | query = "[][][base=Mann]"; |
| 468 | expected = |
| 469 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 470 | "{@type=korap:group, operation=operation:repetition, operands=[" + |
| 471 | "{@type=korap:token}" + |
Joachim Bingel | 6163156 | 2014-07-24 14:26:02 +0000 | [diff] [blame] | 472 | "], boundary={@type=korap:boundary, min=2, max=2}, min=2, max=2}," + |
Joachim Bingel | 14239d8 | 2014-07-22 09:55:04 +0000 | [diff] [blame] | 473 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" + |
| 474 | "]}"; |
| 475 | ppt = new PoliqarpPlusTree(query); |
| 476 | map = ppt.getRequestMap().get("query").toString(); |
| 477 | assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 478 | |
| 479 | query = "[][]*[base=Mann]"; |
| 480 | expected = |
| 481 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 482 | "{@type=korap:group, operation=operation:repetition, operands=[" + |
| 483 | "{@type=korap:token}" + |
Joachim Bingel | 687e4d4 | 2014-07-30 09:34:18 +0000 | [diff] [blame] | 484 | "], boundary={@type=korap:boundary, min=1}, min=1}," + |
Joachim Bingel | 14239d8 | 2014-07-22 09:55:04 +0000 | [diff] [blame] | 485 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" + |
| 486 | "]}"; |
| 487 | ppt = new PoliqarpPlusTree(query); |
| 488 | map = ppt.getRequestMap().get("query").toString(); |
| 489 | assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 490 | |
| 491 | query = "[][]*[base=Mann][][]"; |
| 492 | expected = |
| 493 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 494 | "{@type=korap:group, operation=operation:repetition, operands=[" + |
| 495 | "{@type=korap:token}" + |
Joachim Bingel | 687e4d4 | 2014-07-30 09:34:18 +0000 | [diff] [blame] | 496 | "], boundary={@type=korap:boundary, min=1}, min=1}," + |
Joachim Bingel | 14239d8 | 2014-07-22 09:55:04 +0000 | [diff] [blame] | 497 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}," + |
| 498 | "{@type=korap:group, operation=operation:repetition, operands=[" + |
| 499 | "{@type=korap:token}" + |
Joachim Bingel | 6163156 | 2014-07-24 14:26:02 +0000 | [diff] [blame] | 500 | "], boundary={@type=korap:boundary, min=2, max=2}, min=2, max=2}" + |
Joachim Bingel | 14239d8 | 2014-07-22 09:55:04 +0000 | [diff] [blame] | 501 | "]}"; |
| 502 | ppt = new PoliqarpPlusTree(query); |
| 503 | map = ppt.getRequestMap().get("query").toString(); |
| 504 | assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 505 | |
| 506 | query = "[][]*contains(<s>, <np>)[][]"; |
| 507 | expected = |
| 508 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 509 | "{@type=korap:group, operation=operation:repetition, operands=[" + |
| 510 | "{@type=korap:token}" + |
Joachim Bingel | 687e4d4 | 2014-07-30 09:34:18 +0000 | [diff] [blame] | 511 | "], boundary={@type=korap:boundary, min=1}, min=1}," + |
Joachim Bingel | 832800e | 2014-10-17 14:46:39 +0000 | [diff] [blame] | 512 | "{@type=korap:group, operation=operation:position, frames=[frames:contains], operands=[" + |
Joachim Bingel | 14239d8 | 2014-07-22 09:55:04 +0000 | [diff] [blame] | 513 | "{@type=korap:span, key=s}," + |
| 514 | "{@type=korap:span, key=np}" + |
Joachim Bingel | 6b52d76 | 2014-09-30 15:29:11 +0000 | [diff] [blame] | 515 | "], frame=frame:contains}," + |
Joachim Bingel | 14239d8 | 2014-07-22 09:55:04 +0000 | [diff] [blame] | 516 | "{@type=korap:group, operation=operation:repetition, operands=[" + |
| 517 | "{@type=korap:token}" + |
Joachim Bingel | 6163156 | 2014-07-24 14:26:02 +0000 | [diff] [blame] | 518 | "], boundary={@type=korap:boundary, min=2, max=2}, min=2, max=2}" + |
Joachim Bingel | 14239d8 | 2014-07-22 09:55:04 +0000 | [diff] [blame] | 519 | "]}"; |
| 520 | ppt = new PoliqarpPlusTree(query); |
| 521 | map = ppt.getRequestMap().get("query").toString(); |
| 522 | assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 523 | } |
| 524 | |
| 525 | @Test |
Joachim Bingel | 16da4e1 | 2013-12-17 09:48:12 +0000 | [diff] [blame] | 526 | public void testCoordinatedFields() throws QueryException { |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 527 | // [base=Mann&(cas=N|cas=A)] |
| 528 | String cof1 = |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 529 | "{@type=korap:token, wrap=" + |
Joachim Bingel | 2980bda | 2014-04-04 12:09:46 +0000 | [diff] [blame] | 530 | "{@type=korap:termGroup, relation=relation:and, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 531 | "{@type=korap:term, layer=lemma, key=Mann, match=match:eq}," + |
Joachim Bingel | 2980bda | 2014-04-04 12:09:46 +0000 | [diff] [blame] | 532 | "{@type=korap:termGroup, relation=relation:or, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 533 | "{@type=korap:term, layer=cas, key=N, match=match:eq}," + |
| 534 | "{@type=korap:term, layer=cas, key=A, match=match:eq}" + |
Joachim Bingel | ee3b21d | 2014-02-12 12:34:59 +0000 | [diff] [blame] | 535 | "]}" + |
| 536 | "]}" + |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 537 | "}"; |
| 538 | ppt = new PoliqarpPlusTree("[base=Mann&(cas=N|cas=A)]"); |
| 539 | map = ppt.getRequestMap().get("query").toString(); |
| 540 | assertEquals(cof1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Nils Diewald | 7d486c2 | 2013-12-13 16:32:18 +0000 | [diff] [blame] | 541 | |
| 542 | |
| 543 | assertEquals( |
| 544 | new PoliqarpPlusTree(" [ base=Mann & ( cas=N | cas=A)] ").getRequestMap().get("query").toString(), |
| 545 | new PoliqarpPlusTree("[base=Mann &(cas=N|cas=A)]").getRequestMap().get("query").toString() |
| 546 | ); |
Joachim Bingel | ba9a0ab | 2014-01-29 10:12:25 +0000 | [diff] [blame] | 547 | |
| 548 | // [base=Mann&cas=N&gen=m] |
| 549 | String cof2 = |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 550 | "{@type=korap:token, wrap=" + |
Joachim Bingel | 2980bda | 2014-04-04 12:09:46 +0000 | [diff] [blame] | 551 | "{@type=korap:termGroup, relation=relation:and, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 552 | "{@type=korap:term, layer=lemma, key=Mann, match=match:eq}," + |
| 553 | "{@type=korap:termGroup, relation=relation:and, operands=[" + |
| 554 | "{@type=korap:term, layer=cas, key=N, match=match:eq}," + |
| 555 | "{@type=korap:term, layer=gen, key=m, match=match:eq}" + |
| 556 | "]}" + |
Joachim Bingel | ee3b21d | 2014-02-12 12:34:59 +0000 | [diff] [blame] | 557 | "]}" + |
Joachim Bingel | ba9a0ab | 2014-01-29 10:12:25 +0000 | [diff] [blame] | 558 | "}"; |
| 559 | ppt = new PoliqarpPlusTree("[base=Mann&cas=N&gen=m]"); |
| 560 | map = ppt.getRequestMap().get("query").toString(); |
| 561 | assertEquals(cof2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | @Test |
Joachim Bingel | 16da4e1 | 2013-12-17 09:48:12 +0000 | [diff] [blame] | 565 | public void testOccurrence() throws QueryException { |
Joachim Bingel | cd9ed33 | 2013-12-09 21:01:35 +0000 | [diff] [blame] | 566 | // [base=foo]* |
Joachim Bingel | 33bd45f | 2014-06-25 15:00:54 +0000 | [diff] [blame] | 567 | String occ1 = "{@type=korap:group, operation=operation:repetition, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 568 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" + |
Joachim Bingel | 687e4d4 | 2014-07-30 09:34:18 +0000 | [diff] [blame] | 569 | "], boundary={@type=korap:boundary, min=0}, min=0}"; |
Joachim Bingel | cd9ed33 | 2013-12-09 21:01:35 +0000 | [diff] [blame] | 570 | ppt = new PoliqarpPlusTree("[base=foo]*"); |
| 571 | map = ppt.getRequestMap().get("query").toString(); |
| 572 | assertEquals(occ1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 573 | |
| 574 | // [base=foo]*[base=bar] |
| 575 | String occ2 = |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 576 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 33bd45f | 2014-06-25 15:00:54 +0000 | [diff] [blame] | 577 | "{@type=korap:group, operation=operation:repetition, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 578 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" + |
Joachim Bingel | 687e4d4 | 2014-07-30 09:34:18 +0000 | [diff] [blame] | 579 | "], boundary={@type=korap:boundary, min=0}, min=0 }," + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 580 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}" + |
Joachim Bingel | cd9ed33 | 2013-12-09 21:01:35 +0000 | [diff] [blame] | 581 | "]}"; |
| 582 | ppt = new PoliqarpPlusTree("[base=foo]*[base=bar]"); |
| 583 | map = ppt.getRequestMap().get("query").toString(); |
| 584 | assertEquals(occ2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 585 | |
| 586 | // [base=bar][base=foo]* |
| 587 | String occ3 = |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 588 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 589 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," + |
Joachim Bingel | 33bd45f | 2014-06-25 15:00:54 +0000 | [diff] [blame] | 590 | "{@type=korap:group, operation=operation:repetition, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 591 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" + |
Joachim Bingel | 687e4d4 | 2014-07-30 09:34:18 +0000 | [diff] [blame] | 592 | "], boundary={@type=korap:boundary, min=0}, min=0 }" + |
Joachim Bingel | cd9ed33 | 2013-12-09 21:01:35 +0000 | [diff] [blame] | 593 | "]}"; |
| 594 | ppt = new PoliqarpPlusTree("[base=bar][base=foo]*"); |
| 595 | map = ppt.getRequestMap().get("query").toString(); |
| 596 | assertEquals(occ3.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | b4da702 | 2013-12-09 23:17:24 +0000 | [diff] [blame] | 597 | |
| 598 | // ([base=bar][base=foo])* |
| 599 | String occ4 = |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 600 | "{@type=korap:group, operation=operation:repetition, operands=[" + |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 601 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 602 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," + |
| 603 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" + |
Joachim Bingel | b4da702 | 2013-12-09 23:17:24 +0000 | [diff] [blame] | 604 | "]}" + |
Joachim Bingel | 687e4d4 | 2014-07-30 09:34:18 +0000 | [diff] [blame] | 605 | "], boundary={@type=korap:boundary, min=0}, min=0}" ; |
Joachim Bingel | b4da702 | 2013-12-09 23:17:24 +0000 | [diff] [blame] | 606 | ppt = new PoliqarpPlusTree("([base=bar][base=foo])*"); |
| 607 | map = ppt.getRequestMap().get("query").toString(); |
| 608 | assertEquals(occ4.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 609 | |
| 610 | // <s>([base=bar][base=foo])* |
| 611 | String occ5 = |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 612 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 613 | "{@type=korap:span, key=s}," + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 614 | "{@type=korap:group, operation=operation:repetition, operands=[" + |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 615 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 616 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," + |
| 617 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" + |
Joachim Bingel | b4da702 | 2013-12-09 23:17:24 +0000 | [diff] [blame] | 618 | "]}" + |
Joachim Bingel | 687e4d4 | 2014-07-30 09:34:18 +0000 | [diff] [blame] | 619 | "], boundary={@type=korap:boundary, min=0}, min=0 }" + |
Joachim Bingel | b4da702 | 2013-12-09 23:17:24 +0000 | [diff] [blame] | 620 | "]}" ; |
| 621 | ppt = new PoliqarpPlusTree("<s>([base=bar][base=foo])*"); |
| 622 | map = ppt.getRequestMap().get("query").toString(); |
| 623 | assertEquals(occ5.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 624 | |
| 625 | // <s><np>([base=bar][base=foo])* |
Joachim Bingel | b4da702 | 2013-12-09 23:17:24 +0000 | [diff] [blame] | 626 | String occ6 = |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 627 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 628 | "{@type=korap:span, key=s}," + |
| 629 | "{@type=korap:span, key=np}," + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 630 | "{@type=korap:group, operation=operation:repetition, operands=[" + |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 631 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 632 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," + |
| 633 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" + |
Joachim Bingel | b4da702 | 2013-12-09 23:17:24 +0000 | [diff] [blame] | 634 | "]}" + |
Joachim Bingel | 687e4d4 | 2014-07-30 09:34:18 +0000 | [diff] [blame] | 635 | "], boundary={@type=korap:boundary, min=0}, min=0 }" + |
Joachim Bingel | b4da702 | 2013-12-09 23:17:24 +0000 | [diff] [blame] | 636 | "]}" ; |
| 637 | ppt = new PoliqarpPlusTree("<s><np>([base=bar][base=foo])*"); |
| 638 | map = ppt.getRequestMap().get("query").toString(); |
| 639 | assertEquals(occ6.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 640 | |
| 641 | // <s><np>([base=bar][base=foo])*[p=NN] |
| 642 | // comment: embedded sequence shouldn't really be here, but does not really hurt, either. (?) |
| 643 | // really hard to get this behaviour out of the PQPlus grammar... |
| 644 | String occ7 = |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 645 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 646 | "{@type=korap:span, key=s}," + |
| 647 | "{@type=korap:span, key=np}," + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 648 | "{@type=korap:group, operation=operation:repetition, operands=[" + |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 649 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 650 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," + |
| 651 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" + |
Joachim Bingel | b4da702 | 2013-12-09 23:17:24 +0000 | [diff] [blame] | 652 | "]}" + |
Joachim Bingel | 687e4d4 | 2014-07-30 09:34:18 +0000 | [diff] [blame] | 653 | "], boundary={@type=korap:boundary, min=0}, min=0 }," + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 654 | "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}" + |
Joachim Bingel | b4da702 | 2013-12-09 23:17:24 +0000 | [diff] [blame] | 655 | "]}" ; |
| 656 | ppt = new PoliqarpPlusTree("<s><np>([base=bar][base=foo])*[p=NN]"); |
| 657 | map = ppt.getRequestMap().get("query").toString(); |
| 658 | assertEquals(occ7.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 659 | |
| 660 | // ([base=bar][base=foo])*[p=NN] |
Joachim Bingel | b4da702 | 2013-12-09 23:17:24 +0000 | [diff] [blame] | 661 | String occ8 = |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 662 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 663 | "{@type=korap:group, operation=operation:repetition, operands=[" + |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 664 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 665 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=bar, match=match:eq}}," + |
| 666 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" + |
Joachim Bingel | b4da702 | 2013-12-09 23:17:24 +0000 | [diff] [blame] | 667 | "]}" + |
Joachim Bingel | 687e4d4 | 2014-07-30 09:34:18 +0000 | [diff] [blame] | 668 | "], boundary={@type=korap:boundary, min=0}, min=0 }," + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 669 | "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}" + |
Joachim Bingel | b4da702 | 2013-12-09 23:17:24 +0000 | [diff] [blame] | 670 | "]}" ; |
| 671 | ppt = new PoliqarpPlusTree("([base=bar][base=foo])*[p=NN]"); |
| 672 | map = ppt.getRequestMap().get("query").toString(); |
| 673 | assertEquals(occ8.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | ba9a0ab | 2014-01-29 10:12:25 +0000 | [diff] [blame] | 674 | |
| 675 | // [base=foo]+ |
Joachim Bingel | 33bd45f | 2014-06-25 15:00:54 +0000 | [diff] [blame] | 676 | String occ9 = "{@type=korap:group, operation=operation:repetition, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 677 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" + |
Joachim Bingel | 687e4d4 | 2014-07-30 09:34:18 +0000 | [diff] [blame] | 678 | "], boundary={@type=korap:boundary, min=1}, min=1}"; |
Joachim Bingel | ba9a0ab | 2014-01-29 10:12:25 +0000 | [diff] [blame] | 679 | ppt = new PoliqarpPlusTree("[base=foo]+"); |
| 680 | map = ppt.getRequestMap().get("query").toString(); |
| 681 | assertEquals(occ9.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 682 | |
| 683 | // [base=foo]? |
Joachim Bingel | 33bd45f | 2014-06-25 15:00:54 +0000 | [diff] [blame] | 684 | String occ10 = "{@type=korap:group, operation=operation:repetition, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 685 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" + |
Joachim Bingel | 6163156 | 2014-07-24 14:26:02 +0000 | [diff] [blame] | 686 | "], boundary={@type=korap:boundary, min=0, max=1}, min=0, max=1}"; |
Joachim Bingel | ba9a0ab | 2014-01-29 10:12:25 +0000 | [diff] [blame] | 687 | ppt = new PoliqarpPlusTree("[base=foo]?"); |
| 688 | map = ppt.getRequestMap().get("query").toString(); |
| 689 | assertEquals(occ10.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 690 | |
| 691 | // [base=foo]{2,5} |
Joachim Bingel | 33bd45f | 2014-06-25 15:00:54 +0000 | [diff] [blame] | 692 | String occ11 = "{@type=korap:group, operation=operation:repetition, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 693 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" + |
Joachim Bingel | 6163156 | 2014-07-24 14:26:02 +0000 | [diff] [blame] | 694 | "], boundary={@type=korap:boundary, min=2, max=5}, min=2, max=5}"; |
Joachim Bingel | ba9a0ab | 2014-01-29 10:12:25 +0000 | [diff] [blame] | 695 | ppt = new PoliqarpPlusTree("[base=foo]{2,5}"); |
| 696 | map = ppt.getRequestMap().get("query").toString(); |
| 697 | assertEquals(occ11.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 2980bda | 2014-04-04 12:09:46 +0000 | [diff] [blame] | 698 | |
| 699 | // [base=foo]{2} |
Joachim Bingel | 33bd45f | 2014-06-25 15:00:54 +0000 | [diff] [blame] | 700 | String occ12 = "{@type=korap:group, operation=operation:repetition, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 701 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" + |
Joachim Bingel | 6163156 | 2014-07-24 14:26:02 +0000 | [diff] [blame] | 702 | "], boundary={@type=korap:boundary, min=2, max=2}, min=2, max=2}"; |
Joachim Bingel | 2980bda | 2014-04-04 12:09:46 +0000 | [diff] [blame] | 703 | ppt = new PoliqarpPlusTree("[base=foo]{2}"); |
| 704 | map = ppt.getRequestMap().get("query").toString(); |
| 705 | assertEquals(occ12.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | b2aa1c7 | 2014-07-01 12:48:46 +0000 | [diff] [blame] | 706 | |
| 707 | // [base=foo]{2} |
| 708 | String occ13 = "{@type=korap:group, operation=operation:repetition, operands=[" + |
| 709 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" + |
Joachim Bingel | 687e4d4 | 2014-07-30 09:34:18 +0000 | [diff] [blame] | 710 | "], boundary={@type=korap:boundary, min=2}, min=2}"; |
Joachim Bingel | b2aa1c7 | 2014-07-01 12:48:46 +0000 | [diff] [blame] | 711 | ppt = new PoliqarpPlusTree("[base=foo]{2,}"); |
| 712 | map = ppt.getRequestMap().get("query").toString(); |
| 713 | assertEquals(occ13.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 714 | |
| 715 | // [base=foo]{2} |
| 716 | String occ14 = "{@type=korap:group, operation=operation:repetition, operands=[" + |
| 717 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=foo, match=match:eq}}" + |
Joachim Bingel | 6163156 | 2014-07-24 14:26:02 +0000 | [diff] [blame] | 718 | "], boundary={@type=korap:boundary, min=0, max=2}, min=0, max=2}"; |
Joachim Bingel | b2aa1c7 | 2014-07-01 12:48:46 +0000 | [diff] [blame] | 719 | ppt = new PoliqarpPlusTree("[base=foo]{,2}"); |
| 720 | map = ppt.getRequestMap().get("query").toString(); |
| 721 | assertEquals(occ14.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 722 | } |
| 723 | |
| 724 | @Test |
Joachim Bingel | 16da4e1 | 2013-12-17 09:48:12 +0000 | [diff] [blame] | 725 | public void testTokenSequence() throws QueryException { |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 726 | // [base=Mann][orth=Frau] |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 727 | String seq1 = "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 728 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}, " + |
| 729 | "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}" + |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 730 | "]}"; |
| 731 | assertTrue(equalsQueryContent(seq1, "[base=Mann][orth=Frau]")); |
| 732 | |
| 733 | // [base=Mann][orth=Frau][p=NN] |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 734 | String seq2 = "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 735 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}, " + |
| 736 | "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}, " + |
| 737 | "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}" + |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 738 | "]}"; |
| 739 | assertTrue(equalsQueryContent(seq2, "[base=Mann][orth=Frau][p=NN]")); |
| 740 | } |
| 741 | |
| 742 | @Test |
Joachim Bingel | 16da4e1 | 2013-12-17 09:48:12 +0000 | [diff] [blame] | 743 | public void testDisjSegments() throws QueryException { |
Joachim Bingel | 94a1ccd | 2013-12-10 10:37:29 +0000 | [diff] [blame] | 744 | // ([base=der]|[base=das])[base=Schild] |
| 745 | String disj1 = |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 746 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 747 | "{@type=korap:group, operation=operation:or, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 748 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," + |
| 749 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=das, match=match:eq}}" + |
Joachim Bingel | 94a1ccd | 2013-12-10 10:37:29 +0000 | [diff] [blame] | 750 | "]}," + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 751 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Schild, match=match:eq}}" + |
Joachim Bingel | 94a1ccd | 2013-12-10 10:37:29 +0000 | [diff] [blame] | 752 | "]}"; |
| 753 | ppt = new PoliqarpPlusTree("([base=der]|[base=das])[base=Schild]"); |
| 754 | map = ppt.getRequestMap().get("query").toString(); |
| 755 | assertEquals(disj1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 756 | |
| 757 | // [base=Schild]([base=der]|[base=das]) |
| 758 | String disj2 = |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 759 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 760 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Schild, match=match:eq}}," + |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 761 | "{@type=korap:group, operation=operation:or, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 762 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," + |
| 763 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=das, match=match:eq}}" + |
Joachim Bingel | 94a1ccd | 2013-12-10 10:37:29 +0000 | [diff] [blame] | 764 | "]}" + |
| 765 | "]}"; |
| 766 | ppt = new PoliqarpPlusTree("[base=Schild]([base=der]|[base=das])"); |
| 767 | map = ppt.getRequestMap().get("query").toString(); |
| 768 | assertEquals(disj2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 76b498d | 2014-06-06 12:06:46 +0000 | [diff] [blame] | 769 | |
| 770 | // "([orth=der][base=katze])|([orth=eine][base=baum])" |
| 771 | String disj3 = |
| 772 | "{@type=korap:group, operation=operation:or, operands=[" + |
| 773 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 774 | "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," + |
| 775 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=katze, match=match:eq}}" + |
Joachim Bingel | 76b498d | 2014-06-06 12:06:46 +0000 | [diff] [blame] | 776 | "]}," + |
| 777 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 778 | "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=eine, match=match:eq}}," + |
| 779 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=baum, match=match:eq}}" + |
Joachim Bingel | 76b498d | 2014-06-06 12:06:46 +0000 | [diff] [blame] | 780 | "]}" + |
| 781 | "]}"; |
| 782 | ppt = new PoliqarpPlusTree("([orth=der][base=katze])|([orth=eine][base=baum])"); |
| 783 | map = ppt.getRequestMap().get("query").toString(); |
| 784 | assertEquals(disj3.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 785 | |
| 786 | // "[orth=der][base=katze]|[orth=eine][base=baum]" |
| 787 | String disj4 = |
| 788 | "{@type=korap:group, operation=operation:or, operands=[" + |
| 789 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 790 | "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," + |
| 791 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=katze, match=match:eq}}" + |
Joachim Bingel | 76b498d | 2014-06-06 12:06:46 +0000 | [diff] [blame] | 792 | "]}," + |
| 793 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 794 | "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=eine, match=match:eq}}," + |
| 795 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=baum, match=match:eq}}" + |
Joachim Bingel | 76b498d | 2014-06-06 12:06:46 +0000 | [diff] [blame] | 796 | "]}" + |
| 797 | "]}"; |
| 798 | ppt = new PoliqarpPlusTree("[orth=der][base=katze]|[orth=eine][base=baum]"); |
| 799 | map = ppt.getRequestMap().get("query").toString(); |
| 800 | assertEquals(disj4.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 801 | |
| 802 | PoliqarpPlusTree ppt1 = new PoliqarpPlusTree("[orth=der][base=katze]|[orth=eine][base=baum]"); |
| 803 | PoliqarpPlusTree ppt2 = new PoliqarpPlusTree("([orth=der][base=katze])|([orth=eine][base=baum])"); |
| 804 | assertEquals(ppt1.getRequestMap().toString(), ppt2.getRequestMap().toString()); |
| 805 | |
| 806 | // "[orth=der][base=katze]|[orth=der][base=hund]|[orth=der][base=baum]" |
| 807 | String disj5 = |
| 808 | "{@type=korap:group, operation=operation:or, operands=[" + |
| 809 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 810 | "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," + |
| 811 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=katze, match=match:eq}}" + |
Joachim Bingel | 76b498d | 2014-06-06 12:06:46 +0000 | [diff] [blame] | 812 | "]}," + |
| 813 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 814 | "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," + |
| 815 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=hund, match=match:eq}}" + |
Joachim Bingel | 76b498d | 2014-06-06 12:06:46 +0000 | [diff] [blame] | 816 | "]}," + |
| 817 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 818 | "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," + |
| 819 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=baum, match=match:eq}}" + |
Joachim Bingel | 76b498d | 2014-06-06 12:06:46 +0000 | [diff] [blame] | 820 | "]}" + |
| 821 | "]}"; |
| 822 | ppt = new PoliqarpPlusTree("[orth=der][base=katze]|[orth=der][base=hund]|[orth=der][base=baum]"); |
| 823 | map = ppt.getRequestMap().get("query").toString(); |
| 824 | assertEquals(disj5.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 825 | |
| 826 | // [orth=der]([base=katze]|[base=hund]|[base=baum]) |
| 827 | String disj6 = |
| 828 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 829 | "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," + |
Joachim Bingel | 76b498d | 2014-06-06 12:06:46 +0000 | [diff] [blame] | 830 | "{@type=korap:group, operation=operation:or, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 831 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=katze, match=match:eq}}," + |
| 832 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=hund, match=match:eq}}," + |
| 833 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=baum, match=match:eq}}" + |
Joachim Bingel | 76b498d | 2014-06-06 12:06:46 +0000 | [diff] [blame] | 834 | "]}" + |
| 835 | "]}"; |
| 836 | ppt = new PoliqarpPlusTree("[orth=der]([base=katze]|[base=hund]|[base=baum])"); |
| 837 | map = ppt.getRequestMap().get("query").toString(); |
| 838 | assertEquals(disj6.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 94a1ccd | 2013-12-10 10:37:29 +0000 | [diff] [blame] | 839 | } |
| 840 | |
| 841 | @Test |
Joachim Bingel | 16da4e1 | 2013-12-17 09:48:12 +0000 | [diff] [blame] | 842 | public void testTokenElemSequence() throws QueryException { |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 843 | // [base=Mann]<vp> |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 844 | String seq1 = "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 845 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}, " + |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 846 | "{@type=korap:span, key=vp}" + |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 847 | "]}"; |
| 848 | assertTrue(equalsQueryContent(seq1, "[base=Mann]<vp>")); |
| 849 | |
| 850 | // <vp>[base=Mann] |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 851 | String seq2 = "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 852 | "{@type=korap:span, key=vp}, "+ |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 853 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}} " + |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 854 | "]}"; |
| 855 | assertTrue(equalsQueryContent(seq2, "<vp>[base=Mann]")); |
| 856 | |
| 857 | // <vp>[base=Mann]<pp> |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 858 | String seq3 = "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 859 | "{@type=korap:span, key=vp}, "+ |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 860 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}, " + |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 861 | "{@type=korap:span, key=pp} "+ |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 862 | "]}"; |
| 863 | assertTrue(equalsQueryContent(seq3, "<vp>[base=Mann]<pp>")); |
| 864 | } |
| 865 | |
| 866 | @Test |
Joachim Bingel | 16da4e1 | 2013-12-17 09:48:12 +0000 | [diff] [blame] | 867 | public void testElemSequence() throws QueryException { |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 868 | // <np><vp> |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 869 | String seq1 = "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 870 | "{@type=korap:span, key=np}," + |
| 871 | "{@type=korap:span, key=vp}" + |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 872 | "]}"; |
| 873 | assertTrue(equalsQueryContent(seq1, "<np><vp>")); |
| 874 | |
| 875 | // <np><vp><pp> |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 876 | String seq2 = "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 877 | "{@type=korap:span, key=np}," + |
| 878 | "{@type=korap:span, key=vp}," + |
| 879 | "{@type=korap:span, key=pp}" + |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 880 | "]}"; |
| 881 | assertTrue(equalsQueryContent(seq2, "<np><vp><pp>")); |
| 882 | } |
| 883 | |
| 884 | @Test |
Joachim Bingel | 16da4e1 | 2013-12-17 09:48:12 +0000 | [diff] [blame] | 885 | public void testClasses() throws QueryException { |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 886 | String query; |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 887 | // {[base=Mann]} |
Joachim Bingel | 4c0c201 | 2014-10-22 09:35:22 +0000 | [diff] [blame] | 888 | String cls1 = "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 889 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" + |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 890 | "]}"; |
Joachim Bingel | 8c640e4 | 2014-02-07 16:20:47 +0000 | [diff] [blame] | 891 | ppt = new PoliqarpPlusTree("{[base=Mann]}"); |
| 892 | map = ppt.getRequestMap().get("query").toString(); |
| 893 | assertEquals(cls1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 894 | |
| 895 | // {[base=Mann][orth=Frau]} |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 896 | query = "{[base=Mann][orth=Frau]}"; |
Joachim Bingel | 4c0c201 | 2014-10-22 09:35:22 +0000 | [diff] [blame] | 897 | String cls2 = "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" + |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 898 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 899 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}," + |
| 900 | "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}" + |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 901 | "]}" + |
| 902 | "]}"; |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 903 | ppt = new PoliqarpPlusTree(query); |
| 904 | map = ppt.getRequestMap().get("query").toString(); |
| 905 | assertEquals(cls2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 906 | |
| 907 | // [p=NN]{[base=Mann][orth=Frau]} |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 908 | String cls3 = "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 909 | "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}," + |
Joachim Bingel | 4c0c201 | 2014-10-22 09:35:22 +0000 | [diff] [blame] | 910 | "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" + |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 911 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 912 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}," + |
| 913 | "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}" + |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 914 | "]}" + |
| 915 | "]}" + |
| 916 | "]}"; |
Joachim Bingel | 33bd45f | 2014-06-25 15:00:54 +0000 | [diff] [blame] | 917 | ppt = new PoliqarpPlusTree("[p=NN]{[base=Mann][orth=Frau]}"); |
| 918 | map = ppt.getRequestMap().get("query").toString(); |
| 919 | assertEquals(cls3.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 920 | |
| 921 | // {[base=Mann][orth=Frau]}[p=NN] |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 922 | String cls4 = "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 4c0c201 | 2014-10-22 09:35:22 +0000 | [diff] [blame] | 923 | "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" + |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 924 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 925 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}," + |
| 926 | "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Frau, match=match:eq}}" + |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 927 | "]}" + |
| 928 | "]}," + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 929 | "{@type=korap:token, wrap={@type=korap:term, layer=p, key=NN, match=match:eq}}" + |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 930 | "]}"; |
Joachim Bingel | ba9a0ab | 2014-01-29 10:12:25 +0000 | [diff] [blame] | 931 | ppt = new PoliqarpPlusTree("{[base=Mann][orth=Frau]}[p=NN]"); |
| 932 | map = ppt.getRequestMap().get("query").toString(); |
| 933 | assertEquals(cls4.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | cd9ed33 | 2013-12-09 21:01:35 +0000 | [diff] [blame] | 934 | |
| 935 | // {2:{1:[tt/p=ADJA]}[mate/p=NN]}" |
Joachim Bingel | 832800e | 2014-10-17 14:46:39 +0000 | [diff] [blame] | 936 | String cls5 = "{@type=korap:group, operation=operation:class, class=2, classOut=2, operands=[" + |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 937 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 832800e | 2014-10-17 14:46:39 +0000 | [diff] [blame] | 938 | "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 939 | "{@type=korap:token, wrap={@type=korap:term, foundry=tt, layer=p, key=ADJA, match=match:eq}}" + |
Joachim Bingel | cd9ed33 | 2013-12-09 21:01:35 +0000 | [diff] [blame] | 940 | "]}," + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 941 | "{@type=korap:token, wrap={@type=korap:term, foundry=mate, layer=p, key=NN, match=match:eq}}" + |
Joachim Bingel | cd9ed33 | 2013-12-09 21:01:35 +0000 | [diff] [blame] | 942 | "]}" + |
| 943 | "]}"; |
| 944 | ppt = new PoliqarpPlusTree("{2: {1:[tt/p=ADJA]}[mate/p=NN]}"); |
| 945 | map = ppt.getRequestMap().get("query").toString(); |
| 946 | assertEquals(cls5.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 947 | } |
| 948 | |
| 949 | @Test |
Joachim Bingel | 16da4e1 | 2013-12-17 09:48:12 +0000 | [diff] [blame] | 950 | public void testPositions() throws QueryException { |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 951 | // contains(<s>,<np>) |
Joachim Bingel | 832800e | 2014-10-17 14:46:39 +0000 | [diff] [blame] | 952 | String pos1 = "{@type=korap:group, operation=operation:position, frames=[frames:contains], operands=[" + |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 953 | "{@type=korap:span, key=s}," + |
| 954 | "{@type=korap:span, key=np}" + |
Joachim Bingel | 6b52d76 | 2014-09-30 15:29:11 +0000 | [diff] [blame] | 955 | "], frame=frame:contains}"; |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 956 | assertTrue(equalsQueryContent(pos1, "contains(<s>,<np>)")); |
| 957 | |
| 958 | // contains(<s>,[base=Mann]) |
Joachim Bingel | 832800e | 2014-10-17 14:46:39 +0000 | [diff] [blame] | 959 | String pos2 = "{@type=korap:group, operation=operation:position, frames=[frames:contains], operands=[" + |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 960 | "{@type=korap:span, key=s}," + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 961 | "{@type=korap:token, wrap= {@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" + |
Joachim Bingel | 6b52d76 | 2014-09-30 15:29:11 +0000 | [diff] [blame] | 962 | "], frame=frame:contains}"; |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 963 | assertTrue(equalsQueryContent(pos2, "contains(<s>,[base=Mann])")); |
| 964 | |
| 965 | // contains(<s>,[orth=der][orth=Mann]) |
Joachim Bingel | 832800e | 2014-10-17 14:46:39 +0000 | [diff] [blame] | 966 | String pos3 = "{@type=korap:group, operation=operation:position, frames=[frames:contains], operands=[" + |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 967 | "{@type=korap:span, key=s}," + |
| 968 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 969 | "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," + |
| 970 | "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" + |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 971 | "]}" + |
Joachim Bingel | 6b52d76 | 2014-09-30 15:29:11 +0000 | [diff] [blame] | 972 | "], frame=frame:contains}"; |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 973 | ppt = new PoliqarpPlusTree("contains(<s>,[orth=der][orth=Mann])"); |
| 974 | map = ppt.getRequestMap().get("query").toString(); |
| 975 | assertEquals(pos3.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 976 | |
| 977 | // [base=Auto]contains(<s>,[base=Mann]) |
| 978 | String pos4 = |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 979 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 980 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Auto, match=match:eq}}," + |
Joachim Bingel | 832800e | 2014-10-17 14:46:39 +0000 | [diff] [blame] | 981 | "{@type=korap:group, operation=operation:position, frames=[frames:contains], operands=[" + |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 982 | "{@type=korap:span, key=s}," + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 983 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Mann, match=match:eq}}" + |
Joachim Bingel | 6b52d76 | 2014-09-30 15:29:11 +0000 | [diff] [blame] | 984 | "], frame=frame:contains}" + |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 985 | "]}"; |
| 986 | ppt = new PoliqarpPlusTree("[base=Auto]contains(<s>,[base=Mann])"); |
| 987 | map = ppt.getRequestMap().get("query").toString(); |
| 988 | assertEquals(pos4.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | ef7059b | 2014-04-22 13:44:19 +0000 | [diff] [blame] | 989 | |
| 990 | // contains(<s>,[pos=N]*) |
| 991 | String pos5 = |
Joachim Bingel | 832800e | 2014-10-17 14:46:39 +0000 | [diff] [blame] | 992 | "{@type=korap:group, operation=operation:position, frames=[frames:contains], operands=[" + |
Joachim Bingel | ef7059b | 2014-04-22 13:44:19 +0000 | [diff] [blame] | 993 | "{@type=korap:span, key=s}," + |
Joachim Bingel | 33bd45f | 2014-06-25 15:00:54 +0000 | [diff] [blame] | 994 | "{@type=korap:group, operation=operation:repetition, " + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 995 | "operands=[{@type=korap:token, wrap={@type=korap:term, layer=pos, key=N, match=match:eq}}" + |
Joachim Bingel | 687e4d4 | 2014-07-30 09:34:18 +0000 | [diff] [blame] | 996 | "], boundary={@type=korap:boundary, min=0}, min=0" + |
Joachim Bingel | ef7059b | 2014-04-22 13:44:19 +0000 | [diff] [blame] | 997 | "}" + |
Joachim Bingel | 6b52d76 | 2014-09-30 15:29:11 +0000 | [diff] [blame] | 998 | "], frame=frame:contains}"; |
Joachim Bingel | ef7059b | 2014-04-22 13:44:19 +0000 | [diff] [blame] | 999 | ppt = new PoliqarpPlusTree("contains(<s>,[pos=N]*)"); |
| 1000 | map = ppt.getRequestMap().get("query").toString(); |
| 1001 | assertEquals(pos5.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 1002 | |
| 1003 | // [base=Auto]contains(<s>,[pos=N]*) |
| 1004 | String pos6 = |
| 1005 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 1006 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Auto, match=match:eq}}," + |
Joachim Bingel | 832800e | 2014-10-17 14:46:39 +0000 | [diff] [blame] | 1007 | "{@type=korap:group, operation=operation:position, frames=[frames:contains], operands=[" + |
Joachim Bingel | ef7059b | 2014-04-22 13:44:19 +0000 | [diff] [blame] | 1008 | "{@type=korap:span, key=s}," + |
Joachim Bingel | 33bd45f | 2014-06-25 15:00:54 +0000 | [diff] [blame] | 1009 | "{@type=korap:group, operation=operation:repetition, " + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 1010 | "operands=[{@type=korap:token, wrap={@type=korap:term, layer=pos, key=N, match=match:eq}}" + |
Joachim Bingel | 687e4d4 | 2014-07-30 09:34:18 +0000 | [diff] [blame] | 1011 | "], boundary={@type=korap:boundary, min=0}, min=0" + |
Joachim Bingel | ef7059b | 2014-04-22 13:44:19 +0000 | [diff] [blame] | 1012 | "}" + |
Joachim Bingel | 6b52d76 | 2014-09-30 15:29:11 +0000 | [diff] [blame] | 1013 | "], frame=frame:contains}" + |
Joachim Bingel | ef7059b | 2014-04-22 13:44:19 +0000 | [diff] [blame] | 1014 | "]}"; |
| 1015 | ppt = new PoliqarpPlusTree("[base=Auto]contains(<s>,[pos=N]*)"); |
| 1016 | map = ppt.getRequestMap().get("query").toString(); |
| 1017 | assertEquals(pos6.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 1018 | } |
| 1019 | |
| 1020 | @Test |
Joachim Bingel | 16da4e1 | 2013-12-17 09:48:12 +0000 | [diff] [blame] | 1021 | public void testNestedPositions() throws QueryException { |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 1022 | // contains(<s>,startswith(<np>,[orth=Der])) |
| 1023 | String npos1 = |
Joachim Bingel | 832800e | 2014-10-17 14:46:39 +0000 | [diff] [blame] | 1024 | "{@type=korap:group, operation=operation:position, frames=[frames:contains], operands=[" + |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 1025 | "{@type=korap:span, key=s}," + |
Joachim Bingel | 832800e | 2014-10-17 14:46:39 +0000 | [diff] [blame] | 1026 | "{@type=korap:group, operation=operation:position, frames=[frames:startswith], operands=[" + |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 1027 | "{@type=korap:span, key=np}," + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 1028 | "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}" + |
Joachim Bingel | 6b52d76 | 2014-09-30 15:29:11 +0000 | [diff] [blame] | 1029 | "], frame=frame:startswith}" + |
| 1030 | "], frame=frame:contains}"; |
Joachim Bingel | cd9ed33 | 2013-12-09 21:01:35 +0000 | [diff] [blame] | 1031 | ppt = new PoliqarpPlusTree("contains(<s>, startswith(<np>,[orth=Der]))"); |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 1032 | map = ppt.getRequestMap().get("query").toString(); |
| 1033 | assertEquals(npos1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 1034 | } |
| 1035 | |
| 1036 | @Test |
Joachim Bingel | 23c31ad | 2014-08-11 09:44:46 +0000 | [diff] [blame] | 1037 | public void testFocusSplit() throws QueryException { |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 1038 | // focus([orth=Der]{[orth=Mann]}) |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 1039 | String shr1 = |
Joachim Bingel | 4c0c201 | 2014-10-22 09:35:22 +0000 | [diff] [blame] | 1040 | "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" + |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 1041 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 1042 | "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}," + |
Joachim Bingel | 4c0c201 | 2014-10-22 09:35:22 +0000 | [diff] [blame] | 1043 | "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 1044 | "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" + |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 1045 | "]}" + |
| 1046 | "]}" + |
| 1047 | "]}"; |
Joachim Bingel | f8dfcf8 | 2014-06-25 09:57:44 +0000 | [diff] [blame] | 1048 | ppt = new PoliqarpPlusTree("focus([orth=Der]{[orth=Mann]})"); |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 1049 | map = ppt.getRequestMap().get("query").toString(); |
| 1050 | assertEquals(shr1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 1051 | |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 1052 | // focus([orth=Der]{[orth=Mann][orth=geht]}) |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 1053 | String shr2 = |
Joachim Bingel | 4c0c201 | 2014-10-22 09:35:22 +0000 | [diff] [blame] | 1054 | "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" + |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 1055 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 1056 | "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}," + |
Joachim Bingel | 4c0c201 | 2014-10-22 09:35:22 +0000 | [diff] [blame] | 1057 | "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" + |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 1058 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 1059 | "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}," + |
| 1060 | "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=geht, match=match:eq}}" + |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 1061 | "]}" + |
| 1062 | "]}" + |
| 1063 | "]}" + |
| 1064 | "]}"; |
Joachim Bingel | f8dfcf8 | 2014-06-25 09:57:44 +0000 | [diff] [blame] | 1065 | ppt = new PoliqarpPlusTree("focus([orth=Der]{[orth=Mann][orth=geht]})"); |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 1066 | map = ppt.getRequestMap().get("query").toString(); |
| 1067 | assertEquals(shr2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 1068 | |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 1069 | // focus(1:[orth=Der]{1:[orth=Mann][orth=geht]}) |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 1070 | String shr3 = |
Joachim Bingel | d1a3e71 | 2014-07-16 08:02:05 +0000 | [diff] [blame] | 1071 | "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" + |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 1072 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 1073 | "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}," + |
Joachim Bingel | 832800e | 2014-10-17 14:46:39 +0000 | [diff] [blame] | 1074 | "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" + |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 1075 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 1076 | "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}," + |
| 1077 | "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=geht, match=match:eq}}" + |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 1078 | "]}" + |
| 1079 | "]}" + |
| 1080 | "]}" + |
| 1081 | "]}"; |
Joachim Bingel | f8dfcf8 | 2014-06-25 09:57:44 +0000 | [diff] [blame] | 1082 | ppt = new PoliqarpPlusTree("focus(1:[orth=Der]{1:[orth=Mann][orth=geht]})"); |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 1083 | map = ppt.getRequestMap().get("query").toString(); |
| 1084 | assertEquals(shr3.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 1085 | |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 1086 | // focus(1:startswith(<s>,{1:<np>})) |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 1087 | String shr4 = |
Joachim Bingel | d1a3e71 | 2014-07-16 08:02:05 +0000 | [diff] [blame] | 1088 | "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" + |
Joachim Bingel | 832800e | 2014-10-17 14:46:39 +0000 | [diff] [blame] | 1089 | "{@type=korap:group, operation=operation:position, frames=[frames:startswith], operands=[" + |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 1090 | "{@type=korap:span, key=s}," + |
Joachim Bingel | 832800e | 2014-10-17 14:46:39 +0000 | [diff] [blame] | 1091 | "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" + |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 1092 | "{@type=korap:span, key=np}" + |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 1093 | "]}" + |
Joachim Bingel | 6b52d76 | 2014-09-30 15:29:11 +0000 | [diff] [blame] | 1094 | "], frame=frame:startswith}" + |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 1095 | "]}"; |
Joachim Bingel | f8dfcf8 | 2014-06-25 09:57:44 +0000 | [diff] [blame] | 1096 | ppt = new PoliqarpPlusTree("focus(1:startswith(<s>,{1:<np>}))"); |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 1097 | map = ppt.getRequestMap().get("query").toString(); |
| 1098 | assertEquals(shr4.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | cd9ed33 | 2013-12-09 21:01:35 +0000 | [diff] [blame] | 1099 | |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 1100 | // focus(3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) |
Joachim Bingel | cd9ed33 | 2013-12-09 21:01:35 +0000 | [diff] [blame] | 1101 | String shr5 = |
Joachim Bingel | d1a3e71 | 2014-07-16 08:02:05 +0000 | [diff] [blame] | 1102 | "{@type=korap:reference, operation=operation:focus, classRef=[3], operands=[" + |
Joachim Bingel | 832800e | 2014-10-17 14:46:39 +0000 | [diff] [blame] | 1103 | "{@type=korap:group, operation=operation:position, frames=[frames:startswith], operands=[" + |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 1104 | "{@type=korap:span, key=s}," + |
Joachim Bingel | 832800e | 2014-10-17 14:46:39 +0000 | [diff] [blame] | 1105 | "{@type=korap:group, operation=operation:class, class=3, classOut=3, operands=[" + |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 1106 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 1107 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," + |
Joachim Bingel | 832800e | 2014-10-17 14:46:39 +0000 | [diff] [blame] | 1108 | "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" + |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 1109 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 1110 | "{@type=korap:token, wrap={@type=korap:term, foundry=mate, layer=p, key=ADJA, match=match:eq}}," + |
Joachim Bingel | 832800e | 2014-10-17 14:46:39 +0000 | [diff] [blame] | 1111 | "{@type=korap:group, operation=operation:class, class=2, classOut=2, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 1112 | "{@type=korap:token, wrap={@type=korap:term, foundry=tt, layer=p, key=NN, match=match:eq}}" + |
Joachim Bingel | cd9ed33 | 2013-12-09 21:01:35 +0000 | [diff] [blame] | 1113 | "]}" + |
| 1114 | "]}" + |
| 1115 | "]}" + |
| 1116 | "]}" + |
| 1117 | "]}" + |
Joachim Bingel | 6b52d76 | 2014-09-30 15:29:11 +0000 | [diff] [blame] | 1118 | "], frame=frame:startswith}" + |
Joachim Bingel | cd9ed33 | 2013-12-09 21:01:35 +0000 | [diff] [blame] | 1119 | "]}"; |
Joachim Bingel | f8dfcf8 | 2014-06-25 09:57:44 +0000 | [diff] [blame] | 1120 | ppt = new PoliqarpPlusTree("focus(3:startswith(<s>,{3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) "); |
Joachim Bingel | cd9ed33 | 2013-12-09 21:01:35 +0000 | [diff] [blame] | 1121 | map = ppt.getRequestMap().get("query").toString(); |
| 1122 | assertEquals(shr5.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | ba9a0ab | 2014-01-29 10:12:25 +0000 | [diff] [blame] | 1123 | |
| 1124 | // split(3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) |
| 1125 | String shr6 = |
Joachim Bingel | d1a3e71 | 2014-07-16 08:02:05 +0000 | [diff] [blame] | 1126 | "{@type=korap:reference, operation=operation:split, classRef=[3], operands=[" + |
Joachim Bingel | 832800e | 2014-10-17 14:46:39 +0000 | [diff] [blame] | 1127 | "{@type=korap:group, operation=operation:position, frames=[frames:startswith], operands=[" + |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 1128 | "{@type=korap:span, key=s}," + |
Joachim Bingel | 832800e | 2014-10-17 14:46:39 +0000 | [diff] [blame] | 1129 | "{@type=korap:group, operation=operation:class, class=3, classOut=3, operands=[" + |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 1130 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 1131 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," + |
Joachim Bingel | 832800e | 2014-10-17 14:46:39 +0000 | [diff] [blame] | 1132 | "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" + |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 1133 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 1134 | "{@type=korap:token, wrap={@type=korap:term, foundry=mate, layer=p, key=ADJA, match=match:eq}}," + |
Joachim Bingel | 832800e | 2014-10-17 14:46:39 +0000 | [diff] [blame] | 1135 | "{@type=korap:group, operation=operation:class, class=2, classOut=2, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 1136 | "{@type=korap:token, wrap={@type=korap:term, foundry=tt, layer=p, key=NN, match=match:eq}}" + |
Joachim Bingel | ba9a0ab | 2014-01-29 10:12:25 +0000 | [diff] [blame] | 1137 | "]}" + |
| 1138 | "]}" + |
| 1139 | "]}" + |
| 1140 | "]}" + |
| 1141 | "]}" + |
Joachim Bingel | 6b52d76 | 2014-09-30 15:29:11 +0000 | [diff] [blame] | 1142 | "], frame=frame:startswith}" + |
Joachim Bingel | ba9a0ab | 2014-01-29 10:12:25 +0000 | [diff] [blame] | 1143 | "]}"; |
| 1144 | ppt = new PoliqarpPlusTree("split(3:startswith(<s>,{3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) "); |
| 1145 | map = ppt.getRequestMap().get("query").toString(); |
| 1146 | assertEquals(shr6.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 8c640e4 | 2014-02-07 16:20:47 +0000 | [diff] [blame] | 1147 | |
| 1148 | // split(2|3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) |
| 1149 | String shr7 = |
Joachim Bingel | d1a3e71 | 2014-07-16 08:02:05 +0000 | [diff] [blame] | 1150 | "{@type=korap:reference, operation=operation:split, classRef=[2, 3], classRefOp=classRefOp:intersection, operands=[" + |
Joachim Bingel | 832800e | 2014-10-17 14:46:39 +0000 | [diff] [blame] | 1151 | "{@type=korap:group, operation=operation:position, frames=[frames:startswith], operands=[" + |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 1152 | "{@type=korap:span, key=s}," + |
Joachim Bingel | 832800e | 2014-10-17 14:46:39 +0000 | [diff] [blame] | 1153 | "{@type=korap:group, operation=operation:class, class=3, classOut=3, operands=[" + |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 1154 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 1155 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}," + |
Joachim Bingel | 832800e | 2014-10-17 14:46:39 +0000 | [diff] [blame] | 1156 | "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" + |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 1157 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 1158 | "{@type=korap:token, wrap={@type=korap:term, foundry=mate, layer=p, key=ADJA, match=match:eq}}," + |
Joachim Bingel | 832800e | 2014-10-17 14:46:39 +0000 | [diff] [blame] | 1159 | "{@type=korap:group, operation=operation:class, class=2, classOut=2, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 1160 | "{@type=korap:token, wrap={@type=korap:term, foundry=tt, layer=p, key=NN, match=match:eq}}" + |
Joachim Bingel | 8c640e4 | 2014-02-07 16:20:47 +0000 | [diff] [blame] | 1161 | "]}" + |
| 1162 | "]}" + |
| 1163 | "]}" + |
| 1164 | "]}" + |
| 1165 | "]}" + |
Joachim Bingel | 6b52d76 | 2014-09-30 15:29:11 +0000 | [diff] [blame] | 1166 | "], frame=frame:startswith}" + |
Joachim Bingel | 8c640e4 | 2014-02-07 16:20:47 +0000 | [diff] [blame] | 1167 | "]}"; |
| 1168 | ppt = new PoliqarpPlusTree("split(2|3:startswith(<s>,{3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) "); |
| 1169 | map = ppt.getRequestMap().get("query").toString(); |
| 1170 | assertEquals(shr7.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 5146ebe | 2014-06-12 08:49:21 +0000 | [diff] [blame] | 1171 | |
| 1172 | |
| 1173 | String shr8 = |
Joachim Bingel | d1a3e71 | 2014-07-16 08:02:05 +0000 | [diff] [blame] | 1174 | "{@type=korap:reference, operation=operation:focus, classRef=[1], operands=[" + |
Joachim Bingel | add0fb1 | 2014-06-24 08:54:14 +0000 | [diff] [blame] | 1175 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 4c0c201 | 2014-10-22 09:35:22 +0000 | [diff] [blame] | 1176 | "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 1177 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=der, match=match:eq}}" + |
Joachim Bingel | add0fb1 | 2014-06-24 08:54:14 +0000 | [diff] [blame] | 1178 | "]}," + |
Joachim Bingel | 832800e | 2014-10-17 14:46:39 +0000 | [diff] [blame] | 1179 | "{@type=korap:group, operation=operation:class, class=1, classOut=1, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 1180 | "{@type=korap:token, wrap={@type=korap:term, layer=pos, key=ADJA, match=match:eq}}" + |
Joachim Bingel | 5146ebe | 2014-06-12 08:49:21 +0000 | [diff] [blame] | 1181 | "]}" + |
Joachim Bingel | add0fb1 | 2014-06-24 08:54:14 +0000 | [diff] [blame] | 1182 | "]}" + |
| 1183 | "]}"; |
Joachim Bingel | f8dfcf8 | 2014-06-25 09:57:44 +0000 | [diff] [blame] | 1184 | ppt = new PoliqarpPlusTree("focus(1:{[base=der]}{1:[pos=ADJA]})"); |
Joachim Bingel | add0fb1 | 2014-06-24 08:54:14 +0000 | [diff] [blame] | 1185 | map = ppt.getRequestMap().get("query").toString(); |
| 1186 | assertEquals(shr8.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 5146ebe | 2014-06-12 08:49:21 +0000 | [diff] [blame] | 1187 | |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 1188 | } |
| 1189 | |
Joachim Bingel | 23c31ad | 2014-08-11 09:44:46 +0000 | [diff] [blame] | 1190 | @Test |
| 1191 | public void testSubspan() throws QueryException { |
Joachim Bingel | 9bbd4fc | 2014-08-11 14:56:48 +0000 | [diff] [blame] | 1192 | query = "submatch(1,:<s>)"; |
Joachim Bingel | 23c31ad | 2014-08-11 09:44:46 +0000 | [diff] [blame] | 1193 | expected = |
| 1194 | "{@type=korap:reference, operation=operation:focus, operands=[" + |
| 1195 | "{@type=korap:span, key=s}" + |
| 1196 | "], spanRef=[1]" + |
| 1197 | "}"; |
| 1198 | ppt = new PoliqarpPlusTree(query); |
| 1199 | map = ppt.getRequestMap().get("query").toString(); |
| 1200 | assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 1201 | |
Joachim Bingel | 9bbd4fc | 2014-08-11 14:56:48 +0000 | [diff] [blame] | 1202 | query = "submatch(1,4:<s>)"; |
Joachim Bingel | 23c31ad | 2014-08-11 09:44:46 +0000 | [diff] [blame] | 1203 | expected = |
| 1204 | "{@type=korap:reference, operation=operation:focus, operands=[" + |
| 1205 | "{@type=korap:span, key=s}" + |
| 1206 | "], spanRef=[1,4]" + |
| 1207 | "}"; |
| 1208 | ppt = new PoliqarpPlusTree(query); |
| 1209 | map = ppt.getRequestMap().get("query").toString(); |
| 1210 | assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 1211 | |
Joachim Bingel | 9bbd4fc | 2014-08-11 14:56:48 +0000 | [diff] [blame] | 1212 | query = "submatch(1,4:contains(<s>,[base=Haus]))"; |
Joachim Bingel | 23c31ad | 2014-08-11 09:44:46 +0000 | [diff] [blame] | 1213 | expected = |
| 1214 | "{@type=korap:reference, operation=operation:focus, operands=[" + |
Joachim Bingel | 832800e | 2014-10-17 14:46:39 +0000 | [diff] [blame] | 1215 | "{@type=korap:group, operation=operation:position, frames=[frames:contains], operands=[" + |
Joachim Bingel | 23c31ad | 2014-08-11 09:44:46 +0000 | [diff] [blame] | 1216 | "{@type=korap:span, key=s}," + |
| 1217 | "{@type=korap:token, wrap= {@type=korap:term, layer=lemma, key=Haus, match=match:eq}}" + |
Joachim Bingel | 6b52d76 | 2014-09-30 15:29:11 +0000 | [diff] [blame] | 1218 | "], frame=frame:contains}" + |
Joachim Bingel | 23c31ad | 2014-08-11 09:44:46 +0000 | [diff] [blame] | 1219 | "], spanRef=[1,4]" + |
| 1220 | "}"; |
| 1221 | ppt = new PoliqarpPlusTree(query); |
| 1222 | map = ppt.getRequestMap().get("query").toString(); |
| 1223 | assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 1224 | } |
| 1225 | |
| 1226 | @Test |
| 1227 | public void testRelations() throws QueryException { |
| 1228 | query = "relatesTo(<s>,<np>)"; |
| 1229 | expected = |
| 1230 | "{@type=korap:group, operation=operation:relation, operands=[" + |
| 1231 | "{@type=korap:span, key=s}," + |
| 1232 | "{@type=korap:span, key=np}" + |
| 1233 | "], relation={@type=korap:relation}" + |
| 1234 | "}"; |
| 1235 | ppt = new PoliqarpPlusTree(query); |
| 1236 | map = ppt.getRequestMap().get("query").toString(); |
| 1237 | assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 1238 | |
| 1239 | query = "relatesTo([base=Baum],<np>)"; |
| 1240 | expected = |
| 1241 | "{@type=korap:group, operation=operation:relation, operands=[" + |
| 1242 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Baum, match=match:eq}}," + |
| 1243 | "{@type=korap:span, key=np}" + |
| 1244 | "], relation={@type=korap:relation}" + |
| 1245 | "}"; |
| 1246 | ppt = new PoliqarpPlusTree(query); |
| 1247 | map = ppt.getRequestMap().get("query").toString(); |
| 1248 | assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 1249 | |
| 1250 | query = "dominates(<np>,[base=Baum])"; |
| 1251 | expected = |
| 1252 | "{@type=korap:group, operation=operation:relation, operands=[" + |
| 1253 | "{@type=korap:span, key=np}," + |
| 1254 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Baum, match=match:eq}}" + |
| 1255 | "], relation={@type=korap:relation, layer=c}" + |
| 1256 | "}"; |
| 1257 | ppt = new PoliqarpPlusTree(query); |
| 1258 | map = ppt.getRequestMap().get("query").toString(); |
| 1259 | assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 1260 | |
| 1261 | query = "dominates(cnx/c:<np>,[base=Baum])"; |
| 1262 | expected = |
| 1263 | "{@type=korap:group, operation=operation:relation, operands=[" + |
| 1264 | "{@type=korap:span, key=np}," + |
| 1265 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Baum, match=match:eq}}" + |
| 1266 | "], relation={@type=korap:relation, layer=c, foundry=cnx}" + |
| 1267 | "}"; |
| 1268 | ppt = new PoliqarpPlusTree(query); |
| 1269 | map = ppt.getRequestMap().get("query").toString(); |
| 1270 | assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 1271 | |
| 1272 | query = "dominates(cnx/c*:<np>,[base=Baum])"; |
| 1273 | expected = |
| 1274 | "{@type=korap:group, operation=operation:relation, operands=[" + |
| 1275 | "{@type=korap:span, key=np}," + |
| 1276 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Baum, match=match:eq}}" + |
| 1277 | "], relation={@type=korap:relation, layer=c, foundry=cnx, boundary={@type=korap:boundary, min=0}}" + |
| 1278 | "}"; |
| 1279 | ppt = new PoliqarpPlusTree(query); |
| 1280 | map = ppt.getRequestMap().get("query").toString(); |
| 1281 | assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 1282 | |
| 1283 | query = "dominates(cnx/c{1,5}:<np>,[base=Baum])"; |
| 1284 | expected = |
| 1285 | "{@type=korap:group, operation=operation:relation, operands=[" + |
| 1286 | "{@type=korap:span, key=np}," + |
| 1287 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Baum, match=match:eq}}" + |
| 1288 | "], relation={@type=korap:relation, layer=c, foundry=cnx, boundary={@type=korap:boundary, min=1, max=5}}" + |
| 1289 | "}"; |
| 1290 | ppt = new PoliqarpPlusTree(query); |
| 1291 | map = ppt.getRequestMap().get("query").toString(); |
| 1292 | assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 1293 | |
| 1294 | query = "relatesTo(mate/d=HEAD:<np>,[base=Baum])"; |
| 1295 | expected = |
| 1296 | "{@type=korap:group, operation=operation:relation, operands=[" + |
| 1297 | "{@type=korap:span, key=np}," + |
| 1298 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=Baum, match=match:eq}}" + |
| 1299 | "], relation={@type=korap:relation, foundry=mate, layer=d, key=HEAD}" + |
| 1300 | "}"; |
| 1301 | ppt = new PoliqarpPlusTree(query); |
| 1302 | map = ppt.getRequestMap().get("query").toString(); |
| 1303 | assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 1304 | |
| 1305 | } |
| 1306 | |
| 1307 | |
Joachim Bingel | 0388270 | 2013-12-31 19:53:05 +0000 | [diff] [blame] | 1308 | |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 1309 | @Test |
Joachim Bingel | ba9a0ab | 2014-01-29 10:12:25 +0000 | [diff] [blame] | 1310 | public void testFoundries() throws QueryException { |
| 1311 | // [tt/base=Mann] |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 1312 | String layer1 = "{@type=korap:token, wrap={@type=korap:term, foundry=tt, layer=lemma, key=Mann, match=match:eq}}"; |
Joachim Bingel | ba9a0ab | 2014-01-29 10:12:25 +0000 | [diff] [blame] | 1313 | ppt = new PoliqarpPlusTree("[tt/base=Mann]"); |
| 1314 | map = ppt.getRequestMap().get("query").toString(); |
| 1315 | assertEquals(layer1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 1316 | |
| 1317 | } |
Joachim Bingel | 16da4e1 | 2013-12-17 09:48:12 +0000 | [diff] [blame] | 1318 | |
| 1319 | @Test |
Joachim Bingel | 8c640e4 | 2014-02-07 16:20:47 +0000 | [diff] [blame] | 1320 | public void testAlign() throws QueryException { |
Joachim Bingel | 16da4e1 | 2013-12-17 09:48:12 +0000 | [diff] [blame] | 1321 | // [orth=der]^[orth=Mann] |
Joachim Bingel | 832800e | 2014-10-17 14:46:39 +0000 | [diff] [blame] | 1322 | query = "[orth=der]^[orth=Mann]"; |
| 1323 | expected = |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 1324 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 1325 | "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," + |
Joachim Bingel | 6b491c2 | 2014-10-21 08:35:18 +0000 | [diff] [blame] | 1326 | "{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 1327 | "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" + |
Joachim Bingel | 832800e | 2014-10-17 14:46:39 +0000 | [diff] [blame] | 1328 | "]}" + |
Joachim Bingel | 16da4e1 | 2013-12-17 09:48:12 +0000 | [diff] [blame] | 1329 | "]}"; |
Joachim Bingel | 832800e | 2014-10-17 14:46:39 +0000 | [diff] [blame] | 1330 | metaExpected = |
Joachim Bingel | 6b491c2 | 2014-10-21 08:35:18 +0000 | [diff] [blame] | 1331 | "{alignment=129}"; |
Joachim Bingel | 832800e | 2014-10-17 14:46:39 +0000 | [diff] [blame] | 1332 | ppt = new PoliqarpPlusTree(query); |
Joachim Bingel | 16da4e1 | 2013-12-17 09:48:12 +0000 | [diff] [blame] | 1333 | map = ppt.getRequestMap().get("query").toString(); |
Joachim Bingel | 832800e | 2014-10-17 14:46:39 +0000 | [diff] [blame] | 1334 | metaMap = ppt.getRequestMap().get("meta").toString(); |
| 1335 | assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 1336 | assertEquals(metaExpected.replaceAll(" ", ""), metaMap.replaceAll(" ", "")); |
Joachim Bingel | 16da4e1 | 2013-12-17 09:48:12 +0000 | [diff] [blame] | 1337 | |
Joachim Bingel | 84e33df | 2014-01-31 14:02:46 +0000 | [diff] [blame] | 1338 | // [orth=der]^[orth=große][orth=Mann] |
Joachim Bingel | 832800e | 2014-10-17 14:46:39 +0000 | [diff] [blame] | 1339 | query = "[orth=der]^[orth=große][orth=Mann]"; |
| 1340 | String expected = |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 1341 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 1342 | "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=der, match=match:eq}}," + |
Joachim Bingel | 6b491c2 | 2014-10-21 08:35:18 +0000 | [diff] [blame] | 1343 | "{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" + |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 1344 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 1345 | "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=große, match=match:eq}}," + |
| 1346 | "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Mann, match=match:eq}}" + |
Joachim Bingel | 84e33df | 2014-01-31 14:02:46 +0000 | [diff] [blame] | 1347 | "]}" + |
Joachim Bingel | 832800e | 2014-10-17 14:46:39 +0000 | [diff] [blame] | 1348 | "]}" + |
Joachim Bingel | 84e33df | 2014-01-31 14:02:46 +0000 | [diff] [blame] | 1349 | "]}"; |
Joachim Bingel | 832800e | 2014-10-17 14:46:39 +0000 | [diff] [blame] | 1350 | metaExpected = |
Joachim Bingel | 6b491c2 | 2014-10-21 08:35:18 +0000 | [diff] [blame] | 1351 | "{alignment=129}"; |
Joachim Bingel | 84e33df | 2014-01-31 14:02:46 +0000 | [diff] [blame] | 1352 | ppt = new PoliqarpPlusTree(query); |
| 1353 | map = ppt.getRequestMap().get("query").toString(); |
Joachim Bingel | 832800e | 2014-10-17 14:46:39 +0000 | [diff] [blame] | 1354 | metaMap = ppt.getRequestMap().get("meta").toString(); |
| 1355 | assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 1356 | assertEquals(metaExpected.replaceAll(" ", ""), metaMap.replaceAll(" ", "")); |
Joachim Bingel | 84e33df | 2014-01-31 14:02:46 +0000 | [diff] [blame] | 1357 | |
Joachim Bingel | 832800e | 2014-10-17 14:46:39 +0000 | [diff] [blame] | 1358 | query = "([base=a]^[base=b])|[base=c]"; |
| 1359 | expected = |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 1360 | "{@type=korap:group, operation=operation:or, operands=[" + |
| 1361 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 1362 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=a, match=match:eq}}," + |
Joachim Bingel | 6b491c2 | 2014-10-21 08:35:18 +0000 | [diff] [blame] | 1363 | "{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 1364 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=b, match=match:eq}}" + |
Joachim Bingel | 832800e | 2014-10-17 14:46:39 +0000 | [diff] [blame] | 1365 | "]}" + |
Joachim Bingel | 16da4e1 | 2013-12-17 09:48:12 +0000 | [diff] [blame] | 1366 | "]}," + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 1367 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=c, match=match:eq}}" + |
Joachim Bingel | 16da4e1 | 2013-12-17 09:48:12 +0000 | [diff] [blame] | 1368 | "]}"; |
Joachim Bingel | 832800e | 2014-10-17 14:46:39 +0000 | [diff] [blame] | 1369 | metaExpected = |
Joachim Bingel | 6b491c2 | 2014-10-21 08:35:18 +0000 | [diff] [blame] | 1370 | "{alignment=129}"; |
Joachim Bingel | 832800e | 2014-10-17 14:46:39 +0000 | [diff] [blame] | 1371 | ppt = new PoliqarpPlusTree(query); |
Joachim Bingel | 16da4e1 | 2013-12-17 09:48:12 +0000 | [diff] [blame] | 1372 | map = ppt.getRequestMap().get("query").toString(); |
Joachim Bingel | 832800e | 2014-10-17 14:46:39 +0000 | [diff] [blame] | 1373 | metaMap = ppt.getRequestMap().get("meta").toString(); |
| 1374 | assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 1375 | assertEquals(metaExpected.replaceAll(" ", ""), metaMap.replaceAll(" ", "")); |
Joachim Bingel | a67e6a3 | 2014-01-02 18:35:24 +0000 | [diff] [blame] | 1376 | |
Joachim Bingel | 832800e | 2014-10-17 14:46:39 +0000 | [diff] [blame] | 1377 | query = "([base=a]^[base=b][base=c])|[base=d]"; |
| 1378 | expected = |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 1379 | "{@type=korap:group, operation=operation:or, operands=[" + |
| 1380 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 1381 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=a, match=match:eq}}," + |
Joachim Bingel | 6b491c2 | 2014-10-21 08:35:18 +0000 | [diff] [blame] | 1382 | "{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" + |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 1383 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 1384 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=b, match=match:eq}}," + |
| 1385 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=c, match=match:eq}}" + |
Joachim Bingel | 84e33df | 2014-01-31 14:02:46 +0000 | [diff] [blame] | 1386 | "]}" + |
Joachim Bingel | 832800e | 2014-10-17 14:46:39 +0000 | [diff] [blame] | 1387 | "]}" + |
Joachim Bingel | a67e6a3 | 2014-01-02 18:35:24 +0000 | [diff] [blame] | 1388 | "]}," + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 1389 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=d, match=match:eq}}" + |
Joachim Bingel | a67e6a3 | 2014-01-02 18:35:24 +0000 | [diff] [blame] | 1390 | "]}"; |
Joachim Bingel | 832800e | 2014-10-17 14:46:39 +0000 | [diff] [blame] | 1391 | metaExpected = |
Joachim Bingel | 6b491c2 | 2014-10-21 08:35:18 +0000 | [diff] [blame] | 1392 | "{alignment=129}"; |
Joachim Bingel | 832800e | 2014-10-17 14:46:39 +0000 | [diff] [blame] | 1393 | ppt = new PoliqarpPlusTree(query); |
Joachim Bingel | a67e6a3 | 2014-01-02 18:35:24 +0000 | [diff] [blame] | 1394 | map = ppt.getRequestMap().get("query").toString(); |
Joachim Bingel | 832800e | 2014-10-17 14:46:39 +0000 | [diff] [blame] | 1395 | metaMap = ppt.getRequestMap().get("meta").toString(); |
| 1396 | assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 1397 | assertEquals(metaExpected.replaceAll(" ", ""), metaMap.replaceAll(" ", "")); |
Joachim Bingel | a67e6a3 | 2014-01-02 18:35:24 +0000 | [diff] [blame] | 1398 | |
Joachim Bingel | 832800e | 2014-10-17 14:46:39 +0000 | [diff] [blame] | 1399 | query = "([base=a]^[base=b]^[base=c])|[base=d]"; |
| 1400 | expected = |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 1401 | "{@type=korap:group, operation=operation:or, operands=[" + |
| 1402 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 1403 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=a, match=match:eq}}," + |
Joachim Bingel | 6b491c2 | 2014-10-21 08:35:18 +0000 | [diff] [blame] | 1404 | "{@type=korap:group, operation=operation:class, class=129, classOut=129, operands=[" + |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 1405 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 1406 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=b, match=match:eq}}," + |
Joachim Bingel | 6b491c2 | 2014-10-21 08:35:18 +0000 | [diff] [blame] | 1407 | "{@type=korap:group, operation=operation:class, class=130, classOut=130, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 1408 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=c, match=match:eq}}" + |
Joachim Bingel | 832800e | 2014-10-17 14:46:39 +0000 | [diff] [blame] | 1409 | "]}" + |
Joachim Bingel | 84e33df | 2014-01-31 14:02:46 +0000 | [diff] [blame] | 1410 | "]}" + |
Joachim Bingel | 832800e | 2014-10-17 14:46:39 +0000 | [diff] [blame] | 1411 | "]}" + |
Joachim Bingel | a67e6a3 | 2014-01-02 18:35:24 +0000 | [diff] [blame] | 1412 | "]}," + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 1413 | "{@type=korap:token, wrap={@type=korap:term, layer=lemma, key=d, match=match:eq}}" + |
Joachim Bingel | a67e6a3 | 2014-01-02 18:35:24 +0000 | [diff] [blame] | 1414 | "]}"; |
Joachim Bingel | 832800e | 2014-10-17 14:46:39 +0000 | [diff] [blame] | 1415 | metaExpected = |
Joachim Bingel | 6b491c2 | 2014-10-21 08:35:18 +0000 | [diff] [blame] | 1416 | "{alignment=[129,130]}"; |
Joachim Bingel | 832800e | 2014-10-17 14:46:39 +0000 | [diff] [blame] | 1417 | ppt = new PoliqarpPlusTree(query); |
Joachim Bingel | a67e6a3 | 2014-01-02 18:35:24 +0000 | [diff] [blame] | 1418 | map = ppt.getRequestMap().get("query").toString(); |
Joachim Bingel | 832800e | 2014-10-17 14:46:39 +0000 | [diff] [blame] | 1419 | metaMap = ppt.getRequestMap().get("meta").toString(); |
| 1420 | assertEquals(expected.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 1421 | assertEquals(metaExpected.replaceAll(" ", ""), metaMap.replaceAll(" ", "")); |
Joachim Bingel | a67e6a3 | 2014-01-02 18:35:24 +0000 | [diff] [blame] | 1422 | |
| 1423 | |
Joachim Bingel | 16da4e1 | 2013-12-17 09:48:12 +0000 | [diff] [blame] | 1424 | } |
| 1425 | |
| 1426 | @Test |
Joachim Bingel | 8c640e4 | 2014-02-07 16:20:47 +0000 | [diff] [blame] | 1427 | public void testSimpleQueries() throws QueryException { |
Joachim Bingel | a67e6a3 | 2014-01-02 18:35:24 +0000 | [diff] [blame] | 1428 | // Baum |
| 1429 | String simple1 = |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 1430 | "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq}}"; |
Joachim Bingel | a67e6a3 | 2014-01-02 18:35:24 +0000 | [diff] [blame] | 1431 | ppt = new PoliqarpPlusTree("Baum"); |
| 1432 | map = ppt.getRequestMap().get("query").toString(); |
| 1433 | assertEquals(simple1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 1434 | |
| 1435 | // Baum/i |
| 1436 | String simple1b = |
| 1437 | "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq, caseInsensitive=true}}"; |
| 1438 | ppt = new PoliqarpPlusTree("Baum/i"); |
| 1439 | map = ppt.getRequestMap().get("query").toString(); |
| 1440 | assertEquals(simple1b.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 16da4e1 | 2013-12-17 09:48:12 +0000 | [diff] [blame] | 1441 | |
Joachim Bingel | a67e6a3 | 2014-01-02 18:35:24 +0000 | [diff] [blame] | 1442 | // Der Baum |
| 1443 | String simple2 = |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 1444 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 1445 | "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}, " + |
| 1446 | "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq}}" + |
Joachim Bingel | a67e6a3 | 2014-01-02 18:35:24 +0000 | [diff] [blame] | 1447 | "]}"; |
| 1448 | ppt = new PoliqarpPlusTree("Der Baum"); |
| 1449 | map = ppt.getRequestMap().get("query").toString(); |
| 1450 | assertEquals(simple2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 1451 | |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 1452 | // Der Baum/i |
| 1453 | String simple2b = |
| 1454 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 1455 | "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}, " + |
| 1456 | "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq, caseInsensitive=true}}" + |
| 1457 | "]}"; |
| 1458 | ppt = new PoliqarpPlusTree("Der Baum/i"); |
| 1459 | map = ppt.getRequestMap().get("query").toString(); |
| 1460 | assertEquals(simple2b.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 1461 | |
Joachim Bingel | a67e6a3 | 2014-01-02 18:35:24 +0000 | [diff] [blame] | 1462 | // Der große Baum |
| 1463 | String simple3 = |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 1464 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 1465 | "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Der, match=match:eq}}, " + |
| 1466 | "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=große, match=match:eq}}, " + |
| 1467 | "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq}}" + |
Joachim Bingel | a67e6a3 | 2014-01-02 18:35:24 +0000 | [diff] [blame] | 1468 | "]}"; |
| 1469 | ppt = new PoliqarpPlusTree("Der große Baum"); |
| 1470 | map = ppt.getRequestMap().get("query").toString(); |
| 1471 | assertEquals(simple3.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 1472 | |
| 1473 | // Baum | Stein |
| 1474 | String simple4 = |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 1475 | "{@type=korap:group, operation=operation:or, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 1476 | "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq}}, " + |
| 1477 | "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Stein, match=match:eq}}" + |
Joachim Bingel | a67e6a3 | 2014-01-02 18:35:24 +0000 | [diff] [blame] | 1478 | "]}"; |
| 1479 | ppt = new PoliqarpPlusTree("Baum | Stein"); |
| 1480 | map = ppt.getRequestMap().get("query").toString(); |
| 1481 | assertEquals(simple4.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 84e33df | 2014-01-31 14:02:46 +0000 | [diff] [blame] | 1482 | |
| 1483 | // Baum | Stein Haus |
| 1484 | String query = "(Baum | Stein) Haus"; |
| 1485 | String simple5 = |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 1486 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 1487 | "{@type=korap:group, operation=operation:or, operands=[" + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 1488 | "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Baum, match=match:eq}}, " + |
| 1489 | "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Stein, match=match:eq}}" + |
Joachim Bingel | 84e33df | 2014-01-31 14:02:46 +0000 | [diff] [blame] | 1490 | "]}," + |
Joachim Bingel | 0900a89 | 2014-06-30 16:26:21 +0000 | [diff] [blame] | 1491 | "{@type=korap:token, wrap={@type=korap:term, layer=orth, key=Haus, match=match:eq}} " + |
Joachim Bingel | 84e33df | 2014-01-31 14:02:46 +0000 | [diff] [blame] | 1492 | "]}"; |
| 1493 | ppt = new PoliqarpPlusTree(query); |
| 1494 | map = ppt.getRequestMap().get("query").toString(); |
| 1495 | assertEquals(simple5.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 16da4e1 | 2013-12-17 09:48:12 +0000 | [diff] [blame] | 1496 | } |
Joachim Bingel | b68361c | 2014-10-22 14:15:09 +0000 | [diff] [blame] | 1497 | |
| 1498 | @Test |
| 1499 | public void testUnnecessaryParantheses() throws QueryException { |
| 1500 | String query1, query2; |
| 1501 | PoliqarpPlusTree tree1, tree2; |
| 1502 | |
| 1503 | query1 = "Test"; |
| 1504 | query2 = "(Test)"; |
| 1505 | tree1 = new PoliqarpPlusTree(query1); |
| 1506 | tree2 = new PoliqarpPlusTree(query2); |
| 1507 | assertEquals(tree1.getRequestMap(), tree2.getRequestMap()); |
| 1508 | |
| 1509 | query1 = "pass|fail"; |
| 1510 | query2 = "(pass|fail)"; |
| 1511 | tree1 = new PoliqarpPlusTree(query1); |
| 1512 | tree2 = new PoliqarpPlusTree(query2); |
| 1513 | assertEquals(tree1.getRequestMap(), tree2.getRequestMap()); |
| 1514 | |
| 1515 | query1 = "pass|fail"; |
| 1516 | query2 = "pass|(fail)"; |
| 1517 | tree1 = new PoliqarpPlusTree(query1); |
| 1518 | tree2 = new PoliqarpPlusTree(query2); |
| 1519 | assertEquals(tree1.getRequestMap(), tree2.getRequestMap()); |
| 1520 | |
| 1521 | query1 = "pass|fail"; |
| 1522 | query2 = "(pass|(fail))"; |
| 1523 | tree1 = new PoliqarpPlusTree(query1); |
| 1524 | tree2 = new PoliqarpPlusTree(query2); |
| 1525 | assertEquals(tree1.getRequestMap(), tree2.getRequestMap()); |
| 1526 | |
| 1527 | query1 = "contains(<s>,Mann)"; |
| 1528 | query2 = "contains((<s>),Mann)"; |
| 1529 | tree1 = new PoliqarpPlusTree(query1); |
| 1530 | tree2 = new PoliqarpPlusTree(query2); |
| 1531 | assertEquals(tree1.getRequestMap(), tree2.getRequestMap()); |
| 1532 | } |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 1533 | } |
| 1534 | |