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