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

java.lang.Object
  extended by adams.core.ConsoleObject
      extended by adams.core.option.AbstractOptionHandler
          extended by adams.data.instances.AbstractInstanceGenerator<T>
All Implemented Interfaces:
CleanUpHandler, Debuggable, Destroyable, OptionHandler, ShallowCopySupporter<AbstractInstanceGenerator>, SizeOfHandler, DatabaseConnectionHandler, DatabaseConnectionProvider, Serializable, Comparable

public abstract class AbstractInstanceGenerator<T extends DataContainer & ReportHandler>
extends AbstractOptionHandler
implements Comparable, CleanUpHandler, DatabaseConnectionHandler, ShallowCopySupporter<AbstractInstanceGenerator>

Abstract base class for schemes that turn temperature profiles into weka.core.Instance objects.

Version:
$Revision: 5189 $ the type of data to process
Author:
fracpete (fracpete at waikato dot ac dot nz)
See Also:
Serialized Form

Field Summary
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  AbstractDatabaseConnection m_DatabaseConnection
          the database connection.
protected  weka.core.Instances m_OutputHeader
          the generated header.
 
Fields inherited from class adams.core.option.AbstractOptionHandler
m_DebugLevel, m_OptionManager
 
Constructor Summary
AbstractInstanceGenerator()
           
 
Method Summary
 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.
 AbstractDatabaseConnection getDatabaseConnection()
          Returns the currently used database connection object, can be null.
protected abstract  AbstractDatabaseConnection getDefaultDatabaseConnection()
          Returns the default database connection.
static String[] getGenerators()
          Returns a list with classnames of generators.
 weka.core.Instances getOutputHeader()
          Returns the current header.
protected  void initialize()
          Initializes the members.
protected  String interpretePosition(weka.core.Instances data, String position)
          Interpretes the position string based on the given dataset.
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(AbstractDatabaseConnection value)
          Sets the database connection object to use.
 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.
 
Methods inherited from class adams.core.option.AbstractOptionHandler
cleanUpOptions, debug, debug, debugLevelTipText, finishInit, getDebugLevel, getOptionManager, globalInfo, isDebugOn, newOptionManager, setDebugLevel, toCommandLine, toString
 
Methods inherited from class adams.core.ConsoleObject
getDebugging, getSystemErr, getSystemOut, sizeOf
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

LABEL_TRUE

public static final String LABEL_TRUE
the "true" label for boolean data types.

See Also:
Constant Field Values

LABEL_FALSE

public static final String LABEL_FALSE
the "false" label for boolean data types.

See Also:
Constant Field Values

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 AbstractDatabaseConnection m_DatabaseConnection
the database connection.

Constructor Detail

AbstractInstanceGenerator

public AbstractInstanceGenerator()
Method Detail

defineOptions

public void defineOptions()
Adds options to the internal list of options.

Specified by:
defineOptions in interface OptionHandler
Overrides:
defineOptions in class AbstractOptionHandler

initialize

protected void initialize()
Initializes the members.

Overrides:
initialize in class 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 AbstractOptionHandler

cleanUp

public void cleanUp()
Cleans up data structures, frees up memory. Sets the input data to null.

Specified by:
cleanUp in interface 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 Destroyable
Overrides:
destroy in class 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.

getDefaultDatabaseConnection

protected abstract AbstractDatabaseConnection getDefaultDatabaseConnection()
Returns the default database connection.

Returns:
the default database connection

getDatabaseConnection

public AbstractDatabaseConnection getDatabaseConnection()
Returns the currently used database connection object, can be null.

Specified by:
getDatabaseConnection in interface DatabaseConnectionProvider
Returns:
the current object

setDatabaseConnection

public void setDatabaseConnection(AbstractDatabaseConnection value)
Sets the database connection object to use.

Specified by:
setDatabaseConnection in interface 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
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 ShallowCopySupporter<AbstractInstanceGenerator>
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 ShallowCopySupporter<AbstractInstanceGenerator>
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


Copyright © 2012 University of Waikato, Hamilton, NZ. All Rights Reserved.