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