| Eliza Margaretha | f13b8ad | 2014-10-13 16:36:28 +0000 | [diff] [blame] | 1 | package de.ids_mannheim.korap.query.spans; |
| 2 | |
| 3 | import java.io.IOException; |
| Eliza Margaretha | 0170b88 | 2014-10-29 15:49:31 +0000 | [diff] [blame] | 4 | import java.nio.ByteBuffer; |
| Eliza Margaretha | f13b8ad | 2014-10-13 16:36:28 +0000 | [diff] [blame] | 5 | import java.util.ArrayList; |
| 6 | import java.util.Collections; |
| 7 | import java.util.List; |
| 8 | import java.util.Map; |
| 9 | |
| Akron | 700c1eb | 2015-09-25 16:57:30 +0200 | [diff] [blame] | 10 | import org.apache.lucene.index.LeafReaderContext; |
| Eliza Margaretha | f13b8ad | 2014-10-13 16:36:28 +0000 | [diff] [blame] | 11 | import org.apache.lucene.index.Term; |
| 12 | import org.apache.lucene.index.TermContext; |
| Eliza Margaretha | f13b8ad | 2014-10-13 16:36:28 +0000 | [diff] [blame] | 13 | import org.apache.lucene.search.spans.TermSpans; |
| 14 | import org.apache.lucene.util.Bits; |
| Eliza Margaretha | f13b8ad | 2014-10-13 16:36:28 +0000 | [diff] [blame] | 15 | import org.slf4j.Logger; |
| 16 | import org.slf4j.LoggerFactory; |
| 17 | |
| 18 | import de.ids_mannheim.korap.query.SpanRelationQuery; |
| Eliza Margaretha | f13b8ad | 2014-10-13 16:36:28 +0000 | [diff] [blame] | 19 | |
| Eliza Margaretha | 493bfa9 | 2015-01-13 16:16:38 +0000 | [diff] [blame] | 20 | /** |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 21 | * Enumeration of spans denoting relations between two |
| margaretha | ca8d622 | 2015-04-15 13:46:41 +0200 | [diff] [blame] | 22 | * tokens/elements. The start and end of a RelationSpan always denote |
| 23 | * the start and end of the left-side token/element. |
| Eliza Margaretha | f13b8ad | 2014-10-13 16:36:28 +0000 | [diff] [blame] | 24 | * |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 25 | * There are 4 types of relations, which is differentiated by the |
| margaretha | ca8d622 | 2015-04-15 13:46:41 +0200 | [diff] [blame] | 26 | * payload length in bytes. |
| Eliza Margaretha | 493bfa9 | 2015-01-13 16:16:38 +0000 | [diff] [blame] | 27 | * <ol> |
| 28 | * <li>Token to token relation (1 int & 3 short, length: 10)</li> |
| 29 | * <li>Token to span (2 int & 3 short, length: 14)</li> |
| 30 | * <li>Span to token (int, byte, int, 3 short, length: 15)</li> |
| 31 | * <li>Span to Span (3 int & 3 short, length: 18)</li> |
| 32 | * </ol> |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 33 | * Every integer value denotes the start/end position of the |
| margaretha | ca8d622 | 2015-04-15 13:46:41 +0200 | [diff] [blame] | 34 | * start/target of a relation, in this format: (sourceEndPos?, |
| 35 | * startTargetPos, endTargetPos?). The end position of a token is |
| 36 | * identical to its start position, and therefore not is saved in a |
| 37 | * payload. |
| Eliza Margaretha | f13b8ad | 2014-10-13 16:36:28 +0000 | [diff] [blame] | 38 | * |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 39 | * The short values denote the relation id, left id, and right id. The |
| margaretha | ca8d622 | 2015-04-15 13:46:41 +0200 | [diff] [blame] | 40 | * byte in relation #3 is just a dummy to create a different length |
| 41 | * from the relation #2. |
| Eliza Margaretha | f13b8ad | 2014-10-13 16:36:28 +0000 | [diff] [blame] | 42 | * |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 43 | * NOTE: Sorting of the candidate spans can alternatively be done in |
| margaretha | ca8d622 | 2015-04-15 13:46:41 +0200 | [diff] [blame] | 44 | * indexing, instead of here. (first by left positions and then by |
| 45 | * right positions) |
| 46 | * |
| 47 | * The class number of relation source is always 1 and that of |
| 48 | * relation target is always 2 regardless of the relation direction. |
| Eliza Margaretha | 493bfa9 | 2015-01-13 16:16:38 +0000 | [diff] [blame] | 49 | * |
| 50 | * @author margaretha |
| Eliza Margaretha | f13b8ad | 2014-10-13 16:36:28 +0000 | [diff] [blame] | 51 | * */ |
| Eliza Margaretha | 493bfa9 | 2015-01-13 16:16:38 +0000 | [diff] [blame] | 52 | public class RelationSpans extends RelationBaseSpans { |
| Eliza Margaretha | f13b8ad | 2014-10-13 16:36:28 +0000 | [diff] [blame] | 53 | |
| Eliza Margaretha | 493bfa9 | 2015-01-13 16:16:38 +0000 | [diff] [blame] | 54 | private int currentDoc, currentPosition; |
| margaretha | ca8d622 | 2015-04-15 13:46:41 +0200 | [diff] [blame] | 55 | private int direction; |
| Eliza Margaretha | 493bfa9 | 2015-01-13 16:16:38 +0000 | [diff] [blame] | 56 | private TermSpans relationTermSpan; |
| Eliza Margaretha | f13b8ad | 2014-10-13 16:36:28 +0000 | [diff] [blame] | 57 | |
| Eliza Margaretha | 493bfa9 | 2015-01-13 16:16:38 +0000 | [diff] [blame] | 58 | protected Logger logger = LoggerFactory.getLogger(RelationSpans.class); |
| margaretha | 7ee6595 | 2015-12-14 15:39:12 +0100 | [diff] [blame^] | 59 | private List<CandidateSpan> candidateList; |
| margaretha | f70addb | 2015-04-27 13:17:18 +0200 | [diff] [blame] | 60 | private byte tempSourceNum, tempTargetNum; |
| 61 | private byte sourceClass, targetClass; |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 62 | |
| margaretha | 7ee6595 | 2015-12-14 15:39:12 +0100 | [diff] [blame^] | 63 | public static enum PayloadTypeIdentifier { |
| 64 | TERM_TO_TERM(32), TERM_TO_ELEMENT(33), ELEMENT_TO_TERM(34), ELEMENT_TO_ELEMENT( |
| 65 | 35); |
| 66 | |
| 67 | private byte value; |
| 68 | |
| 69 | private PayloadTypeIdentifier (int value) { |
| 70 | this.value = (byte) value; |
| 71 | } |
| 72 | } |
| Akron | bb5d173 | 2015-06-22 01:22:40 +0200 | [diff] [blame] | 73 | |
| Eliza Margaretha | 493bfa9 | 2015-01-13 16:16:38 +0000 | [diff] [blame] | 74 | /** |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 75 | * Constructs RelationSpans from the given |
| 76 | * {@link SpanRelationQuery}. |
| Eliza Margaretha | 493bfa9 | 2015-01-13 16:16:38 +0000 | [diff] [blame] | 77 | * |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 78 | * @param relationSpanQuery |
| 79 | * a SpanRelationQuery |
| Eliza Margaretha | 493bfa9 | 2015-01-13 16:16:38 +0000 | [diff] [blame] | 80 | * @param context |
| 81 | * @param acceptDocs |
| 82 | * @param termContexts |
| 83 | * @throws IOException |
| 84 | */ |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 85 | public RelationSpans (SpanRelationQuery relationSpanQuery, |
| Akron | 700c1eb | 2015-09-25 16:57:30 +0200 | [diff] [blame] | 86 | LeafReaderContext context, Bits acceptDocs, |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 87 | Map<Term, TermContext> termContexts) |
| 88 | throws IOException { |
| Eliza Margaretha | 493bfa9 | 2015-01-13 16:16:38 +0000 | [diff] [blame] | 89 | super(relationSpanQuery, context, acceptDocs, termContexts); |
| margaretha | ca8d622 | 2015-04-15 13:46:41 +0200 | [diff] [blame] | 90 | direction = relationSpanQuery.getDirection(); |
| margaretha | f70addb | 2015-04-27 13:17:18 +0200 | [diff] [blame] | 91 | tempSourceNum = relationSpanQuery.getTempSourceNum(); |
| 92 | tempTargetNum = relationSpanQuery.getTempTargetNum(); |
| 93 | sourceClass = relationSpanQuery.getSourceClass(); |
| 94 | targetClass = relationSpanQuery.getTargetClass(); |
| 95 | |
| Eliza Margaretha | 493bfa9 | 2015-01-13 16:16:38 +0000 | [diff] [blame] | 96 | candidateList = new ArrayList<>(); |
| 97 | relationTermSpan = (TermSpans) firstSpans; |
| 98 | hasMoreSpans = relationTermSpan.next(); |
| 99 | } |
| Eliza Margaretha | f13b8ad | 2014-10-13 16:36:28 +0000 | [diff] [blame] | 100 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 101 | |
| Eliza Margaretha | 493bfa9 | 2015-01-13 16:16:38 +0000 | [diff] [blame] | 102 | @Override |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 103 | public boolean next () throws IOException { |
| Eliza Margaretha | 493bfa9 | 2015-01-13 16:16:38 +0000 | [diff] [blame] | 104 | isStartEnumeration = false; |
| 105 | return advance(); |
| 106 | } |
| Eliza Margaretha | f13b8ad | 2014-10-13 16:36:28 +0000 | [diff] [blame] | 107 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 108 | |
| Eliza Margaretha | 493bfa9 | 2015-01-13 16:16:38 +0000 | [diff] [blame] | 109 | /** |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 110 | * Returns true if there is a next match by checking if the |
| 111 | * CandidateList is |
| 112 | * not empty and set the first element of the list as the next |
| 113 | * match. |
| 114 | * Otherwise, if the RelationSpan has not ended yet, try to set |
| 115 | * the |
| Eliza Margaretha | 493bfa9 | 2015-01-13 16:16:38 +0000 | [diff] [blame] | 116 | * CandidateList. |
| 117 | * |
| 118 | * @return true if there is a next match. |
| 119 | * @throws IOException |
| 120 | */ |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 121 | private boolean advance () throws IOException { |
| Eliza Margaretha | 493bfa9 | 2015-01-13 16:16:38 +0000 | [diff] [blame] | 122 | while (hasMoreSpans || !candidateList.isEmpty()) { |
| 123 | if (!candidateList.isEmpty()) { |
| margaretha | 7ee6595 | 2015-12-14 15:39:12 +0100 | [diff] [blame^] | 124 | CandidateSpan cs = candidateList.get(0); |
| Eliza Margaretha | 493bfa9 | 2015-01-13 16:16:38 +0000 | [diff] [blame] | 125 | this.matchDocNumber = cs.getDoc(); |
| 126 | this.matchStartPosition = cs.getStart(); |
| 127 | this.matchEndPosition = cs.getEnd(); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 128 | this.matchPayload = cs.getPayloads(); |
| Eliza Margaretha | 493bfa9 | 2015-01-13 16:16:38 +0000 | [diff] [blame] | 129 | this.setRightStart(cs.getRightStart()); |
| 130 | this.setRightEnd(cs.getRightEnd()); |
| 131 | this.spanId = cs.getSpanId(); // relation id |
| 132 | this.leftId = cs.getLeftId(); |
| 133 | this.rightId = cs.getRightId(); |
| 134 | candidateList.remove(0); |
| 135 | return true; |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 136 | } |
| Eliza Margaretha | 2db5e23 | 2015-03-04 10:20:01 +0000 | [diff] [blame] | 137 | else { |
| Eliza Margaretha | 493bfa9 | 2015-01-13 16:16:38 +0000 | [diff] [blame] | 138 | setCandidateList(); |
| 139 | currentDoc = relationTermSpan.doc(); |
| 140 | currentPosition = relationTermSpan.start(); |
| 141 | } |
| 142 | } |
| 143 | return false; |
| 144 | } |
| Eliza Margaretha | 3e50bc4 | 2014-10-22 15:29:15 +0000 | [diff] [blame] | 145 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 146 | |
| Eliza Margaretha | 493bfa9 | 2015-01-13 16:16:38 +0000 | [diff] [blame] | 147 | /** |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 148 | * Setting the CandidateList by adding all relationTermSpan whose |
| 149 | * start |
| Eliza Margaretha | 493bfa9 | 2015-01-13 16:16:38 +0000 | [diff] [blame] | 150 | * position is the same as the current span position, and sort the |
| 151 | * candidateList. |
| 152 | * |
| 153 | * @throws IOException |
| 154 | */ |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 155 | private void setCandidateList () throws IOException { |
| Eliza Margaretha | 493bfa9 | 2015-01-13 16:16:38 +0000 | [diff] [blame] | 156 | while (hasMoreSpans && relationTermSpan.doc() == currentDoc |
| 157 | && relationTermSpan.start() == currentPosition) { |
| margaretha | 7ee6595 | 2015-12-14 15:39:12 +0100 | [diff] [blame^] | 158 | |
| 159 | CandidateSpan cs = new CandidateSpan( |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 160 | relationTermSpan); |
| Eliza Margaretha | 493bfa9 | 2015-01-13 16:16:38 +0000 | [diff] [blame] | 161 | readPayload(cs); |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 162 | setPayload(cs); |
| Eliza Margaretha | 493bfa9 | 2015-01-13 16:16:38 +0000 | [diff] [blame] | 163 | candidateList.add(cs); |
| 164 | hasMoreSpans = relationTermSpan.next(); |
| 165 | } |
| 166 | Collections.sort(candidateList); |
| Eliza Margaretha | 493bfa9 | 2015-01-13 16:16:38 +0000 | [diff] [blame] | 167 | } |
| Eliza Margaretha | f13b8ad | 2014-10-13 16:36:28 +0000 | [diff] [blame] | 168 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 169 | |
| Eliza Margaretha | 493bfa9 | 2015-01-13 16:16:38 +0000 | [diff] [blame] | 170 | /** |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 171 | * Identify the relation type of the given |
| 172 | * {@link CandidateRelationSpan} by |
| 173 | * checking the length of its payloads, and set some properties of |
| 174 | * the span |
| Eliza Margaretha | 493bfa9 | 2015-01-13 16:16:38 +0000 | [diff] [blame] | 175 | * based on the payloads. |
| 176 | * |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 177 | * @param cs |
| 178 | * a CandidateRelationSpan |
| Eliza Margaretha | 493bfa9 | 2015-01-13 16:16:38 +0000 | [diff] [blame] | 179 | */ |
| margaretha | 7ee6595 | 2015-12-14 15:39:12 +0100 | [diff] [blame^] | 180 | private void readPayload(CandidateSpan cs) { |
| Eliza Margaretha | 493bfa9 | 2015-01-13 16:16:38 +0000 | [diff] [blame] | 181 | List<byte[]> payload = (List<byte[]>) cs.getPayloads(); |
| 182 | int length = payload.get(0).length; |
| 183 | ByteBuffer bb = ByteBuffer.allocate(length); |
| 184 | bb.put(payload.get(0)); |
| Eliza Margaretha | d12cabb | 2014-10-27 17:45:34 +0000 | [diff] [blame] | 185 | |
| margaretha | 50c7633 | 2015-03-19 10:10:39 +0100 | [diff] [blame] | 186 | cs.setLeftStart(cs.start); |
| 187 | |
| Eliza Margaretha | 493bfa9 | 2015-01-13 16:16:38 +0000 | [diff] [blame] | 188 | int i; |
| margaretha | 7ee6595 | 2015-12-14 15:39:12 +0100 | [diff] [blame^] | 189 | this.payloadTypeIdentifier = bb.get(0); |
| 190 | |
| 191 | if (payloadTypeIdentifier == PayloadTypeIdentifier.TERM_TO_TERM.value){ // length 11 |
| 192 | i = bb.getInt(1); |
| 193 | cs.setLeftEnd(cs.start + 1); |
| 194 | cs.setRightStart(i); |
| 195 | cs.setRightEnd(i + 1); |
| 196 | } |
| 197 | else if (payloadTypeIdentifier == PayloadTypeIdentifier.TERM_TO_ELEMENT.value) { // length |
| 198 | // 15 |
| 199 | cs.setLeftEnd(cs.start + 1); |
| 200 | cs.setRightStart(bb.getInt(1)); |
| 201 | cs.setRightEnd(bb.getInt(5)); |
| 202 | } |
| 203 | else if (payloadTypeIdentifier == PayloadTypeIdentifier.ELEMENT_TO_TERM.value) { // length |
| 204 | // 15 |
| 205 | cs.setEnd(bb.getInt(1)); |
| 206 | cs.setLeftEnd(cs.end); |
| 207 | i = bb.getInt(5); |
| 208 | cs.setRightStart(i); |
| 209 | cs.setRightEnd(i + 1); |
| 210 | } |
| 211 | else if (payloadTypeIdentifier == PayloadTypeIdentifier.ELEMENT_TO_ELEMENT.value) { |
| 212 | cs.setEnd(bb.getInt(1)); |
| 213 | cs.setLeftEnd(cs.end); |
| 214 | cs.setRightStart(bb.getInt(5)); |
| 215 | cs.setRightEnd(bb.getInt(9)); |
| Eliza Margaretha | 493bfa9 | 2015-01-13 16:16:38 +0000 | [diff] [blame] | 216 | } |
| Eliza Margaretha | f13b8ad | 2014-10-13 16:36:28 +0000 | [diff] [blame] | 217 | |
| Eliza Margaretha | 493bfa9 | 2015-01-13 16:16:38 +0000 | [diff] [blame] | 218 | cs.setRightId(bb.getShort(length - 2)); //right id |
| 219 | cs.setLeftId(bb.getShort(length - 4)); //left id |
| 220 | cs.setSpanId(bb.getShort(length - 6)); //relation id |
| margaretha | 50c7633 | 2015-03-19 10:10:39 +0100 | [diff] [blame] | 221 | // Payload is cleared. |
| Eliza Margaretha | 493bfa9 | 2015-01-13 16:16:38 +0000 | [diff] [blame] | 222 | } |
| Eliza Margaretha | f13b8ad | 2014-10-13 16:36:28 +0000 | [diff] [blame] | 223 | |
| Eliza Margaretha | 2db5e23 | 2015-03-04 10:20:01 +0000 | [diff] [blame] | 224 | |
| margaretha | 7ee6595 | 2015-12-14 15:39:12 +0100 | [diff] [blame^] | 225 | private void setPayload(CandidateSpan cs) throws IOException { |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 226 | ArrayList<byte[]> payload = new ArrayList<byte[]>(); |
| 227 | if (relationTermSpan.isPayloadAvailable()) { |
| 228 | payload.addAll(relationTermSpan.getPayload()); |
| 229 | } |
| margaretha | ca8d622 | 2015-04-15 13:46:41 +0200 | [diff] [blame] | 230 | if (direction == 0) { |
| 231 | payload.add(createClassPayload(cs.getLeftStart(), cs.getLeftEnd(), |
| margaretha | f70addb | 2015-04-27 13:17:18 +0200 | [diff] [blame] | 232 | tempSourceNum, false)); |
| margaretha | ca8d622 | 2015-04-15 13:46:41 +0200 | [diff] [blame] | 233 | payload.add(createClassPayload(cs.getRightStart(), |
| margaretha | f70addb | 2015-04-27 13:17:18 +0200 | [diff] [blame] | 234 | cs.getRightEnd(), tempTargetNum, false)); |
| 235 | |
| 236 | if (sourceClass > 0) { |
| 237 | payload.add(createClassPayload(cs.getLeftStart(), |
| 238 | cs.getLeftEnd(), sourceClass, true)); |
| 239 | } |
| 240 | if (targetClass > 0) { |
| 241 | payload.add(createClassPayload(cs.getRightStart(), |
| 242 | cs.getRightEnd(), targetClass, true)); |
| 243 | } |
| 244 | |
| margaretha | ca8d622 | 2015-04-15 13:46:41 +0200 | [diff] [blame] | 245 | } |
| 246 | else { |
| 247 | payload.add(createClassPayload(cs.getRightStart(), |
| margaretha | f70addb | 2015-04-27 13:17:18 +0200 | [diff] [blame] | 248 | cs.getRightEnd(), tempSourceNum, false)); |
| margaretha | ca8d622 | 2015-04-15 13:46:41 +0200 | [diff] [blame] | 249 | payload.add(createClassPayload(cs.getLeftStart(), cs.getLeftEnd(), |
| margaretha | f70addb | 2015-04-27 13:17:18 +0200 | [diff] [blame] | 250 | tempTargetNum, false)); |
| 251 | |
| 252 | if (sourceClass > 0) { |
| 253 | payload.add(createClassPayload(cs.getRightStart(), |
| 254 | cs.getRightEnd(), sourceClass, true)); |
| 255 | } |
| 256 | if (targetClass > 0) { |
| 257 | payload.add(createClassPayload(cs.getLeftStart(), |
| 258 | cs.getLeftEnd(), targetClass, true)); |
| 259 | } |
| margaretha | ca8d622 | 2015-04-15 13:46:41 +0200 | [diff] [blame] | 260 | } |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 261 | cs.setPayloads(payload); |
| 262 | } |
| 263 | |
| Akron | bb5d173 | 2015-06-22 01:22:40 +0200 | [diff] [blame] | 264 | |
| 265 | private byte[] createClassPayload (int start, int end, byte classNumber, |
| margaretha | f70addb | 2015-04-27 13:17:18 +0200 | [diff] [blame] | 266 | boolean keep) { |
| 267 | ByteBuffer buffer = null; |
| 268 | if (keep) { |
| 269 | buffer = ByteBuffer.allocate(9); |
| 270 | } |
| 271 | else { |
| 272 | buffer = ByteBuffer.allocate(10); |
| 273 | } |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 274 | buffer.putInt(start); |
| 275 | buffer.putInt(end); |
| 276 | buffer.put(classNumber); |
| 277 | return buffer.array(); |
| 278 | } |
| 279 | |
| Eliza Margaretha | 2db5e23 | 2015-03-04 10:20:01 +0000 | [diff] [blame] | 280 | |
| Eliza Margaretha | 493bfa9 | 2015-01-13 16:16:38 +0000 | [diff] [blame] | 281 | @Override |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 282 | public boolean skipTo (int target) throws IOException { |
| Eliza Margaretha | 493bfa9 | 2015-01-13 16:16:38 +0000 | [diff] [blame] | 283 | if (hasMoreSpans && (firstSpans.doc() < target)) { |
| 284 | if (!firstSpans.skipTo(target)) { |
| 285 | candidateList.clear(); |
| 286 | return false; |
| 287 | } |
| 288 | } |
| 289 | setCandidateList(); |
| 290 | matchPayload.clear(); |
| 291 | isStartEnumeration = false; |
| 292 | return advance(); |
| 293 | } |
| Eliza Margaretha | f13b8ad | 2014-10-13 16:36:28 +0000 | [diff] [blame] | 294 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 295 | |
| Eliza Margaretha | 493bfa9 | 2015-01-13 16:16:38 +0000 | [diff] [blame] | 296 | @Override |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 297 | public long cost () { |
| Eliza Margaretha | 493bfa9 | 2015-01-13 16:16:38 +0000 | [diff] [blame] | 298 | return firstSpans.cost(); |
| 299 | } |
| Eliza Margaretha | f13b8ad | 2014-10-13 16:36:28 +0000 | [diff] [blame] | 300 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 301 | |
| Eliza Margaretha | 493bfa9 | 2015-01-13 16:16:38 +0000 | [diff] [blame] | 302 | /** |
| 303 | * Returns the right start position of the current RelationSpan. |
| 304 | * |
| 305 | * @return the right start position of the current RelationSpan. |
| 306 | */ |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 307 | public int getRightStart () { |
| Eliza Margaretha | 493bfa9 | 2015-01-13 16:16:38 +0000 | [diff] [blame] | 308 | return rightStart; |
| 309 | } |
| Eliza Margaretha | d12cabb | 2014-10-27 17:45:34 +0000 | [diff] [blame] | 310 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 311 | |
| Eliza Margaretha | 493bfa9 | 2015-01-13 16:16:38 +0000 | [diff] [blame] | 312 | /** |
| 313 | * Sets the right start position of the current RelationSpan. |
| 314 | * |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 315 | * @param rightStart |
| 316 | * the right start position of the current RelationSpan |
| Eliza Margaretha | 493bfa9 | 2015-01-13 16:16:38 +0000 | [diff] [blame] | 317 | */ |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 318 | public void setRightStart (int rightStart) { |
| Eliza Margaretha | 493bfa9 | 2015-01-13 16:16:38 +0000 | [diff] [blame] | 319 | this.rightStart = rightStart; |
| 320 | } |
| Eliza Margaretha | d12cabb | 2014-10-27 17:45:34 +0000 | [diff] [blame] | 321 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 322 | |
| Eliza Margaretha | 493bfa9 | 2015-01-13 16:16:38 +0000 | [diff] [blame] | 323 | /** |
| 324 | * Returns the right end position of the current RelationSpan. |
| 325 | * |
| 326 | * @return the right end position of the current RelationSpan. |
| 327 | */ |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 328 | public int getRightEnd () { |
| Eliza Margaretha | 493bfa9 | 2015-01-13 16:16:38 +0000 | [diff] [blame] | 329 | return rightEnd; |
| 330 | } |
| Eliza Margaretha | d12cabb | 2014-10-27 17:45:34 +0000 | [diff] [blame] | 331 | |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 332 | |
| Eliza Margaretha | 493bfa9 | 2015-01-13 16:16:38 +0000 | [diff] [blame] | 333 | /** |
| 334 | * Sets the right end position of the current RelationSpan. |
| 335 | * |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 336 | * @param rightEnd |
| 337 | * the right end position of the current RelationSpan. |
| Eliza Margaretha | 493bfa9 | 2015-01-13 16:16:38 +0000 | [diff] [blame] | 338 | */ |
| Nils Diewald | bb33da2 | 2015-03-04 16:24:25 +0000 | [diff] [blame] | 339 | public void setRightEnd (int rightEnd) { |
| Eliza Margaretha | 493bfa9 | 2015-01-13 16:16:38 +0000 | [diff] [blame] | 340 | this.rightEnd = rightEnd; |
| 341 | } |
| Eliza Margaretha | d12cabb | 2014-10-27 17:45:34 +0000 | [diff] [blame] | 342 | |
| Eliza Margaretha | f13b8ad | 2014-10-13 16:36:28 +0000 | [diff] [blame] | 343 | } |