/** * Gets the coded text of the first part of the source of a given text unit resource. * * @param textUnit * the text unit resource which source text should be returned. * @return the source part of the given text unit resource. */ public static String getSourceText (ITextUnit textUnit) { // if ( textUnit == null ) return ""; // return getCodedText(textUnit.getSourceContent()); return textUnit.getSource().getFirstContent().getCodedText(); }
/** * Effectively marks the segment for removal by emptying the content for the * given target. the text unit will be pruned by a different method * ({@link #pruneTextUnit(ITextUnit, LocaleId)}). * * @param tu the text unit containing the content * @param seg the segment to be marked for removal * @param targetLocale the locale for which the segment should be removed */ protected void markSegmentForRemoval(ITextUnit tu, Segment seg, LocaleId targetLocale) { tu.getTargetSegment(targetLocale, seg.getId(), false).getContent().clear(); }
@Override public Segment getCorrespondingSource(Segment trgSeg, LocaleId trgLoc) { ISegments srcSegs = getSource(trgLoc).getSegments(); return srcSegs.get(trgSeg.id); }
public static void unsegmentTU(ITextUnit tu) { tu.getSource().joinAll(); for (LocaleId trgLoc : tu.getTargetLocales()) { tu.getTarget(trgLoc).joinAll(); } } }
public void simplifyOpeningClosing (TextFragment tf) { prepare(tf.getCodedText(), tf.getCodes()); simplifyOpeningClosing(); tf.setCodedText(getCodedText(), getCodes()); }
@Override public Segment getTargetSegment(LocaleId trgLoc, String segId, boolean createIfNeeded) { Segment seg = createTarget(trgLoc, false, IResource.COPY_SEGMENTATION).getSegments().get(segId); if (( seg == null ) && createIfNeeded ) { // If the segment does not exists: create a new one if requested seg = new Segment(segId); getTarget(trgLoc).getSegments().append(seg); //TODO consider appending a segment to variant source if present } return seg; }
@Override public Segment getSourceSegment(String segId, boolean createIfNeeded) { Segment seg = getSource().getSegments().get(segId); if ((seg == null) && createIfNeeded) { seg = new Segment(segId); getSource().getSegments().append(seg); } return seg; }
private static int incrementCodeIdsByOffset(TextFragment tf, int delta) { int count = 0; for ( Code code : tf.getCodes() ) { code.setId(code.getId() + delta); if (code.getTagType() != TagType.CLOSING) count++; } return count; } }
@Override public TextFragment setTargetContent (LocaleId locId, TextFragment content) { TextContainer tc = createTarget(locId, false, CREATE_EMPTY); tc.setContent(content); // We can use this because the setContent() removed any segmentation return tc.getSegments().getFirstContent(); }
@Override public TextFragment setSourceContent (TextFragment content) { getSource().setContent(content); return getSource().getFirstContent(); }
private void doJoinWithNext(TextContainer cont, String segId) { int segIndex; ISegments segs = cont.getSegments(); segIndex = segs.getIndex(segId); if (segIndex != -1) segs.joinWithNext(segIndex); }
@Override public Iterator<Segment> iterator(LocaleId trgLoc) { return getSource(trgLoc).getSegments().iterator(); }
/** * Indicates if this text has at least one annotation of a given type. * @param type the type of annotation to look for. * @return true if there is at least one annotation of the given type, false otherwise. */ public boolean hasAnnotation (String type) { if ( !hasCode() ) return false; for ( Code code : codes ) { if ( code.hasAnnotation(type) ) return true; } return false; }
@Override public AlignmentStatus getAlignmentStatus() { for (LocaleId loc : parent.getTargetLocales()) { ISegments trgSegs = parent.getTargetSegments(loc); if (trgSegs.getAlignmentStatus() == AlignmentStatus.NOT_ALIGNED) { return AlignmentStatus.NOT_ALIGNED; } } return AlignmentStatus.ALIGNED; }
/** * Gets the string representation of the default source container. * If the container is segmented, the representation shows the merged segments. * Inline codes are also included. * * @return the string representation of the source container. */ @Override public String toString () { return getSource().toString(); }
public static void renumberCodes(TextContainer tc) { for (TextPart textPart : tc) { textPart.getContent().renumberCodes(1); } }
@Override public void joinWithNext(Segment seg, LocaleId trgLoc) { ContainerIterator ci = new ContainerIterator(trgLoc); if (ci.hasSource()) doJoinWithNext(ci.getSource(), seg.id); if (ci.hasTarget()) doJoinWithNext(ci.getTarget(), seg.id); }
/** * Indicates if this text has at least one annotation. * @return true if there is at least one annotation, false otherwise. */ public boolean hasAnnotation () { if ( !hasCode() ) return false; for ( Code code : codes ) { if ( code.hasAnnotation() ) return true; } return false; }