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