private static AlignedString createBase(final String base) { final AlignedString d = new AlignedString(); d._first._next = d.new BaseSegment(d._first, d._last, base); d._last._prev = d._first._next; return d; }
/** * Deletes data. * * @param start * the start offset. * @param end * the end offset+1. */ public void delete(final int start, final int end) { replace(start, end, null); }
public void updateCaches() { if (_underlying != null) { _underlying.updateCaches(); } get(); if (_startDirty) { int length = 0; AbstractDataSegment seg = _first; while (seg != null) { seg._cachedStart = length; length += seg.length(); seg = seg._next; } _startDirty = false; System.out.println("startDirty false"); } }
public AlignedString(final AlignedString underlying) { _underlying = underlying; _underlying.addChangeListener(this); _first._next = new ObliqueSegment(_first, _last, _underlying.getAnchor(0), _underlying.getAnchor(_underlying.length())); _last._prev = _first._next; }
@Override public void afterProcess(JCas aInput, JCas aOutput) AlignedString alignedString = new AlignedString(aInput.getDocumentText()); switch (change.getAction()) { case INSERT: alignedString.insert(change.getStart(), change.getText()); break; case DELETE: alignedString.delete(change.getStart(), change.getEnd()); break; case REPLACE: alignedString.replace(change.getStart(), change.getEnd(), change.getText()); break; default: aOutput.setDocumentText(alignedString.get()); Interval i = alignedString.inverseResolve(new ImmutableInterval(annoFs .getBegin(), annoFs.getEnd())); fsCopy.setIntValue(beginFeature, i.getStart());
AlignedString alignmentState = new AlignedString(aSourceView.getDocumentText()); for (SofaChangeAnnotation a : edits) { if (ApplyChangesAnnotator.OP_INSERT.equals(a.getOperation())) { alignmentState.insert(a.getBegin(), a.getValue()); alignmentState.delete(a.getBegin(), a.getEnd()); alignmentState.replace(a.getBegin(), a.getEnd(), a.getValue());
public static void applyChanges(AlignedString as, List<SofaChangeAnnotation> changes) { // If we remove or add stuff all offsets right of the change location // will change and thus the offsets in the change annotation are no // longer valid. If we move from right to left it works better because // the left offsets remain stable. Collections.reverse(changes); for (SofaChangeAnnotation c : changes) { if (OP_INSERT.equals(c.getOperation())) { // getContext().getLogger().log(INFO, // "Performing insert: "+a.getBegin()+"-"+a.getEnd()); as.insert(c.getBegin(), c.getValue()); } if (OP_DELETE.equals(c.getOperation())) { // getContext().getLogger().log(INFO, // "Performing delete: "+a.getBegin()+"-"+a.getEnd()); as.delete(c.getBegin(), c.getEnd()); } if (OP_REPLACE.equals(c.getOperation())) { // getContext().getLogger().log(INFO, // "Performing replace: "+a.getBegin()+"-"+a.getEnd()); as.replace(c.getBegin(), c.getEnd(), c.getValue()); } } } }
insert(start, d); return; final AbstractDataSegment segAtStart = getSegmentAt(start); final AbstractDataSegment segAtEnd = getSegmentAt(end - 1, end > 1); dropSuperflourous(prefix); dropSuperflourous(suffix); fireChange();
/** * Fetch data * * @param start * the start offset. * @param end * the end offset. * @return the data. */ public String get(final int start, final int end) { return get().substring(start, end); }
private void updateOffsets(CAS sourceView, JCas targetView, AlignedString as, PositiveIntSet aCopiedFs) throws CASException, AnalysisEngineProcessException { // We only update annotations that were copied, nothing that was already there. IntListIterator it = aCopiedFs.iterator(); while (it.hasNext()) { FeatureStructure fs = targetView.getLowLevelCas().ll_getFSForRef(it.next()); if (fs instanceof Annotation) { // Now we update the offsets Annotation a = (Annotation) fs; // System.out.printf("Orig %s %3d %3d : %s%n", a.getType().getShortName(), // a.getBegin(), a.getEnd(), // sourceView.getDocumentText().substring(a.getBegin(), a.getEnd())); // System.out.printf("Before %s %3d %3d : %s%n", a.getType().getShortName(), // a.getBegin(), a.getEnd(), a.getCoveredText()); Interval resolved = as.resolve(new ImmutableInterval(a.getBegin(), a.getEnd())); a.setBegin(resolved.getStart()); a.setEnd(resolved.getEnd()); // System.out.printf("After %s %3d %3d : %s%n", a.getType().getShortName(), // a.getBegin(), a.getEnd(), a.getCoveredText()); } } } }
@Override public String toString() { return dataSegmentsToString(); }
public AlignedString(final String base) { this(createBase(base)); }
protected void applyChanges(JCas aSourceView, JCas aTargetView) { AlignedString as = AlignmentFactory.createAlignmentsFor(aSourceView); // Set the text of the new Sofa aTargetView.setDocumentText(as.get()); // Set document language aTargetView.setDocumentLanguage(aSourceView.getDocumentLanguage()); // Optionally we may want to remember the AlignedString for the backmapper. AlignmentStorage.getInstance().put(aSourceView.getCasImpl().getBaseCAS(), aSourceView.getViewName(), aTargetView.getViewName(), as); } }
final Interval ulpos = resolve(new ImmutableInterval(seg.getStart(), seg.getEnd()));
AlignedString as = new AlignedString(jcas.getDocumentText()); NormalizationUtils.applyChanges(as, allChanges);