public void add(long originalStart, long originalEnd, long tempStart, long tempEnd) { NodePosition mapping = new NodePosition(originalStart, originalEnd, tempStart, tempEnd); add(mapping); }
/** Find the start offset of the latest original annotation * that starts at or before this temporary annotation. * This method MUST return a valid original annotation * start offset or -1. * @param tempStartOffset * @return -1 is the error code, sorry */ public long getBestOriginalStart(long tempStartOffset) { update(); int i = Arrays.binarySearch(tempStartOffsets, tempStartOffset); // According to the binarySearch API, i = - insPt - 1 if (i == -1) { // This means we've undershot the first original annotation return -1L; } if (i >= 0) { return startMap.get(tempStartOffsets[i]).getOriginalStartOffset(); } /* Now we want the position before the insertion point * (we've already tested for undershooting the first * original annotation) */ i = - i - 2; return startMap.get(tempStartOffsets[i]).getOriginalStartOffset(); }
FlexGazMappingTable mappingTable = new FlexGazMappingTable(); fireStatusChanged("Creating temporary Document for feature " + aFeature); StringBuilder newdocString = totalDeductedSpaces += lengthDifference; mappingTable.add(startOffset, endOffset, newStartOffset, newEndOffset); if(mappingTable.isEmpty()) continue; for (NodePosition mapping : mappingTable.getMappings()) { tempDoc.getAnnotations(wrappedInputASName).add(mapping.getTempStartOffset(), mapping.getTempEndOffset(), "Input", Factory.newFeatureMap()); long destinationStart = mappingTable.getBestOriginalStart(tempStartOffset); long destinationEnd = mappingTable.getBestOriginalEnd(tempEndOffset);
/** Find the end offset of the first original annotation * that ends at or after this temporary annotation. This method * MUST return a valid original annotation end offset or -1. * * @param tempEndOffset * @return -1 is the error code, sorry */ public long getBestOriginalEnd(long tempEndOffset) { update(); int i = Arrays.binarySearch(tempEndOffsets, tempEndOffset); // Exact key is found in the array: if (i >= 0) { return endMap.get(tempEndOffsets[i]).getOriginalEndOffset(); } /* Exact key is not in the array; according * to the binarySearch API, i = - insPt - 1 * We want the insertion point, but if that is past the * existing end of the array, then * we have overshot the first input annotation */ i = - i - 1; if (i >= size) { return -1L; } return endMap.get(tempEndOffsets[i]).getOriginalEndOffset(); }
public void dump() { update(); for (int i = 0 ; i < size ; i++) { long start = tempStartOffsets[i]; long end = tempEndOffsets[i]; NodePosition m = startMap.get(start); System.out.format("FGMT: %d, %d : o(%d, %d) t(%d, %d)%n", start, end, m.getOriginalStartOffset(), m.getOriginalEndOffset(), m.getTempStartOffset(), m.getTempEndOffset() ); } }