blob: de9a089e75e3bb1c9397aad6171d0829fe4aed24 [file] [log] [blame]
Michael Hanlfb839b92015-09-19 21:32:34 +02001import com.fasterxml.jackson.databind.JsonNode;
2import de.ids_mannheim.korap.utils.CollectionQueryBuilder3;
3import de.ids_mannheim.korap.utils.JsonUtils;
4import org.junit.Test;
5
6/**
7 * @author hanl
8 * @date 12/08/2015
9 */
10public class CollectionQueryBuilderTest {
11
12 @Test
13 public void testsimpleAdd() {
14 CollectionQueryBuilder3 b = new CollectionQueryBuilder3();
15 b.addSegment("corpusID", CollectionQueryBuilder3.EQ.EQUAL, "WPD");
16 // System.out.println(b.toJSON());
17 }
18
19 @Test
20 public void testSimpleConjunctive() {
21 CollectionQueryBuilder3 b = new CollectionQueryBuilder3();
22 b.addSegment("corpusID", CollectionQueryBuilder3.EQ.EQUAL, "WPD").and()
23 .addSegment("textClass", CollectionQueryBuilder3.EQ.EQUAL,
24 "freizeit");
25 // System.out.println(b.toJSON());
26 }
27
28 @Test
29 public void testSimpleDisjunctive() {
30 CollectionQueryBuilder3 b = new CollectionQueryBuilder3();
31 b.addSegment("corpusID", CollectionQueryBuilder3.EQ.EQUAL, "WPD").and()
32 .addSegment("textClass", CollectionQueryBuilder3.EQ.EQUAL,
33 "freizeit");
34 // System.out.println(b.toJSON());
35 }
36
37 @Test
38 public void testComplexSubQuery() {
39
40 CollectionQueryBuilder3 b = new CollectionQueryBuilder3();
41 b.addSegment("corpusID", CollectionQueryBuilder3.EQ.EQUAL, "ADF").and()
42 .addSub("textClass=freizeit & corpusID=WPD");
43 // System.out.println(b.toJSON());
44 }
45
46 @Test // basically joining two or more resource queries
47 public void testAddResourceQueryAfter() {
48 CollectionQueryBuilder3 b = new CollectionQueryBuilder3();
49 b.addSegment("corpusID", CollectionQueryBuilder3.EQ.EQUAL, "ADF").and()
50 .addSub("textClass=freizeit & corpusID=WPD");
51 // System.out.println(b.toJSON());
52
53 // join.addSegment("textClass", "politik");
54 }
55
56 @Test // basically joining two or more resource queries
57 public void testAddResourceQueryBefore() {
58 CollectionQueryBuilder3 b = new CollectionQueryBuilder3();
59 b.addSegment("corpusID", CollectionQueryBuilder3.EQ.EQUAL, "ADF").and()
60 .addSub("textClass!=freizeit & corpusID=WPD");
61
62 // CollectionQueryBuilder3 join = new CollectionQueryBuilder3();
63 // join.addRaw(b.toJSON());
64 // join.addSegment("textClass", "politik");
65 // System.out.println("JOINED " + join.toJSON());
66 }
67
68 @Test
69 public void test1() {
70 CollectionQueryBuilder3 b = new CollectionQueryBuilder3();
71 b.addSegment("corpusID", CollectionQueryBuilder3.EQ.EQUAL, "ADF").or()
72 .addSub("textClass=freizeit & corpusID=WPD");
73
74 CollectionQueryBuilder3 c = new CollectionQueryBuilder3();
75 c.setBaseQuery(b.toJSON());
76 c.addSub("textClass=wissenschaft");
77
78 JsonNode node = JsonUtils.readTree(c.toJSON());
79
80 assert node != null;
81 assert node.at("/collection/operands/2/@type").asText()
82 .equals("koral:doc");
83 assert node.at("/collection/operands/2/value").asText()
84 .equals("wissenschaft");
85 }
86
87}