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