public VersifiedTextWriter() { formatter = new GenericContent(); }
RequestInfo(TextFragment fragment) { this.originalFragment = fragment; this.preparedText = GenericContent.fromFragmentToLetterCoded(originalFragment, true); }
/** * Converts a letter-coded text to a fragment. * <p>A letter-coded text is like "<g1>text<x2/></g1><b3/>". * @param text the text to convert. * @param fragment optional existing fragment where to set the converted data, or null to create a new fragment. * If an existing fragment is provided, no existing code is preserved: all codes are coming from the parsing * of the input text, except if reuseCodes is set to true. * @param reuseCodes true to re-use the codes of the provided text fragment. If a code is not found in the * provided text fragment, one is created for the output. * @return the new fragment created from the text. */ @Deprecated public static TextFragment fromLetterCodedToFragment (String text, TextFragment fragment, boolean reuseCodes) { return fromLetterCodedToFragment(text, fragment, reuseCodes, false); }
public static String printMarkerIndexes (TextFragment textFragment) { return (new GenericContent(textFragment)).printMarkerIndexes(); }
public static String printMarkers (TextFragment textFragment) { return (new GenericContent(textFragment)).toString(); }
for ( Segment seg : textCont.getSegments() ) { writer.write("<p>"); //$NON-NLS-1$ writer.write(Util.escapeToXML(sampleOutput.setContent(seg.text).toString(true), 0, false, null)); writer.write("</p>"); //$NON-NLS-1$ writer.write(sampleOutput.printSegmentedContent(textCont, true, true));
plain = GenericContent.fromFragmentToLetterCoded(text, true); qr.source = GenericContent.fromLetterCodedToFragment((String)map.get("source"), null, false, true); qr.target = GenericContent.fromLetterCodedToFragment((String)map.get("target"), null, false, true);
if ( forExtractMerge ) { if ( tc.contentIsOneSegment() ) { tmp = GenericContent.fromFragmentToLetterCoded(tc.getFirstContent(), true); tmp = GenericContent.fromFragmentToLetterCoded(tc.getUnSegmentedContentCopy(), true); tmp = fmt.printSegmentedContent(tc, false, !params.getOutputGeneric());
/** * Prints a string representation of a given segmented text, with optional * markers to indicate the segments boundaries. * @param container the container to output. * @param showSegments true if segment boundaries should be shown. * @param normalText true to show in-line real data instead of generic codes. * @return a string with the segmented text output. */ public String printSegmentedContent (TextContainer container, boolean showSegments, boolean normalText) { StringBuilder tmp = new StringBuilder(); for ( TextPart part : container ) { if ( part instanceof Segment ) { if ( showSegments ) tmp.append("["); tmp.append(setContent(part.text).toString(normalText)); if ( showSegments ) tmp.append("]"); } else { tmp.append(setContent(part.text).toString(normalText)); } } return tmp.toString(); }
/** * Prints a generic string representation of a given segmented text, with optional * markers to indicate the segments boundaries. * @param container The container to output. * @param showSegments True if segment boundaries should be shown. * @return A string with the segmented text output. */ public String printSegmentedContent (TextContainer container, boolean showSegments) { return printSegmentedContent(container, showSegments, false); }
/** * Generates an generic coded string from the content. * @return The generic string. */ @Override public String toString () { return toString(false); }
public GenericContent (TextFragment content) { setContent(content); }
writer.writeRawXML("</td>"); //$NON-NLS-1$ writer.writeRawXML("<td class='p'>"); //$NON-NLS-1$ fmt.setContent(srcFrag); writer.writeString(fmt.toString(!params.getGenericCodes())); if ( srcFrag != null ) writer.writeRawXML("<td>"); //$NON-NLS-1$ else writer.writeRawXML("<td class='p'>"); //$NON-NLS-1$ fmt.setContent(trgFrag1); writer.writeString(fmt.toString(!params.getGenericCodes())); writer.writeRawXML("</td></tr>"); //$NON-NLS-1$ writer.writeString(params.getDocument2Label()+":"); writer.writeRawXML("</td><td>"); //$NON-NLS-1$ fmt.setContent(trgFrag2); writer.writeString(fmt.toString(!params.getGenericCodes())); writer.writeRawXML("</td></tr>"); //$NON-NLS-1$ writer.writeString(params.getDocument3Label()+":"); writer.writeRawXML("</td><td>"); //$NON-NLS-1$ fmt.setContent(trgFrag3); writer.writeString(fmt.toString(!params.getGenericCodes())); writer.writeRawXML("</td></tr>"); //$NON-NLS-1$
private boolean writeTextContainer(TextContainer tc) { try { if (tc == null) { return false; } String tmp; tmp = formatter.printSegmentedContent(tc, false, false); // replace with original format linefeeds tmp = tmp.replace("\n", linebreak); writer.write(tmp); // No wrapping needed if (tmp.endsWith("\n")) { return true; } return false; } catch (IOException e) { throw new OkapiIOException("Error writing TextContainer.", e); } } }
public FileProcessor () { patternOpening = Pattern.compile("\\<(\\w+[^\\>]*)\\>"); //$NON-NLS-1$ patternClosing = Pattern.compile("\\</(\\w+[^\\>]*)\\>"); //$NON-NLS-1$ patternPlaceholder = Pattern.compile("\\<(\\w+[^\\>]*)/\\>"); //$NON-NLS-1$ sampleOutput = new GenericContent(); }
/** * Converts a text fragment into a letter-coded text. * Use {@link #fromLetterCodedToFragment(String, TextFragment, boolean)} to convert back to a fragment. * @param fragment the fragment to convert. * @return the resulting letter-coded text. */ @Deprecated public static String fromFragmentToLetterCoded (TextFragment fragment) { return fromFragmentToLetterCoded(fragment, false); }
TextFragment generateResult(String translated) { return GenericContent.fromLetterCodedToFragment(translated, originalFragment.clone(), true, true); } }
sampleText.getSegments().create(segmenter.getRanges()); edResults.setText(sampleOutput.printSegmentedContent(sampleText, true, true));
public POWriter () { params = new Parameters(); fmt = new GenericContent(); plurals = new ArrayList<ITextUnit>(); makePOT = false; forExtractMerge = false; transFuzzy = true; }
private void writeQuotedContent (TextFragment tf) { try { String tmp = GenericContent.fromFragmentToLetterCoded(tf, true); tmp = escapeIfNeeded(tmp); writer.write("\""); writer.write(tmp); // No wrapping needed writer.write("\""); } catch ( IOException e ) { throw new OkapiIOException("Error writing a quoted text.", e); } }