| Nils Diewald | 92729ce | 2014-10-06 16:00:17 +0000 | [diff] [blame] | 1 | package de.ids_mannheim.korap.query.wrap; |
| 2 | |
| 3 | import org.apache.lucene.search.spans.SpanQuery; |
| Nils Diewald | be5943e | 2014-10-21 19:35:34 +0000 | [diff] [blame] | 4 | import de.ids_mannheim.korap.util.QueryException; |
| Akron | a7b936d | 2016-03-04 13:40:54 +0100 | [diff] [blame] | 5 | import de.ids_mannheim.korap.query.SpanFocusQuery; |
| 6 | import de.ids_mannheim.korap.query.SpanClassQuery; |
| 7 | import de.ids_mannheim.korap.query.SpanWithinQuery; |
| Nils Diewald | 92729ce | 2014-10-06 16:00:17 +0000 | [diff] [blame] | 8 | |
| Nils Diewald | 0339d46 | 2015-02-26 14:53:56 +0000 | [diff] [blame] | 9 | // TODO: Add warnings and errors - using KrillQuery |
| Nils Diewald | 92729ce | 2014-10-06 16:00:17 +0000 | [diff] [blame] | 10 | |
| 11 | /** |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 12 | * A wrapper base class for Lucene SpanQueries, |
| 13 | * that add certain information, |
| 14 | * necessary for the correct and optimized |
| 15 | * deserialization of nested queries. |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 16 | * |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 17 | * This class is meant to be extended by |
| 18 | * wrapper classes. |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 19 | * |
| Nils Diewald | 6535c52 | 2015-02-26 17:45:24 +0000 | [diff] [blame] | 20 | * <strong>Warning</strong>: SpanQueryWrapper |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 21 | * will probably be merged with {@link KrillQuery} in near future. Use |
| 22 | * of this API is on your own risk. |
| 23 | * |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 24 | * @author diewald |
| Nils Diewald | 92729ce | 2014-10-06 16:00:17 +0000 | [diff] [blame] | 25 | */ |
| 26 | public class SpanQueryWrapper { |
| Nils Diewald | 92729ce | 2014-10-06 16:00:17 +0000 | [diff] [blame] | 27 | |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 28 | // Boundaries, e.g. for repetitions |
| 29 | protected int min = 1, max = 1; |
| 30 | |
| 31 | // Class number |
| Nils Diewald | be5943e | 2014-10-21 19:35:34 +0000 | [diff] [blame] | 32 | protected byte number = (byte) 0; |
| Nils Diewald | be5943e | 2014-10-21 19:35:34 +0000 | [diff] [blame] | 33 | |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 34 | // Boolean properties |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 35 | protected boolean hasClass = false, isNull = true, isOptional = false, |
| 36 | isNegative = false, isEmpty = false, isExtended = false, |
| 37 | isExtendedToTheRight = false, maybeUnsorted = false, |
| 38 | retrieveNode = false; |
| 39 | |
| Nils Diewald | be5943e | 2014-10-21 19:35:34 +0000 | [diff] [blame] | 40 | |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 41 | /** |
| 42 | * Serialize the wrapped query and return a SpanQuery. |
| 43 | * This should be overwritten. |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 44 | * |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 45 | * @return A {@link SpanQuery} object. |
| 46 | * @throws QueryException |
| 47 | */ |
| Akron | a7b936d | 2016-03-04 13:40:54 +0100 | [diff] [blame] | 48 | public SpanQuery toFragmentQuery () throws QueryException { |
| 49 | System.err.println("||||||||||||||||||||||||||"); |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 50 | return (SpanQuery) null; |
| Nils Diewald | 92729ce | 2014-10-06 16:00:17 +0000 | [diff] [blame] | 51 | }; |
| 52 | |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 53 | |
| Akron | a7b936d | 2016-03-04 13:40:54 +0100 | [diff] [blame] | 54 | |
| 55 | /** |
| 56 | * Serialize the wrapped query and return a SpanQuery. |
| 57 | * This will be the final query and may be rewritten. |
| 58 | * |
| 59 | * @return A {@link SpanQuery} object. |
| 60 | * @throws QueryException |
| 61 | */ |
| 62 | public SpanQuery toQuery () throws QueryException { |
| 63 | |
| 64 | if (this.isNull() || this.isEmpty()) |
| 65 | return null; |
| 66 | |
| 67 | // Wrap the query in a <base/s=t>, if it's extended to the right |
| 68 | if (this.isExtendedToTheRight()) { |
| Akron | 6759b04 | 2016-04-28 01:25:00 +0200 | [diff] [blame^] | 69 | return new SpanFocusQuery(new SpanWithinQuery("base/s:t", |
| 70 | new SpanClassQuery(this.toFragmentQuery(), (byte) 254)), |
| 71 | (byte) 254); |
| Akron | a7b936d | 2016-03-04 13:40:54 +0100 | [diff] [blame] | 72 | }; |
| 73 | |
| 74 | return this.toFragmentQuery(); |
| 75 | }; |
| 76 | |
| Akron | 6759b04 | 2016-04-28 01:25:00 +0200 | [diff] [blame^] | 77 | |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 78 | /** |
| 79 | * Boolean value indicating that the wrapped query |
| 80 | * is optional. |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 81 | * |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 82 | * For example the segment denoting an adjective |
| 83 | * in the following Poliqarp expression is optional. |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 84 | * |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 85 | * <blockquote><pre> |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 86 | * the [pos=ADJ]? tree |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 87 | * </pre></blockquote> |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 88 | * |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 89 | * @return <tt>true</tt> in case the wrapped query is |
| 90 | * optional and <tt>false</tt> in case it is |
| 91 | * mandatory. |
| 92 | */ |
| Nils Diewald | 92729ce | 2014-10-06 16:00:17 +0000 | [diff] [blame] | 93 | public boolean isOptional () { |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 94 | return this.isOptional; |
| Nils Diewald | 92729ce | 2014-10-06 16:00:17 +0000 | [diff] [blame] | 95 | }; |
| 96 | |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 97 | |
| 98 | /** |
| 99 | * Boolean value indicating that the wrapped query is |
| 100 | * <tt>null</tt>, meaning it doesn't match anything at |
| 101 | * all. |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 102 | * |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 103 | * For example the segment denoting an adjective |
| 104 | * in the following Poliqarp expression doen't match |
| 105 | * anything. |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 106 | * |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 107 | * <blockquote><pre> |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 108 | * the [pos=ADJ]{0} tree |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 109 | * </pre></blockquote> |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 110 | * |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 111 | * @return <tt>true</tt> in case the wrapped query can't |
| 112 | * match anything, otherwise <tt>false</tt>. |
| 113 | */ |
| Nils Diewald | 92729ce | 2014-10-06 16:00:17 +0000 | [diff] [blame] | 114 | public boolean isNull () { |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 115 | if (this.getMin() == 0 && this.getMax() == 0) |
| 116 | return true; |
| 117 | return this.isNull; |
| Nils Diewald | 92729ce | 2014-10-06 16:00:17 +0000 | [diff] [blame] | 118 | }; |
| 119 | |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 120 | |
| 121 | /** |
| 122 | * Boolean value indicating that the wrapped query matches |
| 123 | * in case the condition of the query is not true. |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 124 | * |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 125 | * For example the segment denoting an adjective |
| 126 | * in the following Poliqarp expression is negative. |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 127 | * |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 128 | * <blockquote><pre> |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 129 | * the [pos!=ADJ] |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 130 | * </pre></blockquote> |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 131 | * |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 132 | * @return <tt>true</tt> in case the wrapped query is |
| 133 | * negative, otherwise <tt>false</tt>. |
| 134 | */ |
| Nils Diewald | 92729ce | 2014-10-06 16:00:17 +0000 | [diff] [blame] | 135 | public boolean isNegative () { |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 136 | return this.isNegative; |
| Nils Diewald | 92729ce | 2014-10-06 16:00:17 +0000 | [diff] [blame] | 137 | }; |
| 138 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 139 | |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 140 | /** |
| 141 | * Boolean value indicating that the wrapped query has |
| 142 | * no further condition for matching and therefore |
| 143 | * matches everywhere. |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 144 | * |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 145 | * For example the empty segment in the following |
| 146 | * Poliqarp expression matches without any condition. |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 147 | * |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 148 | * <blockquote><pre> |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 149 | * the [] |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 150 | * </pre></blockquote> |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 151 | * |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 152 | * @return <tt>true</tt> in case the wrapped query is |
| 153 | * empty, otherwise <tt>false</tt>. |
| 154 | */ |
| Nils Diewald | be5943e | 2014-10-21 19:35:34 +0000 | [diff] [blame] | 155 | public boolean isEmpty () { |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 156 | return this.isEmpty; |
| Nils Diewald | be5943e | 2014-10-21 19:35:34 +0000 | [diff] [blame] | 157 | }; |
| 158 | |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 159 | |
| 160 | /** |
| 161 | * Boolean value indicating that the wrapped query |
| 162 | * is extended by subquery. |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 163 | * |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 164 | * For example the segment denoting an adjective may |
| 165 | * be wrapped as having an extension to the left. |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 166 | * |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 167 | * <blockquote><pre> |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 168 | * []{3,4}[base=tree] |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 169 | * </pre></blockquote> |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 170 | * |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 171 | * @return <tt>true</tt> in case the wrapped query is |
| 172 | * extended, otherwise <tt>false</tt>. |
| 173 | */ |
| Nils Diewald | 8db8f92 | 2014-10-24 17:43:13 +0000 | [diff] [blame] | 174 | public boolean isExtended () { |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 175 | return this.isExtended; |
| Nils Diewald | 8db8f92 | 2014-10-24 17:43:13 +0000 | [diff] [blame] | 176 | }; |
| 177 | |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 178 | |
| Akron | a7b936d | 2016-03-04 13:40:54 +0100 | [diff] [blame] | 179 | public SpanQueryWrapper isExtended (boolean extended) { |
| 180 | this.isExtended = extended; |
| 181 | return this; |
| 182 | }; |
| 183 | |
| 184 | |
| 185 | |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 186 | /** |
| 187 | * Boolean value indicating that the wrapped query |
| 188 | * is extended by a subquery to the right. |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 189 | * |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 190 | * For example the segment denoting the lemma tree |
| 191 | * may be wrapped as being extended to the right |
| 192 | * in the following Poliqarp expression. |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 193 | * |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 194 | * <blockquote><pre> |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 195 | * [base=tree][]{3,4} |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 196 | * </pre></blockquote> |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 197 | * |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 198 | * This information is necessary to ensure a match |
| 199 | * is valid even at the end of a document. |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 200 | * |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 201 | * @return <tt>true</tt> in case the wrapped query is |
| 202 | * extended to the right, otherwise <tt>false</tt>. |
| 203 | */ |
| Nils Diewald | 3b07c37 | 2014-10-22 21:59:17 +0000 | [diff] [blame] | 204 | public boolean isExtendedToTheRight () { |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 205 | return this.isExtendedToTheRight; |
| Nils Diewald | 3b07c37 | 2014-10-22 21:59:17 +0000 | [diff] [blame] | 206 | }; |
| 207 | |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 208 | |
| Akron | a7b936d | 2016-03-04 13:40:54 +0100 | [diff] [blame] | 209 | public SpanQueryWrapper isExtendedToTheRight (boolean extended) { |
| 210 | this.isExtendedToTheRight = extended; |
| 211 | return this; |
| 212 | }; |
| 213 | |
| 214 | |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 215 | /** |
| 216 | * Check, if the wrapped query can be used as an |
| 217 | * anchor query in a sequence, i.e. a query that |
| 218 | * has a condition that must be positively evaluated. |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 219 | * |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 220 | * Wrapped queries with positive conditions are neither |
| 221 | * negative, optional, nor empty. |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 222 | * |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 223 | * This is the opposite of {@link #maybeExtension}. |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 224 | * |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 225 | * @return <tt>true</tt> in case the wrapped query |
| 226 | * can be used as an anchor in a sequence, |
| 227 | * otherwise <tt>false</tt>. |
| 228 | * @see SpanSequenceQueryWrapper |
| 229 | */ |
| Nils Diewald | be5943e | 2014-10-21 19:35:34 +0000 | [diff] [blame] | 230 | public boolean maybeAnchor () { |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 231 | if (this.isNegative()) |
| 232 | return false; |
| 233 | if (this.isOptional()) |
| 234 | return false; |
| 235 | if (this.isEmpty()) { |
| 236 | return false; |
| 237 | } |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 238 | return true; |
| Nils Diewald | be5943e | 2014-10-21 19:35:34 +0000 | [diff] [blame] | 239 | }; |
| 240 | |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 241 | |
| 242 | /** |
| 243 | * Check, if the wrapped query can't be used as an |
| 244 | * anchor query in a sequence, meaning it has to be |
| 245 | * constructed as an extension to an anchor query. |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 246 | * |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 247 | * Wrapped queries with negative conditions are either |
| 248 | * negative, optional, or empty. |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 249 | * |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 250 | * This is the opposite of {@link #maybeAnchor}. |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 251 | * |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 252 | * @return <tt>true</tt> in case the wrapped query |
| 253 | * has to be used as an extension in a sequence, |
| 254 | * otherwise <tt>false</tt>. |
| 255 | * @see SpanSequenceQueryWrapper |
| 256 | */ |
| Nils Diewald | be5943e | 2014-10-21 19:35:34 +0000 | [diff] [blame] | 257 | public boolean maybeExtension () { |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 258 | return !this.maybeAnchor(); |
| Nils Diewald | be5943e | 2014-10-21 19:35:34 +0000 | [diff] [blame] | 259 | }; |
| 260 | |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 261 | |
| 262 | /** |
| Nils Diewald | 0981c21 | 2015-02-13 20:47:10 +0000 | [diff] [blame] | 263 | * Check, if the wrapped query may need to be sorted |
| 264 | * on focussing on a specific class. |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 265 | * |
| Nils Diewald | 0981c21 | 2015-02-13 20:47:10 +0000 | [diff] [blame] | 266 | * Normally spans are always sorted, but in case of |
| 267 | * a wrapped relation query, classed operands may |
| 268 | * be in arbitrary order. When focussing on these |
| 269 | * classes, the span has to me reordered. |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 270 | * |
| Nils Diewald | 0981c21 | 2015-02-13 20:47:10 +0000 | [diff] [blame] | 271 | * @return <tt>true</tt> in case the wrapped query |
| 272 | * has to be sorted on focussing, |
| 273 | * otherwise <tt>false</tt>. |
| 274 | */ |
| 275 | public boolean maybeUnsorted () { |
| 276 | return this.maybeUnsorted; |
| 277 | }; |
| 278 | |
| 279 | |
| 280 | /** |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 281 | * Get the minimum number of repetitions of the |
| 282 | * wrapped query. |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 283 | * |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 284 | * @return The minimum number of repetions. |
| 285 | * @see SpanRepetitionQueryWrapper |
| 286 | */ |
| Nils Diewald | be5943e | 2014-10-21 19:35:34 +0000 | [diff] [blame] | 287 | public int getMin () { |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 288 | return this.min; |
| Nils Diewald | 92729ce | 2014-10-06 16:00:17 +0000 | [diff] [blame] | 289 | }; |
| 290 | |
| Nils Diewald | be5943e | 2014-10-21 19:35:34 +0000 | [diff] [blame] | 291 | |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 292 | /** |
| 293 | * Set the minimum number of repetitions of the |
| 294 | * wrapped query. |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 295 | * |
| 296 | * @param min |
| 297 | * The minimum number of repetions. |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 298 | * @return The {@link SpanQueryWrapper} object for chaining. |
| 299 | */ |
| Nils Diewald | be5943e | 2014-10-21 19:35:34 +0000 | [diff] [blame] | 300 | public SpanQueryWrapper setMin (int min) { |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 301 | this.min = min; |
| 302 | return this; |
| Nils Diewald | be5943e | 2014-10-21 19:35:34 +0000 | [diff] [blame] | 303 | }; |
| 304 | |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 305 | |
| 306 | /** |
| 307 | * Get the maximum number of repetitions of the |
| 308 | * wrapped query. |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 309 | * |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 310 | * @return The maximum number of repetions. |
| 311 | * @see SpanRepetitionQueryWrapper |
| 312 | */ |
| 313 | public int getMax () { |
| 314 | return this.max; |
| 315 | }; |
| 316 | |
| 317 | |
| 318 | /** |
| 319 | * Set the maximum number of repetitions of the |
| 320 | * wrapped query. |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 321 | * |
| 322 | * @param max |
| 323 | * The maximum number of repetions. |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 324 | * @return The {@link SpanQueryWrapper} object for chaining. |
| 325 | */ |
| Nils Diewald | be5943e | 2014-10-21 19:35:34 +0000 | [diff] [blame] | 326 | public SpanQueryWrapper setMax (int max) { |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 327 | this.max = max; |
| 328 | return this; |
| Nils Diewald | be5943e | 2014-10-21 19:35:34 +0000 | [diff] [blame] | 329 | }; |
| 330 | |
| 331 | |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 332 | /** |
| Nils Diewald | b9dd413 | 2015-02-16 16:32:41 +0000 | [diff] [blame] | 333 | * Make the query request node information in addition to |
| 334 | * span information. |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 335 | * |
| 336 | * @param retrieve |
| 337 | * Boolean value saying the wrapper |
| 338 | * has or has not to respect node information. |
| Nils Diewald | b9dd413 | 2015-02-16 16:32:41 +0000 | [diff] [blame] | 339 | * @return The {@link SpanQueryWrapper} object for chaining. |
| 340 | */ |
| 341 | public SpanQueryWrapper retrieveNode (boolean retrieve) { |
| 342 | this.retrieveNode = retrieve; |
| 343 | return this; |
| 344 | }; |
| 345 | |
| 346 | |
| 347 | /** |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 348 | * Boolean value indicating that a wrapped query |
| 349 | * has a class. This is especially relevant for classed |
| 350 | * extension queries. |
| 351 | */ |
| Nils Diewald | be5943e | 2014-10-21 19:35:34 +0000 | [diff] [blame] | 352 | public boolean hasClass () { |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 353 | return this.hasClass; |
| Nils Diewald | be5943e | 2014-10-21 19:35:34 +0000 | [diff] [blame] | 354 | }; |
| 355 | |
| Nils Diewald | be5943e | 2014-10-21 19:35:34 +0000 | [diff] [blame] | 356 | |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 357 | /** |
| 358 | * Get the class number, if set. |
| 359 | * Returns <tt>0</tt> in case no class is set. |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 360 | * |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 361 | * @return The class number. |
| 362 | */ |
| Nils Diewald | be5943e | 2014-10-21 19:35:34 +0000 | [diff] [blame] | 363 | public byte getClassNumber () { |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 364 | return this.number; |
| Nils Diewald | be5943e | 2014-10-21 19:35:34 +0000 | [diff] [blame] | 365 | }; |
| 366 | |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 367 | |
| 368 | /** |
| 369 | * Set the class number. |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 370 | * |
| 371 | * @param number |
| 372 | * The class number as a byte value. |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 373 | * @return The {@link SpanQueryWrapper} object for chaining. |
| 374 | */ |
| Nils Diewald | be5943e | 2014-10-21 19:35:34 +0000 | [diff] [blame] | 375 | public SpanQueryWrapper setClassNumber (byte number) { |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 376 | this.hasClass = true; |
| 377 | this.number = number; |
| 378 | return this; |
| Nils Diewald | be5943e | 2014-10-21 19:35:34 +0000 | [diff] [blame] | 379 | }; |
| 380 | |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 381 | |
| 382 | /** |
| 383 | * Set the class number. |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 384 | * |
| 385 | * @param number |
| 386 | * The class number as a short value. |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 387 | * @return The {@link SpanQueryWrapper} object for chaining. |
| 388 | */ |
| Nils Diewald | be5943e | 2014-10-21 19:35:34 +0000 | [diff] [blame] | 389 | public SpanQueryWrapper setClassNumber (short number) { |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 390 | return this.setClassNumber((byte) number); |
| Nils Diewald | be5943e | 2014-10-21 19:35:34 +0000 | [diff] [blame] | 391 | }; |
| 392 | |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 393 | |
| 394 | /** |
| 395 | * Set the class number. |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 396 | * |
| 397 | * @param number |
| 398 | * The class number as an integer value. |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 399 | * @return The {@link SpanQueryWrapper} object for chaining. |
| 400 | */ |
| Nils Diewald | be5943e | 2014-10-21 19:35:34 +0000 | [diff] [blame] | 401 | public SpanQueryWrapper setClassNumber (int number) { |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 402 | return this.setClassNumber((byte) number); |
| Nils Diewald | be5943e | 2014-10-21 19:35:34 +0000 | [diff] [blame] | 403 | }; |
| 404 | |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 405 | |
| 406 | /** |
| 407 | * Serialize the wrapped query to a string representation. |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 408 | * |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 409 | * This is meant to be overwritten. |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 410 | * |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 411 | * @return A string containg the query representation. |
| 412 | */ |
| Nils Diewald | be5943e | 2014-10-21 19:35:34 +0000 | [diff] [blame] | 413 | public String toString () { |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 414 | String string = "" + (this.isNull() ? "isNull" : "notNull") + "-" |
| 415 | + (this.isEmpty() ? "isEmpty" : "notEmpty") + "-" |
| 416 | + (this.isOptional() ? "isOptional" : "notOptional"); |
| Nils Diewald | 5dfbd50 | 2015-01-29 03:54:36 +0000 | [diff] [blame] | 417 | return string; |
| Nils Diewald | be5943e | 2014-10-21 19:35:34 +0000 | [diff] [blame] | 418 | }; |
| Nils Diewald | 92729ce | 2014-10-06 16:00:17 +0000 | [diff] [blame] | 419 | }; |