/** * 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 void append(TextFragment fragment, boolean collapseIfPreviousEmpty) { append(new Segment(null, fragment), collapseIfPreviousEmpty); }
private boolean hasExistingCandidate (Segment srcSeg, ISegments trgSegs) { if ( trgSegs == null ) return false; // No target at all Segment trgSeg = trgSegs.get(srcSeg.getId()); if ( trgSeg == null ) return false; // No target segment // Do we have the annotation? AltTranslationsAnnotation ann = trgSeg.getAnnotation(AltTranslationsAnnotation.class); if ( ann == null ) return false; // No AltTranslationsAnnotation // Do we have at least one entry return (ann.getFirst() != null); }
protected void saveToMetrics(Segment seg, long count) { if (seg == null) return; if (count == 0) return; MetricsAnnotation ma = seg.getAnnotation(MetricsAnnotation.class); if (ma == null) { ma = new MetricsAnnotation(); seg.setAnnotation(ma); } Metrics m = ma.getMetrics(); if (m == null) return; saveCount(m, count); }
public static boolean checkSegments(Segment sseg, Segment tseg) { // tseg is allowed to be null return sseg != null && (sseg.getContent().hasText() || (tseg != null && tseg.getContent().hasText())); }
Segment tseg = null; if (tsegments != null) { tseg = tsegments.get(seg.getId()); TextFragment content = seg.getContent(); if (content.isEmpty()) continue; RepetitiveSegmentAnnotation ann = new RepetitiveSegmentAnnotation(info, hits); seg.setAnnotation(ann); AltTranslationsAnnotation ata = tseg.getAnnotation(AltTranslationsAnnotation.class); if (ata == null) { ata = new AltTranslationsAnnotation(); tseg.setAnnotation(ata); if (seg.getAnnotation(RepetitiveSegmentAnnotation.class) == null) { RepetitiveSegmentAnnotation ann = new RepetitiveSegmentAnnotation(info, (List<TmHit>) null); seg.setAnnotation(ann);
String itsAllowedCharsPattern = "\u0000"; StringBuilder trgOri = new StringBuilder(tu.getTargetSegment(targetLocale, seg.getId(), false).text);
private void writeSegment(Segment segment) { try { TextFragment content = segment.getContent(); String codedText = content.getCodedText(); List<Code> codes = content.getCodes(); for (int i = 0; i < codedText.length(); i++) { char c = codedText.charAt(i); if (TextFragment.isMarker(c)) { int codeIndex = TextFragment.toIndex(codedText.charAt(++i)); writeCode(codes.get(codeIndex)); } else { writeChar(c); } } } catch (Exception e) { LOGGER.error("Threw {} writing segment id {} '{}'", e.getClass().getSimpleName(), segment.getId(), segment.toString()); throw e; } }
Segment trgSeg = trgSegs.get(srcSeg.getId()); if ( doEliminateEmptyTargetsWithNonEmptySource && trgSeg.getContent().isEmpty() && !srcSeg.getContent().isEmpty() ) trgSeg = null; int trgSegIndex = trgSegs.getIndex(srcSeg.getId()); if ( srcSegIndex != trgSegIndex ) { Segment trgSeg = trgSegs.get(srcSeg.getId()); if ( trgSeg != null ) { if ( doEliminateEmptyTargetsWithNonEmptySource && trgSeg.getContent().isEmpty() && !srcSeg.getContent().isEmpty() ) trgSeg = null; net.sf.okapi.lib.xliff2.core.Segment xSeg = unit.getSegment(srcSegIndex); AltTranslationsAnnotation ann = trgSeg.getAnnotation(AltTranslationsAnnotation.class); if ( ann != null ) { for ( AltTranslation alt : ann ) {
protected Tokens getTokens(Segment segment, LocaleId locale) { TokensAnnotation ta = segment.getAnnotation(TokensAnnotation.class); Tokens allTokens = ta != null ? ta.getTokens() : Tokenizer.tokenize(segment.getContent(), locale); return filterTokens(allTokens); }
public static long getCount(Segment segment, String metricName) { return getValue(segment.getAnnotation(MetricsAnnotation.class), metricName); }
continue; if ( seg.getAnnotations() == null ) { continue; for (IAnnotation ann : seg.getAnnotations()) { tseg.setAnnotation(ann);
private void assembleSegmentContent(Segment segment, StringBuilder textContentBuilder) { TextFragment content = segment.getContent(); String codedText = content.getCodedText(); for (int i = 0; i < codedText.length(); i++) { char c = codedText.charAt(i); textContentBuilder.append(c); } } }
/** * Adds an {@link AltTranslation} object to a given {@link Segment}. * The {@link AltTranslationsAnnotation} annotation is created if it does not exist already. * @param seg the segment where to add the object. * @param alt alternate translation to add. * @return the annotation where the object was added, * it may be a new annotation or the one already associated with the segment. */ public static AltTranslationsAnnotation addAltTranslation (Segment seg, AltTranslation alt) { AltTranslationsAnnotation altTrans = seg.getAnnotation(AltTranslationsAnnotation.class); if ( altTrans == null ) { altTrans = new AltTranslationsAnnotation(); seg.setAnnotation(altTrans); } altTrans.add(alt); return altTrans; }
@Override protected Unit toXLIFF2Unit(ITextUnit unit) { Unit xliffUnit = super.toXLIFF2Unit(unit); int segmentIndex = 0; for (Segment segment : unit.getSourceSegments()) { GlossaryAnnotation glossaryAnnotation = segment.getAnnotation(GlossaryAnnotation.class); net.sf.okapi.lib.xliff2.core.Segment xliffSegment = xliffUnit.getSegment(segmentIndex); addGlossaryReferences(xliffSegment, glossaryAnnotation); segmentIndex++; } for (Segment segment : unit.getSourceSegments()) { GlossaryAnnotation glossaryAnnotation = segment.getAnnotation(GlossaryAnnotation.class); addGlossary(xliffUnit, glossaryAnnotation); } return xliffUnit; }
/** * Converts whitespace ({tab}, {space}, {CR}, {LF}) to single space. * * @param tu: the TextUnit containing the segments to update * @param seg: the Segment to update * @param targetLocale: the language for which the text should be updated */ protected void normalizeWhitespace(ITextUnit tu, Segment seg, LocaleId targetLocale) { TextFragment.unwrap(seg.getContent()); TextFragment.unwrap(tu.getTargetSegment(targetLocale, seg.getId(), false).getContent()); }
Segment ts = trgSegs.get(srcSeg.getId()); if ( hasAlreadyCandidate(ts, null) ) continue; fragsIds.add(tu.getId()+"_"+srcSeg.getId()); if ( !fragsIds.contains(tu.getId()+"_"+srcSeg.getId()) ) { continue; Segment ts = trgSegs.get(srcSeg.getId()); if ( ts == null ) { ts = new Segment(srcSeg.id, new TextFragment("")); trgSegs.append(ts);