blob: 1b28c5a0f7f695cae4a41a674faf53091af2e33a [file] [log] [blame]
Joachim Bingelb5f7bf02014-01-07 16:36:54 +00001import static org.junit.Assert.*;
2
3import org.junit.Test;
4
5import de.ids_mannheim.korap.query.serialize.CosmasTree;
Joachim Bingelb5f7bf02014-01-07 16:36:54 +00006import de.ids_mannheim.korap.util.QueryException;
7
8public class CosmasTreeTest {
9
Joachim Bingel2daf9862014-02-12 10:18:54 +000010 CosmasTree ct;
Joachim Bingelb5f7bf02014-01-07 16:36:54 +000011 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 Bingel2daf9862014-02-12 10:18:54 +000022 ct = new CosmasTree(query);
23 String queryMap = ct.getRequestMap().get("query").toString().replaceAll(" ", "");
Joachim Bingelb5f7bf02014-01-07 16:36:54 +000024 return res.equals(queryMap);
25 }
26
Joachim Bingel11d5b152014-02-11 21:33:47 +000027// @Test
Joachim Bingelb5f7bf02014-01-07 16:36:54 +000028 public void testContext() throws QueryException {
Joachim Bingel2daf9862014-02-12 10:18:54 +000029 String contextString = "{korap = http://korap.ids-mannheim.de/ns/KorAP/json-ld/v0.1/, " +
Joachim Bingel11d5b152014-02-11 21:33:47 +000030 "boundary = korap:boundary/,"+
31 "group = korap:group/,"+
32 "operation = {@id = group:operation/, @type = @id},"+
33 "class = {@id = group:class, @type = xsd:integer},"+
34 "operands = {@id = group:operands, @container = @list},"+
Joachim Bingel2daf9862014-02-12 10:18:54 +000035 "frame = {@id = group:frame/, @type = @id},"+
Joachim Bingel11d5b152014-02-11 21:33:47 +000036 "classRef = {@id = group:classRef, @type = xsd:integer},"+
37 "spanRef = {@id = group:spanRef, @type = xsd:integer},"+
38 "classRefOp = {@id = group:classRefOp, @type = @id},"+
39 "min = {@id = boundary:min, @type = xsd:integer},"+
40 "max = {@id = boundary:max, @type = xsd:integer},"+
41 "exclude = {@id = group:exclude, @type = xsd:boolean},"+
42 "distances = {@id = group:distances, @container = @list},"+
Joachim Bingel2daf9862014-02-12 10:18:54 +000043 "inOrder = {@id = group:inOrder, @type = xsd:boolean}"+
Joachim Bingel11d5b152014-02-11 21:33:47 +000044 "}";
Joachim Bingel2daf9862014-02-12 10:18:54 +000045 ct = new CosmasTree("Test");
46 assertEquals(contextString.replaceAll(" ", ""), ct.getRequestMap().get("@context").toString().replaceAll(" ", ""));
Joachim Bingelb5f7bf02014-01-07 16:36:54 +000047 }
48
49
50 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +000051 public void testSingleToken() throws QueryException {
Joachim Bingelb5f7bf02014-01-07 16:36:54 +000052 query="der";
53 String single1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +000054 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=eq}}";
55 ct = new CosmasTree(query);
56 map = ct.getRequestMap().get("query").toString();
Joachim Bingelb5f7bf02014-01-07 16:36:54 +000057 assertEquals(single1.replaceAll(" ", ""), map.replaceAll(" ", ""));
58
59 query="Mann";
60 String single2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +000061 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=eq}}";
62 ct = new CosmasTree(query);
63 map = ct.getRequestMap().get("query").toString();
Joachim Bingelb5f7bf02014-01-07 16:36:54 +000064 assertEquals(single2.replaceAll(" ", ""), map.replaceAll(" ", ""));
65
66 query="&Mann";
67 String single3 =
Joachim Bingel2daf9862014-02-12 10:18:54 +000068 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=lemma, match=eq}}";
69 ct = new CosmasTree(query);
70 map = ct.getRequestMap().get("query").toString();
Joachim Bingelb5f7bf02014-01-07 16:36:54 +000071 assertEquals(single3.replaceAll(" ", ""), map.replaceAll(" ", ""));
72 }
73
Joachim Bingelba9a0ab2014-01-29 10:12:25 +000074 @Test
Joachim Bingel8c640e42014-02-07 16:20:47 +000075 public void testCaseSensitivityFlag() throws QueryException {
76 //TODO ignorieroperator $ http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/syntax/ignorierung.html
77 }
78
79 @Test
Joachim Bingelffd65e32014-01-22 14:22:57 +000080 public void testMORPH() throws QueryException {
81 query="#MORPH(V)";
82 String morph1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +000083 "{@type=korap:token, wrap={@type=korap:term, key=V, match=eq}}";
84 ct = new CosmasTree(query);
85 map = ct.getRequestMap().get("query").toString();
Joachim Bingelffd65e32014-01-22 14:22:57 +000086 assertEquals(morph1.replaceAll(" ", ""), map.replaceAll(" ", ""));
87 }
88
Joachim Bingelb5f7bf02014-01-07 16:36:54 +000089 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +000090 public void testSequence() throws QueryException {
Joachim Bingelb5f7bf02014-01-07 16:36:54 +000091 query="der Mann";
92 String seq1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +000093 "{@type=korap:group, operation=operation:sequence, operands=[" +
94 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=eq}}," +
95 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=eq}}" +
Joachim Bingelb5f7bf02014-01-07 16:36:54 +000096 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +000097 ct = new CosmasTree(query);
98 map = ct.getRequestMap().get("query").toString();
Joachim Bingelb5f7bf02014-01-07 16:36:54 +000099 assertEquals(seq1.replaceAll(" ", ""), map.replaceAll(" ", ""));
100
Joachim Bingeld5161a12014-01-08 11:15:49 +0000101 query="der Mann schläft";
102 String seq2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000103 "{@type=korap:group, operation=operation:sequence, operands=[" +
104 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=eq}}," +
105 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=eq}}," +
106 "{@type=korap:token, wrap={@type=korap:term, key=schläft, layer=orth, match=eq}}" +
Joachim Bingeld5161a12014-01-08 11:15:49 +0000107 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000108 ct = new CosmasTree(query);
109 map = ct.getRequestMap().get("query").toString();
Joachim Bingeld5161a12014-01-08 11:15:49 +0000110 assertEquals(seq2.replaceAll(" ", ""), map.replaceAll(" ", ""));
111
112 query="der Mann schläft lang";
113 String seq3 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000114 "{@type=korap:group, operation=operation:sequence, operands=[" +
115 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=eq}}," +
116 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=eq}}," +
117 "{@type=korap:token, wrap={@type=korap:term, key=schläft, layer=orth, match=eq}}," +
118 "{@type=korap:token, wrap={@type=korap:term, key=lang, layer=orth, match=eq}}" +
Joachim Bingeld5161a12014-01-08 11:15:49 +0000119 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000120 ct = new CosmasTree(query);
121 map = ct.getRequestMap().get("query").toString();
Joachim Bingeld5161a12014-01-08 11:15:49 +0000122 assertEquals(seq3.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000123 }
124
125 @Test
126 public void testOPOR() throws QueryException {
127 query="Sonne oder Mond";
128 String disj1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000129 "{@type=korap:group, operation=operation:or, operands=[" +
130 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=eq}}," +
131 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=eq}}" +
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000132 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000133 ct = new CosmasTree(query);
134 map = ct.getRequestMap().get("query").toString();
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000135 assertEquals(disj1.replaceAll(" ", ""), map.replaceAll(" ", ""));
136
Joachim Bingeld5161a12014-01-08 11:15:49 +0000137 query="(Sonne scheint) oder Mond";
138 String disj2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000139 "{@type=korap:group, operation=operation:or, operands=[" +
140 "{@type=korap:group, operation=operation:sequence, operands=[" +
141 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=eq}}," +
142 "{@type=korap:token, wrap={@type=korap:term, key=scheint, layer=orth, match=eq}}" +
Joachim Bingeld5161a12014-01-08 11:15:49 +0000143 "]}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000144 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=eq}}" +
Joachim Bingeld5161a12014-01-08 11:15:49 +0000145 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000146 ct = new CosmasTree(query);
147 map = ct.getRequestMap().get("query").toString();
Joachim Bingeld5161a12014-01-08 11:15:49 +0000148 assertEquals(disj2.replaceAll(" ", ""), map.replaceAll(" ", ""));
149
150 query="(Sonne scheint) oder (Mond scheint)";
151 String disj3 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000152 "{@type=korap:group, operation=operation:or, operands=[" +
153 "{@type=korap:group, operation=operation:sequence, operands=[" +
154 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=eq}}," +
155 "{@type=korap:token, wrap={@type=korap:term, key=scheint, layer=orth, match=eq}}" +
Joachim Bingeld5161a12014-01-08 11:15:49 +0000156 "]}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000157 "{@type=korap:group, operation=operation:sequence, operands=[" +
158 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=eq}}," +
159 "{@type=korap:token, wrap={@type=korap:term, key=scheint, layer=orth, match=eq}}" +
Joachim Bingeld5161a12014-01-08 11:15:49 +0000160 "]}" +
161 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000162 ct = new CosmasTree(query);
163 map = ct.getRequestMap().get("query").toString();
Joachim Bingeld5161a12014-01-08 11:15:49 +0000164 assertEquals(disj3.replaceAll(" ", ""), map.replaceAll(" ", ""));
165
166 }
167
168 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000169 public void testOPORAND() throws QueryException {
Joachim Bingeld5161a12014-01-08 11:15:49 +0000170 query="(Sonne oder Mond) und scheint";
171 String orand1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000172 "{@type=korap:group, operation=operation:and, operands=[" +
173 "{@type=korap:group, operation=operation:or, operands=[" +
174 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=eq}}," +
175 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=eq}}" +
Joachim Bingeld5161a12014-01-08 11:15:49 +0000176 "]}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000177 "{@type=korap:token, wrap={@type=korap:term, key=scheint, layer=orth, match=eq}}" +
Joachim Bingeld5161a12014-01-08 11:15:49 +0000178 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000179 ct = new CosmasTree(query);
180 map = ct.getRequestMap().get("query").toString();
Joachim Bingeld5161a12014-01-08 11:15:49 +0000181 assertEquals(orand1.replaceAll(" ", ""), map.replaceAll(" ", ""));
182
183 query="scheint und (Sonne oder Mond)";
184 String orand2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000185 "{@type=korap:group, operation=operation:and, operands=[" +
186 "{@type=korap:token, wrap={@type=korap:term, key=scheint, layer=orth, match=eq}}," +
187 "{@type=korap:group, operation=operation:or, operands=[" +
188 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=eq}}," +
189 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=eq}}" +
Joachim Bingeld5161a12014-01-08 11:15:49 +0000190 "]}" +
191 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000192 ct = new CosmasTree(query);
193 map = ct.getRequestMap().get("query").toString();
Joachim Bingeld5161a12014-01-08 11:15:49 +0000194 assertEquals(orand2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000195 }
196
197 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000198 public void testOPPROX() throws QueryException {
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000199 query="Sonne /+w1:4 Mond";
200 String prox1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000201 "{@type=korap:group, operation=operation:sequence, inOrder=true, " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000202 "distances=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000203 "{@type=korap:distance, key=w, min=1, max=4}" +
Joachim Bingel89cceac2014-01-08 15:51:08 +0000204 "], " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000205 "operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000206 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=eq}}," +
207 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=eq}}" +
Joachim Bingel89cceac2014-01-08 15:51:08 +0000208 "]" +
209 "}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000210 ct = new CosmasTree(query);
211 map = ct.getRequestMap().get("query").toString();
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000212 assertEquals(prox1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel89cceac2014-01-08 15:51:08 +0000213
214 query="Sonne /+w1:4,s0,p1:3 Mond";
215 String prox2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000216 "{@type=korap:group, operation=operation:sequence, inOrder=true, " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000217 "distances=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000218 "{@type=korap:group, operation=operation:and, operands=[" +
219 "{@type=korap:distance, key=w, min=1, max=4}," +
220 "{@type=korap:distance, key=s, min=0, max=0}," +
221 "{@type=korap:distance, key=p, min=1, max=3}" +
Joachim Bingel89cceac2014-01-08 15:51:08 +0000222 "]}" +
223 "], " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000224 "operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000225 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=eq}}," +
226 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=eq}}" +
Joachim Bingel89cceac2014-01-08 15:51:08 +0000227 "]" +
228 "}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000229 ct = new CosmasTree(query);
230 map = ct.getRequestMap().get("query").toString();
Joachim Bingel89cceac2014-01-08 15:51:08 +0000231 assertEquals(prox2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel87480d02014-01-17 14:07:46 +0000232
233 query="Sonne %+w1:4,s0,p1:3 Mond";
234 String prox3 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000235 "{@type=korap:group, operation=operation:sequence, inOrder=true, " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000236 "distances=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000237 "{@type=korap:group, operation=operation:and, operands=[" +
238 "{@type=korap:distance, key=w, min=1, max=4, exclude=true}," +
239 "{@type=korap:distance, key=s, min=0, max=0, exclude=true}," +
240 "{@type=korap:distance, key=p, min=1, max=3, exclude=true}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000241 "]}" +
242 "], " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000243 "operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000244 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=eq}}," +
245 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=eq}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000246 "]" +
247 "}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000248 ct = new CosmasTree(query);
249 map = ct.getRequestMap().get("query").toString();
Joachim Bingel87480d02014-01-17 14:07:46 +0000250 assertEquals(prox3.replaceAll(" ", ""), map.replaceAll(" ", ""));
251
252 query="Sonne /+w4 Mond";
253 String prox4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000254 "{@type=korap:group, operation=operation:sequence, inOrder=true, " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000255 "distances=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000256 "{@type=korap:distance, key=w, min=0, max=4}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000257 "], " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000258 "operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000259 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=eq}}," +
260 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=eq}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000261 "]" +
262 "}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000263 ct = new CosmasTree(query);
264 map = ct.getRequestMap().get("query").toString();
Joachim Bingel87480d02014-01-17 14:07:46 +0000265 assertEquals(prox4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000266
267 query="Sonne /-w4 Mond";
268 String prox5 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000269 "{@type=korap:group, operation=operation:sequence, inOrder=true, " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000270 "distances=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000271 "{@type=korap:distance, key=w, min=0, max=4}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000272 "], " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000273 "operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000274 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=eq}}," +
275 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=eq}}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000276 "]" +
277 "}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000278 ct = new CosmasTree(query);
279 map = ct.getRequestMap().get("query").toString();
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000280 assertEquals(prox5.replaceAll(" ", ""), map.replaceAll(" ", ""));
281 }
282
283 @Test
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000284 public void testOPPROXNested() throws QueryException {
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000285 query="Sonne /-w4 Mond /+w2 Sterne";
286 String prox6 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000287 "{@type=korap:group, operation=operation:sequence, inOrder=true, " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000288 "distances=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000289 "{@type=korap:distance, key=w, min=0, max=4}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000290 "], " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000291 "operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000292 "{@type=korap:group, operation=operation:sequence, inOrder=true, " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000293 "distances=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000294 "{@type=korap:distance, key=w, min=0, max=2}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000295 "], " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000296 "operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000297 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=eq}}," +
298 "{@type=korap:token, wrap={@type=korap:term, key=Sterne, layer=orth, match=eq}}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000299 "]}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000300 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=eq}}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000301 "]" +
302 "}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000303 ct = new CosmasTree(query);
304 map = ct.getRequestMap().get("query").toString();
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000305 assertEquals(prox6.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000306 }
307
308 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000309 public void testOPIN() throws QueryException {
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000310 query="wegen #IN <s>";
Joachim Bingel3a9f7932014-01-07 17:11:31 +0000311 String opin1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000312 "{@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=[" +
316 "{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=eq}}" +
Joachim Bingeleecc7652014-01-11 17:21:07 +0000317 "]}" +
318 "]}" +
Joachim Bingeld5161a12014-01-08 11:15:49 +0000319 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000320 ct = new CosmasTree(query);
321 map = ct.getRequestMap().get("query").toString();
Joachim Bingeld5161a12014-01-08 11:15:49 +0000322 assertEquals(opin1.replaceAll(" ", ""), map.replaceAll(" ", ""));
323
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000324 query="wegen #IN(L) <s>";
325 String opin2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000326 "{@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=[" +
330 "{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=eq}}" +
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000331 "]}" +
332 "]}" +
333 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000334 ct = new CosmasTree(query);
335 map = ct.getRequestMap().get("query").toString();
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000336 assertEquals(opin2.replaceAll(" ", ""), map.replaceAll(" ", ""));
337
Joachim Bingel87480d02014-01-17 14:07:46 +0000338 query="wegen #IN(%, L) <s>";
339 String opin3 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000340 "{@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=[" +
344 "{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=eq}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000345 "]}" +
346 "]}" +
347 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000348 ct = new CosmasTree(query);
349 map = ct.getRequestMap().get("query").toString();
Joachim Bingel87480d02014-01-17 14:07:46 +0000350 assertEquals(opin3.replaceAll(" ", ""), map.replaceAll(" ", ""));
351
352 query="wegen #IN('FE,ALL,%,MIN') <s>";
353 String opin4 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000354 "{@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=[" +
358 "{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=eq}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000359 "]}" +
360 "]}" +
361 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000362 ct = new CosmasTree(query);
363 map = ct.getRequestMap().get("query").toString();
Joachim Bingel87480d02014-01-17 14:07:46 +0000364 assertEquals(opin4.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeld5161a12014-01-08 11:15:49 +0000365 }
366
367 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000368 public void testOPOV() throws QueryException {
Joachim Bingeld5161a12014-01-08 11:15:49 +0000369 query="wegen #OV <s>";
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000370 String opov1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000371 "{@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=[" +
375 "{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=eq}}" +
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000376 "]}" +
377 "]}" +
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000378 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000379 ct = new CosmasTree(query);
380 map = ct.getRequestMap().get("query").toString();
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000381 assertEquals(opov1.replaceAll(" ", ""), map.replaceAll(" ", ""));
382
383 query="wegen #OV(L) <s>";
384 String opov2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000385 "{@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=[" +
389 "{@type=korap:token, wrap={@type=korap:term, key=wegen, layer=orth, match=eq}}" +
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000390 "]}" +
391 "]}" +
392 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000393 ct = new CosmasTree(query);
394 map = ct.getRequestMap().get("query").toString();
Joachim Bingelcc1dc242014-01-15 09:32:38 +0000395 assertEquals(opov2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000396 }
397
398 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000399 public void testOPNOT() throws QueryException {
Joachim Bingel3a9f7932014-01-07 17:11:31 +0000400 query="Sonne nicht Mond";
401 String opnot1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000402 "{@type=korap:group, operation=operation:not, operands=[" +
403 "{@type=korap:token, wrap={@type=korap:term, key=Sonne, layer=orth, match=eq}}," +
404 "{@type=korap:token, wrap={@type=korap:term, key=Mond, layer=orth, match=eq}}" +
Joachim Bingel3a9f7932014-01-07 17:11:31 +0000405 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000406 ct = new CosmasTree(query);
407 map = ct.getRequestMap().get("query").toString();
Joachim Bingel3a9f7932014-01-07 17:11:31 +0000408 assertEquals(opnot1.replaceAll(" ", ""), map.replaceAll(" ", ""));
409 }
410
411 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000412 public void testBEG_END() throws QueryException {
Joachim Bingel3a9f7932014-01-07 17:11:31 +0000413 // BEG and END operators
414 // http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/syntax/links.html
415 // http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/syntax/rechts.html
416 // http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/thematische-bsp/bsp-satzlaenge.html
Joachim Bingel87480d02014-01-17 14:07:46 +0000417 query="#BEG(der /w3:5 Mann)";
418 String beg1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000419 "{@type=korap:group, operation=operation:submatch, @spanRef=[0,1], operands=[" +
420 "{@type=korap:group, operation=operation:sequence, inOrder=false, distances=[" +
421 "{@type=korap:distance, key=w, min=3, max=5}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000422 "]," +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000423 "operands = [" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000424 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=eq}}," +
425 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=eq}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000426 "]}" +
427 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000428 ct = new CosmasTree(query);
429 map = ct.getRequestMap().get("query").toString();
Joachim Bingel87480d02014-01-17 14:07:46 +0000430 assertEquals(beg1.replaceAll(" ", ""), map.replaceAll(" ", ""));
431
432 query="#BEG(der /w3:5 Mann) /+w10 kommt"; // nesting #BEG() in a distance group
433 String beg2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000434 "{@type=korap:group, operation=operation:sequence, inOrder=true, distances=[" +
435 "{@type=korap:distance, key=w, min=0, max=10}" +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000436 "], operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000437 "{@type=korap:group, operation=operation:submatch, @spanRef=[0,1], operands=[" +
438 "{@type=korap:group, operation=operation:sequence, inOrder=false, distances=[" +
439 "{@type=korap:distance, key=w, min=3, max=5}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000440 "]," +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000441 "operands = [" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000442 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=eq}}," +
443 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=eq}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000444 "]}" +
445 "]}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000446 "{@type=korap:token, wrap={@type=korap:term, key=kommt, layer=orth, match=eq}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000447 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000448 ct = new CosmasTree(query);
449 map = ct.getRequestMap().get("query").toString();
Joachim Bingel87480d02014-01-17 14:07:46 +0000450 assertEquals(beg2.replaceAll(" ", ""), map.replaceAll(" ", ""));
451
452 query="#END(der /w3:5 Mann)";
453 String end1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000454 "{@type=korap:group, operation=operation:submatch, @spanRef=[-1,1], operands=[" +
455 "{@type=korap:group, operation=operation:sequence, inOrder=false, distances=[" +
456 "{@type=korap:distance, key=w, min=3, max=5}" +
Joachim Bingelba9a0ab2014-01-29 10:12:25 +0000457 "], " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000458 "operands = [" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000459 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=eq}}," +
460 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=eq}}" +
Joachim Bingel87480d02014-01-17 14:07:46 +0000461 "]}" +
462 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000463 ct = new CosmasTree(query);
464 map = ct.getRequestMap().get("query").toString();
Joachim Bingel87480d02014-01-17 14:07:46 +0000465 assertEquals(end1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000466 }
Joachim Bingeld5161a12014-01-08 11:15:49 +0000467
468
469 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000470 public void testELEM() throws QueryException {
Joachim Bingeld5161a12014-01-08 11:15:49 +0000471 // http://www.ids-mannheim.de/cosmas2/web-app/hilfe/suchanfrage/eingabe-zeile/syntax/elem.html
Joachim Bingeleecc7652014-01-11 17:21:07 +0000472 query="#ELEM(S)";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000473 String elem1 = "{@type=korap:span, key=s}";
474 ct = new CosmasTree(query);
475 map = ct.getRequestMap().get("query").toString();
Joachim Bingeleecc7652014-01-11 17:21:07 +0000476 assertEquals(elem1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeld5161a12014-01-08 11:15:49 +0000477 }
478
479 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000480 public void testOPALL() throws QueryException {
Joachim Bingel89cceac2014-01-08 15:51:08 +0000481 query="#ALL(gehen /w1:10 voran)";
Joachim Bingele98d0882014-01-21 12:58:54 +0000482 String all1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000483 "{@type=korap:group, operation=operation:sequence, inOrder=false, " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000484 "distances=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000485 "{@type=korap:distance, key=w, min=1, max=10}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000486 "], " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000487 "operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000488 "{@type=korap:token, wrap={@type=korap:term, key=gehen, layer=orth, match=eq}}," +
489 "{@type=korap:token, wrap={@type=korap:term, key=voran, layer=orth, match=eq}}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000490 "]" +
491 "}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000492 ct = new CosmasTree(query);
493 map = ct.getRequestMap().get("query").toString();
Joachim Bingel89cceac2014-01-08 15:51:08 +0000494 assertEquals(all1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeld5161a12014-01-08 11:15:49 +0000495 }
496
Joachim Bingel8c640e42014-02-07 16:20:47 +0000497// @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000498 public void testOPNHIT() throws QueryException {
Joachim Bingel89cceac2014-01-08 15:51:08 +0000499 query="#NHIT(gehen /w1:10 voran)";
500 String nhit1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000501 "{@type=korap:group, operation=operation:sequence, inOrder=false, " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000502 "distances=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000503 "{@type=korap:distance, key=w, min=1, max=10}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000504 "], " +
Joachim Bingel11d5b152014-02-11 21:33:47 +0000505 "operands=[" +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000506 "{@type=korap:token, wrap={@type=korap:term, key=gehen, layer=orth, match=eq}}," +
507 "{@type=korap:token, wrap={@type=korap:term, key=voran, layer=orth, match=eq}}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000508 "]" +
509 "}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000510 ct = new CosmasTree(query);
511 map = ct.getRequestMap().get("query").toString();
Joachim Bingel89cceac2014-01-08 15:51:08 +0000512 assertEquals(nhit1.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeld5161a12014-01-08 11:15:49 +0000513 }
514
515 @Test
Joachim Bingel87480d02014-01-17 14:07:46 +0000516 public void testOPBED() throws QueryException {
Joachim Bingeleecc7652014-01-11 17:21:07 +0000517 query = "#BED(der , sa)";
518 String bed1 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000519 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
520 "{@type=korap:span, key=s}," +
521 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=eq}}" +
Joachim Bingeleecc7652014-01-11 17:21:07 +0000522 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000523 ct = new CosmasTree(query);
524 map = ct.getRequestMap().get("query").toString();
Joachim Bingeleecc7652014-01-11 17:21:07 +0000525 assertEquals(bed1.replaceAll(" ", ""), map.replaceAll(" ", ""));
526
527 query = "#BED(der Mann , +pe)";
528 String bed2 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000529 "{@type=korap:group, operation=operation:position, frame=frame:endswith, operands=[" +
530 "{@type=korap:span, key=p}," +
531 "{@type=korap:group, operation=operation:sequence, operands=[" +
532 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=eq}}," +
533 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=eq}}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000534 "]}" +
Joachim Bingeleecc7652014-01-11 17:21:07 +0000535 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000536 ct = new CosmasTree(query);
537 map = ct.getRequestMap().get("query").toString();
Joachim Bingeleecc7652014-01-11 17:21:07 +0000538 assertEquals(bed2.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000539
540 query = "#BED(der Mann , sa,-pa)";
541 String bed3 =
Joachim Bingel2daf9862014-02-12 10:18:54 +0000542 "{@type=korap:group, operation=operation:and, operands=[" +
543 "{@type=korap:group, operation=operation:position, frame=frame:startswith, operands=[" +
544 "{@type=korap:span, key=s}," +
545 "{@type=korap:group, operation=operation:sequence, operands=[" +
546 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=eq}}," +
547 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=eq}}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000548 "]}" +
549 "]}," +
Joachim Bingel2daf9862014-02-12 10:18:54 +0000550 "{@type=korap:group, operation=operation:position, frame=frame:startswith, exclude=true, operands=[" +
551 "{@type=korap:span, key=p}," +
552 "{@type=korap:group, operation=operation:sequence, operands=[" +
553 "{@type=korap:token, wrap={@type=korap:term, key=der, layer=orth, match=eq}}," +
554 "{@type=korap:token, wrap={@type=korap:term, key=Mann, layer=orth, match=eq}}" +
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000555 "]}" +
556 "]}" +
557 "]}";
Joachim Bingel2daf9862014-02-12 10:18:54 +0000558 ct = new CosmasTree(query);
559 map = ct.getRequestMap().get("query").toString();
Joachim Bingel3f0850c2014-01-17 16:50:10 +0000560 assertEquals(bed3.replaceAll(" ", ""), map.replaceAll(" ", ""));
Joachim Bingeld5161a12014-01-08 11:15:49 +0000561 }
562
Joachim Bingelb5f7bf02014-01-07 16:36:54 +0000563}
564