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