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 | 8c640e4 | 2014-02-07 16:20:47 +0000 | [diff] [blame] | 404 | String cls1 = "{@type=korap:group, @relation=class, class=0, @operands=[" + |
Joachim Bingel | ba9a0ab | 2014-01-29 10:12:25 +0000 | [diff] [blame] | 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 | "]}"; |
Joachim Bingel | 8c640e4 | 2014-02-07 16:20:47 +0000 | [diff] [blame] | 407 | ppt = new PoliqarpPlusTree("{[base=Mann]}"); |
| 408 | map = ppt.getRequestMap().get("query").toString(); |
| 409 | assertEquals(cls1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 410 | |
| 411 | // {[base=Mann][orth=Frau]} |
Joachim Bingel | 8c640e4 | 2014-02-07 16:20:47 +0000 | [diff] [blame] | 412 | String cls2 = "{@type=korap:group, @relation=class, class=0, @operands=[" + |
Joachim Bingel | ba9a0ab | 2014-01-29 10:12:25 +0000 | [diff] [blame] | 413 | "{@type=korap:sequence, @operands=[" + |
| 414 | "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=base, @relation==}}," + |
| 415 | "{@type=korap:token, @value={@type=korap:term, @value=Frau, @attr=orth, @relation==}}" + |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 416 | "]}" + |
| 417 | "]}"; |
| 418 | assertTrue(equalsQueryContent(cls2, "{[base=Mann][orth=Frau]}")); |
| 419 | |
| 420 | // [p=NN]{[base=Mann][orth=Frau]} |
Joachim Bingel | ba9a0ab | 2014-01-29 10:12:25 +0000 | [diff] [blame] | 421 | String cls3 = "{@type=korap:sequence, @operands=[" + |
| 422 | "{@type=korap:token, @value={@type=korap:term, @value=NN, @attr=p, @relation==}}," + |
Joachim Bingel | 8c640e4 | 2014-02-07 16:20:47 +0000 | [diff] [blame] | 423 | "{@type=korap:group, @relation=class, class=0, @operands=[" + |
Joachim Bingel | ba9a0ab | 2014-01-29 10:12:25 +0000 | [diff] [blame] | 424 | "{@type=korap:sequence, @operands=[" + |
| 425 | "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=base, @relation==}}," + |
| 426 | "{@type=korap:token, @value={@type=korap:term, @value=Frau, @attr=orth, @relation==}}" + |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 427 | "]}" + |
| 428 | "]}" + |
| 429 | "]}"; |
| 430 | assertTrue(equalsQueryContent(cls3, "[p=NN]{[base=Mann][orth=Frau]}")); |
| 431 | |
| 432 | // {[base=Mann][orth=Frau]}[p=NN] |
Joachim Bingel | ba9a0ab | 2014-01-29 10:12:25 +0000 | [diff] [blame] | 433 | String cls4 = "{@type=korap:sequence, @operands=[" + |
Joachim Bingel | 8c640e4 | 2014-02-07 16:20:47 +0000 | [diff] [blame] | 434 | "{@type=korap:group, @relation=class, class=0, @operands=[" + |
Joachim Bingel | ba9a0ab | 2014-01-29 10:12:25 +0000 | [diff] [blame] | 435 | "{@type=korap:sequence, @operands=[" + |
| 436 | "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=base, @relation==}}," + |
| 437 | "{@type=korap:token, @value={@type=korap:term, @value=Frau, @attr=orth, @relation==}}" + |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 438 | "]}" + |
| 439 | "]}," + |
Joachim Bingel | ba9a0ab | 2014-01-29 10:12:25 +0000 | [diff] [blame] | 440 | "{@type=korap:token, @value={@type=korap:term, @value=NN, @attr=p, @relation==}}" + |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 441 | "]}"; |
Joachim Bingel | ba9a0ab | 2014-01-29 10:12:25 +0000 | [diff] [blame] | 442 | ppt = new PoliqarpPlusTree("{[base=Mann][orth=Frau]}[p=NN]"); |
| 443 | map = ppt.getRequestMap().get("query").toString(); |
| 444 | assertEquals(cls4.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | cd9ed33 | 2013-12-09 21:01:35 +0000 | [diff] [blame] | 445 | |
| 446 | // {2:{1:[tt/p=ADJA]}[mate/p=NN]}" |
Joachim Bingel | 8c640e4 | 2014-02-07 16:20:47 +0000 | [diff] [blame] | 447 | String cls5 = "{@type=korap:group, @relation=class, class=2, @operands=[" + |
Joachim Bingel | ba9a0ab | 2014-01-29 10:12:25 +0000 | [diff] [blame] | 448 | "{@type=korap:sequence, @operands=[" + |
Joachim Bingel | 8c640e4 | 2014-02-07 16:20:47 +0000 | [diff] [blame] | 449 | "{@type=korap:group, @relation=class, class=1, @operands=[" + |
Joachim Bingel | ba9a0ab | 2014-01-29 10:12:25 +0000 | [diff] [blame] | 450 | "{@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] | 451 | "]}," + |
Joachim Bingel | ba9a0ab | 2014-01-29 10:12:25 +0000 | [diff] [blame] | 452 | "{@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] | 453 | "]}" + |
| 454 | "]}"; |
| 455 | ppt = new PoliqarpPlusTree("{2: {1:[tt/p=ADJA]}[mate/p=NN]}"); |
| 456 | map = ppt.getRequestMap().get("query").toString(); |
| 457 | assertEquals(cls5.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | @Test |
Joachim Bingel | 16da4e1 | 2013-12-17 09:48:12 +0000 | [diff] [blame] | 461 | public void testPositions() throws QueryException { |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 462 | // contains(<s>,<np>) |
Joachim Bingel | ba9a0ab | 2014-01-29 10:12:25 +0000 | [diff] [blame] | 463 | String pos1 = "{@type=korap:group, @relation=position, @position=contains, @operands=[" + |
| 464 | "{@type=korap:span, @value=s}," + |
| 465 | "{@type=korap:span, @value=np}" + |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 466 | "]}"; |
| 467 | assertTrue(equalsQueryContent(pos1, "contains(<s>,<np>)")); |
| 468 | |
| 469 | // contains(<s>,[base=Mann]) |
Joachim Bingel | ba9a0ab | 2014-01-29 10:12:25 +0000 | [diff] [blame] | 470 | String pos2 = "{@type=korap:group, @relation=position, @position=contains, @operands=[" + |
| 471 | "{@type=korap:span, @value=s}," + |
| 472 | "{@type=korap:token, @value= {@type=korap:term, @value=Mann, @attr=base, @relation==}}" + |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 473 | "]}"; |
| 474 | assertTrue(equalsQueryContent(pos2, "contains(<s>,[base=Mann])")); |
| 475 | |
| 476 | // contains(<s>,[orth=der][orth=Mann]) |
Joachim Bingel | ba9a0ab | 2014-01-29 10:12:25 +0000 | [diff] [blame] | 477 | String pos3 = "{@type=korap:group, @relation=position, @position=contains, @operands=[" + |
| 478 | "{@type=korap:span, @value=s}," + |
| 479 | "{@type=korap:sequence, @operands=[" + |
| 480 | "{@type=korap:token, @value={@type=korap:term, @value=der, @attr=orth, @relation==}}," + |
| 481 | "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=orth, @relation==}}" + |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 482 | "]}" + |
| 483 | "]}"; |
| 484 | ppt = new PoliqarpPlusTree("contains(<s>,[orth=der][orth=Mann])"); |
| 485 | map = ppt.getRequestMap().get("query").toString(); |
| 486 | assertEquals(pos3.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 487 | |
| 488 | // [base=Auto]contains(<s>,[base=Mann]) |
| 489 | String pos4 = |
Joachim Bingel | ba9a0ab | 2014-01-29 10:12:25 +0000 | [diff] [blame] | 490 | "{@type=korap:sequence, @operands=[" + |
| 491 | "{@type=korap:token, @value={@type=korap:term, @value=Auto, @attr=base, @relation==}}," + |
| 492 | "{@type=korap:group, @relation=position, @position=contains, @operands=[" + |
| 493 | "{@type=korap:span, @value=s}," + |
| 494 | "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=base, @relation==}}" + |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 495 | "]}" + |
| 496 | "]}"; |
| 497 | ppt = new PoliqarpPlusTree("[base=Auto]contains(<s>,[base=Mann])"); |
| 498 | map = ppt.getRequestMap().get("query").toString(); |
| 499 | assertEquals(pos4.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 500 | } |
| 501 | |
| 502 | @Test |
Joachim Bingel | 16da4e1 | 2013-12-17 09:48:12 +0000 | [diff] [blame] | 503 | public void testNestedPositions() throws QueryException { |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 504 | // contains(<s>,startswith(<np>,[orth=Der])) |
| 505 | String npos1 = |
Joachim Bingel | ba9a0ab | 2014-01-29 10:12:25 +0000 | [diff] [blame] | 506 | "{@type=korap:group, @relation=position, @position=contains, @operands=[" + |
| 507 | "{@type=korap:span, @value=s}," + |
| 508 | "{@type=korap:group, @relation=position, @position=startswith, @operands=[" + |
| 509 | "{@type=korap:span, @value=np}," + |
| 510 | "{@type=korap:token, @value={@type=korap:term, @value=Der, @attr=orth, @relation==}}" + |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 511 | "]}" + |
| 512 | "]}"; |
Joachim Bingel | cd9ed33 | 2013-12-09 21:01:35 +0000 | [diff] [blame] | 513 | ppt = new PoliqarpPlusTree("contains(<s>, startswith(<np>,[orth=Der]))"); |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 514 | map = ppt.getRequestMap().get("query").toString(); |
| 515 | assertEquals(npos1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 516 | } |
| 517 | |
| 518 | @Test |
Joachim Bingel | 16da4e1 | 2013-12-17 09:48:12 +0000 | [diff] [blame] | 519 | public void testShrinkSplit() throws QueryException { |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 520 | // shrink([orth=Der]{[orth=Mann]}) |
| 521 | String shr1 = |
Joachim Bingel | 8c640e4 | 2014-02-07 16:20:47 +0000 | [diff] [blame] | 522 | "{@type=korap:group, @relation=shrink, classRef=[0], @operands=[" + |
Joachim Bingel | ba9a0ab | 2014-01-29 10:12:25 +0000 | [diff] [blame] | 523 | "{@type=korap:sequence, @operands=[" + |
| 524 | "{@type=korap:token, @value={@type=korap:term, @value=Der, @attr=orth, @relation==}}," + |
Joachim Bingel | 8c640e4 | 2014-02-07 16:20:47 +0000 | [diff] [blame] | 525 | "{@type=korap:group, @relation=class, class=0, @operands=[" + |
Joachim Bingel | ba9a0ab | 2014-01-29 10:12:25 +0000 | [diff] [blame] | 526 | "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=orth, @relation==}}" + |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 527 | "]}" + |
| 528 | "]}" + |
| 529 | "]}"; |
| 530 | ppt = new PoliqarpPlusTree("shrink([orth=Der]{[orth=Mann]})"); |
| 531 | map = ppt.getRequestMap().get("query").toString(); |
| 532 | assertEquals(shr1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 533 | |
| 534 | // shrink([orth=Der]{[orth=Mann][orth=geht]}) |
| 535 | String shr2 = |
Joachim Bingel | 8c640e4 | 2014-02-07 16:20:47 +0000 | [diff] [blame] | 536 | "{@type=korap:group, @relation=shrink, classRef=[0], @operands=[" + |
Joachim Bingel | ba9a0ab | 2014-01-29 10:12:25 +0000 | [diff] [blame] | 537 | "{@type=korap:sequence, @operands=[" + |
| 538 | "{@type=korap:token, @value={@type=korap:term, @value=Der, @attr=orth, @relation==}}," + |
Joachim Bingel | 8c640e4 | 2014-02-07 16:20:47 +0000 | [diff] [blame] | 539 | "{@type=korap:group, @relation=class, class=0, @operands=[" + |
Joachim Bingel | ba9a0ab | 2014-01-29 10:12:25 +0000 | [diff] [blame] | 540 | "{@type=korap:sequence, @operands=[" + |
| 541 | "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=orth, @relation==}}," + |
| 542 | "{@type=korap:token, @value={@type=korap:term, @value=geht, @attr=orth, @relation==}}" + |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 543 | "]}" + |
| 544 | "]}" + |
| 545 | "]}" + |
| 546 | "]}"; |
| 547 | ppt = new PoliqarpPlusTree("shrink([orth=Der]{[orth=Mann][orth=geht]})"); |
| 548 | map = ppt.getRequestMap().get("query").toString(); |
| 549 | assertEquals(shr2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 550 | |
| 551 | // shrink(1:[orth=Der]{1:[orth=Mann][orth=geht]}) |
| 552 | String shr3 = |
Joachim Bingel | 8c640e4 | 2014-02-07 16:20:47 +0000 | [diff] [blame] | 553 | "{@type=korap:group, @relation=shrink, classRef=[1], @operands=[" + |
Joachim Bingel | ba9a0ab | 2014-01-29 10:12:25 +0000 | [diff] [blame] | 554 | "{@type=korap:sequence, @operands=[" + |
| 555 | "{@type=korap:token, @value={@type=korap:term, @value=Der, @attr=orth, @relation==}}," + |
Joachim Bingel | 8c640e4 | 2014-02-07 16:20:47 +0000 | [diff] [blame] | 556 | "{@type=korap:group, @relation=class, class=1, @operands=[" + |
Joachim Bingel | ba9a0ab | 2014-01-29 10:12:25 +0000 | [diff] [blame] | 557 | "{@type=korap:sequence, @operands=[" + |
| 558 | "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=orth, @relation==}}," + |
| 559 | "{@type=korap:token, @value={@type=korap:term, @value=geht, @attr=orth, @relation==}}" + |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 560 | "]}" + |
| 561 | "]}" + |
| 562 | "]}" + |
| 563 | "]}"; |
| 564 | ppt = new PoliqarpPlusTree("shrink(1:[orth=Der]{1:[orth=Mann][orth=geht]})"); |
| 565 | map = ppt.getRequestMap().get("query").toString(); |
| 566 | assertEquals(shr3.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 567 | |
| 568 | // shrink(1:startswith(<s>,{1:<np>})) |
| 569 | String shr4 = |
Joachim Bingel | 8c640e4 | 2014-02-07 16:20:47 +0000 | [diff] [blame] | 570 | "{@type=korap:group, @relation=shrink, classRef=[1], @operands=[" + |
Joachim Bingel | ba9a0ab | 2014-01-29 10:12:25 +0000 | [diff] [blame] | 571 | "{@type=korap:group, @relation=position, @position=startswith, @operands=[" + |
| 572 | "{@type=korap:span, @value=s}," + |
Joachim Bingel | 8c640e4 | 2014-02-07 16:20:47 +0000 | [diff] [blame] | 573 | "{@type=korap:group, @relation=class, class=1, @operands=[" + |
Joachim Bingel | ba9a0ab | 2014-01-29 10:12:25 +0000 | [diff] [blame] | 574 | "{@type=korap:span, @value=np}" + |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 575 | "]}" + |
| 576 | "]}" + |
| 577 | "]}"; |
Joachim Bingel | adefa62 | 2013-12-13 10:51:48 +0000 | [diff] [blame] | 578 | ppt = new PoliqarpPlusTree("shrink(1:startswith(<s>,{1:<np>}))"); |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 579 | map = ppt.getRequestMap().get("query").toString(); |
| 580 | assertEquals(shr4.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | cd9ed33 | 2013-12-09 21:01:35 +0000 | [diff] [blame] | 581 | |
| 582 | // shrink(3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) |
| 583 | String shr5 = |
Joachim Bingel | 8c640e4 | 2014-02-07 16:20:47 +0000 | [diff] [blame] | 584 | "{@type=korap:group, @relation=shrink, classRef=[3], @operands=[" + |
Joachim Bingel | ba9a0ab | 2014-01-29 10:12:25 +0000 | [diff] [blame] | 585 | "{@type=korap:group, @relation=position, @position=startswith, @operands=[" + |
| 586 | "{@type=korap:span, @value=s}," + |
Joachim Bingel | 8c640e4 | 2014-02-07 16:20:47 +0000 | [diff] [blame] | 587 | "{@type=korap:group, @relation=class, class=3, @operands=[" + |
Joachim Bingel | ba9a0ab | 2014-01-29 10:12:25 +0000 | [diff] [blame] | 588 | "{@type=korap:sequence, @operands=[" + |
| 589 | "{@type=korap:token, @value={@type=korap:term, @value=der, @attr=base, @relation==}}," + |
Joachim Bingel | 8c640e4 | 2014-02-07 16:20:47 +0000 | [diff] [blame] | 590 | "{@type=korap:group, @relation=class, class=1, @operands=[" + |
Joachim Bingel | ba9a0ab | 2014-01-29 10:12:25 +0000 | [diff] [blame] | 591 | "{@type=korap:sequence, @operands=[" + |
| 592 | "{@type=korap:token, @value={@type=korap:term, @value=ADJA, @attr=p, @foundry=mate, @relation==}}," + |
Joachim Bingel | 8c640e4 | 2014-02-07 16:20:47 +0000 | [diff] [blame] | 593 | "{@type=korap:group, @relation=class, class=2, @operands=[" + |
Joachim Bingel | ba9a0ab | 2014-01-29 10:12:25 +0000 | [diff] [blame] | 594 | "{@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] | 595 | "]}" + |
| 596 | "]}" + |
| 597 | "]}" + |
| 598 | "]}" + |
| 599 | "]}" + |
| 600 | "]}" + |
| 601 | "]}"; |
Joachim Bingel | adefa62 | 2013-12-13 10:51:48 +0000 | [diff] [blame] | 602 | 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] | 603 | map = ppt.getRequestMap().get("query").toString(); |
| 604 | assertEquals(shr5.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | ba9a0ab | 2014-01-29 10:12:25 +0000 | [diff] [blame] | 605 | |
| 606 | // split(3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) |
| 607 | String shr6 = |
Joachim Bingel | 8c640e4 | 2014-02-07 16:20:47 +0000 | [diff] [blame] | 608 | "{@type=korap:group, @relation=split, classRef=[3], @operands=[" + |
Joachim Bingel | ba9a0ab | 2014-01-29 10:12:25 +0000 | [diff] [blame] | 609 | "{@type=korap:group, @relation=position, @position=startswith, @operands=[" + |
| 610 | "{@type=korap:span, @value=s}," + |
Joachim Bingel | 8c640e4 | 2014-02-07 16:20:47 +0000 | [diff] [blame] | 611 | "{@type=korap:group, @relation=class, class=3, @operands=[" + |
Joachim Bingel | ba9a0ab | 2014-01-29 10:12:25 +0000 | [diff] [blame] | 612 | "{@type=korap:sequence, @operands=[" + |
| 613 | "{@type=korap:token, @value={@type=korap:term, @value=der, @attr=base, @relation==}}," + |
Joachim Bingel | 8c640e4 | 2014-02-07 16:20:47 +0000 | [diff] [blame] | 614 | "{@type=korap:group, @relation=class, class=1, @operands=[" + |
Joachim Bingel | ba9a0ab | 2014-01-29 10:12:25 +0000 | [diff] [blame] | 615 | "{@type=korap:sequence, @operands=[" + |
| 616 | "{@type=korap:token, @value={@type=korap:term, @value=ADJA, @attr=p, @foundry=mate, @relation==}}," + |
Joachim Bingel | 8c640e4 | 2014-02-07 16:20:47 +0000 | [diff] [blame] | 617 | "{@type=korap:group, @relation=class, class=2, @operands=[" + |
Joachim Bingel | ba9a0ab | 2014-01-29 10:12:25 +0000 | [diff] [blame] | 618 | "{@type=korap:token, @value={@type=korap:term, @value=NN, @attr=p, @foundry=tt, @relation==}}" + |
| 619 | "]}" + |
| 620 | "]}" + |
| 621 | "]}" + |
| 622 | "]}" + |
| 623 | "]}" + |
| 624 | "]}" + |
| 625 | "]}"; |
| 626 | ppt = new PoliqarpPlusTree("split(3:startswith(<s>,{3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) "); |
| 627 | map = ppt.getRequestMap().get("query").toString(); |
| 628 | assertEquals(shr6.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 8c640e4 | 2014-02-07 16:20:47 +0000 | [diff] [blame] | 629 | |
| 630 | // split(2|3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) |
| 631 | String shr7 = |
| 632 | "{@type=korap:group, @relation=split, classRef=[2, 3], classRefOp=intersection, @operands=[" + |
| 633 | "{@type=korap:group, @relation=position, @position=startswith, @operands=[" + |
| 634 | "{@type=korap:span, @value=s}," + |
| 635 | "{@type=korap:group, @relation=class, class=3, @operands=[" + |
| 636 | "{@type=korap:sequence, @operands=[" + |
| 637 | "{@type=korap:token, @value={@type=korap:term, @value=der, @attr=base, @relation==}}," + |
| 638 | "{@type=korap:group, @relation=class, class=1, @operands=[" + |
| 639 | "{@type=korap:sequence, @operands=[" + |
| 640 | "{@type=korap:token, @value={@type=korap:term, @value=ADJA, @attr=p, @foundry=mate, @relation==}}," + |
| 641 | "{@type=korap:group, @relation=class, class=2, @operands=[" + |
| 642 | "{@type=korap:token, @value={@type=korap:term, @value=NN, @attr=p, @foundry=tt, @relation==}}" + |
| 643 | "]}" + |
| 644 | "]}" + |
| 645 | "]}" + |
| 646 | "]}" + |
| 647 | "]}" + |
| 648 | "]}" + |
| 649 | "]}"; |
| 650 | ppt = new PoliqarpPlusTree("split(2|3:startswith(<s>,{3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}})) "); |
| 651 | map = ppt.getRequestMap().get("query").toString(); |
| 652 | assertEquals(shr7.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 653 | } |
| 654 | |
Joachim Bingel | 0388270 | 2013-12-31 19:53:05 +0000 | [diff] [blame] | 655 | |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 656 | @Test |
Joachim Bingel | ba9a0ab | 2014-01-29 10:12:25 +0000 | [diff] [blame] | 657 | public void testFoundries() throws QueryException { |
| 658 | // [tt/base=Mann] |
| 659 | String layer1 = "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=base, @foundry=tt, @relation==}}"; |
| 660 | ppt = new PoliqarpPlusTree("[tt/base=Mann]"); |
| 661 | map = ppt.getRequestMap().get("query").toString(); |
| 662 | assertEquals(layer1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 663 | |
| 664 | } |
Joachim Bingel | 16da4e1 | 2013-12-17 09:48:12 +0000 | [diff] [blame] | 665 | |
| 666 | @Test |
Joachim Bingel | 8c640e4 | 2014-02-07 16:20:47 +0000 | [diff] [blame] | 667 | public void testAlign() throws QueryException { |
Joachim Bingel | 16da4e1 | 2013-12-17 09:48:12 +0000 | [diff] [blame] | 668 | // [orth=der]^[orth=Mann] |
| 669 | String align1 = |
Joachim Bingel | ba9a0ab | 2014-01-29 10:12:25 +0000 | [diff] [blame] | 670 | "{@type=korap:sequence, @operands=[" + |
| 671 | "{@type=korap:token, @value={@type=korap:term, @value=der, @attr=orth, @relation==}}," + |
Joachim Bingel | 84e33df | 2014-01-31 14:02:46 +0000 | [diff] [blame] | 672 | "{@type=korap:group, @alignment=left, @operands=[" + |
Joachim Bingel | ba9a0ab | 2014-01-29 10:12:25 +0000 | [diff] [blame] | 673 | "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=orth, @relation==}}" + |
Joachim Bingel | 0388270 | 2013-12-31 19:53:05 +0000 | [diff] [blame] | 674 | "]}" + |
Joachim Bingel | 16da4e1 | 2013-12-17 09:48:12 +0000 | [diff] [blame] | 675 | "]}"; |
| 676 | ppt = new PoliqarpPlusTree("[orth=der]^[orth=Mann]"); |
| 677 | map = ppt.getRequestMap().get("query").toString(); |
| 678 | assertEquals(align1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 679 | |
Joachim Bingel | 84e33df | 2014-01-31 14:02:46 +0000 | [diff] [blame] | 680 | // [orth=der]^[orth=große][orth=Mann] |
| 681 | String query = "[orth=der]^[orth=große][orth=Mann]"; |
| 682 | String align1b = |
| 683 | "{@type=korap:sequence, @operands=[" + |
| 684 | "{@type=korap:token, @value={@type=korap:term, @value=der, @attr=orth, @relation==}}," + |
| 685 | "{@type=korap:group, @alignment=left, @operands=[" + |
| 686 | "{@type=korap:sequence, @operands=[" + |
| 687 | "{@type=korap:token, @value={@type=korap:term, @value=große, @attr=orth, @relation==}}," + |
| 688 | "{@type=korap:token, @value={@type=korap:term, @value=Mann, @attr=orth, @relation==}}" + |
| 689 | "]}" + |
| 690 | "]}" + |
| 691 | "]}"; |
| 692 | ppt = new PoliqarpPlusTree(query); |
| 693 | map = ppt.getRequestMap().get("query").toString(); |
| 694 | assertEquals(align1b.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 695 | |
Joachim Bingel | 16da4e1 | 2013-12-17 09:48:12 +0000 | [diff] [blame] | 696 | // "([base=a]^[base=b])|[base=c]", |
| 697 | String align2 = |
Joachim Bingel | ba9a0ab | 2014-01-29 10:12:25 +0000 | [diff] [blame] | 698 | "{@type=korap:group, @relation=or, @operands=[" + |
| 699 | "{@type=korap:sequence, @operands=[" + |
| 700 | "{@type=korap:token, @value={@type=korap:term, @value=a, @attr=base, @relation==}}," + |
Joachim Bingel | 84e33df | 2014-01-31 14:02:46 +0000 | [diff] [blame] | 701 | "{@type=korap:group, @alignment=left, @operands=[" + |
Joachim Bingel | ba9a0ab | 2014-01-29 10:12:25 +0000 | [diff] [blame] | 702 | "{@type=korap:token, @value={@type=korap:term, @value=b, @attr=base, @relation==}}" + |
Joachim Bingel | 0388270 | 2013-12-31 19:53:05 +0000 | [diff] [blame] | 703 | "]}" + |
Joachim Bingel | 16da4e1 | 2013-12-17 09:48:12 +0000 | [diff] [blame] | 704 | "]}," + |
Joachim Bingel | ba9a0ab | 2014-01-29 10:12:25 +0000 | [diff] [blame] | 705 | "{@type=korap:token, @value={@type=korap:term, @value=c, @attr=base, @relation==}}" + |
Joachim Bingel | 16da4e1 | 2013-12-17 09:48:12 +0000 | [diff] [blame] | 706 | "]}"; |
| 707 | ppt = new PoliqarpPlusTree("([base=a]^[base=b])|[base=c]"); |
| 708 | map = ppt.getRequestMap().get("query").toString(); |
| 709 | assertEquals(align2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | a67e6a3 | 2014-01-02 18:35:24 +0000 | [diff] [blame] | 710 | |
| 711 | // "([base=a]^[base=b][base=c])|[base=d]", |
| 712 | String align3 = |
Joachim Bingel | ba9a0ab | 2014-01-29 10:12:25 +0000 | [diff] [blame] | 713 | "{@type=korap:group, @relation=or, @operands=[" + |
| 714 | "{@type=korap:sequence, @operands=[" + |
| 715 | "{@type=korap:token, @value={@type=korap:term, @value=a, @attr=base, @relation==}}," + |
Joachim Bingel | 84e33df | 2014-01-31 14:02:46 +0000 | [diff] [blame] | 716 | "{@type=korap:group, @alignment=left, @operands=[" + |
| 717 | "{@type=korap:sequence, @operands=[" + |
| 718 | "{@type=korap:token, @value={@type=korap:term, @value=b, @attr=base, @relation==}}," + |
| 719 | "{@type=korap:token, @value={@type=korap:term, @value=c, @attr=base, @relation==}}" + |
| 720 | "]}" + |
| 721 | "]}" + |
Joachim Bingel | a67e6a3 | 2014-01-02 18:35:24 +0000 | [diff] [blame] | 722 | "]}," + |
Joachim Bingel | ba9a0ab | 2014-01-29 10:12:25 +0000 | [diff] [blame] | 723 | "{@type=korap:token, @value={@type=korap:term, @value=d, @attr=base, @relation==}}" + |
Joachim Bingel | a67e6a3 | 2014-01-02 18:35:24 +0000 | [diff] [blame] | 724 | "]}"; |
| 725 | ppt = new PoliqarpPlusTree("([base=a]^[base=b][base=c])|[base=d]"); |
| 726 | map = ppt.getRequestMap().get("query").toString(); |
| 727 | assertEquals(align3.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 728 | |
| 729 | // "([base=a]^[base=b]^[base=c])|[base=d]", |
| 730 | String align4 = |
Joachim Bingel | ba9a0ab | 2014-01-29 10:12:25 +0000 | [diff] [blame] | 731 | "{@type=korap:group, @relation=or, @operands=[" + |
| 732 | "{@type=korap:sequence, @operands=[" + |
| 733 | "{@type=korap:token, @value={@type=korap:term, @value=a, @attr=base, @relation==}}," + |
Joachim Bingel | 84e33df | 2014-01-31 14:02:46 +0000 | [diff] [blame] | 734 | "{@type=korap:group, @alignment=left, @operands=[" + |
| 735 | "{@type=korap:sequence, @operands=[" + |
| 736 | "{@type=korap:token, @value={@type=korap:term, @value=b, @attr=base, @relation==}}," + |
| 737 | "{@type=korap:group, @alignment=left, @operands=[" + |
| 738 | "{@type=korap:token, @value={@type=korap:term, @value=c, @attr=base, @relation==}}" + |
| 739 | "]}" + |
| 740 | "]}" + |
Joachim Bingel | a67e6a3 | 2014-01-02 18:35:24 +0000 | [diff] [blame] | 741 | "]}" + |
| 742 | "]}," + |
Joachim Bingel | ba9a0ab | 2014-01-29 10:12:25 +0000 | [diff] [blame] | 743 | "{@type=korap:token, @value={@type=korap:term, @value=d, @attr=base, @relation==}}" + |
Joachim Bingel | a67e6a3 | 2014-01-02 18:35:24 +0000 | [diff] [blame] | 744 | "]}"; |
| 745 | ppt = new PoliqarpPlusTree("([base=a]^[base=b]^[base=c])|[base=d]"); |
| 746 | map = ppt.getRequestMap().get("query").toString(); |
| 747 | assertEquals(align4.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 748 | |
| 749 | |
Joachim Bingel | 16da4e1 | 2013-12-17 09:48:12 +0000 | [diff] [blame] | 750 | } |
| 751 | |
| 752 | @Test |
Joachim Bingel | 8c640e4 | 2014-02-07 16:20:47 +0000 | [diff] [blame] | 753 | public void testSimpleQueries() throws QueryException { |
Joachim Bingel | a67e6a3 | 2014-01-02 18:35:24 +0000 | [diff] [blame] | 754 | // Baum |
| 755 | String simple1 = |
Joachim Bingel | ba9a0ab | 2014-01-29 10:12:25 +0000 | [diff] [blame] | 756 | "{@type=korap:token, @value={@type=korap:term, @value=Baum, @attr=orth, @relation==}}"; |
Joachim Bingel | a67e6a3 | 2014-01-02 18:35:24 +0000 | [diff] [blame] | 757 | ppt = new PoliqarpPlusTree("Baum"); |
| 758 | map = ppt.getRequestMap().get("query").toString(); |
| 759 | assertEquals(simple1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 16da4e1 | 2013-12-17 09:48:12 +0000 | [diff] [blame] | 760 | |
Joachim Bingel | a67e6a3 | 2014-01-02 18:35:24 +0000 | [diff] [blame] | 761 | // Der Baum |
| 762 | String simple2 = |
Joachim Bingel | ba9a0ab | 2014-01-29 10:12:25 +0000 | [diff] [blame] | 763 | "{@type=korap:sequence, @operands=[" + |
| 764 | "{@type=korap:token, @value={@type=korap:term, @value=Der, @attr=orth, @relation==}}, " + |
| 765 | "{@type=korap:token, @value={@type=korap:term, @value=Baum, @attr=orth, @relation==}}" + |
Joachim Bingel | a67e6a3 | 2014-01-02 18:35:24 +0000 | [diff] [blame] | 766 | "]}"; |
| 767 | ppt = new PoliqarpPlusTree("Der Baum"); |
| 768 | map = ppt.getRequestMap().get("query").toString(); |
| 769 | assertEquals(simple2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 770 | |
| 771 | // Der große Baum |
| 772 | String simple3 = |
Joachim Bingel | ba9a0ab | 2014-01-29 10:12:25 +0000 | [diff] [blame] | 773 | "{@type=korap:sequence, @operands=[" + |
| 774 | "{@type=korap:token, @value={@type=korap:term, @value=Der, @attr=orth, @relation==}}, " + |
| 775 | "{@type=korap:token, @value={@type=korap:term, @value=große, @attr=orth, @relation==}}, " + |
| 776 | "{@type=korap:token, @value={@type=korap:term, @value=Baum, @attr=orth, @relation==}}" + |
Joachim Bingel | a67e6a3 | 2014-01-02 18:35:24 +0000 | [diff] [blame] | 777 | "]}"; |
| 778 | ppt = new PoliqarpPlusTree("Der große Baum"); |
| 779 | map = ppt.getRequestMap().get("query").toString(); |
| 780 | assertEquals(simple3.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 781 | |
| 782 | // Baum | Stein |
| 783 | String simple4 = |
Joachim Bingel | ba9a0ab | 2014-01-29 10:12:25 +0000 | [diff] [blame] | 784 | "{@type=korap:group, @relation=or, @operands=[" + |
| 785 | "{@type=korap:token, @value={@type=korap:term, @value=Baum, @attr=orth, @relation==}}, " + |
| 786 | "{@type=korap:token, @value={@type=korap:term, @value=Stein, @attr=orth, @relation==}}" + |
Joachim Bingel | a67e6a3 | 2014-01-02 18:35:24 +0000 | [diff] [blame] | 787 | "]}"; |
| 788 | ppt = new PoliqarpPlusTree("Baum | Stein"); |
| 789 | map = ppt.getRequestMap().get("query").toString(); |
| 790 | assertEquals(simple4.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 84e33df | 2014-01-31 14:02:46 +0000 | [diff] [blame] | 791 | |
| 792 | // Baum | Stein Haus |
| 793 | String query = "(Baum | Stein) Haus"; |
| 794 | String simple5 = |
| 795 | "{@type=korap:sequence, @operands=[" + |
| 796 | "{@type=korap:group, @relation=or, @operands=[" + |
| 797 | "{@type=korap:token, @value={@type=korap:term, @value=Baum, @attr=orth, @relation==}}, " + |
| 798 | "{@type=korap:token, @value={@type=korap:term, @value=Stein, @attr=orth, @relation==}}" + |
| 799 | "]}," + |
| 800 | "{@type=korap:token, @value={@type=korap:term, @value=Haus, @attr=orth, @relation==}} " + |
| 801 | "]}"; |
| 802 | ppt = new PoliqarpPlusTree(query); |
| 803 | map = ppt.getRequestMap().get("query").toString(); |
| 804 | assertEquals(simple5.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 16da4e1 | 2013-12-17 09:48:12 +0000 | [diff] [blame] | 805 | } |
Joachim Bingel | 53333e6 | 2013-12-09 19:25:52 +0000 | [diff] [blame] | 806 | } |
| 807 | |