Michael Hanl | fb839b9 | 2015-09-19 21:32:34 +0200 | [diff] [blame] | 1 | import com.fasterxml.jackson.databind.JsonNode; |
Michael Hanl | 1939065 | 2016-01-16 11:01:24 +0100 | [diff] [blame] | 2 | import de.ids_mannheim.korap.query.serialize.QuerySerializer; |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 3 | import de.ids_mannheim.korap.utils.KoralCollectionQueryBuilder; |
Michael Hanl | fb839b9 | 2015-09-19 21:32:34 +0200 | [diff] [blame] | 4 | import de.ids_mannheim.korap.utils.JsonUtils; |
Michael Hanl | cedf721 | 2016-05-28 10:43:09 +0200 | [diff] [blame] | 5 | import org.junit.Ignore; |
Michael Hanl | fb839b9 | 2015-09-19 21:32:34 +0200 | [diff] [blame] | 6 | import org.junit.Test; |
| 7 | |
Michael Hanl | daf8660 | 2016-05-12 14:31:52 +0200 | [diff] [blame] | 8 | import static org.junit.Assert.assertEquals; |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 9 | import static org.junit.Assert.assertNotEquals; |
Michael Hanl | daf8660 | 2016-05-12 14:31:52 +0200 | [diff] [blame] | 10 | import static org.junit.Assert.assertNotNull; |
| 11 | |
Michael Hanl | fb839b9 | 2015-09-19 21:32:34 +0200 | [diff] [blame] | 12 | /** |
| 13 | * @author hanl |
| 14 | * @date 12/08/2015 |
| 15 | */ |
| 16 | public class CollectionQueryBuilderTest { |
| 17 | |
| 18 | @Test |
Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 19 | public void testsimpleAdd () { |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 20 | KoralCollectionQueryBuilder b = new KoralCollectionQueryBuilder(); |
| 21 | b.with("corpusSigle=WPD"); |
Michael Hanl | 482f30d | 2015-09-25 12:39:46 +0200 | [diff] [blame] | 22 | |
| 23 | JsonNode node = JsonUtils.readTree(b.toJSON()); |
| 24 | |
Michael Hanl | daf8660 | 2016-05-12 14:31:52 +0200 | [diff] [blame] | 25 | assertNotNull(node); |
Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 26 | assertEquals("koral:doc", node.at("/collection/@type").asText()); |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 27 | assertEquals("corpusSigle", node.at("/collection/key").asText()); |
Michael Hanl | fb839b9 | 2015-09-19 21:32:34 +0200 | [diff] [blame] | 28 | } |
| 29 | |
Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 30 | |
Michael Hanl | fb839b9 | 2015-09-19 21:32:34 +0200 | [diff] [blame] | 31 | @Test |
Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 32 | public void testSimpleConjunction () { |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 33 | KoralCollectionQueryBuilder b = new KoralCollectionQueryBuilder(); |
| 34 | b.with("corpusSigle=WPD & textClass=freizeit"); |
Michael Hanl | 482f30d | 2015-09-25 12:39:46 +0200 | [diff] [blame] | 35 | JsonNode node = JsonUtils.readTree(b.toJSON()); |
| 36 | |
Michael Hanl | daf8660 | 2016-05-12 14:31:52 +0200 | [diff] [blame] | 37 | assertNotNull(node); |
Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 38 | assertEquals("koral:docGroup", node.at("/collection/@type").asText()); |
| 39 | assertEquals("operation:and", node.at("/collection/operation").asText()); |
Michael Hanl | daf8660 | 2016-05-12 14:31:52 +0200 | [diff] [blame] | 40 | |
Michael Hanl | 33829ec | 2016-05-28 17:03:38 +0200 | [diff] [blame] | 41 | assertEquals("corpusSigle", node.at("/collection/operands/0/key") |
| 42 | .asText()); |
Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 43 | assertEquals("textClass", node.at("/collection/operands/1/key") |
| 44 | .asText()); |
Michael Hanl | fb839b9 | 2015-09-19 21:32:34 +0200 | [diff] [blame] | 45 | } |
| 46 | |
Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 47 | |
Michael Hanl | fb839b9 | 2015-09-19 21:32:34 +0200 | [diff] [blame] | 48 | @Test |
Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 49 | public void testSimpleDisjunction () { |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 50 | KoralCollectionQueryBuilder b = new KoralCollectionQueryBuilder(); |
| 51 | b.with("corpusSigle=WPD | textClass=freizeit"); |
Michael Hanl | 482f30d | 2015-09-25 12:39:46 +0200 | [diff] [blame] | 52 | JsonNode node = JsonUtils.readTree(b.toJSON()); |
| 53 | |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 54 | assertNotNull(node); |
Michael Hanl | 482f30d | 2015-09-25 12:39:46 +0200 | [diff] [blame] | 55 | assert node.at("/collection/operation").asText().equals("operation:or"); |
| 56 | assert node.at("/collection/operands/0/key").asText() |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 57 | .equals("corpusSigle"); |
Michael Hanl | 482f30d | 2015-09-25 12:39:46 +0200 | [diff] [blame] | 58 | assert node.at("/collection/operands/1/key").asText() |
| 59 | .equals("textClass"); |
Michael Hanl | fb839b9 | 2015-09-19 21:32:34 +0200 | [diff] [blame] | 60 | } |
| 61 | |
Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 62 | |
Michael Hanl | fb839b9 | 2015-09-19 21:32:34 +0200 | [diff] [blame] | 63 | @Test |
Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 64 | public void testComplexSubQuery () { |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 65 | KoralCollectionQueryBuilder b = new KoralCollectionQueryBuilder(); |
| 66 | b.with("(corpusSigle=WPD) | (textClass=freizeit & corpusSigle=BRZ13)"); |
Michael Hanl | 482f30d | 2015-09-25 12:39:46 +0200 | [diff] [blame] | 67 | JsonNode node = JsonUtils.readTree(b.toJSON()); |
Michael Hanl | fb839b9 | 2015-09-19 21:32:34 +0200 | [diff] [blame] | 68 | |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 69 | assertNotNull(node); |
Michael Hanl | 482f30d | 2015-09-25 12:39:46 +0200 | [diff] [blame] | 70 | assert node.at("/collection/operation").asText().equals("operation:or"); |
| 71 | assert node.at("/collection/operands/0/key").asText() |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 72 | .equals("corpusSigle"); |
Michael Hanl | 482f30d | 2015-09-25 12:39:46 +0200 | [diff] [blame] | 73 | assert node.at("/collection/operands/1/@type").asText() |
| 74 | .equals("koral:docGroup"); |
Michael Hanl | fb839b9 | 2015-09-19 21:32:34 +0200 | [diff] [blame] | 75 | |
Michael Hanl | fb839b9 | 2015-09-19 21:32:34 +0200 | [diff] [blame] | 76 | } |
| 77 | |
Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 78 | |
Michael Hanl | fb839b9 | 2015-09-19 21:32:34 +0200 | [diff] [blame] | 79 | @Test |
Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 80 | public void testAddResourceQueryAfter () { |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 81 | KoralCollectionQueryBuilder b = new KoralCollectionQueryBuilder(); |
| 82 | b.with("(textClass=politik & title=\"random title\") | textClass=wissenschaft"); |
Michael Hanl | fb839b9 | 2015-09-19 21:32:34 +0200 | [diff] [blame] | 83 | |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 84 | KoralCollectionQueryBuilder c = new KoralCollectionQueryBuilder(); |
Michael Hanl | fb839b9 | 2015-09-19 21:32:34 +0200 | [diff] [blame] | 85 | c.setBaseQuery(b.toJSON()); |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 86 | c.with("corpusSigle=WPD"); |
Michael Hanl | fb839b9 | 2015-09-19 21:32:34 +0200 | [diff] [blame] | 87 | |
| 88 | JsonNode node = JsonUtils.readTree(c.toJSON()); |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 89 | assertNotNull(node); |
Michael Hanl | cedf721 | 2016-05-28 10:43:09 +0200 | [diff] [blame] | 90 | assertEquals("koral:doc", node.at("/collection/operands/1/@type") |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 91 | .asText()); |
Michael Hanl | cedf721 | 2016-05-28 10:43:09 +0200 | [diff] [blame] | 92 | assertEquals("koral:docGroup", node.at("/collection/operands/0/@type") |
| 93 | .asText()); |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 94 | assertEquals(2, node.at("/collection/operands").size()); |
Michael Hanl | cedf721 | 2016-05-28 10:43:09 +0200 | [diff] [blame] | 95 | assertEquals(2, node.at("/collection/operands/0/operands").size()); |
Michael Hanl | 33829ec | 2016-05-28 17:03:38 +0200 | [diff] [blame] | 96 | assertEquals(2, node.at("/collection/operands/0/operands/0/operands") |
| 97 | .size()); |
Michael Hanl | cedf721 | 2016-05-28 10:43:09 +0200 | [diff] [blame] | 98 | |
| 99 | assertEquals("operation:and", node.at("/collection/operation").asText()); |
Michael Hanl | 33829ec | 2016-05-28 17:03:38 +0200 | [diff] [blame] | 100 | assertEquals("operation:or", node |
| 101 | .at("/collection/operands/0/operation").asText()); |
| 102 | assertEquals("operation:and", |
| 103 | node.at("/collection/operands/0/operands/0/operation").asText()); |
Michael Hanl | cedf721 | 2016-05-28 10:43:09 +0200 | [diff] [blame] | 104 | assertEquals("WPD", node.at("/collection/operands/1/value").asText()); |
Michael Hanl | fb839b9 | 2015-09-19 21:32:34 +0200 | [diff] [blame] | 105 | } |
| 106 | |
Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 107 | |
Michael Hanl | 482f30d | 2015-09-25 12:39:46 +0200 | [diff] [blame] | 108 | @Test |
Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 109 | public void testAddComplexResourceQueryAfter () { |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 110 | KoralCollectionQueryBuilder b = new KoralCollectionQueryBuilder(); |
| 111 | b.with("(title=\"random title\") | (textClass=wissenschaft)"); |
Michael Hanl | 482f30d | 2015-09-25 12:39:46 +0200 | [diff] [blame] | 112 | |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 113 | KoralCollectionQueryBuilder c = new KoralCollectionQueryBuilder(); |
Michael Hanl | 482f30d | 2015-09-25 12:39:46 +0200 | [diff] [blame] | 114 | c.setBaseQuery(b.toJSON()); |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 115 | c.with("(corpusSigle=BRZ13 | corpusSigle=AZPS)"); |
Michael Hanl | 482f30d | 2015-09-25 12:39:46 +0200 | [diff] [blame] | 116 | |
| 117 | JsonNode node = JsonUtils.readTree(c.toJSON()); |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 118 | assertNotNull(node); |
| 119 | assertEquals("koral:docGroup", node.at("/collection/operands/0/@type") |
| 120 | .asText()); |
| 121 | assertEquals("koral:docGroup", node.at("/collection/operands/1/@type") |
| 122 | .asText()); |
| 123 | assertEquals("BRZ13", node |
Michael Hanl | cedf721 | 2016-05-28 10:43:09 +0200 | [diff] [blame] | 124 | .at("/collection/operands/1/operands/0/value").asText()); |
| 125 | assertEquals("AZPS", node.at("/collection/operands/1/operands/1/value") |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 126 | .asText()); |
| 127 | assertEquals("random title", |
Michael Hanl | cedf721 | 2016-05-28 10:43:09 +0200 | [diff] [blame] | 128 | node.at("/collection/operands/0/operands/0/value").asText()); |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 129 | assertEquals("wissenschaft", |
Michael Hanl | cedf721 | 2016-05-28 10:43:09 +0200 | [diff] [blame] | 130 | node.at("/collection/operands/0/operands/1/value").asText()); |
Michael Hanl | 482f30d | 2015-09-25 12:39:46 +0200 | [diff] [blame] | 131 | } |
| 132 | |
Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 133 | |
Michael Hanl | 1939065 | 2016-01-16 11:01:24 +0100 | [diff] [blame] | 134 | @Test |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 135 | public void testBuildQuery () { |
| 136 | String coll = "corpusSigle=WPD"; |
Michael Hanl | 1939065 | 2016-01-16 11:01:24 +0100 | [diff] [blame] | 137 | String query = "[base=Haus]"; |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 138 | QuerySerializer check = new QuerySerializer(); |
| 139 | check.setQuery(query, "poliqarp"); |
| 140 | check.setCollection(coll); |
Michael Hanl | 1939065 | 2016-01-16 11:01:24 +0100 | [diff] [blame] | 141 | |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 142 | KoralCollectionQueryBuilder b = new KoralCollectionQueryBuilder(); |
| 143 | b.setBaseQuery(check.toJSON()); |
| 144 | b.with("textClass=freizeit"); |
| 145 | |
| 146 | JsonNode res = (JsonNode) b.rebaseCollection(); |
| 147 | assertNotNull(res); |
| 148 | assertEquals("koral:docGroup", res.at("/collection/@type").asText()); |
| 149 | assertEquals("operation:and", res.at("/collection/operation").asText()); |
| 150 | assertEquals("koral:doc", res.at("/collection/operands/0/@type") |
| 151 | .asText()); |
Michael Hanl | cedf721 | 2016-05-28 10:43:09 +0200 | [diff] [blame] | 152 | assertEquals("freizeit", res.at("/collection/operands/1/value") |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 153 | .asText()); |
Michael Hanl | cedf721 | 2016-05-28 10:43:09 +0200 | [diff] [blame] | 154 | assertEquals("textClass", res.at("/collection/operands/1/key").asText()); |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 155 | |
| 156 | assertEquals("koral:doc", res.at("/collection/operands/1/@type") |
| 157 | .asText()); |
Michael Hanl | cedf721 | 2016-05-28 10:43:09 +0200 | [diff] [blame] | 158 | assertEquals("WPD", res.at("/collection/operands/0/value").asText()); |
Michael Hanl | 33829ec | 2016-05-28 17:03:38 +0200 | [diff] [blame] | 159 | assertEquals("corpusSigle", res.at("/collection/operands/0/key") |
| 160 | .asText()); |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 161 | |
| 162 | // check also that query is still there |
| 163 | assertEquals("koral:token", res.at("/query/@type").asText()); |
| 164 | assertEquals("koral:term", res.at("/query/wrap/@type").asText()); |
| 165 | assertEquals("Haus", res.at("/query/wrap/key").asText()); |
| 166 | assertEquals("lemma", res.at("/query/wrap/layer").asText()); |
Michael Hanl | 1939065 | 2016-01-16 11:01:24 +0100 | [diff] [blame] | 167 | } |
| 168 | |
Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 169 | |
Michael Hanl | 1939065 | 2016-01-16 11:01:24 +0100 | [diff] [blame] | 170 | @Test |
Michael Hanl | 8abaf9e | 2016-05-23 16:46:35 +0200 | [diff] [blame] | 171 | public void testBaseQueryBuild () { |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 172 | KoralCollectionQueryBuilder b = new KoralCollectionQueryBuilder(); |
| 173 | b.with("(corpusSigle=ADF) | (textClass=freizeit & corpusSigle=WPD)"); |
| 174 | |
| 175 | KoralCollectionQueryBuilder c = new KoralCollectionQueryBuilder(); |
| 176 | c.setBaseQuery(b.toJSON()); |
| 177 | |
| 178 | c.with("corpusSigle=BRZ13"); |
| 179 | JsonNode base = (JsonNode) c.rebaseCollection(); |
| 180 | assertNotNull(base); |
| 181 | assertEquals(base.at("/collection/@type").asText(), "koral:docGroup"); |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 182 | assertEquals(base.at("/collection/operands/1/@type").asText(), |
Michael Hanl | cedf721 | 2016-05-28 10:43:09 +0200 | [diff] [blame] | 183 | "koral:doc"); |
| 184 | assertEquals(base.at("/collection/operands/1/value").asText(), "BRZ13"); |
| 185 | assertEquals(base.at("/collection/operands/0/@type").asText(), |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 186 | "koral:docGroup"); |
Michael Hanl | cedf721 | 2016-05-28 10:43:09 +0200 | [diff] [blame] | 187 | assertEquals(base.at("/collection/operands/0/operands").size(), 2); |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 188 | } |
| 189 | |
Michael Hanl | 33829ec | 2016-05-28 17:03:38 +0200 | [diff] [blame] | 190 | |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 191 | @Test |
Michael Hanl | 33829ec | 2016-05-28 17:03:38 +0200 | [diff] [blame] | 192 | public void testNodeMergeWithBase () { |
Michael Hanl | 00b64e0 | 2016-05-24 20:24:27 +0200 | [diff] [blame] | 193 | String coll = "corpusSigle=WPD"; |
| 194 | String query = "[base=Haus]"; |
| 195 | QuerySerializer check = new QuerySerializer(); |
| 196 | check.setQuery(query, "poliqarp"); |
| 197 | check.setCollection(coll); |
| 198 | |
| 199 | KoralCollectionQueryBuilder b = new KoralCollectionQueryBuilder(); |
| 200 | b.setBaseQuery(check.toJSON()); |
| 201 | |
| 202 | KoralCollectionQueryBuilder test = new KoralCollectionQueryBuilder(); |
| 203 | test.with("textClass=wissenschaft | textClass=politik"); |
| 204 | JsonNode node = (JsonNode) test.rebaseCollection(); |
| 205 | node = b.mergeWith(node); |
| 206 | assertNotNull(node); |
| 207 | assertEquals("koral:docGroup", node.at("/collection/@type").asText()); |
| 208 | assertEquals("operation:and", node.at("/collection/operation").asText()); |
| 209 | assertEquals(2, node.at("/collection/operands").size()); |
| 210 | } |
| 211 | |
| 212 | |
| 213 | @Test |
| 214 | public void testStoredCollectionBaseQueryBuild () { |
Michael Hanl | 1939065 | 2016-01-16 11:01:24 +0100 | [diff] [blame] | 215 | |
| 216 | } |
| 217 | |
Michael Hanl | 33829ec | 2016-05-28 17:03:38 +0200 | [diff] [blame] | 218 | |
Michael Hanl | cedf721 | 2016-05-28 10:43:09 +0200 | [diff] [blame] | 219 | @Test |
Michael Hanl | 33829ec | 2016-05-28 17:03:38 +0200 | [diff] [blame] | 220 | public void testAddOROperator () { |
Michael Hanl | cedf721 | 2016-05-28 10:43:09 +0200 | [diff] [blame] | 221 | String coll = "corpusSigle=WPD"; |
| 222 | String query = "[base=Haus]"; |
| 223 | QuerySerializer check = new QuerySerializer(); |
| 224 | check.setQuery(query, "poliqarp"); |
| 225 | check.setCollection(coll); |
| 226 | |
| 227 | KoralCollectionQueryBuilder test = new KoralCollectionQueryBuilder(); |
| 228 | test.setBaseQuery(check.toJSON()); |
| 229 | test.or().with("textClass=wissenschaft | textClass=politik"); |
| 230 | JsonNode node = (JsonNode) test.rebaseCollection(); |
| 231 | assertNotNull(node); |
| 232 | assertEquals("koral:docGroup", node.at("/collection/@type").asText()); |
| 233 | assertEquals("operation:or", node.at("/collection/operation").asText()); |
| 234 | assertEquals(2, node.at("/collection/operands/1/operands").size()); |
| 235 | } |
| 236 | |
Michael Hanl | 33829ec | 2016-05-28 17:03:38 +0200 | [diff] [blame] | 237 | |
Michael Hanl | cedf721 | 2016-05-28 10:43:09 +0200 | [diff] [blame] | 238 | @Test |
Michael Hanl | 33829ec | 2016-05-28 17:03:38 +0200 | [diff] [blame] | 239 | public void testAddANDOperator () { |
Michael Hanl | cedf721 | 2016-05-28 10:43:09 +0200 | [diff] [blame] | 240 | String coll = "corpusSigle=WPD"; |
| 241 | String query = "[base=Haus]"; |
| 242 | QuerySerializer check = new QuerySerializer(); |
| 243 | check.setQuery(query, "poliqarp"); |
| 244 | check.setCollection(coll); |
| 245 | |
| 246 | KoralCollectionQueryBuilder test = new KoralCollectionQueryBuilder(); |
| 247 | test.setBaseQuery(check.toJSON()); |
| 248 | test.and().with("textClass=wissenschaft | textClass=politik"); |
| 249 | JsonNode node = (JsonNode) test.rebaseCollection(); |
| 250 | assertNotNull(node); |
| 251 | assertEquals("koral:docGroup", node.at("/collection/@type").asText()); |
| 252 | assertEquals("operation:and", node.at("/collection/operation").asText()); |
| 253 | assertEquals(2, node.at("/collection/operands/1/operands").size()); |
| 254 | } |
| 255 | |
Michael Hanl | 33829ec | 2016-05-28 17:03:38 +0200 | [diff] [blame] | 256 | |
Michael Hanl | cedf721 | 2016-05-28 10:43:09 +0200 | [diff] [blame] | 257 | @Test |
Michael Hanl | 33829ec | 2016-05-28 17:03:38 +0200 | [diff] [blame] | 258 | public void testAddDefaultOperator () { |
Michael Hanl | cedf721 | 2016-05-28 10:43:09 +0200 | [diff] [blame] | 259 | String coll = "corpusSigle=WPD"; |
| 260 | String query = "[base=Haus]"; |
| 261 | QuerySerializer check = new QuerySerializer(); |
| 262 | check.setQuery(query, "poliqarp"); |
| 263 | check.setCollection(coll); |
| 264 | |
| 265 | KoralCollectionQueryBuilder test = new KoralCollectionQueryBuilder(); |
| 266 | test.setBaseQuery(check.toJSON()); |
| 267 | test.with("textClass=wissenschaft | textClass=politik"); |
| 268 | JsonNode node = (JsonNode) test.rebaseCollection(); |
| 269 | assertNotNull(node); |
| 270 | assertEquals("koral:docGroup", node.at("/collection/@type").asText()); |
| 271 | assertEquals("operation:and", node.at("/collection/operation").asText()); |
| 272 | assertEquals(2, node.at("/collection/operands/1/operands").size()); |
| 273 | } |
| 274 | |
Michael Hanl | 33829ec | 2016-05-28 17:03:38 +0200 | [diff] [blame] | 275 | |
Michael Hanl | cedf721 | 2016-05-28 10:43:09 +0200 | [diff] [blame] | 276 | @Test |
| 277 | @Ignore |
Michael Hanl | 33829ec | 2016-05-28 17:03:38 +0200 | [diff] [blame] | 278 | public void testMergeOperator () { |
Michael Hanl | cedf721 | 2016-05-28 10:43:09 +0200 | [diff] [blame] | 279 | String coll = "corpusSigle=WPD"; |
| 280 | String query = "[base=Haus]"; |
| 281 | QuerySerializer check = new QuerySerializer(); |
| 282 | check.setQuery(query, "poliqarp"); |
| 283 | check.setCollection(coll); |
| 284 | |
| 285 | KoralCollectionQueryBuilder b = new KoralCollectionQueryBuilder(); |
| 286 | b.setBaseQuery(check.toJSON()); |
| 287 | |
| 288 | KoralCollectionQueryBuilder test = new KoralCollectionQueryBuilder(); |
| 289 | test.with("textClass=wissenschaft | textClass=politik"); |
| 290 | JsonNode node = (JsonNode) test.rebaseCollection(); |
| 291 | node = b.mergeWith(node); |
| 292 | assertNotNull(node); |
| 293 | assertEquals("koral:docGroup", node.at("/collection/@type").asText()); |
| 294 | assertEquals("operation:and", node.at("/collection/operation").asText()); |
| 295 | assertEquals(2, node.at("/collection/operands").size()); |
| 296 | } |
| 297 | |
Michael Hanl | fb839b9 | 2015-09-19 21:32:34 +0200 | [diff] [blame] | 298 | } |