| Eliza Margaretha | 198e4ef | 2014-02-10 13:50:50 +0000 | [diff] [blame] | 1 | package de.ids_mannheim.korap.query; |
| 2 | |
| Eliza Margaretha | d69516c | 2014-11-24 11:36:02 +0000 | [diff] [blame] | 3 | /** |
| Eliza Margaretha | 7ebd6d9 | 2014-12-02 11:48:36 +0000 | [diff] [blame] | 4 | * DistanceConstraint specifies the constraints used in |
| Eliza Margaretha | 8551e5b | 2014-12-15 16:46:18 +0000 | [diff] [blame] | 5 | * {@link SpanDistanceQuery SpanDistanceQueries} or |
| 6 | * {@link SpanMultipleDistanceQuery SpanMultipleDistanceQueries}. The |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 7 | * constraints comprise the distance unit, the minimum and maximum |
| 8 | * distances, |
| Eliza Margaretha | 8551e5b | 2014-12-15 16:46:18 +0000 | [diff] [blame] | 9 | * the order and the co-occurence of the compared spans. |
| Eliza Margaretha | d69516c | 2014-11-24 11:36:02 +0000 | [diff] [blame] | 10 | * |
| Eliza Margaretha | 7ebd6d9 | 2014-12-02 11:48:36 +0000 | [diff] [blame] | 11 | * Distance constraint examples: |
| Eliza Margaretha | d69516c | 2014-11-24 11:36:02 +0000 | [diff] [blame] | 12 | * |
| Eliza Margaretha | 7ebd6d9 | 2014-12-02 11:48:36 +0000 | [diff] [blame] | 13 | * <ol> |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 14 | * <li>Two terms x and y are separated by minimum two and maximum |
| 15 | * three other |
| Eliza Margaretha | 7ebd6d9 | 2014-12-02 11:48:36 +0000 | [diff] [blame] | 16 | * words. The order of x and y does not matter. |
| 17 | * |
| 18 | * <pre> |
| 19 | * DistanceConstraint dc = new DistanceConstraint(2, 3, false, false); |
| 20 | * </pre> |
| 21 | * |
| 22 | * </li> |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 23 | * <li>Two terms x and y are separated by minimum two and maximum |
| 24 | * three other |
| Eliza Margaretha | 7ebd6d9 | 2014-12-02 11:48:36 +0000 | [diff] [blame] | 25 | * words. X must precede y. |
| 26 | * |
| 27 | * <pre> |
| 28 | * DistanceConstraint dc = new DistanceConstraint(2, 3, true, false); |
| 29 | * </pre> |
| 30 | * |
| 31 | * </li> |
| 32 | * <li> |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 33 | * Term x do not occur with term y in minimum two and maximum three |
| 34 | * other words. |
| Eliza Margaretha | 7ebd6d9 | 2014-12-02 11:48:36 +0000 | [diff] [blame] | 35 | * X must precede y. |
| 36 | * |
| 37 | * <pre> |
| 38 | * DistanceConstraint dc = new DistanceConstraint(2, 3, true, true); |
| 39 | * </pre> |
| 40 | * |
| 41 | * </li> |
| 42 | * <li>Two terms x and y separated by minimum one and maximum two |
| 43 | * <em>sentences</em>. X must precede y. |
| 44 | * |
| 45 | * <pre> |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 46 | * SpanElementQuery e = new SpanElementQuery("tokens", |
| 47 | * "s"); |
| 48 | * DistanceConstraint dc = new DistanceConstraint(e, 2, 3, true, |
| 49 | * false); |
| Eliza Margaretha | 7ebd6d9 | 2014-12-02 11:48:36 +0000 | [diff] [blame] | 50 | * </pre> |
| 51 | * |
| 52 | * </li> |
| 53 | * </ol> |
| Eliza Margaretha | d69516c | 2014-11-24 11:36:02 +0000 | [diff] [blame] | 54 | * |
| 55 | * @author margaretha |
| Eliza Margaretha | 0a41251 | 2014-02-28 12:52:16 +0000 | [diff] [blame] | 56 | * */ |
| 57 | |
| Eliza Margaretha | 198e4ef | 2014-02-10 13:50:50 +0000 | [diff] [blame] | 58 | public class DistanceConstraint { |
| Eliza Margaretha | d69516c | 2014-11-24 11:36:02 +0000 | [diff] [blame] | 59 | private int minDistance, maxDistance; |
| 60 | private String unit; |
| 61 | private SpanElementQuery elementQuery; |
| 62 | private boolean exclusion; |
| 63 | private boolean isOrdered; |
| Eliza Margaretha | 609fcc6 | 2014-02-13 14:10:20 +0000 | [diff] [blame] | 64 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 65 | |
| Eliza Margaretha | 8551e5b | 2014-12-15 16:46:18 +0000 | [diff] [blame] | 66 | /** |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 67 | * Constructs a DistanceConstraint object with the specified |
| 68 | * minimum and |
| 69 | * maximum distances. If isOrdered is true, the spans must occur |
| 70 | * in order. |
| 71 | * If exclusion is true, the second span must <em>not</em> occur |
| 72 | * together |
| Eliza Margaretha | 8551e5b | 2014-12-15 16:46:18 +0000 | [diff] [blame] | 73 | * with the first span. |
| 74 | * |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 75 | * @param min |
| 76 | * the minimum distance |
| 77 | * @param max |
| 78 | * the maximum distance |
| 79 | * @param isOrdered |
| 80 | * a boolean flag representing the value |
| 81 | * <code>true</code> |
| 82 | * if the spans should occur in order, false otherwise. |
| 83 | * @param exclusion |
| 84 | * a boolean flag representing the value |
| 85 | * <code>true</code>, |
| 86 | * if the second span should occur together with the |
| 87 | * first span, |
| 88 | * false otherwise. |
| Eliza Margaretha | 8551e5b | 2014-12-15 16:46:18 +0000 | [diff] [blame] | 89 | */ |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 90 | public DistanceConstraint (int min, int max, boolean isOrdered, |
| 91 | boolean exclusion) { |
| Eliza Margaretha | d69516c | 2014-11-24 11:36:02 +0000 | [diff] [blame] | 92 | this.unit = "w"; |
| 93 | this.minDistance = min; |
| 94 | this.maxDistance = max; |
| 95 | this.isOrdered = isOrdered; |
| 96 | this.exclusion = exclusion; |
| 97 | } |
| Eliza Margaretha | 609fcc6 | 2014-02-13 14:10:20 +0000 | [diff] [blame] | 98 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 99 | |
| Eliza Margaretha | 8551e5b | 2014-12-15 16:46:18 +0000 | [diff] [blame] | 100 | /** |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 101 | * Constructs a DistanceContraint object with the specified |
| 102 | * SpanElementQuery |
| Eliza Margaretha | 8551e5b | 2014-12-15 16:46:18 +0000 | [diff] [blame] | 103 | * as the distance unit, and the specified minimum and the maximum |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 104 | * distances. If isOrdered is true, the spans must occur in order. |
| 105 | * If |
| 106 | * exclusion is true, the second span must <em>not</em> occur |
| 107 | * together with |
| Eliza Margaretha | 8551e5b | 2014-12-15 16:46:18 +0000 | [diff] [blame] | 108 | * the first span. |
| 109 | * |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 110 | * @param elementQuery |
| 111 | * the distance unit |
| 112 | * @param min |
| 113 | * the minimum distance |
| 114 | * @param max |
| 115 | * the maximum distance |
| 116 | * @param isOrdered |
| 117 | * a boolean flag representing the value |
| 118 | * <code>true</code> |
| 119 | * if the spans should occur in order, false otherwise. |
| 120 | * @param exclusion |
| 121 | * a boolean flag representing the value |
| 122 | * <code>true</code>, |
| 123 | * if the second span should occur together with the |
| 124 | * first span, |
| 125 | * false otherwise. |
| Eliza Margaretha | 8551e5b | 2014-12-15 16:46:18 +0000 | [diff] [blame] | 126 | */ |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 127 | public DistanceConstraint (SpanElementQuery elementQuery, int min, int max, |
| 128 | boolean isOrdered, boolean exclusion) { |
| Eliza Margaretha | d69516c | 2014-11-24 11:36:02 +0000 | [diff] [blame] | 129 | if (elementQuery == null) { |
| 130 | throw new IllegalArgumentException("Element query cannot be null."); |
| 131 | } |
| Eliza Margaretha | d469346 | 2014-03-17 13:16:18 +0000 | [diff] [blame] | 132 | |
| Eliza Margaretha | d69516c | 2014-11-24 11:36:02 +0000 | [diff] [blame] | 133 | this.unit = elementQuery.getElementStr(); |
| 134 | this.minDistance = min; |
| 135 | this.maxDistance = max; |
| 136 | this.isOrdered = isOrdered; |
| 137 | this.exclusion = exclusion; |
| 138 | this.elementQuery = elementQuery; |
| 139 | } |
| Eliza Margaretha | d469346 | 2014-03-17 13:16:18 +0000 | [diff] [blame] | 140 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 141 | |
| Eliza Margaretha | 8551e5b | 2014-12-15 16:46:18 +0000 | [diff] [blame] | 142 | /** |
| 143 | * Returns the minimum distance. |
| 144 | * |
| 145 | * @return the minimum distance |
| 146 | */ |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 147 | public int getMinDistance () { |
| Eliza Margaretha | d69516c | 2014-11-24 11:36:02 +0000 | [diff] [blame] | 148 | return minDistance; |
| 149 | } |
| 150 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 151 | |
| Eliza Margaretha | 8551e5b | 2014-12-15 16:46:18 +0000 | [diff] [blame] | 152 | /** |
| 153 | * Sets the minimum distance. |
| 154 | * |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 155 | * @param minDistance |
| 156 | * the minimum distance |
| Eliza Margaretha | 8551e5b | 2014-12-15 16:46:18 +0000 | [diff] [blame] | 157 | */ |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 158 | public void setMinDistance (int minDistance) { |
| Eliza Margaretha | d69516c | 2014-11-24 11:36:02 +0000 | [diff] [blame] | 159 | this.minDistance = minDistance; |
| 160 | } |
| 161 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 162 | |
| Eliza Margaretha | 8551e5b | 2014-12-15 16:46:18 +0000 | [diff] [blame] | 163 | /** |
| 164 | * Returns the maximum distance. |
| 165 | * |
| 166 | * @return the maximum distance |
| 167 | */ |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 168 | public int getMaxDistance () { |
| Eliza Margaretha | d69516c | 2014-11-24 11:36:02 +0000 | [diff] [blame] | 169 | return maxDistance; |
| 170 | } |
| 171 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 172 | |
| Eliza Margaretha | 8551e5b | 2014-12-15 16:46:18 +0000 | [diff] [blame] | 173 | /** |
| 174 | * Sets the maximum distance. |
| 175 | * |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 176 | * @param maxDistance |
| 177 | * the maximum distance |
| Eliza Margaretha | 8551e5b | 2014-12-15 16:46:18 +0000 | [diff] [blame] | 178 | */ |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 179 | public void setMaxDistance (int maxDistance) { |
| Eliza Margaretha | d69516c | 2014-11-24 11:36:02 +0000 | [diff] [blame] | 180 | this.maxDistance = maxDistance; |
| 181 | } |
| 182 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 183 | |
| Eliza Margaretha | 8551e5b | 2014-12-15 16:46:18 +0000 | [diff] [blame] | 184 | /** |
| 185 | * Returns the distance unit. |
| 186 | * |
| 187 | * @return the distance unit |
| 188 | */ |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 189 | public String getUnit () { |
| Eliza Margaretha | d69516c | 2014-11-24 11:36:02 +0000 | [diff] [blame] | 190 | return unit; |
| 191 | } |
| 192 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 193 | |
| Eliza Margaretha | 8551e5b | 2014-12-15 16:46:18 +0000 | [diff] [blame] | 194 | /** |
| 195 | * Sets the distance unit. |
| 196 | * |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 197 | * @param unit |
| 198 | * the distance unit |
| Eliza Margaretha | 8551e5b | 2014-12-15 16:46:18 +0000 | [diff] [blame] | 199 | */ |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 200 | public void setUnit (String unit) { |
| Eliza Margaretha | d69516c | 2014-11-24 11:36:02 +0000 | [diff] [blame] | 201 | this.unit = unit; |
| 202 | } |
| 203 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 204 | |
| Eliza Margaretha | 8551e5b | 2014-12-15 16:46:18 +0000 | [diff] [blame] | 205 | /** |
| 206 | * Returns the element query used as the distance unit. |
| 207 | * |
| 208 | * @return the element query used as the distance unit |
| 209 | */ |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 210 | public SpanElementQuery getElementQuery () { |
| Eliza Margaretha | d69516c | 2014-11-24 11:36:02 +0000 | [diff] [blame] | 211 | return elementQuery; |
| 212 | } |
| 213 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 214 | |
| Eliza Margaretha | 8551e5b | 2014-12-15 16:46:18 +0000 | [diff] [blame] | 215 | /** |
| 216 | * Sets the element query used as the distance unit. |
| 217 | * |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 218 | * @param elementQuery |
| 219 | * the element query used as the distance unit. |
| Eliza Margaretha | 8551e5b | 2014-12-15 16:46:18 +0000 | [diff] [blame] | 220 | */ |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 221 | public void setElementQuery (SpanElementQuery elementQuery) { |
| Eliza Margaretha | d69516c | 2014-11-24 11:36:02 +0000 | [diff] [blame] | 222 | this.elementQuery = elementQuery; |
| 223 | } |
| 224 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 225 | |
| Eliza Margaretha | 8551e5b | 2014-12-15 16:46:18 +0000 | [diff] [blame] | 226 | /** |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 227 | * Tells if the second span must occur together with the first |
| 228 | * span, or not. |
| Eliza Margaretha | 8551e5b | 2014-12-15 16:46:18 +0000 | [diff] [blame] | 229 | * |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 230 | * @return <code>true</code> if the second span must <em>not</em> |
| 231 | * occur |
| 232 | * together with the first span, <code>false</code> |
| 233 | * otherwise. |
| Eliza Margaretha | 8551e5b | 2014-12-15 16:46:18 +0000 | [diff] [blame] | 234 | */ |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 235 | public boolean isExclusion () { |
| Eliza Margaretha | d69516c | 2014-11-24 11:36:02 +0000 | [diff] [blame] | 236 | return exclusion; |
| 237 | } |
| 238 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 239 | |
| Eliza Margaretha | 8551e5b | 2014-12-15 16:46:18 +0000 | [diff] [blame] | 240 | /** |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 241 | * Sets <code>true</code> if the second span must <em>not</em> |
| 242 | * occur |
| Eliza Margaretha | 8551e5b | 2014-12-15 16:46:18 +0000 | [diff] [blame] | 243 | * together with the first span, <code>false</code> otherwise. |
| 244 | * |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 245 | * @param exclusion |
| 246 | * a boolean with value <code>true</code> if the second |
| 247 | * span must <em>not</em> occur together with the first |
| 248 | * span, |
| 249 | * <code>false</code> otherwise. |
| Eliza Margaretha | 8551e5b | 2014-12-15 16:46:18 +0000 | [diff] [blame] | 250 | */ |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 251 | public void setExclusion (boolean exclusion) { |
| Eliza Margaretha | d69516c | 2014-11-24 11:36:02 +0000 | [diff] [blame] | 252 | this.exclusion = exclusion; |
| 253 | } |
| 254 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 255 | |
| Eliza Margaretha | 8551e5b | 2014-12-15 16:46:18 +0000 | [diff] [blame] | 256 | /** |
| 257 | * Tells if the spans must occur in order or not. |
| 258 | * |
| 259 | * @return <code>true</code> if the spans must occur in order, |
| 260 | * <code>false</code> otherwise. |
| 261 | */ |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 262 | public boolean isOrdered () { |
| Eliza Margaretha | d69516c | 2014-11-24 11:36:02 +0000 | [diff] [blame] | 263 | return isOrdered; |
| 264 | } |
| 265 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 266 | |
| Eliza Margaretha | 8551e5b | 2014-12-15 16:46:18 +0000 | [diff] [blame] | 267 | /** |
| 268 | * Sets if the spans must occur in order or not. |
| 269 | * |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 270 | * @param isOrdered |
| 271 | * a boolean with value <code>true</code> if the spans |
| 272 | * must |
| 273 | * occur in order, <code>false</code> otherwise. |
| Eliza Margaretha | 8551e5b | 2014-12-15 16:46:18 +0000 | [diff] [blame] | 274 | */ |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 275 | public void setOrdered (boolean isOrdered) { |
| Eliza Margaretha | d69516c | 2014-11-24 11:36:02 +0000 | [diff] [blame] | 276 | this.isOrdered = isOrdered; |
| 277 | } |
| Eliza Margaretha | 198e4ef | 2014-02-10 13:50:50 +0000 | [diff] [blame] | 278 | } |