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