Package adams.data.instances
Class AbstractInstanceGenerator<T extends DataContainer & ReportHandler>
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.core.logging.CustomLoggingLevelObject
-
- adams.core.option.AbstractOptionHandler
-
- adams.data.instances.AbstractInstanceGenerator<T>
-
- All Implemented Interfaces:
CleanUpHandler,Destroyable,GlobalInfoSupporter,LoggingLevelHandler,LoggingSupporter,OptionHandler,ShallowCopySupporter<AbstractInstanceGenerator>,SizeOfHandler,DatabaseConnectionHandler,DatabaseConnectionProvider,DatabaseConnectionUser,OptionalDatabaseConnectionUser,Serializable,Comparable
public abstract class AbstractInstanceGenerator<T extends DataContainer & ReportHandler> extends AbstractOptionHandler implements Comparable, CleanUpHandler, DatabaseConnectionHandler, ShallowCopySupporter<AbstractInstanceGenerator>, 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 StringLABEL_FALSEthe "false" label for boolean data types.static StringLABEL_TRUEthe "true" label for boolean data types.protected booleanm_AddDatabaseIDwhether to add the database ID.protected AbstractDatabaseConnectionm_DatabaseConnectionthe database connection.protected booleanm_Offlinewhether to operate in offline mode.protected weka.core.Instancesm_OutputHeaderthe generated header.protected booleanm_TolerateHeaderChangeswhether 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
-
-
Constructor Summary
Constructors Constructor Description AbstractInstanceGenerator()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description StringaddDatabaseIDTipText()Returns the tip text for this property.protected abstract voidcheckHeader(T data)Checks whether the number of waves are the same.protected voidcheckInput(T data)Checks the input profile.StringcheckSetup()Checks whether the setup is consistent.voidcleanUp()Cleans up data structures, frees up memory.intcompareTo(Object o)Compares this object with the specified object for order.voiddefineOptions()Adds options to the internal list of options.voiddestroy()Frees up memory in a "destructive" non-reversible way.booleanequals(Object o)Returns whether the two objects are the same.static AbstractInstanceGeneratorforCommandLine(String cmdline)Instantiates the generator from the given commandline (i.e., classname and optional options).static AbstractInstanceGeneratorforName(String classname, String[] options)Instantiates the generator with the given options.weka.core.Instancegenerate(T data)Returns the generated data, generates it if necessary.protected abstract voidgenerateHeader(T data)Generates the header of the output data.protected abstract weka.core.InstancegenerateOutput(T data)Generates the actual data.booleangetAddDatabaseID()Returns whether the database ID is added.AbstractDatabaseConnectiongetDatabaseConnection()Returns the currently used database connection object, can be null.protected abstract AbstractDatabaseConnectiongetDefaultDatabaseConnection()Returns the default database connection.static String[]getGenerators()Returns a list with classnames of generators.booleangetOffline()Returns whether the generator operates in offline mode.weka.core.InstancesgetOutputHeader()Returns the current header.booleangetTolerateHeaderChanges()Returns whether to tolerate header changes and merely re-generating the header instead of throwing an exception.protected voidinitialize()Initializes the members.protected StringinterpretePosition(weka.core.Instances data, String position)Interpretes the position string based on the given dataset.StringofflineTipText()Returns the tip text for this property.protected voidpostProcessHeader(T data)Adds IDs, notes, additional fields to header.protected weka.core.InstancepostProcessOutput(T data, weka.core.Instance inst)For adding IDs, notes, additional fields to the data.protected voidreset()Resets the generator (but does not clear the input data!).voidsetAddDatabaseID(boolean value)Sets whether the database ID is added to the data or not.voidsetDatabaseConnection(AbstractDatabaseConnection value)Sets the database connection object to use.voidsetOffline(boolean value)Sets whether to operate in offline mode.voidsetTolerateHeaderChanges(boolean value)Sets whether to tolerate header changes and merely re-generating the header instead of throwing an exception.AbstractInstanceGeneratorshallowCopy()Returns a shallow copy of itself, i.e., based on the commandline options.AbstractInstanceGeneratorshallowCopy(boolean expand)Returns a shallow copy of itself, i.e., based on the commandline options.StringtolerateHeaderChangesTipText()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 class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface adams.core.logging.LoggingLevelHandler
getLoggingLevel
-
-
-
-
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.
-
m_TolerateHeaderChanges
protected boolean m_TolerateHeaderChanges
whether to tolerate header changes.
-
m_Offline
protected boolean m_Offline
whether to operate in offline mode.
-
-
Method Detail
-
defineOptions
public void defineOptions()
Adds options to the internal list of options.- Specified by:
defineOptionsin interfaceOptionHandler- Overrides:
defineOptionsin classAbstractOptionHandler
-
initialize
protected void initialize()
Initializes the members.- Overrides:
initializein classAbstractOptionHandler
-
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:
resetin classAbstractOptionHandler
-
cleanUp
public void cleanUp()
Cleans up data structures, frees up memory. Sets the input data to null.- Specified by:
cleanUpin interfaceCleanUpHandler
-
destroy
public void destroy()
Frees up memory in a "destructive" non-reversible way.
Calls cleanUp() and cleans up the options.- Specified by:
destroyin interfaceDestroyable- Overrides:
destroyin classAbstractOptionHandler- See Also:
AbstractOptionHandler.cleanUpOptions()
-
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:
setOfflinein interfaceOptionalDatabaseConnectionUser- Parameters:
value- true if to operate in offline mode
-
getOffline
public boolean getOffline()
Returns whether the generator operates in offline mode.- Specified by:
getOfflinein interfaceOptionalDatabaseConnectionUser- Returns:
- true if operating in offline mode
-
offlineTipText
public String offlineTipText()
Returns the tip text for this property.- Specified by:
offlineTipTextin interfaceOptionalDatabaseConnectionUser- 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 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:
getDatabaseConnectionin interfaceDatabaseConnectionProvider- Returns:
- the current object
-
setDatabaseConnection
public void setDatabaseConnection(AbstractDatabaseConnection value)
Sets the database connection object to use.- Specified by:
setDatabaseConnectionin interfaceDatabaseConnectionHandler- 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 onposition- 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 datainst- 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:
compareToin interfaceComparable<T extends DataContainer & 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.
-
shallowCopy
public AbstractInstanceGenerator shallowCopy()
Returns a shallow copy of itself, i.e., based on the commandline options.- Specified by:
shallowCopyin interfaceShallowCopySupporter<T extends DataContainer & 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:
shallowCopyin interfaceShallowCopySupporter<T extends DataContainer & 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 instantiateoptions- 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
-
-