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