Class WekaReorderAttributesToReference

  • All Implemented Interfaces:
    adams.core.AdditionalInformationHandler, adams.core.CleanUpHandler, adams.core.Destroyable, adams.core.GlobalInfoSupporter, adams.core.LenientModeSupporter, adams.core.logging.LoggingLevelHandler, adams.core.logging.LoggingSupporter, adams.core.option.OptionHandler, adams.core.QuickInfoSupporter, adams.core.ShallowCopySupporter<adams.flow.core.Actor>, adams.core.SizeOfHandler, adams.core.Stoppable, adams.core.StoppableWithFeedback, adams.core.VariablesInspectionHandler, adams.event.VariableChangeListener, adams.flow.core.Actor, adams.flow.core.DynamicInitializer, adams.flow.core.ErrorHandler, adams.flow.core.InputConsumer, adams.flow.core.OptionalOneTimeInitializer, adams.flow.core.OutputProducer, Serializable, Comparable

    public class WekaReorderAttributesToReference
    extends adams.flow.transformer.AbstractTransformer
    implements adams.flow.core.OptionalOneTimeInitializer, adams.flow.core.DynamicInitializer, adams.core.LenientModeSupporter
    Reorders the attributes of the Instance/Instances passing through according to the provided reference dataset (callable actor or reference file).
    This ensures that the generated data always has the same structure as the reference dataset.

    Input/output:
    - accepts:
       weka.core.Instance
       weka.core.Instances
    - generates:
       weka.core.Instance
       weka.core.Instances


    -logging-level <OFF|SEVERE|WARNING|INFO|CONFIG|FINE|FINER|FINEST> (property: loggingLevel)
        The logging level for outputting errors and debugging output.
        default: WARNING
     
    -name <java.lang.String> (property: name)
        The name of the actor.
        default: WekaReorderAttributesToReference
     
    -annotation <adams.core.base.BaseText> (property: annotations)
        The annotations to attach to this actor.
        default: 
     
    -skip <boolean> (property: skip)
        If set to true, transformation is skipped and the input token is just forwarded 
        as it is.
        default: false
     
    -stop-flow-on-error <boolean> (property: stopFlowOnError)
        If set to true, the flow gets stopped in case this actor encounters an error;
         useful for critical actors.
        default: false
     
    -reference-file <adams.core.io.PlaceholderFile> (property: referenceFile)
        The reference dataset to load (when not pointing to a directory).
        default: ${CWD}
     
    -use-custom <boolean> (property: useCustomLoader)
        If set to true, then the custom loader will be used for loading the data.
        default: false
     
    -loader <weka.core.converters.AbstractFileLoader> (property: customLoader)
        The custom loader to use if enabled.
        default: weka.core.converters.ArffLoader
     
    -reference-actor <adams.flow.core.CallableActorReference> (property: referenceActor)
        The callable actor to use for obtaining the reference dataset in case reference 
        file points to a directory.
        default: unknown
     
    -on-the-fly <boolean> (property: onTheFly)
        If set to true, the reference file is not required to be present at set 
        up time (eg if built on the fly), only at execution time.
        default: false
     
    -init-once <boolean> (property: initializeOnce)
        If set to true, then the internal reorder filter will get initialized only 
        with the first batch of data; otherwise every time data gets passed through.
        default: false
     
    -lenient <boolean> (property: lenient)
        If set to true, attributes from the reference data that are missing in the 
        incoming data get tolerated.
        default: false
     
    -keep <boolean> (property: keepRelationName)
        If set to true, then the filter won't change the relation name of the incoming 
        dataset.
        default: false
     
    Author:
    fracpete (fracpete at waikato dot ac dot nz)
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static String BACKUP_REFERENCE
      the key for storing the reference dataset in the backup.
      static String BACKUP_REORDER
      the key for storing the reorder filter in the backup.
      protected weka.core.converters.AbstractFileLoader m_CustomLoader
      the custom loader.
      protected boolean m_InitializeOnce
      whether to initialize filter only with the first batch.
      protected boolean m_KeepRelationName
      whether to keep the incoming relation name.
      protected boolean m_Lenient
      whether to tolerate attributes that are not present in the incoming data.
      protected boolean m_OnTheFly
      whether the dataset gets generated on the fly and might not be available at setUp time.
      protected weka.core.Instances m_Reference
      the reference dataset.
      protected adams.flow.core.CallableActorReference m_ReferenceActor
      the callable actor to get the reference data from.
      protected adams.core.io.PlaceholderFile m_ReferenceFile
      the reference dataset to load.
      protected weka.filters.MultiFilter m_Reorder
      the reorder filter to use.
      protected boolean m_UseCustomLoader
      whether to use a custom converter.
      • Fields inherited from class adams.flow.transformer.AbstractTransformer

        BACKUP_INPUT, BACKUP_OUTPUT, m_InputToken, m_OutputToken
      • Fields inherited from class adams.flow.core.AbstractActor

        m_Annotations, m_BackupState, m_DetectedObjectVariables, m_DetectedVariables, m_ErrorHandler, m_Executed, m_Executing, m_ExecutionListeningSupporter, m_FullName, m_LoggingPrefix, m_Name, m_Parent, m_ScopeHandler, m_Self, m_Silent, m_Skip, m_StopFlowOnError, m_StopMessage, m_Stopped, m_StorageHandler, m_VariablesUpdated
      • Fields inherited from class adams.core.option.AbstractOptionHandler

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

        m_Logger, m_LoggingIsEnabled, m_LoggingLevel
      • Fields inherited from interface adams.flow.core.Actor

        FILE_EXTENSION, FILE_EXTENSION_GZ
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Class[] accepts()
      Returns the class that the consumer accepts.
      protected Hashtable<String,​Object> backupState()
      Backs up the current state of the actor before update the variables.
      String customLoaderTipText()
      Returns the tip text for this property.
      void defineOptions()
      Adds options to the internal list of options.
      protected String doExecute()
      Executes the flow item.
      Class[] generates()
      Returns the class of objects that it generates.
      weka.core.converters.AbstractFileLoader getCustomLoader()
      Returns the custom loader in use.
      boolean getInitializeOnce()
      Returns whether the internal reorder filter gets initialized only with the first batch.
      boolean getKeepRelationName()
      Returns whether the filter doesn't change the relation name.
      boolean getLenient()
      Returns whether to tolerate attributes that are missing in the incoming data.
      boolean getOnTheFly()
      Returns whether the reference file gets built on the fly and might not be present at start up time.
      String getQuickInfo()
      Returns a quick info about the actor, which will be displayed in the GUI.
      adams.flow.core.CallableActorReference getReferenceActor()
      Returns the callable actor to obtain the reference dataset from if reference file is pointing to a directory.
      adams.core.io.PlaceholderFile getReferenceFile()
      Returns the file to load the reference dataset from.
      boolean getUseCustomLoader()
      Returns whether a custom loader is used or not.
      String globalInfo()
      Returns a string describing the object.
      String initializeOnceTipText()
      Returns the tip text for this property.
      String keepRelationNameTipText()
      Returns the tip text for this property.
      String lenientTipText()
      Returns the tip text for this property.
      String onTheFlyTipText()
      Returns the tip text for this property.
      protected void pruneBackup()
      Removes entries from the backup.
      String referenceActorTipText()
      Returns the tip text for this property.
      String referenceFileTipText()
      Returns the tip text for this property.
      protected void reset()
      Resets the actor.
      protected void restoreState​(Hashtable<String,​Object> state)
      Restores the state of the actor before the variables got updated.
      void setCustomLoader​(weka.core.converters.AbstractFileLoader value)
      Sets the custom loader to use.
      void setInitializeOnce​(boolean value)
      Sets whether the internal reorder filter gets initialized only with the first batch.
      void setKeepRelationName​(boolean value)
      Sets whether the filter doesn't change the relation name.
      void setLenient​(boolean value)
      Sets whether to tolerate attributes that are missing in the incoming data.
      void setOnTheFly​(boolean value)
      Sets whether the reference file gets built on the fly and might not be present at start up time.
      void setReferenceActor​(adams.flow.core.CallableActorReference value)
      Sets the callable actor to obtain the reference dataset from if reference file is pointing to a directory.
      void setReferenceFile​(adams.core.io.PlaceholderFile value)
      Sets the file to load the reference dataset from.
      String setUp()
      Initializes the item for flow execution.
      protected String setUpReference()
      Loads the reference data.
      void setUseCustomLoader​(boolean value)
      Sets whether to use a custom loader or not.
      String useCustomLoaderTipText()
      Returns the tip text for this property.
      • Methods inherited from class adams.flow.transformer.AbstractTransformer

        currentInput, execute, hasInput, hasPendingOutput, input, output, postExecute, wrapUp
      • Methods inherited from class adams.flow.core.AbstractActor

        annotationsTipText, canInspectOptions, canPerformSetUpCheck, cleanUp, compareTo, configureLogger, destroy, equals, finalUpdateVariables, findVariables, findVariables, forceVariables, forCommandLine, forName, forName, getAdditionalInformation, getAnnotations, getDefaultName, getDetectedVariables, getErrorHandler, getFlowActors, getFlowExecutionListeningSupporter, getFullName, getName, getNextSibling, getParent, getParentComponent, getPreviousSibling, getRoot, getScopeHandler, getSilent, getSkip, getStopFlowOnError, getStopMessage, getStorageHandler, getVariables, handleError, handleException, hasErrorHandler, hasStopMessage, index, initialize, isBackedUp, isExecuted, isExecuting, isFinished, isHeadless, isStopped, nameTipText, performSetUpChecks, performVariableChecks, preExecute, pruneBackup, setAnnotations, setErrorHandler, setName, setParent, setSilent, setSkip, setStopFlowOnError, setVariables, shallowCopy, shallowCopy, silentTipText, sizeOf, skipTipText, stopExecution, stopExecution, stopFlowOnErrorTipText, updateDetectedVariables, updatePrefix, updateVariables, variableChanged
      • Methods inherited from class adams.core.option.AbstractOptionHandler

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

        getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled
      • Methods inherited from interface adams.flow.core.Actor

        cleanUp, compareTo, destroy, equals, execute, findVariables, getAnnotations, getDefaultName, getDetectedVariables, getErrorHandler, getFlowExecutionListeningSupporter, getFullName, getName, getNextSibling, getParent, getParentComponent, getPreviousSibling, getRoot, getScopeHandler, getSilent, getSkip, getStopFlowOnError, getStopMessage, getStorageHandler, getVariables, handleError, hasErrorHandler, hasStopMessage, index, isExecuted, isFinished, isHeadless, isStopped, setAnnotations, setErrorHandler, setName, setParent, setSilent, setSkip, setStopFlowOnError, setVariables, shallowCopy, shallowCopy, sizeOf, stopExecution, stopExecution, toCommandLine, variableChanged, wrapUp
      • Methods inherited from interface adams.core.AdditionalInformationHandler

        getAdditionalInformation
      • Methods inherited from interface adams.core.logging.LoggingLevelHandler

        getLoggingLevel, setLoggingLevel
      • Methods inherited from interface adams.core.logging.LoggingSupporter

        getLogger, isLoggingEnabled
      • Methods inherited from interface adams.core.option.OptionHandler

        cleanUpOptions, getOptionManager
      • Methods inherited from interface adams.core.VariablesInspectionHandler

        canInspectOptions
    • Field Detail

      • BACKUP_REFERENCE

        public static final String BACKUP_REFERENCE
        the key for storing the reference dataset in the backup.
        See Also:
        Constant Field Values
      • BACKUP_REORDER

        public static final String BACKUP_REORDER
        the key for storing the reorder filter in the backup.
        See Also:
        Constant Field Values
      • m_ReferenceFile

        protected adams.core.io.PlaceholderFile m_ReferenceFile
        the reference dataset to load.
      • m_UseCustomLoader

        protected boolean m_UseCustomLoader
        whether to use a custom converter.
      • m_CustomLoader

        protected weka.core.converters.AbstractFileLoader m_CustomLoader
        the custom loader.
      • m_ReferenceActor

        protected adams.flow.core.CallableActorReference m_ReferenceActor
        the callable actor to get the reference data from.
      • m_Reference

        protected weka.core.Instances m_Reference
        the reference dataset.
      • m_OnTheFly

        protected boolean m_OnTheFly
        whether the dataset gets generated on the fly and might not be available at setUp time.
      • m_InitializeOnce

        protected boolean m_InitializeOnce
        whether to initialize filter only with the first batch.
      • m_Lenient

        protected boolean m_Lenient
        whether to tolerate attributes that are not present in the incoming data.
      • m_KeepRelationName

        protected boolean m_KeepRelationName
        whether to keep the incoming relation name.
      • m_Reorder

        protected weka.filters.MultiFilter m_Reorder
        the reorder filter to use.
    • Constructor Detail

      • WekaReorderAttributesToReference

        public WekaReorderAttributesToReference()
    • Method Detail

      • globalInfo

        public String globalInfo()
        Returns a string describing the object.
        Specified by:
        globalInfo in interface adams.core.GlobalInfoSupporter
        Specified by:
        globalInfo in class adams.core.option.AbstractOptionHandler
        Returns:
        a description suitable for displaying in the gui
      • 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.flow.core.AbstractActor
      • reset

        protected void reset()
        Resets the actor.
        Overrides:
        reset in class adams.flow.core.AbstractActor
      • setReferenceFile

        public void setReferenceFile​(adams.core.io.PlaceholderFile value)
        Sets the file to load the reference dataset from.
        Parameters:
        value - the reference file
      • getReferenceFile

        public adams.core.io.PlaceholderFile getReferenceFile()
        Returns the file to load the reference dataset from.
        Returns:
        the reference file
      • referenceFileTipText

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

        public void setUseCustomLoader​(boolean value)
        Sets whether to use a custom loader or not.
        Parameters:
        value - if true then the custom loader will be used
      • getUseCustomLoader

        public boolean getUseCustomLoader()
        Returns whether a custom loader is used or not.
        Returns:
        true if a custom loader is used
      • useCustomLoaderTipText

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

        public void setCustomLoader​(weka.core.converters.AbstractFileLoader value)
        Sets the custom loader to use.
        Parameters:
        value - the custom loader
      • getCustomLoader

        public weka.core.converters.AbstractFileLoader getCustomLoader()
        Returns the custom loader in use.
        Returns:
        the custom loader
      • customLoaderTipText

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

        public void setReferenceActor​(adams.flow.core.CallableActorReference value)
        Sets the callable actor to obtain the reference dataset from if reference file is pointing to a directory.
        Parameters:
        value - the actor reference
      • getReferenceActor

        public adams.flow.core.CallableActorReference getReferenceActor()
        Returns the callable actor to obtain the reference dataset from if reference file is pointing to a directory.
        Returns:
        the actor reference
      • referenceActorTipText

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

        public void setOnTheFly​(boolean value)
        Sets whether the reference file gets built on the fly and might not be present at start up time.
        Specified by:
        setOnTheFly in interface adams.flow.core.DynamicInitializer
        Parameters:
        value - if true then the reference does not have to be present at start up time
      • getOnTheFly

        public boolean getOnTheFly()
        Returns whether the reference file gets built on the fly and might not be present at start up time.
        Specified by:
        getOnTheFly in interface adams.flow.core.DynamicInitializer
        Returns:
        true if the reference is not necessarily present at start up time
      • onTheFlyTipText

        public String onTheFlyTipText()
        Returns the tip text for this property.
        Specified by:
        onTheFlyTipText in interface adams.flow.core.DynamicInitializer
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setInitializeOnce

        public void setInitializeOnce​(boolean value)
        Sets whether the internal reorder filter gets initialized only with the first batch.
        Specified by:
        setInitializeOnce in interface adams.flow.core.OptionalOneTimeInitializer
        Parameters:
        value - true if the filter gets only initialized once
      • getInitializeOnce

        public boolean getInitializeOnce()
        Returns whether the internal reorder filter gets initialized only with the first batch.
        Specified by:
        getInitializeOnce in interface adams.flow.core.OptionalOneTimeInitializer
        Returns:
        true if the filter gets only initialized once
      • initializeOnceTipText

        public String initializeOnceTipText()
        Returns the tip text for this property.
        Specified by:
        initializeOnceTipText in interface adams.flow.core.OptionalOneTimeInitializer
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setLenient

        public void setLenient​(boolean value)
        Sets whether to tolerate attributes that are missing in the incoming data.
        Specified by:
        setLenient in interface adams.core.LenientModeSupporter
        Parameters:
        value - true if to tolerate unknown attributes
      • getLenient

        public boolean getLenient()
        Returns whether to tolerate attributes that are missing in the incoming data.
        Specified by:
        getLenient in interface adams.core.LenientModeSupporter
        Returns:
        true if to tolerate unknown attributes
      • lenientTipText

        public String lenientTipText()
        Returns the tip text for this property.
        Specified by:
        lenientTipText in interface adams.core.LenientModeSupporter
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setKeepRelationName

        public void setKeepRelationName​(boolean value)
        Sets whether the filter doesn't change the relation name.
        Parameters:
        value - true if the filter won't change the relation name
      • getKeepRelationName

        public boolean getKeepRelationName()
        Returns whether the filter doesn't change the relation name.
        Returns:
        true if the filter doesn't change the relation name
      • keepRelationNameTipText

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

        public String getQuickInfo()
        Returns a quick info about the actor, which will be displayed in the GUI.
        Specified by:
        getQuickInfo in interface adams.flow.core.Actor
        Specified by:
        getQuickInfo in interface adams.core.QuickInfoSupporter
        Overrides:
        getQuickInfo in class adams.flow.core.AbstractActor
        Returns:
        null if no info available, otherwise short string
      • accepts

        public Class[] accepts()
        Returns the class that the consumer accepts.
        Specified by:
        accepts in interface adams.flow.core.InputConsumer
        Returns:
        the Class of objects that can be processed
      • generates

        public Class[] generates()
        Returns the class of objects that it generates.
        Specified by:
        generates in interface adams.flow.core.OutputProducer
        Returns:
        the Class of the generated tokens
      • pruneBackup

        protected void pruneBackup()
        Removes entries from the backup.
        Overrides:
        pruneBackup in class adams.flow.core.AbstractActor
      • backupState

        protected Hashtable<String,​Object> backupState()
        Backs up the current state of the actor before update the variables.
        Overrides:
        backupState in class adams.flow.transformer.AbstractTransformer
        Returns:
        the backup
      • restoreState

        protected void restoreState​(Hashtable<String,​Object> state)
        Restores the state of the actor before the variables got updated.
        Overrides:
        restoreState in class adams.flow.transformer.AbstractTransformer
        Parameters:
        state - the backup of the state to restore from
      • setUpReference

        protected String setUpReference()
        Loads the reference data.
        Returns:
        null if everything worked, otherwise an error message
      • setUp

        public String setUp()
        Initializes the item for flow execution.
        Specified by:
        setUp in interface adams.flow.core.Actor
        Overrides:
        setUp in class adams.flow.core.AbstractActor
        Returns:
        null if everything is fine, otherwise error message
      • doExecute

        protected String doExecute()
        Executes the flow item.
        Specified by:
        doExecute in class adams.flow.core.AbstractActor
        Returns:
        null if everything is fine, otherwise error message