Class AbstractInstanceGenerator<T extends adams.data.container.DataContainer & adams.data.report.ReportHandler>

  • All Implemented Interfaces:
    adams.core.CleanUpHandler, adams.core.Destroyable, adams.core.GlobalInfoSupporter, adams.core.logging.LoggingLevelHandler, adams.core.logging.LoggingSupporter, adams.core.option.OptionHandler, adams.core.ShallowCopySupporter<AbstractInstanceGenerator>, adams.core.SizeOfHandler, adams.db.DatabaseConnectionHandler, adams.db.DatabaseConnectionProvider, adams.db.DatabaseConnectionUser, adams.db.OptionalDatabaseConnectionUser, Serializable, Comparable

    public abstract class AbstractInstanceGenerator<T extends adams.data.container.DataContainer & adams.data.report.ReportHandler>
    extends adams.core.option.AbstractOptionHandler
    implements Comparable, adams.core.CleanUpHandler, adams.db.DatabaseConnectionHandler, adams.core.ShallowCopySupporter<AbstractInstanceGenerator>, adams.db.OptionalDatabaseConnectionUser
    Abstract base class for schemes that turn temperature profiles into weka.core.Instance objects.
    Author:
    fracpete (fracpete at waikato dot ac dot nz) the type of data to process
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static String LABEL_FALSE
      the "false" label for boolean data types.
      static String LABEL_TRUE
      the "true" label for boolean data types.
      protected boolean m_AddDatabaseID
      whether to add the database ID.
      protected adams.db.AbstractDatabaseConnection m_DatabaseConnection
      the database connection.
      protected boolean m_Offline
      whether to operate in offline mode.
      protected weka.core.Instances m_OutputHeader
      the generated header.
      protected boolean m_TolerateHeaderChanges
      whether to tolerate header changes.
      • Fields inherited from class adams.core.option.AbstractOptionHandler

        m_OptionManager
      • Fields inherited from class adams.core.logging.LoggingObject

        m_Logger, m_LoggingIsEnabled, m_LoggingLevel
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      String addDatabaseIDTipText()
      Returns the tip text for this property.
      protected abstract void checkHeader​(T data)
      Checks whether the number of waves are the same.
      protected void checkInput​(T data)
      Checks the input profile.
      String checkSetup()
      Checks whether the setup is consistent.
      void cleanUp()
      Cleans up data structures, frees up memory.
      int compareTo​(Object o)
      Compares this object with the specified object for order.
      void defineOptions()
      Adds options to the internal list of options.
      void destroy()
      Frees up memory in a "destructive" non-reversible way.
      boolean equals​(Object o)
      Returns whether the two objects are the same.
      static AbstractInstanceGenerator forCommandLine​(String cmdline)
      Instantiates the generator from the given commandline (i.e., classname and optional options).
      static AbstractInstanceGenerator forName​(String classname, String[] options)
      Instantiates the generator with the given options.
      weka.core.Instance generate​(T data)
      Returns the generated data, generates it if necessary.
      protected abstract void generateHeader​(T data)
      Generates the header of the output data.
      protected abstract weka.core.Instance generateOutput​(T data)
      Generates the actual data.
      boolean getAddDatabaseID()
      Returns whether the database ID is added.
      adams.db.AbstractDatabaseConnection getDatabaseConnection()
      Returns the currently used database connection object, can be null.
      protected abstract adams.db.AbstractDatabaseConnection getDefaultDatabaseConnection()
      Returns the default database connection.
      static String[] getGenerators()
      Returns a list with classnames of generators.
      boolean getOffline()
      Returns whether the generator operates in offline mode.
      weka.core.Instances getOutputHeader()
      Returns the current header.
      boolean getTolerateHeaderChanges()
      Returns whether to tolerate header changes and merely re-generating the header instead of throwing an exception.
      protected void initialize()
      Initializes the members.
      protected String interpretePosition​(weka.core.Instances data, String position)
      Interpretes the position string based on the given dataset.
      String offlineTipText()
      Returns the tip text for this property.
      protected void postProcessHeader​(T data)
      Adds IDs, notes, additional fields to header.
      protected weka.core.Instance postProcessOutput​(T data, weka.core.Instance inst)
      For adding IDs, notes, additional fields to the data.
      protected void reset()
      Resets the generator (but does not clear the input data!).
      void setAddDatabaseID​(boolean value)
      Sets whether the database ID is added to the data or not.
      void setDatabaseConnection​(adams.db.AbstractDatabaseConnection value)
      Sets the database connection object to use.
      void setOffline​(boolean value)
      Sets whether to operate in offline mode.
      void setTolerateHeaderChanges​(boolean value)
      Sets whether to tolerate header changes and merely re-generating the header instead of throwing an exception.
      AbstractInstanceGenerator shallowCopy()
      Returns a shallow copy of itself, i.e., based on the commandline options.
      AbstractInstanceGenerator shallowCopy​(boolean expand)
      Returns a shallow copy of itself, i.e., based on the commandline options.
      String tolerateHeaderChangesTipText()
      Returns the tip text for this property.
      • Methods inherited from class adams.core.option.AbstractOptionHandler

        cleanUpOptions, finishInit, getDefaultLoggingLevel, getOptionManager, globalInfo, loggingLevelTipText, newOptionManager, setLoggingLevel, toCommandLine, toString
      • Methods inherited from class adams.core.logging.LoggingObject

        configureLogger, getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, sizeOf
      • Methods inherited from interface adams.core.logging.LoggingLevelHandler

        getLoggingLevel
    • Field Detail

      • m_OutputHeader

        protected weka.core.Instances m_OutputHeader
        the generated header.
      • m_AddDatabaseID

        protected boolean m_AddDatabaseID
        whether to add the database ID.
      • m_DatabaseConnection

        protected adams.db.AbstractDatabaseConnection m_DatabaseConnection
        the database connection.
      • m_TolerateHeaderChanges

        protected boolean m_TolerateHeaderChanges
        whether to tolerate header changes.
      • m_Offline

        protected boolean m_Offline
        whether to operate in offline mode.
    • Constructor Detail

      • AbstractInstanceGenerator

        public AbstractInstanceGenerator()
    • Method Detail

      • defineOptions

        public void defineOptions()
        Adds options to the internal list of options.
        Specified by:
        defineOptions in interface adams.core.option.OptionHandler
        Overrides:
        defineOptions in class adams.core.option.AbstractOptionHandler
      • initialize

        protected void initialize()
        Initializes the members.
        Overrides:
        initialize in class adams.core.option.AbstractOptionHandler
      • reset

        protected void reset()
        Resets the generator (but does not clear the input data!). Derived classes must call this method in set-methods of parameters to assure the invalidation of previously generated data.
        Overrides:
        reset in class adams.core.option.AbstractOptionHandler
      • cleanUp

        public void cleanUp()
        Cleans up data structures, frees up memory. Sets the input data to null.
        Specified by:
        cleanUp in interface adams.core.CleanUpHandler
      • destroy

        public void destroy()
        Frees up memory in a "destructive" non-reversible way.

        Calls cleanUp() and cleans up the options.
        Specified by:
        destroy in interface adams.core.Destroyable
        Overrides:
        destroy in class adams.core.option.AbstractOptionHandler
      • setAddDatabaseID

        public void setAddDatabaseID​(boolean value)
        Sets whether the database ID is added to the data or not.
        Parameters:
        value - true if database ID should be added
      • getAddDatabaseID

        public boolean getAddDatabaseID()
        Returns whether the database ID is added.
        Returns:
        true if database ID is added
      • addDatabaseIDTipText

        public String addDatabaseIDTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setOffline

        public void setOffline​(boolean value)
        Sets whether to operate in offline mode.
        Specified by:
        setOffline in interface adams.db.OptionalDatabaseConnectionUser
        Parameters:
        value - true if to operate in offline mode
      • getOffline

        public boolean getOffline()
        Returns whether the generator operates in offline mode.
        Specified by:
        getOffline in interface adams.db.OptionalDatabaseConnectionUser
        Returns:
        true if operating in offline mode
      • offlineTipText

        public String offlineTipText()
        Returns the tip text for this property.
        Specified by:
        offlineTipText in interface adams.db.OptionalDatabaseConnectionUser
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setTolerateHeaderChanges

        public void setTolerateHeaderChanges​(boolean value)
        Sets whether to tolerate header changes and merely re-generating the header instead of throwing an exception.
        Parameters:
        value - true if to tolerate header changes
      • getTolerateHeaderChanges

        public boolean getTolerateHeaderChanges()
        Returns whether to tolerate header changes and merely re-generating the header instead of throwing an exception.
        Returns:
        true if to tolerate header changes
      • tolerateHeaderChangesTipText

        public String tolerateHeaderChangesTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • getDefaultDatabaseConnection

        protected abstract adams.db.AbstractDatabaseConnection getDefaultDatabaseConnection()
        Returns the default database connection.
        Returns:
        the default database connection
      • getDatabaseConnection

        public adams.db.AbstractDatabaseConnection getDatabaseConnection()
        Returns the currently used database connection object, can be null.
        Specified by:
        getDatabaseConnection in interface adams.db.DatabaseConnectionProvider
        Returns:
        the current object
      • setDatabaseConnection

        public void setDatabaseConnection​(adams.db.AbstractDatabaseConnection value)
        Sets the database connection object to use.
        Specified by:
        setDatabaseConnection in interface adams.db.DatabaseConnectionHandler
        Parameters:
        value - the object to use
      • getOutputHeader

        public weka.core.Instances getOutputHeader()
        Returns the current header.
        Returns:
        the header, can be null
      • checkSetup

        public String checkSetup()
        Checks whether the setup is consistent.

        Default implementation does nothing.
        Returns:
        null if everything OK, otherwise the error message
      • generate

        public weka.core.Instance generate​(T data)
        Returns the generated data, generates it if necessary.
        Parameters:
        data - the profile to turn into an instance
        Returns:
        the generated data
      • checkInput

        protected void checkInput​(T data)
        Checks the input profile.

        The default implementation only checks whether there is any data set.
        Parameters:
        data - the data to process
      • checkHeader

        protected abstract void checkHeader​(T data)
        Checks whether the number of waves are the same.
        Parameters:
        data - the input data
      • generateHeader

        protected abstract void generateHeader​(T data)
        Generates the header of the output data.
        Parameters:
        data - the input data
      • interpretePosition

        protected String interpretePosition​(weka.core.Instances data,
                                            String position)
        Interpretes the position string based on the given dataset. "first", "second", "third", "last-2", "last-1" and "last" and "last+1" are valid as well.
        Parameters:
        data - the data to base the intepretation on
        position - the position string
        Returns:
        the numeric position string
      • postProcessHeader

        protected void postProcessHeader​(T data)
        Adds IDs, notes, additional fields to header.
        Parameters:
        data - the input data
      • generateOutput

        protected abstract weka.core.Instance generateOutput​(T data)
        Generates the actual data.
        Parameters:
        data - the input data to transform
        Returns:
        the generated data
      • postProcessOutput

        protected weka.core.Instance postProcessOutput​(T data,
                                                       weka.core.Instance inst)
        For adding IDs, notes, additional fields to the data.
        Parameters:
        data - the input data
        inst - the generated instance
        Returns:
        the processed instance
      • compareTo

        public int compareTo​(Object o)
        Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

        Only compares the commandlines of the two objects.
        Specified by:
        compareTo in interface Comparable<T extends adams.data.container.DataContainer & adams.data.report.ReportHandler>
        Parameters:
        o - the object to be compared.
        Returns:
        a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
        Throws:
        ClassCastException - if the specified object's type prevents it from being compared to this object.
      • equals

        public boolean equals​(Object o)
        Returns whether the two objects are the same.

        Only compares the commandlines of the two objects.
        Overrides:
        equals in class Object
        Parameters:
        o - the object to be compared
        Returns:
        true if the object is the same as this one
      • shallowCopy

        public AbstractInstanceGenerator shallowCopy()
        Returns a shallow copy of itself, i.e., based on the commandline options.
        Specified by:
        shallowCopy in interface adams.core.ShallowCopySupporter<T extends adams.data.container.DataContainer & adams.data.report.ReportHandler>
        Returns:
        the shallow copy
      • shallowCopy

        public AbstractInstanceGenerator shallowCopy​(boolean expand)
        Returns a shallow copy of itself, i.e., based on the commandline options.
        Specified by:
        shallowCopy in interface adams.core.ShallowCopySupporter<T extends adams.data.container.DataContainer & adams.data.report.ReportHandler>
        Parameters:
        expand - whether to expand variables to their current values
        Returns:
        the shallow copy
      • getGenerators

        public static String[] getGenerators()
        Returns a list with classnames of generators.
        Returns:
        the generator classnames
      • forName

        public static AbstractInstanceGenerator forName​(String classname,
                                                        String[] options)
        Instantiates the generator with the given options.
        Parameters:
        classname - the classname of the generator to instantiate
        options - the options for the generator
        Returns:
        the instantiated generator or null if an error occurred
      • forCommandLine

        public static AbstractInstanceGenerator forCommandLine​(String cmdline)
        Instantiates the generator from the given commandline (i.e., classname and optional options).
        Parameters:
        cmdline - the classname (and optional options) of the generator to instantiate
        Returns:
        the instantiated generator or null if an error occurred