Class WekaReorderAttributesToReference

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

    public class WekaReorderAttributesToReference
    extends AbstractTransformer
    implements OptionalOneTimeInitializer, DynamicInitializer, 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 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 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 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

      • reset

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

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

        public 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​(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 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 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 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 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 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 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 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 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 LenientModeSupporter
        Returns:
        true if to tolerate unknown attributes
      • lenientTipText

        public String lenientTipText()
        Returns the tip text for this property.
        Specified by:
        lenientTipText in interface 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.
      • accepts

        public Class[] accepts()
        Returns the class that the consumer accepts.
        Specified by:
        accepts in interface 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 OutputProducer
        Returns:
        the Class of the generated tokens
      • setUpReference

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

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