private boolean hasExistingCandidate (TextContainer frag) { if ( frag == null ) return false; // No target at all // Do we have the annotation? AltTranslationsAnnotation ann = frag.getAnnotation(AltTranslationsAnnotation.class); if ( ann == null ) return false; // No AltTranslationsAnnotation // Do we have at least one entry return (ann.getFirst() != null); }
public static long getCount(TextContainer tc, String metricName) { return getValue(tc.getAnnotation(MetricsAnnotation.class), metricName); }
private boolean wasDiffLeveraged(ITextUnit tu) { if (tu.getTarget(targetLocale) == null) { return false; } if (tu.getTarget(targetLocale).getAnnotation(DiffMatchAnnotation.class) == null) { return false; } return true; } }
/** * Gets an annotation attached to the source part of a given text unit resource. * * @param <A> a class implementing IAnnotation * @param textUnit * the given text unit resource. * @param type * reference to the requested annotation type. * @return the annotation or null if not found. */ public static <A extends IAnnotation> A getSourceAnnotation (ITextUnit textUnit, Class<A> type) { if (textUnit == null) return null; if (textUnit.getSource() == null) return null; return textUnit.getSource().getAnnotation(type); }
protected Tokens getTokens(TextContainer textContainer, LocaleId locale) { TokensAnnotation ta = textContainer.getAnnotation(TokensAnnotation.class); Tokens allTokens = ta != null ? ta.getTokens() : Tokenizer.tokenize(textContainer, locale); return filterTokens(allTokens); }
/** * Adds an annotation to a text container. If the text container has * no annotation set attached yet one is created and attached, * otherwise the annotation to add is added to the existing set. * @param tc the text container where to attach the annotation. * @param ann the annotation to attach (if null, nothing is attached). */ static public void addAnnotation (TextContainer tc, GenericAnnotation ann) { if ( ann == null ) return; GenericAnnotations anns = tc.getAnnotation(GenericAnnotations.class); if ( anns == null ) { anns = new GenericAnnotations(); tc.setAnnotation(anns); } anns.add(ann); }
/** * Checks if the segment or container has already a translation candidate * with a score equal or above a given value. * @param seg the segment entry (or null to use the container, or if there is no segment) * @param tc the container entry (or null to use the segment) * @return true if the entry has at least one candidate with a score equal or above the given threshold. */ private boolean hasAlreadyCandidate (Segment seg, TextContainer tc) { AltTranslationsAnnotation ann = null; if ( seg != null ) ann = seg.getAnnotation(AltTranslationsAnnotation.class); else if ( tc != null ) ann = tc.getAnnotation(AltTranslationsAnnotation.class); if ( ann == null ) return false; AltTranslation alt = ann.getFirst(); if ( alt == null ) return false; return (alt.getCombinedScore() >= noQueryThreshold); }
/** * Adds an {@link AltTranslation} object to a given {@link TextContainer}. The {@link AltTranslationsAnnotation} * annotation is created if it does not exist already. * @param targetContainer the container 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 container. */ public static AltTranslationsAnnotation addAltTranslation (TextContainer targetContainer, AltTranslation alt) { AltTranslationsAnnotation altTrans = targetContainer.getAnnotation(AltTranslationsAnnotation.class); if ( altTrans == null ) { altTrans = new AltTranslationsAnnotation(); targetContainer.setAnnotation(altTrans); } altTrans.add(alt); return altTrans; }
protected void removeFromMetrics(TextContainer textContainer, String metricName) { if (textContainer == null) return; MetricsAnnotation ma = textContainer.getAnnotation(MetricsAnnotation.class); if (ma == null) { ma = new MetricsAnnotation(); textContainer.setAnnotation(ma); } Metrics m = ma.getMetrics(); if (m == null) return; m.unregisterMetric(metricName); }
protected void saveToMetrics(TextContainer textContainer, long count) { if (textContainer == null) return; //if (count == 0) return; MetricsAnnotation ma = textContainer.getAnnotation(MetricsAnnotation.class); if (ma == null) { ma = new MetricsAnnotation(); textContainer.setAnnotation(ma); } Metrics m = ma.getMetrics(); if (m == null) return; saveCount(m, count); }
protected void saveToMetrics(TextContainer textContainer, Counts count) { if (textContainer == null) return; //if (count == 0) return; MetricsAnnotation ma = textContainer.getAnnotation(MetricsAnnotation.class); if (ma == null) { ma = new MetricsAnnotation(); textContainer.setAnnotation(ma); } Metrics m = ma.getMetrics(); if (m == null) return; saveCount(m, count); }
protected void removeFromMetrics(TextContainer textContainer, String metricName) { if (textContainer == null) return; MetricsAnnotation ma = textContainer.getAnnotation(MetricsAnnotation.class); if (ma == null) { ma = new MetricsAnnotation(); textContainer.setAnnotation(ma); } Metrics m = ma.getMetrics(); if (m == null) return; m.unregisterMetric(metricName); }
/** * Gets an annotation attached to the target part of a given text unit resource in a given locale. * * @param <A> a class implementing IAnnotation * @param textUnit * the given text unit resource. * @param locId * the locale of the target part being sought. * @param type * reference to the requested annotation type. * @return the annotation or null if not found. */ public static <A extends IAnnotation> A getTargetAnnotation (ITextUnit textUnit, LocaleId locId, Class<A> type) { if ( textUnit == null ) return null; if ( Util.isNullOrEmpty(locId) ) return null; if ( textUnit.getTarget(locId) == null ) return null; return textUnit.getTarget(locId).getAnnotation(type); }
TermsAnnotation ann = tu.getSource().getAnnotation(TermsAnnotation.class); if ( ann != null ) { for ( int i=0; i<ann.size(); i++ ) {
private void resolveTU (ITextUnit tu) { MetricsAnnotation ma = tu.getAnnotation(MetricsAnnotation.class); resolve(ma, true); TextContainer tc = tu.getSource(); ma = tc.getAnnotation(MetricsAnnotation.class); resolve(ma, false); for (Segment seg : tc.getSegments()) { ma = seg.getAnnotation(MetricsAnnotation.class); resolve(ma, false); } for (LocaleId trgLoc : tu.getTargetLocales()) { tc = tu.getTarget(trgLoc); ma = tc.getAnnotation(MetricsAnnotation.class); resolve(ma, false); for (Segment seg : tc.getSegments()) { ma = seg.getAnnotation(MetricsAnnotation.class); resolve(ma, false); } } }
@Override protected Event handleTextUnit (Event event) { ITextUnit tu = event.getTextUnit(); long srcWordCount = 0; if ( tu.isEmpty() || !tu.isTranslatable() ) { return event; } if ( !tu.getSource().isEmpty() ) { srcWordCount = countWords(tu.getSource().getUnSegmentedContentCopy().getText()); srcBatchItemWordCount += srcWordCount; } MetricsAnnotation sma = tu.getSource().getAnnotation(MetricsAnnotation.class); if ( sma == null ) { sma = new MetricsAnnotation(); tu.getSource().setAnnotation(sma); } Metrics m = sma.getMetrics(); m.setMetric(GMX.TotalWordCount, srcWordCount); return event; }
if (acceptATA(target.getAnnotation(AltTranslationsAnnotation.class))) { textContainerCount = count(source, srcLocale); saveToMetrics(target, textContainerCount);
ata = tu.getTarget(targetLocale).getAnnotation(AltTranslationsAnnotation.class); if (ata != null) {
srcOriginal = tu.getSource().getUnSegmentedContentCopy(); writeAltTranslations(tc.getAnnotation(AltTranslationsAnnotation.class), srcOriginal);
atAnn = tc.getAnnotation(AltTranslationsAnnotation.class); if ( atAnn != null ) { for ( AltTranslation at : atAnn ) {