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