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() ); } }
private void add(NodePosition mapping) { startMap.put(mapping.getTempStartOffset(), mapping); endMap.put(mapping.getTempEndOffset(), mapping); size++; updated = false; }
private void update() { if (updated) { return; } tempStartOffsets = new long[size]; tempEndOffsets = new long[size]; int i = 0; for (Map.Entry<Long,NodePosition> entry: startMap.entrySet()) { tempStartOffsets[i] = entry.getKey(); tempEndOffsets[i] = entry.getValue().getTempEndOffset(); i++; } Arrays.sort(tempStartOffsets); Arrays.sort(tempEndOffsets); updated = true; }
public void add(long originalStart, long originalEnd, long tempStart, long tempEnd) { NodePosition mapping = new NodePosition(originalStart, originalEnd, tempStart, tempEnd); add(mapping); }
/** 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(); }
/** 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(); }
tempDoc.getAnnotations(wrappedInputASName).add(mapping.getTempStartOffset(), mapping.getTempEndOffset(), "Input", Factory.newFeatureMap());
@Override public int compare(NodePosition arg0, NodePosition arg1) { long diff = arg0.getTempStartOffset() - arg1.getTempStartOffset(); if (diff != 0L) { return Long.signum(diff); } // implied else diff = arg0.getTempEndOffset() - arg1.getTempEndOffset(); if (diff != 0L) { return Long.signum(diff); } // implied else diff = arg0.getOriginalStartOffset() - arg1.getOriginalStartOffset(); if (diff != 0L) { return Long.signum(diff); } // implied else diff = arg0.getOriginalEndOffset() - arg1.getOriginalEndOffset(); return Long.signum(diff); }