/** * Gets the target content of this entry. * * @return the target content of this entry. */ public TextContainer getTarget () { return tu.getTarget(trgLocId); }
public static void unsegmentTU(ITextUnit tu) { tu.getSource().joinAll(); for (LocaleId trgLoc : tu.getTargetLocales()) { tu.getTarget(trgLoc).joinAll(); } } }
/** * * @param trgLoc * used to determine which TextContainers are in which * categories */ public ContainerIterator(LocaleId trgLoc) { theSource = AlignedSegments.this.getSource(trgLoc); theTarget = parent.getTarget(trgLoc); }
/** * Removes all inline tags in the source (or optionally the target) text unit resource. * @param textUnit the given text unit * @param removeTargetCodes - remove target codes? */ public static void removeCodes(ITextUnit textUnit, boolean removeTargetCodes) { Logger localLogger = LoggerFactory.getLogger(TextUnitUtil.class); if (textUnit == null) { localLogger.warn("Text unit is null."); return; } // remove source inline codes TextContainer stc = textUnit.getSource(); removeCodes(stc); // if requested and if targets exist remove inline codes for all targets if (removeTargetCodes && !textUnit.getTargetLocales().isEmpty()) { for (LocaleId locale: textUnit.getTargetLocales()) { TextContainer ttc = textUnit.getTarget(locale); removeCodes(ttc); } } }
public static boolean needsPreserveWhitespaces(ITextUnit tu) { if (needsPreserveWhitespaces(tu.getSource())) return true; for (LocaleId trgLoc : tu.getTargetLocales()) { if (needsPreserveWhitespaces(tu.getTarget(trgLoc))) return true; } return false; }
/** * Attaches an annotation to the target part of a given text unit resource in a given language. * * @param textUnit * the given text unit resource. * @param locId * the locale of the target part being attached to. * @param annotation * the annotation to be attached to the target part of the text unit. */ public static void setTargetAnnotation (ITextUnit textUnit, LocaleId locId, IAnnotation annotation) { if ( textUnit == null ) return; if ( Util.isNullOrEmpty(locId) ) return; if ( textUnit.getTarget(locId) == null ) return; textUnit.getTarget(locId).setAnnotation(annotation); }
private void convertRefs (Event event) { if ( event.isMultiEvent() ) { MultiEvent me = event.getMultiEvent(); for (Event e : me) { convertRefs(e); } } else { if ( event.isTextUnit() ) { ITextUnit tu = event.getTextUnit(); convertTextContainer(tu.getSource()); for (LocaleId locId : tu.getTargetLocales()) { convertTextContainer(tu.getTarget(locId)); } } ISkeleton skel = event.getResource().getSkeleton(); subFilter.convertRefsInSkeleton(skel); } }
public long getWordCount (ITextUnit tu, LocaleId trgId) { if ( !tu.hasTarget(trgId) ) { return 0; } return getWordCount(tu.getTarget(trgId)); }
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); } } }
/** * Sets the coded text of the the target part of a given text unit resource in a given language. * * @param textUnit * the given text unit resource. * @param locId * the locale of the target part being set. * @param text * the text to be set. */ public static void setTargetText (ITextUnit textUnit, LocaleId locId, String text) { TextFragment target = textUnit.getTarget(locId).getFirstContent(); target.setCodedText(text); }
private void mergeTextUnit(ReferenceableEvent referenceableEvent) { ITextUnit textUnit = referenceableEvent.getEvent().getTextUnit(); StyledTextSkeleton styledTextSkeleton = (StyledTextSkeleton) textUnit.getSkeleton(); storyChildElements = styledTextSkeleton.getStoryChildElements(); codeMap = styledTextSkeleton.getCodeMap(); savedStoryChildElements = new ArrayDeque<>(); savedBreak = saveBreak(storyChildElements); storyChildElements.clear(); currentStyleDefinitions = new ArrayDeque<>(); contentTextBuilder = new StringBuilder(); contentEvents = new ArrayList<>(); mergeTextContainer(null == textUnit.getTarget(targetLocale) ? textUnit.getSource() : textUnit.getTarget(targetLocale)); }
private TextContainer getTargetForOutput(ITextUnit tu) { // disallow empty targets if (targetLocale == null) { return tu.getSource(); } TextContainer trgCont = tu.getTarget(targetLocale); if (trgCont == null || trgCont.isEmpty()) { return tu.getSource(); } return trgCont; }
private void processWithoutSegments (ITextUnit tu) { try { // ID reference to allow merging back and duplication of msgid text writer.write("\"" + crumbs + ":" + TEXTUNIT_CRUMB+tu.getId() + "\"\t"); // Source writeQuotedContent(tu.getSource()); writer.write("\t"); // Target TextContainer tc = tu.getTarget(language); if ( tc != null ) { writeQuotedContent(tc); } // EOL writer.write(LINEBREAK); } catch ( IOException e ) { throw new OkapiIOException("Error writing text unit.", e); } }
private void procEndElemAddToTuContent(EndElement endElement, ITextUnit tu) { StringBuilder sb = new StringBuilder(); sb.append("</" + endElement.getName().getLocalPart() + ">"); if (ts.currentMessageLocation == MessageLocation.SOURCE) { TextContainer tc = tu.getSource(); if (!tc.hasText()) { skel.addContentPlaceholder(tu); } tc.getFirstContent().append(sb.toString()); } else if (ts.currentMessageLocation == MessageLocation.TARGET) { TextContainer tc = tu.getTarget(trgLang); if (!tc.hasText()) { skel.addContentPlaceholder(tu, trgLang); } tc.getFirstContent().append(sb.toString()); } }
/** * Gets text of the first part of the target of a given text unit resource in the given locale. * * @param textUnit * the text unit resource which source text should be returned. * @param locId * the locale the target part being sought. * @return the target part of the given text unit resource in the given loacle, or an empty string if the text unit * doesn't contain one. */ public static String getTargetText (ITextUnit textUnit, LocaleId locId) { if (textUnit == null) return ""; if (Util.isNullOrEmpty(locId)) return ""; return getCodedText(textUnit.getTarget(locId).getFirstContent()); }
protected void removeTrailingWhitespace(ITextUnit textUnit) { TextContainer targetTextContainer = textUnit.getTarget(targetLocale); /** * If whitespace trimming was enabled during segmentation, the * whitespace will be trapped in non-Segment TextParts. So * we need to check everything in the container, not just the * results of tu.getTargetSegments(); */ for (TextPart targetTextPart : targetTextContainer.getParts()) { TextFragment textFragment = findAndRemoveWhitespacesAfterPunctuation(targetTextPart.getContent()); targetTextPart.setContent(textFragment); } }
protected void addTrailingWhitespace(ITextUnit textUnit) { TextContainer sourceTextContainer = textUnit.getSource(); TextContainer targetTextContainer = textUnit.getTarget(targetLocale); Iterator<TextPart> sourceTextPartsIterator = sourceTextContainer.getParts().iterator(); Iterator<TextPart> targetTextPartsIterator = targetTextContainer.getParts().iterator(); while (sourceTextPartsIterator.hasNext() && targetTextPartsIterator.hasNext()) { TextPart sourceTextPart = sourceTextPartsIterator.next(); TextPart targetTextPart = targetTextPartsIterator.next(); String sourceText = sourceTextPart.getContent().getText(); if (sourceText.isEmpty() || !isNonSpaceDelimitedPunctuation(lastChar(sourceText))) { // the text does not end with punctuation requiring conversion continue; } if (isWhitespace(lastChar(targetTextPart.getContent().getText()))) { // the whitespace is present at the end continue; } targetTextPart.getContent().append(WHITESPACE); } }
public void endCode() { Code c = null; try { c = codeStack.pop(); } catch (EmptyStackException e) { throw new OkapiIllegalFilterOperationException( "Trying to end a Code that does not exist. Did you call startCode?", e); } ITextUnit tu = peekMostRecentTextUnit(); if (tu == null) return; // We can use the first part as nothing is segment at this point LocaleId trgLoc = getTargetLocale(); if (trgLoc == null) { tu.getSource().getFirstContent().append(c); } else { if (tu.getTarget(trgLoc) == null) { tu.createTarget(trgLoc, true, ITextUnit.CREATE_EMPTY); } tu.getTarget(trgLoc).getFirstContent().append(c); } }
/** * Converts an un-segmented TextUnit into a TranslationUnit. The target may not exist, in that case * its content is stored as a null. * @param sourceLoc the source locale to transform. * @param targetLoc the target locale to transform. * @param textUnit the text unit to convert. * @return a TranslationUnit that represents the TextUnit */ public static TranslationUnit convertToTranslationUnit (LocaleId sourceLoc, LocaleId targetLoc, ITextUnit textUnit) { TranslationUnitVariant source = new TranslationUnitVariant(sourceLoc, textUnit.getSource().getFirstContent()); TextContainer tc = textUnit.getTarget(targetLoc); // Allow null target content TranslationUnitVariant target = new TranslationUnitVariant(targetLoc, (( tc==null ) ? null : tc.getFirstContent())); TranslationUnit tu = new TranslationUnit(source, target); populateMetaDataFromProperties(textUnit, tu); return tu; }