Package org.opensextant.output
Class AbstractFormatter
- java.lang.Object
-
- org.opensextant.output.AbstractFormatter
-
- All Implemented Interfaces:
MatchInterpreter
,ResultsFormatter
- Direct Known Subclasses:
CSVFormatter
,GISDataFormatter
public abstract class AbstractFormatter extends java.lang.Object implements ResultsFormatter, MatchInterpreter
Abstract class encapsulating basic results formatter functionality.- Author:
- Rich Markeloff, MITRE Corp. Initial version created on Aug 22, 2011, Marc Ubaldino, MITRE Corp. Refactored, 2013
-
-
Field Summary
Fields Modifier and Type Field Description boolean
debug
protected MatchInterpreter
geoInterpreter
boolean
includeCoordinate
GIS formats may optionally include coordinates as fields.boolean
includeOffsets
Schema-specific stuff.protected org.slf4j.Logger
log
java.lang.String
outputExtension
File extension for callers to know.protected Parameters
outputParams
protected java.lang.String
outputType
boolean
overwrite
protected static int
TEXT_WIDTH
-
Constructor Summary
Constructors Constructor Description AbstractFormatter()
-
Method Summary
Modifier and Type Method Description protected void
checkOverwrite(java.io.File item)
uniform helper for overwrite check.abstract void
close()
protected java.lang.String
createOutputFileName()
protected abstract void
createOutputStreams()
Create the output stream appropriate for the output type.protected void
deleteOutput(java.io.File previousRun)
This is checked only by internal classes as they create output streams.abstract void
finish()
java.lang.String
formatResults(ExtractionResult res)
Write to a file and return HTML containing a link to the file.Geocoding
getGeocoding(TextMatch m)
The default geocoding interpretation is here.java.lang.String
getJobName()
A basic job name that reflects file namejava.lang.String
getOutputFilepath()
Get the path to the output file.java.lang.String
getOutputType()
Get the type of output produced by this formatter.void
setMatchInterpeter(MatchInterpreter mi)
Override means for how geocoding is determined per row.void
setOutputDir(java.lang.String path)
Set the path to the output directory.void
setOutputFilename(java.lang.String fname)
Set the name of the output file.void
setParameters(Parameters params)
Note - output parameters use tag_XYZ flags to indicate date to include or excludeabstract void
start(java.lang.String nm)
abstract void
writeGeocodingResult(ExtractionResult rowdata)
Write your geocoding result directly to output Result should carry ExtractionResult.recordFile as a URI for original.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.opensextant.output.ResultsFormatter
addField, removeField
-
-
-
-
Field Detail
-
outputParams
protected Parameters outputParams
-
overwrite
public boolean overwrite
-
geoInterpreter
protected MatchInterpreter geoInterpreter
-
log
protected final org.slf4j.Logger log
-
outputExtension
public java.lang.String outputExtension
File extension for callers to know.
-
outputType
protected java.lang.String outputType
-
TEXT_WIDTH
protected static int TEXT_WIDTH
-
debug
public boolean debug
-
includeOffsets
public boolean includeOffsets
Schema-specific stuff. GIS formats would not make use of offsets. CSV format is only one where offsets make sense.
-
includeCoordinate
public boolean includeCoordinate
GIS formats may optionally include coordinates as fields. GDB and SHP have a Point geometry which carries the lat/lon already. KML, CSV, JSON, etc. it makes sense to include these explicitly.
-
-
Method Detail
-
setParameters
public void setParameters(Parameters params)
Note - output parameters use tag_XYZ flags to indicate date to include or exclude- Specified by:
setParameters
in interfaceResultsFormatter
-
setMatchInterpeter
public void setMatchInterpeter(MatchInterpreter mi)
Override means for how geocoding is determined per row.
-
getGeocoding
public Geocoding getGeocoding(TextMatch m)
The default geocoding interpretation is here. This works for simple stuff like Coordinate extraction- Specified by:
getGeocoding
in interfaceMatchInterpreter
- Parameters:
m
- TextMatch -- which may or may not be geographic in nature.- Returns:
-
getJobName
public java.lang.String getJobName()
A basic job name that reflects file name- Specified by:
getJobName
in interfaceResultsFormatter
- Returns:
-
setOutputFilename
public void setOutputFilename(java.lang.String fname)
Description copied from interface:ResultsFormatter
Set the name of the output file.- Specified by:
setOutputFilename
in interfaceResultsFormatter
- Parameters:
fname
- file name of output
-
setOutputDir
public void setOutputDir(java.lang.String path)
Description copied from interface:ResultsFormatter
Set the path to the output directory.- Specified by:
setOutputDir
in interfaceResultsFormatter
- Parameters:
path
- output dir path
-
formatResults
public java.lang.String formatResults(ExtractionResult res) throws ProcessingException
Write to a file and return HTML containing a link to the file.- Specified by:
formatResults
in interfaceResultsFormatter
- Parameters:
res
- result to write- Returns:
- A message for the user
- Throws:
ProcessingException
- processing or formatting error
-
getOutputFilepath
public java.lang.String getOutputFilepath()
Description copied from interface:ResultsFormatter
Get the path to the output file.- Specified by:
getOutputFilepath
in interfaceResultsFormatter
- Returns:
- file path of output
-
createOutputFileName
protected java.lang.String createOutputFileName()
- Returns:
- file name with extension
-
getOutputType
public java.lang.String getOutputType()
Description copied from interface:ResultsFormatter
Get the type of output produced by this formatter.- Specified by:
getOutputType
in interfaceResultsFormatter
- Returns:
- type of output
-
deleteOutput
protected void deleteOutput(java.io.File previousRun)
This is checked only by internal classes as they create output streams.
-
checkOverwrite
protected void checkOverwrite(java.io.File item) throws java.io.IOException
uniform helper for overwrite check.- Throws:
java.io.IOException
-
start
public abstract void start(java.lang.String nm) throws ProcessingException
- Specified by:
start
in interfaceResultsFormatter
- Throws:
ProcessingException
-
finish
public abstract void finish()
- Specified by:
finish
in interfaceResultsFormatter
-
createOutputStreams
protected abstract void createOutputStreams() throws java.lang.Exception
Create the output stream appropriate for the output type. IO is created using the filename represented by getOutputFilepath()- Throws:
java.lang.Exception
-
close
public abstract void close() throws java.io.IOException
- Throws:
java.io.IOException
-
writeGeocodingResult
public abstract void writeGeocodingResult(ExtractionResult rowdata)
Write your geocoding result directly to output Result should carry ExtractionResult.recordFile as a URI for original.- Parameters:
rowdata
- the data to write out
-
-