Class AbstractFormatter

java.lang.Object
org.opensextant.output.AbstractFormatter
All Implemented Interfaces:
MatchInterpreter, ResultsFormatter
Direct Known Subclasses:
CSVFormatter, GISDataFormatter

public abstract class AbstractFormatter extends 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 Details

    • outputParams

      protected Parameters outputParams
    • overwrite

      public boolean overwrite
    • geoInterpreter

      protected MatchInterpreter geoInterpreter
    • log

      protected final org.slf4j.Logger log
    • outputExtension

      public String outputExtension
      File extension for callers to know.
    • outputType

      protected 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.
  • Constructor Details

    • AbstractFormatter

      public AbstractFormatter()
  • Method Details

    • setParameters

      public void setParameters(Parameters params)
      Note - output parameters use tag_XYZ flags to indicate date to include or exclude
      Specified by:
      setParameters in interface ResultsFormatter
    • 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 interface MatchInterpreter
      Parameters:
      m - TextMatch -- which may or may not be geographic in nature.
      Returns:
    • getJobName

      public String getJobName()
      A basic job name that reflects file name
      Specified by:
      getJobName in interface ResultsFormatter
      Returns:
    • setOutputFilename

      public void setOutputFilename(String fname)
      Description copied from interface: ResultsFormatter
      Set the name of the output file.
      Specified by:
      setOutputFilename in interface ResultsFormatter
      Parameters:
      fname - file name of output
    • setOutputDir

      public void setOutputDir(String path)
      Description copied from interface: ResultsFormatter
      Set the path to the output directory.
      Specified by:
      setOutputDir in interface ResultsFormatter
      Parameters:
      path - output dir path
    • formatResults

      public String formatResults(ExtractionResult res) throws ProcessingException
      Write to a file and return HTML containing a link to the file.
      Specified by:
      formatResults in interface ResultsFormatter
      Parameters:
      res - result to write
      Returns:
      A message for the user
      Throws:
      ProcessingException - processing or formatting error
    • getOutputFilepath

      public String getOutputFilepath()
      Description copied from interface: ResultsFormatter
      Get the path to the output file.
      Specified by:
      getOutputFilepath in interface ResultsFormatter
      Returns:
      file path of output
    • createOutputFileName

      protected String createOutputFileName()
      Returns:
      file name with extension
    • getOutputType

      public String getOutputType()
      Description copied from interface: ResultsFormatter
      Get the type of output produced by this formatter.
      Specified by:
      getOutputType in interface ResultsFormatter
      Returns:
      type of output
    • deleteOutput

      protected void deleteOutput(File previousRun)
      This is checked only by internal classes as they create output streams.
    • checkOverwrite

      protected void checkOverwrite(File item) throws IOException
      uniform helper for overwrite check.
      Throws:
      IOException
    • start

      public abstract void start(String nm) throws ProcessingException
      Specified by:
      start in interface ResultsFormatter
      Throws:
      ProcessingException
    • finish

      public abstract void finish()
      Specified by:
      finish in interface ResultsFormatter
    • createOutputStreams

      protected abstract void createOutputStreams() throws Exception
      Create the output stream appropriate for the output type. IO is created using the filename represented by getOutputFilepath()
      Throws:
      Exception
    • close

      public abstract void close() throws IOException
      Throws:
      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