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