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