Joachim Bingel | b5f7bf0 | 2014-01-07 16:36:54 +0000 | [diff] [blame] | 1 | import static org.junit.Assert.*; |
| 2 | |
| 3 | import org.junit.Test; |
| 4 | |
| 5 | import de.ids_mannheim.korap.query.serialize.CosmasTree; |
Joachim Bingel | b5f7bf0 | 2014-01-07 16:36:54 +0000 | [diff] [blame] | 6 | import de.ids_mannheim.korap.util.QueryException; |
| 7 | |
| 8 | public class CosmasTreeTest { |
| 9 | |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 10 | CosmasTree ct; |
Joachim Bingel | b5f7bf0 | 2014-01-07 16:36:54 +0000 | [diff] [blame] | 11 | String map; |
| 12 | String query; |
| 13 | |
| 14 | private boolean equalsContent(String str, Object map) { |
| 15 | str = str.replaceAll(" ", ""); |
| 16 | String mapStr = map.toString().replaceAll(" ", ""); |
| 17 | return str.equals(mapStr); |
| 18 | } |
| 19 | |
| 20 | private boolean equalsQueryContent(String res, String query) throws QueryException { |
| 21 | res = res.replaceAll(" ", ""); |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 22 | ct = new CosmasTree(query); |
| 23 | String queryMap = ct.getRequestMap().get("query").toString().replaceAll(" ", ""); |
Joachim Bingel | b5f7bf0 | 2014-01-07 16:36:54 +0000 | [diff] [blame] | 24 | return res.equals(queryMap); |
| 25 | } |
| 26 | |
Joachim Bingel | 8181263 | 2014-02-18 08:55:22 +0000 | [diff] [blame^] | 27 | @Test |
Joachim Bingel | b5f7bf0 | 2014-01-07 16:36:54 +0000 | [diff] [blame] | 28 | public void testContext() throws QueryException { |
Joachim Bingel | 8181263 | 2014-02-18 08:55:22 +0000 | [diff] [blame^] | 29 | String contextString = "http://ids-mannheim.de/ns/KorAP/json-ld/v0.1/context.jsonld"; |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 30 | ct = new CosmasTree("Test"); |
| 31 | assertEquals(contextString.replaceAll(" ", ""), ct.getRequestMap().get("@context").toString().replaceAll(" ", "")); |
Joachim Bingel | b5f7bf0 | 2014-01-07 16:36:54 +0000 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | |
| 35 | @Test |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame] | 36 | public void testSingleToken() throws QueryException { |
Joachim Bingel | b5f7bf0 | 2014-01-07 16:36:54 +0000 | [diff] [blame] | 37 | query="der"; |
| 38 | String single1 = |
Joachim Bingel | ee3b21d | 2014-02-12 12:34:59 +0000 | [diff] [blame] | 39 | "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}"; |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 40 | ct = new CosmasTree(query); |
| 41 | map = ct.getRequestMap().get("query").toString(); |
Joachim Bingel | b5f7bf0 | 2014-01-07 16:36:54 +0000 | [diff] [blame] | 42 | assertEquals(single1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 43 | |
| 44 | query="Mann"; |
| 45 | String single2 = |
Joachim Bingel | ee3b21d | 2014-02-12 12:34:59 +0000 | [diff] [blame] | 46 | "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}"; |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 47 | ct = new CosmasTree(query); |
| 48 | map = ct.getRequestMap().get("query").toString(); |
Joachim Bingel | b5f7bf0 | 2014-01-07 16:36:54 +0000 | [diff] [blame] | 49 | assertEquals(single2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 50 | |
| 51 | query="&Mann"; |
| 52 | String single3 = |
Joachim Bingel | ee3b21d | 2014-02-12 12:34:59 +0000 | [diff] [blame] | 53 | "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=match:eq}}"; |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 54 | ct = new CosmasTree(query); |
| 55 | map = ct.getRequestMap().get("query").toString(); |
Joachim Bingel | b5f7bf0 | 2014-01-07 16:36:54 +0000 | [diff] [blame] | 56 | assertEquals(single3.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 57 | } |
| 58 | |
Joachim Bingel | ba9a0ab | 2014-01-29 10:12:25 +0000 | [diff] [blame] | 59 | @Test |
Joachim Bingel | 8c640e4 | 2014-02-07 16:20:47 +0000 | [diff] [blame] | 60 | public void testCaseSensitivityFlag() throws QueryException { |
Joachim Bingel | 0207d5e | 2014-02-12 14:18:41 +0000 | [diff] [blame] | 61 | query="$deutscher"; |
| 62 | String cs1 = |
| 63 | "{@type=korap:token, wrap={@type=korap:term, caseInsensitive=true, key=deutscher, layer=orth, match=match:eq}}"; |
| 64 | ct = new CosmasTree(query); |
| 65 | map = ct.getRequestMap().get("query").toString(); |
| 66 | assertEquals(cs1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 67 | |
| 68 | query="$deutscher Bundestag"; |
| 69 | String cs2 = |
| 70 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 71 | "{@type=korap:token, wrap={@type=korap:term, caseInsensitive=true, key=deutscher, layer=orth, match=match:eq}}," + |
| 72 | "{@type=korap:token, wrap={@type=korap:term, key=Bundestag, layer=orth, match=match:eq}}" + |
| 73 | "]}"; |
| 74 | ct = new CosmasTree(query); |
| 75 | map = ct.getRequestMap().get("query").toString(); |
| 76 | assertEquals(cs2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 8c640e4 | 2014-02-07 16:20:47 +0000 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | @Test |
Joachim Bingel | ffd65e3 | 2014-01-22 14:22:57 +0000 | [diff] [blame] | 80 | public void testMORPH() throws QueryException { |
| 81 | query="#MORPH(V)"; |
| 82 | String morph1 = |
Joachim Bingel | 0207d5e | 2014-02-12 14:18:41 +0000 | [diff] [blame] | 83 | "{@type=korap:token, wrap={@type=korap:term, key=V, layer=pos, match=match:eq}}"; |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 84 | ct = new CosmasTree(query); |
| 85 | map = ct.getRequestMap().get("query").toString(); |
Joachim Bingel | ffd65e3 | 2014-01-22 14:22:57 +0000 | [diff] [blame] | 86 | assertEquals(morph1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 87 | } |
| 88 | |
Joachim Bingel | b5f7bf0 | 2014-01-07 16:36:54 +0000 | [diff] [blame] | 89 | @Test |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame] | 90 | public void testSequence() throws QueryException { |
Joachim Bingel | b5f7bf0 | 2014-01-07 16:36:54 +0000 | [diff] [blame] | 91 | query="der Mann"; |
| 92 | String seq1 = |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 93 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | ee3b21d | 2014-02-12 12:34:59 +0000 | [diff] [blame] | 94 | "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," + |
| 95 | "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" + |
Joachim Bingel | b5f7bf0 | 2014-01-07 16:36:54 +0000 | [diff] [blame] | 96 | "]}"; |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 97 | ct = new CosmasTree(query); |
| 98 | map = ct.getRequestMap().get("query").toString(); |
Joachim Bingel | b5f7bf0 | 2014-01-07 16:36:54 +0000 | [diff] [blame] | 99 | assertEquals(seq1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 100 | |
Joachim Bingel | d5161a1 | 2014-01-08 11:15:49 +0000 | [diff] [blame] | 101 | query="der Mann schläft"; |
| 102 | String seq2 = |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 103 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | ee3b21d | 2014-02-12 12:34:59 +0000 | [diff] [blame] | 104 | "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," + |
| 105 | "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}," + |
| 106 | "{@type=korap:token, wrap={@type=korap:term, key=schläft, layer=orth, match=match:eq}}" + |
Joachim Bingel | d5161a1 | 2014-01-08 11:15:49 +0000 | [diff] [blame] | 107 | "]}"; |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 108 | ct = new CosmasTree(query); |
| 109 | map = ct.getRequestMap().get("query").toString(); |
Joachim Bingel | d5161a1 | 2014-01-08 11:15:49 +0000 | [diff] [blame] | 110 | assertEquals(seq2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 111 | |
| 112 | query="der Mann schläft lang"; |
| 113 | String seq3 = |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 114 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | ee3b21d | 2014-02-12 12:34:59 +0000 | [diff] [blame] | 115 | "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," + |
| 116 | "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}," + |
| 117 | "{@type=korap:token, wrap={@type=korap:term, key=schläft, layer=orth, match=match:eq}}," + |
| 118 | "{@type=korap:token, wrap={@type=korap:term, key=lang, layer=orth, match=match:eq}}" + |
Joachim Bingel | d5161a1 | 2014-01-08 11:15:49 +0000 | [diff] [blame] | 119 | "]}"; |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 120 | ct = new CosmasTree(query); |
| 121 | map = ct.getRequestMap().get("query").toString(); |
Joachim Bingel | d5161a1 | 2014-01-08 11:15:49 +0000 | [diff] [blame] | 122 | assertEquals(seq3.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | b5f7bf0 | 2014-01-07 16:36:54 +0000 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | @Test |
| 126 | public void testOPOR() throws QueryException { |
| 127 | query="Sonne oder Mond"; |
| 128 | String disj1 = |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 129 | "{@type=korap:group, operation=operation:or, operands=[" + |
Joachim Bingel | ee3b21d | 2014-02-12 12:34:59 +0000 | [diff] [blame] | 130 | "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}," + |
| 131 | "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" + |
Joachim Bingel | b5f7bf0 | 2014-01-07 16:36:54 +0000 | [diff] [blame] | 132 | "]}"; |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 133 | ct = new CosmasTree(query); |
| 134 | map = ct.getRequestMap().get("query").toString(); |
Joachim Bingel | b5f7bf0 | 2014-01-07 16:36:54 +0000 | [diff] [blame] | 135 | assertEquals(disj1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 136 | |
Joachim Bingel | d5161a1 | 2014-01-08 11:15:49 +0000 | [diff] [blame] | 137 | query="(Sonne scheint) oder Mond"; |
| 138 | String disj2 = |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 139 | "{@type=korap:group, operation=operation:or, operands=[" + |
| 140 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | ee3b21d | 2014-02-12 12:34:59 +0000 | [diff] [blame] | 141 | "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}," + |
| 142 | "{@type=korap:token, wrap={@type=korap:term, key=scheint, layer=orth, match=match:eq}}" + |
Joachim Bingel | d5161a1 | 2014-01-08 11:15:49 +0000 | [diff] [blame] | 143 | "]}," + |
Joachim Bingel | ee3b21d | 2014-02-12 12:34:59 +0000 | [diff] [blame] | 144 | "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" + |
Joachim Bingel | d5161a1 | 2014-01-08 11:15:49 +0000 | [diff] [blame] | 145 | "]}"; |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 146 | ct = new CosmasTree(query); |
| 147 | map = ct.getRequestMap().get("query").toString(); |
Joachim Bingel | d5161a1 | 2014-01-08 11:15:49 +0000 | [diff] [blame] | 148 | assertEquals(disj2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 149 | |
| 150 | query="(Sonne scheint) oder (Mond scheint)"; |
| 151 | String disj3 = |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 152 | "{@type=korap:group, operation=operation:or, operands=[" + |
| 153 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | ee3b21d | 2014-02-12 12:34:59 +0000 | [diff] [blame] | 154 | "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}," + |
| 155 | "{@type=korap:token, wrap={@type=korap:term, key=scheint, layer=orth, match=match:eq}}" + |
Joachim Bingel | d5161a1 | 2014-01-08 11:15:49 +0000 | [diff] [blame] | 156 | "]}," + |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 157 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
Joachim Bingel | ee3b21d | 2014-02-12 12:34:59 +0000 | [diff] [blame] | 158 | "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}," + |
| 159 | "{@type=korap:token, wrap={@type=korap:term, key=scheint, layer=orth, match=match:eq}}" + |
Joachim Bingel | d5161a1 | 2014-01-08 11:15:49 +0000 | [diff] [blame] | 160 | "]}" + |
| 161 | "]}"; |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 162 | ct = new CosmasTree(query); |
| 163 | map = ct.getRequestMap().get("query").toString(); |
Joachim Bingel | d5161a1 | 2014-01-08 11:15:49 +0000 | [diff] [blame] | 164 | assertEquals(disj3.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 165 | |
| 166 | } |
| 167 | |
| 168 | @Test |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame] | 169 | public void testOPORAND() throws QueryException { |
Joachim Bingel | d5161a1 | 2014-01-08 11:15:49 +0000 | [diff] [blame] | 170 | query="(Sonne oder Mond) und scheint"; |
| 171 | String orand1 = |
Joachim Bingel | b7a5979 | 2014-02-14 13:52:29 +0000 | [diff] [blame] | 172 | "{@type=korap:group, operation=operation:sequence, distances=[" + |
| 173 | "{@type=korap:distance, key=t, min=0, max=0}" + |
| 174 | "], operands=[" + |
| 175 | "{@type=korap:group, operation=operation:or, operands=[" + |
| 176 | "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}," + |
| 177 | "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" + |
| 178 | "]}," + |
| 179 | "{@type=korap:token, wrap={@type=korap:term, key=scheint, layer=orth, match=match:eq}}" + |
Joachim Bingel | d5161a1 | 2014-01-08 11:15:49 +0000 | [diff] [blame] | 180 | "]}"; |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 181 | ct = new CosmasTree(query); |
| 182 | map = ct.getRequestMap().get("query").toString(); |
Joachim Bingel | d5161a1 | 2014-01-08 11:15:49 +0000 | [diff] [blame] | 183 | assertEquals(orand1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 184 | |
| 185 | query="scheint und (Sonne oder Mond)"; |
| 186 | String orand2 = |
Joachim Bingel | b7a5979 | 2014-02-14 13:52:29 +0000 | [diff] [blame] | 187 | "{@type=korap:group, operation=operation:sequence, distances=[" + |
| 188 | "{@type=korap:distance, key=t, min=0, max=0}" + |
| 189 | "], operands=[" + |
| 190 | "{@type=korap:token, wrap={@type=korap:term, key=scheint, layer=orth, match=match:eq}}," + |
| 191 | "{@type=korap:group, operation=operation:or, operands=[" + |
| 192 | "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}," + |
| 193 | "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" + |
Joachim Bingel | d5161a1 | 2014-01-08 11:15:49 +0000 | [diff] [blame] | 194 | "]}" + |
| 195 | "]}"; |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 196 | ct = new CosmasTree(query); |
| 197 | map = ct.getRequestMap().get("query").toString(); |
Joachim Bingel | d5161a1 | 2014-01-08 11:15:49 +0000 | [diff] [blame] | 198 | assertEquals(orand2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | b5f7bf0 | 2014-01-07 16:36:54 +0000 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | @Test |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame] | 202 | public void testOPPROX() throws QueryException { |
Joachim Bingel | b5f7bf0 | 2014-01-07 16:36:54 +0000 | [diff] [blame] | 203 | query="Sonne /+w1:4 Mond"; |
| 204 | String prox1 = |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 205 | "{@type=korap:group, operation=operation:sequence, inOrder=true, " + |
Joachim Bingel | 11d5b15 | 2014-02-11 21:33:47 +0000 | [diff] [blame] | 206 | "distances=[" + |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 207 | "{@type=korap:distance, key=w, min=1, max=4}" + |
Joachim Bingel | 89cceac | 2014-01-08 15:51:08 +0000 | [diff] [blame] | 208 | "], " + |
Joachim Bingel | 11d5b15 | 2014-02-11 21:33:47 +0000 | [diff] [blame] | 209 | "operands=[" + |
Joachim Bingel | ee3b21d | 2014-02-12 12:34:59 +0000 | [diff] [blame] | 210 | "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}," + |
| 211 | "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" + |
Joachim Bingel | 89cceac | 2014-01-08 15:51:08 +0000 | [diff] [blame] | 212 | "]" + |
| 213 | "}"; |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 214 | ct = new CosmasTree(query); |
| 215 | map = ct.getRequestMap().get("query").toString(); |
Joachim Bingel | b5f7bf0 | 2014-01-07 16:36:54 +0000 | [diff] [blame] | 216 | assertEquals(prox1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 89cceac | 2014-01-08 15:51:08 +0000 | [diff] [blame] | 217 | |
| 218 | query="Sonne /+w1:4,s0,p1:3 Mond"; |
| 219 | String prox2 = |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 220 | "{@type=korap:group, operation=operation:sequence, inOrder=true, " + |
Joachim Bingel | 11d5b15 | 2014-02-11 21:33:47 +0000 | [diff] [blame] | 221 | "distances=[" + |
Joachim Bingel | cd7b725 | 2014-02-13 08:49:14 +0000 | [diff] [blame] | 222 | "{@type=korap:distance, key=w, min=1, max=4}," + |
| 223 | "{@type=korap:distance, key=s, min=0, max=0}," + |
| 224 | "{@type=korap:distance, key=p, min=1, max=3}" + |
Joachim Bingel | 89cceac | 2014-01-08 15:51:08 +0000 | [diff] [blame] | 225 | "], " + |
Joachim Bingel | 11d5b15 | 2014-02-11 21:33:47 +0000 | [diff] [blame] | 226 | "operands=[" + |
Joachim Bingel | ee3b21d | 2014-02-12 12:34:59 +0000 | [diff] [blame] | 227 | "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}," + |
| 228 | "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" + |
Joachim Bingel | 89cceac | 2014-01-08 15:51:08 +0000 | [diff] [blame] | 229 | "]" + |
| 230 | "}"; |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 231 | ct = new CosmasTree(query); |
| 232 | map = ct.getRequestMap().get("query").toString(); |
Joachim Bingel | 89cceac | 2014-01-08 15:51:08 +0000 | [diff] [blame] | 233 | assertEquals(prox2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame] | 234 | |
| 235 | query="Sonne %+w1:4,s0,p1:3 Mond"; |
| 236 | String prox3 = |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 237 | "{@type=korap:group, operation=operation:sequence, inOrder=true, " + |
Joachim Bingel | 11d5b15 | 2014-02-11 21:33:47 +0000 | [diff] [blame] | 238 | "distances=[" + |
Joachim Bingel | cd7b725 | 2014-02-13 08:49:14 +0000 | [diff] [blame] | 239 | "{@type=korap:distance, key=w, min=1, max=4, exclude=true}," + |
| 240 | "{@type=korap:distance, key=s, min=0, max=0, exclude=true}," + |
| 241 | "{@type=korap:distance, key=p, min=1, max=3, exclude=true}" + |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame] | 242 | "], " + |
Joachim Bingel | 11d5b15 | 2014-02-11 21:33:47 +0000 | [diff] [blame] | 243 | "operands=[" + |
Joachim Bingel | ee3b21d | 2014-02-12 12:34:59 +0000 | [diff] [blame] | 244 | "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}," + |
| 245 | "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" + |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame] | 246 | "]" + |
| 247 | "}"; |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 248 | ct = new CosmasTree(query); |
| 249 | map = ct.getRequestMap().get("query").toString(); |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame] | 250 | assertEquals(prox3.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 251 | |
| 252 | query="Sonne /+w4 Mond"; |
| 253 | String prox4 = |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 254 | "{@type=korap:group, operation=operation:sequence, inOrder=true, " + |
Joachim Bingel | 11d5b15 | 2014-02-11 21:33:47 +0000 | [diff] [blame] | 255 | "distances=[" + |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 256 | "{@type=korap:distance, key=w, min=0, max=4}" + |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame] | 257 | "], " + |
Joachim Bingel | 11d5b15 | 2014-02-11 21:33:47 +0000 | [diff] [blame] | 258 | "operands=[" + |
Joachim Bingel | ee3b21d | 2014-02-12 12:34:59 +0000 | [diff] [blame] | 259 | "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}," + |
| 260 | "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" + |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame] | 261 | "]" + |
| 262 | "}"; |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 263 | ct = new CosmasTree(query); |
| 264 | map = ct.getRequestMap().get("query").toString(); |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame] | 265 | assertEquals(prox4.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 3f0850c | 2014-01-17 16:50:10 +0000 | [diff] [blame] | 266 | |
| 267 | query="Sonne /-w4 Mond"; |
| 268 | String prox5 = |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 269 | "{@type=korap:group, operation=operation:sequence, inOrder=true, " + |
Joachim Bingel | 11d5b15 | 2014-02-11 21:33:47 +0000 | [diff] [blame] | 270 | "distances=[" + |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 271 | "{@type=korap:distance, key=w, min=0, max=4}" + |
Joachim Bingel | 3f0850c | 2014-01-17 16:50:10 +0000 | [diff] [blame] | 272 | "], " + |
Joachim Bingel | 11d5b15 | 2014-02-11 21:33:47 +0000 | [diff] [blame] | 273 | "operands=[" + |
Joachim Bingel | ee3b21d | 2014-02-12 12:34:59 +0000 | [diff] [blame] | 274 | "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}," + |
| 275 | "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" + |
Joachim Bingel | 3f0850c | 2014-01-17 16:50:10 +0000 | [diff] [blame] | 276 | "]" + |
| 277 | "}"; |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 278 | ct = new CosmasTree(query); |
| 279 | map = ct.getRequestMap().get("query").toString(); |
Joachim Bingel | 3f0850c | 2014-01-17 16:50:10 +0000 | [diff] [blame] | 280 | assertEquals(prox5.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 281 | } |
| 282 | |
| 283 | @Test |
Joachim Bingel | ba9a0ab | 2014-01-29 10:12:25 +0000 | [diff] [blame] | 284 | public void testOPPROXNested() throws QueryException { |
Joachim Bingel | 3f0850c | 2014-01-17 16:50:10 +0000 | [diff] [blame] | 285 | query="Sonne /-w4 Mond /+w2 Sterne"; |
| 286 | String prox6 = |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 287 | "{@type=korap:group, operation=operation:sequence, inOrder=true, " + |
Joachim Bingel | 11d5b15 | 2014-02-11 21:33:47 +0000 | [diff] [blame] | 288 | "distances=[" + |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 289 | "{@type=korap:distance, key=w, min=0, max=4}" + |
Joachim Bingel | 3f0850c | 2014-01-17 16:50:10 +0000 | [diff] [blame] | 290 | "], " + |
Joachim Bingel | 11d5b15 | 2014-02-11 21:33:47 +0000 | [diff] [blame] | 291 | "operands=[" + |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 292 | "{@type=korap:group, operation=operation:sequence, inOrder=true, " + |
Joachim Bingel | 11d5b15 | 2014-02-11 21:33:47 +0000 | [diff] [blame] | 293 | "distances=[" + |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 294 | "{@type=korap:distance, key=w, min=0, max=2}" + |
Joachim Bingel | 3f0850c | 2014-01-17 16:50:10 +0000 | [diff] [blame] | 295 | "], " + |
Joachim Bingel | 11d5b15 | 2014-02-11 21:33:47 +0000 | [diff] [blame] | 296 | "operands=[" + |
Joachim Bingel | ee3b21d | 2014-02-12 12:34:59 +0000 | [diff] [blame] | 297 | "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}," + |
| 298 | "{@type=korap:token, wrap={@type=korap:term, key=Sterne, layer=orth, match=match:eq}}" + |
Joachim Bingel | 3f0850c | 2014-01-17 16:50:10 +0000 | [diff] [blame] | 299 | "]}," + |
Joachim Bingel | ee3b21d | 2014-02-12 12:34:59 +0000 | [diff] [blame] | 300 | "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}" + |
Joachim Bingel | 3f0850c | 2014-01-17 16:50:10 +0000 | [diff] [blame] | 301 | "]" + |
| 302 | "}"; |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 303 | ct = new CosmasTree(query); |
| 304 | map = ct.getRequestMap().get("query").toString(); |
Joachim Bingel | 3f0850c | 2014-01-17 16:50:10 +0000 | [diff] [blame] | 305 | assertEquals(prox6.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | b5f7bf0 | 2014-01-07 16:36:54 +0000 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | @Test |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame] | 309 | public void testOPIN() throws QueryException { |
Joachim Bingel | cc1dc24 | 2014-01-15 09:32:38 +0000 | [diff] [blame] | 310 | query="wegen #IN <s>"; |
Joachim Bingel | 3a9f793 | 2014-01-07 17:11:31 +0000 | [diff] [blame] | 311 | String opin1 = |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 312 | "{@type=korap:group, operation=operation:submatch, classRef=[1], operands=[" + |
| 313 | "{@type=korap:group, operation=operation:position, frame=frame:contains, operands=[" + |
| 314 | "{@type=korap:span, key=s}," + |
| 315 | "{@type=korap:group, operation=operation:class, class=1, operands=[" + |
Joachim Bingel | ee3b21d | 2014-02-12 12:34:59 +0000 | [diff] [blame] | 316 | "{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" + |
Joachim Bingel | eecc765 | 2014-01-11 17:21:07 +0000 | [diff] [blame] | 317 | "]}" + |
| 318 | "]}" + |
Joachim Bingel | d5161a1 | 2014-01-08 11:15:49 +0000 | [diff] [blame] | 319 | "]}"; |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 320 | ct = new CosmasTree(query); |
| 321 | map = ct.getRequestMap().get("query").toString(); |
Joachim Bingel | d5161a1 | 2014-01-08 11:15:49 +0000 | [diff] [blame] | 322 | assertEquals(opin1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 323 | |
Joachim Bingel | cc1dc24 | 2014-01-15 09:32:38 +0000 | [diff] [blame] | 324 | query="wegen #IN(L) <s>"; |
| 325 | String opin2 = |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 326 | "{@type=korap:group, operation=operation:submatch, classRef=[1], operands=[" + |
| 327 | "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" + |
| 328 | "{@type=korap:span, key=s}," + |
| 329 | "{@type=korap:group, operation=operation:class, class=1, operands=[" + |
Joachim Bingel | ee3b21d | 2014-02-12 12:34:59 +0000 | [diff] [blame] | 330 | "{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" + |
Joachim Bingel | cc1dc24 | 2014-01-15 09:32:38 +0000 | [diff] [blame] | 331 | "]}" + |
| 332 | "]}" + |
| 333 | "]}"; |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 334 | ct = new CosmasTree(query); |
| 335 | map = ct.getRequestMap().get("query").toString(); |
Joachim Bingel | cc1dc24 | 2014-01-15 09:32:38 +0000 | [diff] [blame] | 336 | assertEquals(opin2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 337 | |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame] | 338 | query="wegen #IN(%, L) <s>"; |
| 339 | String opin3 = |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 340 | "{@type=korap:group, operation=operation:submatch, classRef=[1], operands=[" + |
| 341 | "{@type=korap:group, operation=operation:position, frame=frame:startswith, exclude=true, operands=[" + |
| 342 | "{@type=korap:span, key=s}," + |
| 343 | "{@type=korap:group, operation=operation:class, class=1, operands=[" + |
Joachim Bingel | ee3b21d | 2014-02-12 12:34:59 +0000 | [diff] [blame] | 344 | "{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" + |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame] | 345 | "]}" + |
| 346 | "]}" + |
| 347 | "]}"; |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 348 | ct = new CosmasTree(query); |
| 349 | map = ct.getRequestMap().get("query").toString(); |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame] | 350 | assertEquals(opin3.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 351 | |
| 352 | query="wegen #IN('FE,ALL,%,MIN') <s>"; |
| 353 | String opin4 = |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 354 | "{@type=korap:group, operation=operation:submatch, classRef=[1], operands=[" + |
| 355 | "{@type=korap:group, operation=operation:position, frame=frame:matches, range=all, exclude=true, grouping=false, operands=[" + |
| 356 | "{@type=korap:span, key=s}," + |
| 357 | "{@type=korap:group, operation=operation:class, class=1, operands=[" + |
Joachim Bingel | ee3b21d | 2014-02-12 12:34:59 +0000 | [diff] [blame] | 358 | "{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" + |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame] | 359 | "]}" + |
| 360 | "]}" + |
| 361 | "]}"; |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 362 | ct = new CosmasTree(query); |
| 363 | map = ct.getRequestMap().get("query").toString(); |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame] | 364 | assertEquals(opin4.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | d5161a1 | 2014-01-08 11:15:49 +0000 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | @Test |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame] | 368 | public void testOPOV() throws QueryException { |
Joachim Bingel | d5161a1 | 2014-01-08 11:15:49 +0000 | [diff] [blame] | 369 | query="wegen #OV <s>"; |
Joachim Bingel | cc1dc24 | 2014-01-15 09:32:38 +0000 | [diff] [blame] | 370 | String opov1 = |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 371 | "{@type=korap:group, operation=operation:submatch, classRef=[1], operands=[" + |
| 372 | "{@type=korap:group, operation=operation:position, frame=frame:overlaps, operands=[" + |
| 373 | "{@type=korap:span, key=s}," + |
| 374 | "{@type=korap:group, operation=operation:class, class=1, operands=[" + |
Joachim Bingel | ee3b21d | 2014-02-12 12:34:59 +0000 | [diff] [blame] | 375 | "{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" + |
Joachim Bingel | cc1dc24 | 2014-01-15 09:32:38 +0000 | [diff] [blame] | 376 | "]}" + |
| 377 | "]}" + |
Joachim Bingel | b5f7bf0 | 2014-01-07 16:36:54 +0000 | [diff] [blame] | 378 | "]}"; |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 379 | ct = new CosmasTree(query); |
| 380 | map = ct.getRequestMap().get("query").toString(); |
Joachim Bingel | cc1dc24 | 2014-01-15 09:32:38 +0000 | [diff] [blame] | 381 | assertEquals(opov1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 382 | |
| 383 | query="wegen #OV(L) <s>"; |
| 384 | String opov2 = |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 385 | "{@type=korap:group, operation=operation:submatch, classRef=[1], operands=[" + |
| 386 | "{@type=korap:group, operation=operation:position, frame=frame:overlaps-left, operands=[" + |
| 387 | "{@type=korap:span, key=s}," + |
| 388 | "{@type=korap:group, operation=operation:class, class=1, operands=[" + |
Joachim Bingel | ee3b21d | 2014-02-12 12:34:59 +0000 | [diff] [blame] | 389 | "{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=match:eq}}" + |
Joachim Bingel | cc1dc24 | 2014-01-15 09:32:38 +0000 | [diff] [blame] | 390 | "]}" + |
| 391 | "]}" + |
| 392 | "]}"; |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 393 | ct = new CosmasTree(query); |
| 394 | map = ct.getRequestMap().get("query").toString(); |
Joachim Bingel | cc1dc24 | 2014-01-15 09:32:38 +0000 | [diff] [blame] | 395 | assertEquals(opov2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | b5f7bf0 | 2014-01-07 16:36:54 +0000 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | @Test |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame] | 399 | public void testOPNOT() throws QueryException { |
Joachim Bingel | 3a9f793 | 2014-01-07 17:11:31 +0000 | [diff] [blame] | 400 | query="Sonne nicht Mond"; |
| 401 | String opnot1 = |
Joachim Bingel | b7a5979 | 2014-02-14 13:52:29 +0000 | [diff] [blame] | 402 | "{@type=korap:group, operation=operation:sequence, distances=[" + |
| 403 | "{@type=korap:distance, key=t, min=0, max=0, exclude=true}" + |
| 404 | "], operands=[" + |
Joachim Bingel | ee3b21d | 2014-02-12 12:34:59 +0000 | [diff] [blame] | 405 | "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=match:eq}}," + |
| 406 | "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=match:eq}}" + |
Joachim Bingel | 3a9f793 | 2014-01-07 17:11:31 +0000 | [diff] [blame] | 407 | "]}"; |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 408 | ct = new CosmasTree(query); |
| 409 | map = ct.getRequestMap().get("query").toString(); |
Joachim Bingel | 3a9f793 | 2014-01-07 17:11:31 +0000 | [diff] [blame] | 410 | assertEquals(opnot1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 411 | } |
| 412 | |
| 413 | @Test |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame] | 414 | public void testBEG_END() throws QueryException { |
Joachim Bingel | 3a9f793 | 2014-01-07 17:11:31 +0000 | [diff] [blame] | 415 | // BEG and END operators |
| 416 | // http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/syntax/links.html |
| 417 | // http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/syntax/rechts.html |
| 418 | // http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/thematische-bsp/bsp-satzlaenge.html |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame] | 419 | query="#BEG(der /w3:5 Mann)"; |
| 420 | String beg1 = |
Joachim Bingel | cd7b725 | 2014-02-13 08:49:14 +0000 | [diff] [blame] | 421 | "{@type=korap:group, operation=operation:submatch, spanRef=[0,1], operands=[" + |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 422 | "{@type=korap:group, operation=operation:sequence, inOrder=false, distances=[" + |
| 423 | "{@type=korap:distance, key=w, min=3, max=5}" + |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame] | 424 | "]," + |
Joachim Bingel | 11d5b15 | 2014-02-11 21:33:47 +0000 | [diff] [blame] | 425 | "operands = [" + |
Joachim Bingel | ee3b21d | 2014-02-12 12:34:59 +0000 | [diff] [blame] | 426 | "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," + |
| 427 | "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" + |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame] | 428 | "]}" + |
| 429 | "]}"; |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 430 | ct = new CosmasTree(query); |
| 431 | map = ct.getRequestMap().get("query").toString(); |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame] | 432 | assertEquals(beg1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 433 | |
| 434 | query="#BEG(der /w3:5 Mann) /+w10 kommt"; // nesting #BEG() in a distance group |
| 435 | String beg2 = |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 436 | "{@type=korap:group, operation=operation:sequence, inOrder=true, distances=[" + |
| 437 | "{@type=korap:distance, key=w, min=0, max=10}" + |
Joachim Bingel | 11d5b15 | 2014-02-11 21:33:47 +0000 | [diff] [blame] | 438 | "], operands=[" + |
Joachim Bingel | cd7b725 | 2014-02-13 08:49:14 +0000 | [diff] [blame] | 439 | "{@type=korap:group, operation=operation:submatch, spanRef=[0,1], operands=[" + |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 440 | "{@type=korap:group, operation=operation:sequence, inOrder=false, distances=[" + |
| 441 | "{@type=korap:distance, key=w, min=3, max=5}" + |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame] | 442 | "]," + |
Joachim Bingel | 11d5b15 | 2014-02-11 21:33:47 +0000 | [diff] [blame] | 443 | "operands = [" + |
Joachim Bingel | ee3b21d | 2014-02-12 12:34:59 +0000 | [diff] [blame] | 444 | "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," + |
| 445 | "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" + |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame] | 446 | "]}" + |
| 447 | "]}," + |
Joachim Bingel | ee3b21d | 2014-02-12 12:34:59 +0000 | [diff] [blame] | 448 | "{@type=korap:token, wrap={@type=korap:term, key=kommt, layer=orth, match=match:eq}}" + |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame] | 449 | "]}"; |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 450 | ct = new CosmasTree(query); |
| 451 | map = ct.getRequestMap().get("query").toString(); |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame] | 452 | assertEquals(beg2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 453 | |
| 454 | query="#END(der /w3:5 Mann)"; |
| 455 | String end1 = |
Joachim Bingel | cd7b725 | 2014-02-13 08:49:14 +0000 | [diff] [blame] | 456 | "{@type=korap:group, operation=operation:submatch, spanRef=[-1,1], operands=[" + |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 457 | "{@type=korap:group, operation=operation:sequence, inOrder=false, distances=[" + |
| 458 | "{@type=korap:distance, key=w, min=3, max=5}" + |
Joachim Bingel | ba9a0ab | 2014-01-29 10:12:25 +0000 | [diff] [blame] | 459 | "], " + |
Joachim Bingel | 11d5b15 | 2014-02-11 21:33:47 +0000 | [diff] [blame] | 460 | "operands = [" + |
Joachim Bingel | ee3b21d | 2014-02-12 12:34:59 +0000 | [diff] [blame] | 461 | "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," + |
| 462 | "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" + |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame] | 463 | "]}" + |
| 464 | "]}"; |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 465 | ct = new CosmasTree(query); |
| 466 | map = ct.getRequestMap().get("query").toString(); |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame] | 467 | assertEquals(end1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | b5f7bf0 | 2014-01-07 16:36:54 +0000 | [diff] [blame] | 468 | } |
Joachim Bingel | d5161a1 | 2014-01-08 11:15:49 +0000 | [diff] [blame] | 469 | |
| 470 | |
| 471 | @Test |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame] | 472 | public void testELEM() throws QueryException { |
Joachim Bingel | d5161a1 | 2014-01-08 11:15:49 +0000 | [diff] [blame] | 473 | // http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/syntax/elem.html |
Joachim Bingel | eecc765 | 2014-01-11 17:21:07 +0000 | [diff] [blame] | 474 | query="#ELEM(S)"; |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 475 | String elem1 = "{@type=korap:span, key=s}"; |
| 476 | ct = new CosmasTree(query); |
| 477 | map = ct.getRequestMap().get("query").toString(); |
Joachim Bingel | eecc765 | 2014-01-11 17:21:07 +0000 | [diff] [blame] | 478 | assertEquals(elem1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | d5161a1 | 2014-01-08 11:15:49 +0000 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | @Test |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame] | 482 | public void testOPALL() throws QueryException { |
Joachim Bingel | 89cceac | 2014-01-08 15:51:08 +0000 | [diff] [blame] | 483 | query="#ALL(gehen /w1:10 voran)"; |
Joachim Bingel | e98d088 | 2014-01-21 12:58:54 +0000 | [diff] [blame] | 484 | String all1 = |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 485 | "{@type=korap:group, operation=operation:sequence, inOrder=false, " + |
Joachim Bingel | 11d5b15 | 2014-02-11 21:33:47 +0000 | [diff] [blame] | 486 | "distances=[" + |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 487 | "{@type=korap:distance, key=w, min=1, max=10}" + |
Joachim Bingel | 3f0850c | 2014-01-17 16:50:10 +0000 | [diff] [blame] | 488 | "], " + |
Joachim Bingel | 11d5b15 | 2014-02-11 21:33:47 +0000 | [diff] [blame] | 489 | "operands=[" + |
Joachim Bingel | ee3b21d | 2014-02-12 12:34:59 +0000 | [diff] [blame] | 490 | "{@type=korap:token, wrap={@type=korap:term, key=gehen, layer=orth, match=match:eq}}," + |
| 491 | "{@type=korap:token, wrap={@type=korap:term, key=voran, layer=orth, match=match:eq}}" + |
Joachim Bingel | 3f0850c | 2014-01-17 16:50:10 +0000 | [diff] [blame] | 492 | "]" + |
| 493 | "}"; |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 494 | ct = new CosmasTree(query); |
| 495 | map = ct.getRequestMap().get("query").toString(); |
Joachim Bingel | 89cceac | 2014-01-08 15:51:08 +0000 | [diff] [blame] | 496 | assertEquals(all1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | d5161a1 | 2014-01-08 11:15:49 +0000 | [diff] [blame] | 497 | } |
| 498 | |
Joachim Bingel | 36233b5 | 2014-02-13 10:48:24 +0000 | [diff] [blame] | 499 | @Test |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame] | 500 | public void testOPNHIT() throws QueryException { |
Joachim Bingel | 89cceac | 2014-01-08 15:51:08 +0000 | [diff] [blame] | 501 | query="#NHIT(gehen /w1:10 voran)"; |
| 502 | String nhit1 = |
Joachim Bingel | 36233b5 | 2014-02-13 10:48:24 +0000 | [diff] [blame] | 503 | "{@type=korap:group, operation=operation:submatch, classRef=[1,2], classRefOp=classRefOp:intersection, operands=[" + |
| 504 | "{@type=korap:group, operation=operation:sequence, inOrder=false, " + |
| 505 | "distances=[" + |
| 506 | "{@type=korap:distance, key=w, min=1, max=10}" + |
| 507 | "], " + |
| 508 | "operands=[" + |
| 509 | "{@type=korap:group, operation=operation:class, class=1, operands=[" + |
| 510 | "{@type=korap:token, wrap={@type=korap:term, key=gehen, layer=orth, match=match:eq}}" + |
| 511 | "]}," + |
| 512 | "{@type=korap:group, operation=operation:class, class=2, operands=[" + |
| 513 | "{@type=korap:token, wrap={@type=korap:term, key=voran, layer=orth, match=match:eq}}" + |
| 514 | "]}" + |
| 515 | "]" + |
| 516 | "}" + |
| 517 | "]}"; |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 518 | ct = new CosmasTree(query); |
| 519 | map = ct.getRequestMap().get("query").toString(); |
Joachim Bingel | 89cceac | 2014-01-08 15:51:08 +0000 | [diff] [blame] | 520 | assertEquals(nhit1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | d5161a1 | 2014-01-08 11:15:49 +0000 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | @Test |
Joachim Bingel | 87480d0 | 2014-01-17 14:07:46 +0000 | [diff] [blame] | 524 | public void testOPBED() throws QueryException { |
Joachim Bingel | eecc765 | 2014-01-11 17:21:07 +0000 | [diff] [blame] | 525 | query = "#BED(der , sa)"; |
| 526 | String bed1 = |
Joachim Bingel | cd7b725 | 2014-02-13 08:49:14 +0000 | [diff] [blame] | 527 | "{@type=korap:group, operation=operation:submatch, classRef=[1], operands= [" + |
| 528 | "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" + |
| 529 | "{@type=korap:span, key=s}," + |
| 530 | "{@type=korap:group, operation=operation:class, class=1, operands=[" + |
| 531 | "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}" + |
| 532 | "]}" + |
| 533 | "]}" + |
Joachim Bingel | eecc765 | 2014-01-11 17:21:07 +0000 | [diff] [blame] | 534 | "]}"; |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 535 | ct = new CosmasTree(query); |
| 536 | map = ct.getRequestMap().get("query").toString(); |
Joachim Bingel | eecc765 | 2014-01-11 17:21:07 +0000 | [diff] [blame] | 537 | assertEquals(bed1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 538 | |
| 539 | query = "#BED(der Mann , +pe)"; |
| 540 | String bed2 = |
Joachim Bingel | 36233b5 | 2014-02-13 10:48:24 +0000 | [diff] [blame] | 541 | "{@type=korap:group, operation=operation:submatch, classRef=[1], operands= [" + |
| 542 | "{@type=korap:group, operation=operation:position, frame=frame:endswith, operands=[" + |
| 543 | "{@type=korap:span, key=p}," + |
| 544 | "{@type=korap:group, operation=operation:class, class=1, operands=[" + |
| 545 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 546 | "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," + |
| 547 | "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" + |
| 548 | "]}" + |
| 549 | "]}" + |
| 550 | "]}" + |
| 551 | "]}"; |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 552 | ct = new CosmasTree(query); |
| 553 | map = ct.getRequestMap().get("query").toString(); |
Joachim Bingel | 36233b5 | 2014-02-13 10:48:24 +0000 | [diff] [blame] | 554 | assertEquals(bed2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | 3f0850c | 2014-01-17 16:50:10 +0000 | [diff] [blame] | 555 | |
| 556 | query = "#BED(der Mann , sa,-pa)"; |
| 557 | String bed3 = |
Joachim Bingel | 36233b5 | 2014-02-13 10:48:24 +0000 | [diff] [blame] | 558 | "{@type=korap:group, operation=operation:submatch, classRef=[1], operands=[" + |
| 559 | "{@type=korap:group, operation=operation:sequence, distances=[" + |
| 560 | "{@type=korap:distance, key=w, min=0, max=0}" + |
| 561 | "], operands=[" + |
| 562 | "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" + |
| 563 | "{@type=korap:span, key=s}," + |
| 564 | "{@type=korap:group, operation=operation:class, class=1, operands=[" + |
| 565 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 566 | "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," + |
| 567 | "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" + |
| 568 | "]}" + |
| 569 | "]}" + |
| 570 | "]}," + |
| 571 | "{@type=korap:group, operation=operation:position, frame=frame:startswith, exclude=true, operands=[" + |
| 572 | "{@type=korap:span, key=p}," + |
| 573 | "{@type=korap:group, operation=operation:class, class=1, operands=[" + |
| 574 | "{@type=korap:group, operation=operation:sequence, operands=[" + |
| 575 | "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=match:eq}}," + |
| 576 | "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" + |
| 577 | "]}" + |
| 578 | "]}" + |
Joachim Bingel | 3f0850c | 2014-01-17 16:50:10 +0000 | [diff] [blame] | 579 | "]}" + |
| 580 | "]}" + |
| 581 | "]}"; |
Joachim Bingel | 2daf986 | 2014-02-12 10:18:54 +0000 | [diff] [blame] | 582 | ct = new CosmasTree(query); |
| 583 | map = ct.getRequestMap().get("query").toString(); |
Joachim Bingel | 36233b5 | 2014-02-13 10:48:24 +0000 | [diff] [blame] | 584 | assertEquals(bed3.replaceAll(" ", ""), map.replaceAll(" ", "")); |
Joachim Bingel | d5161a1 | 2014-01-08 11:15:49 +0000 | [diff] [blame] | 585 | } |
| 586 | |
Joachim Bingel | 8181263 | 2014-02-18 08:55:22 +0000 | [diff] [blame^] | 587 | @Test |
| 588 | public void testColonSeparatedConditions() throws QueryException { |
| 589 | |
| 590 | query = "Der:sa"; |
| 591 | String col1 = |
| 592 | "{@type=korap:group, operation=operation:submatch, classRef=[1], operands=[" + |
| 593 | "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" + |
| 594 | "{@type=korap:span, key=s}," + |
| 595 | "{@type=korap:group, operation=operation:class, class=1, operands=[" + |
| 596 | "{@type=korap:token, wrap={@type=korap:term, key=Der, layer=orth, match=match:eq}}" + |
| 597 | "]}" + |
| 598 | "]}" + |
| 599 | "]}"; |
| 600 | ct = new CosmasTree(query); |
| 601 | map = ct.getRequestMap().get("query").toString(); |
| 602 | assertEquals(col1.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 603 | |
| 604 | query = "Mann:sa,-pa,+te)"; |
| 605 | String col2 = |
| 606 | "{@type=korap:group, operation=operation:submatch, classRef=[1], operands=[" + |
| 607 | "{@type=korap:group, operation=operation:sequence, distances=[" + |
| 608 | "{@type=korap:distance, key=w, min=0, max=0}" + |
| 609 | "], operands=[" + |
| 610 | "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" + |
| 611 | "{@type=korap:span, key=s}," + |
| 612 | "{@type=korap:group, operation=operation:class, class=1, operands=[" + |
| 613 | "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" + |
| 614 | "]}" + |
| 615 | "]}," + |
| 616 | "{@type=korap:group, operation=operation:position, frame=frame:startswith, exclude=true, operands=[" + |
| 617 | "{@type=korap:span, key=p}," + |
| 618 | "{@type=korap:group, operation=operation:class, class=1, operands=[" + |
| 619 | "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" + |
| 620 | "]}" + |
| 621 | "]}," + |
| 622 | "{@type=korap:group, operation=operation:position, frame=frame:endswith, operands=[" + |
| 623 | "{@type=korap:span, key=t}," + |
| 624 | "{@type=korap:group, operation=operation:class, class=1, operands=[" + |
| 625 | "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=match:eq}}" + |
| 626 | "]}" + |
| 627 | "]}" + |
| 628 | "]}" + |
| 629 | "]}"; |
| 630 | ct = new CosmasTree(query); |
| 631 | map = ct.getRequestMap().get("query").toString(); |
| 632 | assertEquals(col2.replaceAll(" ", ""), map.replaceAll(" ", "")); |
| 633 | } |
Joachim Bingel | b5f7bf0 | 2014-01-07 16:36:54 +0000 | [diff] [blame] | 634 | } |
| 635 | |