Class SpreadSheetLoader

  • All Implemented Interfaces:
    Serializable, weka.core.converters.BatchConverter, weka.core.converters.FileSourcedConverter, weka.core.converters.Loader, weka.core.EnvironmentHandler, weka.core.OptionHandler, weka.core.RevisionHandler

    public class SpreadSheetLoader
    extends weka.core.converters.AbstractFileLoader
    implements weka.core.converters.BatchConverter, weka.core.OptionHandler
    Loads a CSV file using an ADAMS spreadsheet reader and converts it into an Instances object.

    Valid options are:

     -D
      Enables debug output.
      (default: off)
     -reader <classname + options>
      The ADAMS spreadsheet reader to use. (default: adams.data.io.input.CsvSpreadSheetReader)
     -conversion <classname + options>
      The conversion scheme for converting the spreadsheet into an
      Instances object to work on.
      (default: adams.data.conversion.SpreadSheetToWekaInstances)
    Author:
    fracpete (fracpete at waikato dot ac dot nz)
    See Also:
    Loader, Serialized Form
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface weka.core.converters.Loader

        weka.core.converters.Loader.StructureNotReadyException
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected Conversion m_Conversion
      the conversion to use.
      protected weka.core.Instances m_Data
      the actual data.
      protected boolean m_Debug
      whether to print some debug information
      protected SpreadSheetReader m_Reader
      the reader to use.
      protected File m_sourceFile
      Holds the source of the data set.
      protected weka.core.Instances m_structure
      Holds the determined structure (header) of the data set.
      • Fields inherited from class weka.core.converters.AbstractFileLoader

        FILE_EXTENSION_COMPRESSED, m_env, m_File, m_useRelativePath
      • Fields inherited from class weka.core.converters.AbstractLoader

        m_retrieval
      • Fields inherited from interface weka.core.converters.Loader

        BATCH, INCREMENTAL, NONE
    • Constructor Summary

      Constructors 
      Constructor Description
      SpreadSheetLoader()
      default constructor
    • Field Detail

      • m_structure

        protected weka.core.Instances m_structure
        Holds the determined structure (header) of the data set.
      • m_Data

        protected weka.core.Instances m_Data
        the actual data.
      • m_sourceFile

        protected File m_sourceFile
        Holds the source of the data set.
      • m_Debug

        protected boolean m_Debug
        whether to print some debug information
      • m_Conversion

        protected Conversion m_Conversion
        the conversion to use.
    • Constructor Detail

      • SpreadSheetLoader

        public SpreadSheetLoader()
        default constructor
    • Method Detail

      • globalInfo

        public String globalInfo()
        Returns a string describing this loader
        Returns:
        a description of the evaluator suitable for displaying in the explorer/experimenter gui
      • listOptions

        public Enumeration listOptions()
        Lists the available options
        Specified by:
        listOptions in interface weka.core.OptionHandler
        Returns:
        an enumeration of the available options
      • setOptions

        public void setOptions​(String[] options)
                        throws Exception
        Parses a given list of options.

        Valid options are:

         -D
          Enables debug output.
          (default: off)
         -reader <classname + options>
          The ADAMS spreadsheet reader to use. (default: adams.data.io.input.CsvSpreadSheetReader)
         -conversion <classname + options>
          The conversion scheme for converting the spreadsheet into an
          Instances object to work on.
          (default: adams.data.conversion.SpreadSheetToWekaInstances)
        Specified by:
        setOptions in interface weka.core.OptionHandler
        Parameters:
        options - the options
        Throws:
        Exception - if options cannot be set
      • getOptions

        public String[] getOptions()
        Gets the setting
        Specified by:
        getOptions in interface weka.core.OptionHandler
        Returns:
        the current setting
      • setDebug

        public void setDebug​(boolean value)
        Sets whether to print some debug information.
        Parameters:
        value - if true additional debug information will be printed.
      • getDebug

        public boolean getDebug()
        Gets whether additional debug information is printed.
        Returns:
        true if additional debug information is printed
      • debugTipText

        public String debugTipText()
        the tip text for this property
        Returns:
        the tip text
      • setReader

        public void setReader​(SpreadSheetReader value)
        Sets the spreadsheet reader to use.
        Parameters:
        value - the reader to use
      • getReader

        public SpreadSheetReader getReader()
        Returns the spreadsheet reader in use.
        Returns:
        the reader in use.
      • readerTipText

        public String readerTipText()
        The tip text for this property.
        Returns:
        the tip text
      • setConversion

        public void setConversion​(Conversion value)
        Sets the conversion to use for converting the spreadsheet into an Instances object.
        Parameters:
        value - the conversion
      • getConversion

        public Conversion getConversion()
        Returns the conversion in use for converting the spreadsheet into an Instances object.
        Returns:
        the conversion
      • conversionTipText

        public String conversionTipText()
        The tip text for this property.
        Returns:
        the tip text
      • getFileDescription

        public String getFileDescription()
        Returns a description of the file type.
        Specified by:
        getFileDescription in interface weka.core.converters.FileSourcedConverter
        Returns:
        a short file description
      • getFileExtension

        public String getFileExtension()
        Get the file extension used for this type of file
        Specified by:
        getFileExtension in interface weka.core.converters.FileSourcedConverter
        Returns:
        the file extension
      • getFileExtensions

        public String[] getFileExtensions()
        Gets all the file extensions used for this type of file
        Specified by:
        getFileExtensions in interface weka.core.converters.FileSourcedConverter
        Returns:
        the file extensions
      • reset

        public void reset()
                   throws IOException
        Resets the loader ready to read a new data set
        Specified by:
        reset in interface weka.core.converters.Loader
        Overrides:
        reset in class weka.core.converters.AbstractFileLoader
        Throws:
        IOException
      • setSource

        public void setSource​(File file)
                       throws IOException
        Resets the Loader object and sets the source of the data set to be the supplied File object.
        Specified by:
        setSource in interface weka.core.converters.Loader
        Overrides:
        setSource in class weka.core.converters.AbstractFileLoader
        Parameters:
        file - the source file.
        Throws:
        IOException - if an error occurs
      • getStructure

        public weka.core.Instances getStructure()
                                         throws IOException
        Determines and returns (if possible) the structure (internally the header) of the data set as an empty set of instances.
        Specified by:
        getStructure in interface weka.core.converters.Loader
        Specified by:
        getStructure in class weka.core.converters.AbstractLoader
        Returns:
        the structure of the data set as an empty set of Instances
        Throws:
        IOException - if an error occurs
      • getDataSet

        public weka.core.Instances getDataSet()
                                       throws IOException
        Return the full data set. If the structure hasn't yet been determined by a call to getStructure then method should do so before processing the rest of the data set.
        Specified by:
        getDataSet in interface weka.core.converters.Loader
        Specified by:
        getDataSet in class weka.core.converters.AbstractLoader
        Returns:
        the structure of the data set as an empty set of Instances
        Throws:
        IOException - if there is no source or parsing fails
      • getNextInstance

        public weka.core.Instance getNextInstance​(weka.core.Instances structure)
                                           throws IOException
        SpreadSheetLoader is unable to process a data set incrementally.
        Specified by:
        getNextInstance in interface weka.core.converters.Loader
        Specified by:
        getNextInstance in class weka.core.converters.AbstractLoader
        Parameters:
        structure - ignored
        Returns:
        never returns without throwing an exception
        Throws:
        IOException - always. AdamsCsvLoader is unable to process a data set incrementally.
      • getRevision

        public String getRevision()
        Returns the revision string.
        Specified by:
        getRevision in interface weka.core.RevisionHandler
        Returns:
        the revision
      • main

        public static void main​(String[] args)
        Main method.
        Parameters:
        args - should contain the name of an input file.