/** * Gets the source content of this entry (can be empty) * If the result is empty, it means the source is the same as the source of the object (segment or text container) * is attached to. * @return the source content of this entry (can be empty) */ public TextContainer getSource () { return tu.getSource(); }
private TextContainer getSource(LocaleId loc) { return parent.getSource(); }
/** * Indicates if a given text unit resource is null, or its source part is null or empty. * * @param textUnit * the text unit to check. * @return true if the given text unit resource is null, or its source part is null or empty. */ public static boolean isEmpty (ITextUnit textUnit) { return ((textUnit == null) || textUnit.getSource().isEmpty()); }
@Override public String toString() { return String.format("%s %d%% %s", type.name(), combinedScore, tu.getSource()); }
public long getWordCount (ITextUnit tu) { return getWordCount(tu.getSource()); }
/** * 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(); }
@Override public Iterator<Segment> iterator() { return parent.getSource().getSegments().iterator(); }
/** * Sets the coded text of the un-segmented source of a given text unit resource. * * @param textUnit * the given text unit resource. * @param text * the text to be set. */ public static void setSourceText (ITextUnit textUnit, String text) { TextFragment source = textUnit.getSource().getFirstContent(); source.setCodedText(text); }
/** * Call this method inside the overriding {@link #leverage(ITextUnit)} method * of the derived class, if that class offers a fast {@link #batchQuery(List)} method. * @param tu the text unit to leverage. */ protected void leverageUsingBatchQuery (ITextUnit tu) { if (( tu == null ) || !tu.getSource().hasText() || !tu.isTranslatable() ) { return; // No need to query } List<ITextUnit> tuList = new ArrayList<ITextUnit>(); tuList.add(tu); batchLeverageUsingBatchQuery(tuList); }
@Override protected boolean isEmpty(ITextUnit textUnit) { if (textUnit == null) return true; TextContainer source = textUnit.getSource(); Property prop = textUnit.getProperty(PROP_QUALIFIED); boolean isQualified = prop != null && "yes".equals(prop.getValue()); if (source.isEmpty() && !isQualified) return true; // 12/7/2015 Setting this to false otherwise it skips empty targets. // See isssue #511 return false; //return super.isEmpty(textUnit); // Always false in superclass } }
/** * Returns the character count information stored by CharacterCountStep in a given segment of the source part of a given text unit. * @param tu the given tu * @param segIndex index of the segment in the source * @return number of characters (0 if no character count information found) */ public static long getCount(ITextUnit tu, int segIndex) { ISegments segments = tu.getSource().getSegments(); return getCount(segments.get(segIndex)); }
/** * Returns the word count information stored by WordCountStep in a given segment of the source part of a given text unit. * @param tu the given tu * @param segIndex index of the segment in the source * @return number of words (0 if no word count information found) */ public static long getCount(ITextUnit tu, int segIndex) { ISegments segments = tu.getSource().getSegments(); return getCount(segments.get(segIndex)); }
public void endCode(String tag) { 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); } c.appendOuterData(tag); ITextUnit tu = peekMostRecentTextUnit(); if (tu == null) return; // We can use the first part as nothing is segment at this point tu.getSource().getFirstContent().append(c); }
public static void unsegmentTU(ITextUnit tu) { tu.getSource().joinAll(); for (LocaleId trgLoc : tu.getTargetLocales()) { tu.getTarget(trgLoc).joinAll(); } } }
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; }
@Override protected void processTextUnit (Event event) { // XLIFF event = writer.handleEvent(event); // TMX files writeTMXEntries(event.getTextUnit()); // Check if it has been segmented (if not set already) if ( !preSegmented ) { preSegmented = event.getTextUnit().getSource().hasBeenSegmented(); } }
private void removeMetric (ITextUnit textUnit) { TextContainer source = textUnit.getSource(); ISegments segs = source.getSegments(); if (segs != null) { for (Segment seg : segs) { removeFromMetrics(seg, getMetric()); } } removeFromMetrics(source, getMetric()); removeFromMetrics(textUnit, getMetric()); }
@Override protected ITextUnit postProcessTextUnit(ITextUnit textUnit) { TextFragment text = textUnit.getSource().getFirstContent(); text.setCodedText(text.getCodedText()); if ( codeFinder != null ) { encoderManager.updateEncoder(textUnit.getMimeType()); codeFinder.process(text); } text.setCodedText(text.getCodedText()); return textUnit; }
@SuppressWarnings("resource") protected List<Event> callSubfilter(ITextUnit parent) { String parentId = parent.getId(); if (Util.isEmpty(parentId)) { parentId = idGenerator.getLastId(); } // force creation of the parent encoder SubFilter sf = new SubFilter(subFilter, getEncoderManager().getEncoder(), ++subfilterIndex, parentId, parent.getName()); // RawDocument closed inside the subfilter call return sf.getEvents(new RawDocument(parent.getSource().getFirstContent().getText(), srcLang)); }