Package net.sf.okapi.lib.merge.merge
Class SkeletonMergerWriter
- java.lang.Object
-
- net.sf.okapi.lib.merge.merge.SkeletonMergerWriter
-
- All Implemented Interfaces:
AutoCloseable,IFilterWriter
public class SkeletonMergerWriter extends Object implements IFilterWriter
Basic class for skeleton-based merging. Override for specific behaviors.Takes a skeleton file and
Events from a translated document. Translated segments are merged into the skeletonTextUnitevents and written out using the defaultIFilterWriter- Author:
- jimh
-
-
Constructor Summary
Constructors Constructor Description SkeletonMergerWriter()SkeletonMergerWriter(IFilter skeletonFilter, IFilterWriter writer, ITextUnitMerger textUnitMerger)Use specificIFilterandIFilterWriterimplementationsSkeletonMergerWriter(IFilter skeletonFilter, ITextUnitMerger textUnitMerger)Use specificIFilterandIFilterWriterimplementationsSkeletonMergerWriter(ITextUnitMerger textUnitMerger)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcancel()Cancels the current process.voidclose()Closes the output.EncoderManagergetEncoderManager()Gets the current encoder manager for this writer.StringgetName()Gets the name of this writer.ParametersgetParameters()Gets the current parameters for this writer.ISkeletonWritergetSkeletonWriter()Gets the skeleton writer associated with this writer.EventhandleEvent(Event event)Handles the filter events.protected voidprocessEndDocument()There are no moreTextUnits.protected voidprocessStartDocument()Use the skeletonStartDocumentevent to initialize theIFilterWriter.protected voidprocessTextUnit(Event event)Take the translatedTextUnitand match it up with its corresponding skeleton version.protected EventprocessUntilTextUnit()Get events in the original document until the next text unit.voidsetFilter(IFilter skeletonFilter)Set theIFilterneeded to process the skeleton file (normally the original document)voidsetOptions(LocaleId targetLocale, String defaultEncoding)Sets the options for this writer.voidsetOutput(OutputStream output)Sets the output through its output stream.voidsetOutput(String path)Sets the output through the path of the output file.voidsetParameters(IParameters params)Sets new parameters for this writer.voidsetWriter(IFilterWriter writer)Set theIFilterWriterused to write out the skeleton events.
-
-
-
Constructor Detail
-
SkeletonMergerWriter
public SkeletonMergerWriter()
-
SkeletonMergerWriter
public SkeletonMergerWriter(ITextUnitMerger textUnitMerger)
-
SkeletonMergerWriter
public SkeletonMergerWriter(IFilter skeletonFilter, IFilterWriter writer, ITextUnitMerger textUnitMerger)
Use specificIFilterandIFilterWriterimplementations- Parameters:
skeletonFilter- -IFilterused to read skeleton, can be serialized events or original source file. ASSUME FILTER OPEN ALREADY CALLEDwriter- - override the writer specified in the skeletonStartDocumentevent. Can use null value for writer to use the default writer.textUnitMerger- user createdITextUnitMerger
-
SkeletonMergerWriter
public SkeletonMergerWriter(IFilter skeletonFilter, ITextUnitMerger textUnitMerger)
Use specificIFilterandIFilterWriterimplementations- Parameters:
skeletonFilter- -IFilterused to read skeleton, can be serialized events or original source file. ASSUME FILTER OPEN ALREADY CALLED writer to use the default writer.textUnitMerger- user createdITextUnitMerger
-
-
Method Detail
-
getName
public String getName()
Description copied from interface:IFilterWriterGets the name of this writer.- Specified by:
getNamein interfaceIFilterWriter- Returns:
- The name of the writer.
-
setOptions
public void setOptions(LocaleId targetLocale, String defaultEncoding)
Description copied from interface:IFilterWriterSets the options for this writer.- Specified by:
setOptionsin interfaceIFilterWriter- Parameters:
targetLocale- the output locale.defaultEncoding- Name of the character set encoding for the output.
-
setOutput
public void setOutput(String path)
Description copied from interface:IFilterWriterSets the output through the path of the output file.- Specified by:
setOutputin interfaceIFilterWriter- Parameters:
path- Full path of the output file.
-
setOutput
public void setOutput(OutputStream output)
Description copied from interface:IFilterWriterSets the output through its output stream.- Specified by:
setOutputin interfaceIFilterWriter- Parameters:
output- Output stream to use for the output.
-
handleEvent
public Event handleEvent(Event event)
Description copied from interface:IFilterWriterHandles the filter events.- Specified by:
handleEventin interfaceIFilterWriter- Parameters:
event- The event to process.- Returns:
- The event that was processed.
-
close
public void close()
Description copied from interface:IFilterWriterCloses the output. Developers must make sure this method is safe to call even if there is nothing to close.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceIFilterWriter
-
getParameters
public Parameters getParameters()
Description copied from interface:IFilterWriterGets the current parameters for this writer.- Specified by:
getParametersin interfaceIFilterWriter- Returns:
- The current parameters for this writer.
-
setParameters
public void setParameters(IParameters params)
Description copied from interface:IFilterWriterSets new parameters for this writer.- Specified by:
setParametersin interfaceIFilterWriter- Parameters:
params- The new parameters to use.
-
cancel
public void cancel()
Description copied from interface:IFilterWriterCancels the current process.- Specified by:
cancelin interfaceIFilterWriter
-
getEncoderManager
public EncoderManager getEncoderManager()
Description copied from interface:IFilterWriterGets the current encoder manager for this writer. Some special implementation of IFilterWriter may not use an encoder manager (for example writers that do not use skeleton).- Specified by:
getEncoderManagerin interfaceIFilterWriter- Returns:
- the current encoder manager for this writer, or null if none exists for this writer.
-
getSkeletonWriter
public ISkeletonWriter getSkeletonWriter()
Description copied from interface:IFilterWriterGets the skeleton writer associated with this writer. Some implementation of IFilterWriter may not use a skeleton writer.- Specified by:
getSkeletonWriterin interfaceIFilterWriter- Returns:
- the skeleton writer associated with this writer or null if none is associated.
-
processStartDocument
protected void processStartDocument()
Use the skeletonStartDocumentevent to initialize theIFilterWriter. Initialize theITextUnitMerger
-
processTextUnit
protected void processTextUnit(Event event)
Take the translatedTextUnitand match it up with its corresponding skeleton version. CallITextUnitMergerto merge the translated segments into the skeletonTextUnit- Parameters:
event- - the translated version of theITextUnitevent
-
processUntilTextUnit
protected Event processUntilTextUnit()
Get events in the original document until the next text unit. Any event before is passed to the writer.- Returns:
- the event of the next text unit, or null if no next text unit is found.
-
processEndDocument
protected void processEndDocument()
There are no moreTextUnits. Read the remaining skeleton events and write them out.
-
setWriter
public void setWriter(IFilterWriter writer)
Set theIFilterWriterused to write out the skeleton events. This will override the internal writer as defined byStartDocumentin the skeleton.Must be called immediately after construction!!
- Parameters:
writer- -IFilterWriterused to write out the skeleton events
-
-