Class AbstractCleaner

  • All Implemented Interfaces:
    adams.core.Destroyable, adams.core.GlobalInfoSupporter, adams.core.logging.LoggingLevelHandler, adams.core.logging.LoggingSupporter, adams.core.option.OptionHandler, adams.core.ShallowCopySupporter<AbstractCleaner>, adams.core.SizeOfHandler, adams.flow.core.FlowContextHandler, Serializable, Comparable
    Direct Known Subclasses:
    AbstractDatabaseConnectionCleaner, AbstractSerializableCleaner, MinMax, PassThrough, RemoveOutliers

    public abstract class AbstractCleaner
    extends adams.core.option.AbstractOptionHandler
    implements Comparable, adams.core.ShallowCopySupporter<AbstractCleaner>, adams.flow.core.FlowContextHandler
    Abstract base class for cleaners handling weka.core.Instance objects. Derived classes only have to override the check(Instance) method. The reset() method can be used to reset an algorithms internal state, e.g., after setting options.
    Author:
    fracpete (fracpete at waikato dot ac dot nz)
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected weka.filters.Filter m_ActualPreFilter
      the actual pre-filter to use.
      protected String m_CleanInstancesError
      for storing error messages in case the cleaning of the initial Instances object failed.
      protected adams.flow.core.Actor m_FlowContext
      the flow context.
      protected weka.filters.Filter m_PreFilter
      the pre-filter to use.
      • 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
      AbstractCleaner()  
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      String check​(weka.core.Instance data)
      Performs the check.
      weka.core.Instances clean​(weka.core.Instances data)
      Performs the clean.
      int compareTo​(Object o)
      Compares this object with the specified object for order.
      void defineOptions()
      Adds options to the internal list of options.
      boolean equals​(Object o)
      Returns whether the two objects are the same.
      static AbstractCleaner forCommandLine​(String cmdline)
      Instantiates the filter from the given commandline (i.e., classname and optional options).
      static AbstractCleaner forName​(String classname, String[] options)
      Instantiates the filter with the given options.
      static String[] getCleaners()
      Returns a list with classnames of filters.
      String getCleanInstancesError()
      Returns the error message that was recorded during cleaning the Instances object (if any).
      adams.flow.core.Actor getFlowContext()
      Returns the flow context.
      weka.filters.Filter getPreFilter()
      Returns the filter to use for pre-filtering the data.
      boolean hasCleanInstancesError()
      Checks whether there was an error during cleaning the Instances object.
      protected abstract String performCheck​(weka.core.Instance data)
      Performs the actual check.
      protected abstract weka.core.Instances performClean​(weka.core.Instances data)
      Performs the actual check.
      protected void preCheck​(weka.core.Instance data)
      Performs the pre-checks whether the data is actually suitable.
      protected void preCheck​(weka.core.Instances data)
      Performs the some pre-checks whether the data is actually suitable.
      protected weka.core.Instance preFilter​(weka.core.Instance data)
      Performs the filtering.
      protected weka.core.Instances preFilter​(weka.core.Instances data)
      Performs the filtering.
      String preFilterTipText()
      Returns the tip text for this property.
      protected void reset()
      Resets the scheme.
      void setFlowContext​(adams.flow.core.Actor value)
      Sets the flow context.
      void setPreFilter​(weka.filters.Filter value)
      Sets the filter to use for pre-filtering the data.
      AbstractCleaner shallowCopy()
      Returns a shallow copy of itself, i.e., based on the commandline options.
      AbstractCleaner 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, destroy, finishInit, getDefaultLoggingLevel, getOptionManager, globalInfo, initialize, 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_CleanInstancesError

        protected String m_CleanInstancesError
        for storing error messages in case the cleaning of the initial Instances object failed.
      • m_PreFilter

        protected weka.filters.Filter m_PreFilter
        the pre-filter to use.
      • m_ActualPreFilter

        protected weka.filters.Filter m_ActualPreFilter
        the actual pre-filter to use.
      • m_FlowContext

        protected transient adams.flow.core.Actor m_FlowContext
        the flow context.
    • Constructor Detail

      • AbstractCleaner

        public AbstractCleaner()
    • 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
      • reset

        protected void reset()
        Resets the scheme.
        Overrides:
        reset in class adams.core.option.AbstractOptionHandler
      • setPreFilter

        public void setPreFilter​(weka.filters.Filter value)
        Sets the filter to use for pre-filtering the data.
        Parameters:
        value - the filter
      • getPreFilter

        public weka.filters.Filter getPreFilter()
        Returns the filter to use for pre-filtering the data.
        Returns:
        the filter
      • preFilterTipText

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

        public void setFlowContext​(adams.flow.core.Actor value)
        Sets the flow context.
        Specified by:
        setFlowContext in interface adams.flow.core.FlowContextHandler
        Parameters:
        value - the context
      • getFlowContext

        public adams.flow.core.Actor getFlowContext()
        Returns the flow context.
        Specified by:
        getFlowContext in interface adams.flow.core.FlowContextHandler
        Returns:
        the context, null if not available
      • preCheck

        protected void preCheck​(weka.core.Instance data)
        Performs the pre-checks whether the data is actually suitable.
        Parameters:
        data - the instance to check
      • preCheck

        protected void preCheck​(weka.core.Instances data)
        Performs the some pre-checks whether the data is actually suitable.
        Parameters:
        data - the instances to clean
      • performCheck

        protected abstract String performCheck​(weka.core.Instance data)
        Performs the actual check.
        Parameters:
        data - the instance to check
        Returns:
        null if ok, otherwise error message
      • performClean

        protected abstract weka.core.Instances performClean​(weka.core.Instances data)
        Performs the actual check.
        Parameters:
        data - the instance to check
        Returns:
        null if ok, otherwise error message
      • preFilter

        protected weka.core.Instances preFilter​(weka.core.Instances data)
        Performs the filtering.
        Parameters:
        data - the data to filter
      • preFilter

        protected weka.core.Instance preFilter​(weka.core.Instance data)
        Performs the filtering.
        Parameters:
        data - the data to filter
      • check

        public String check​(weka.core.Instance data)
        Performs the check.
        Parameters:
        data - the instance to check
        Returns:
        null if ok, otherwise error message
      • clean

        public weka.core.Instances clean​(weka.core.Instances data)
        Performs the clean.
        Parameters:
        data - the instances to clean
        Returns:
        cleaned instances
      • hasCleanInstancesError

        public boolean hasCleanInstancesError()
        Checks whether there was an error during cleaning the Instances object.
        Returns:
        true if there was an error
      • getCleanInstancesError

        public String getCleanInstancesError()
        Returns the error message that was recorded during cleaning the Instances object (if any).
        Returns:
        the error message, null if none occurred
      • 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 AbstractCleaner shallowCopy()
        Returns a shallow copy of itself, i.e., based on the commandline options.
        Specified by:
        shallowCopy in interface adams.core.ShallowCopySupporter<AbstractCleaner>
        Returns:
        the shallow copy
      • shallowCopy

        public AbstractCleaner shallowCopy​(boolean expand)
        Returns a shallow copy of itself, i.e., based on the commandline options.
        Specified by:
        shallowCopy in interface adams.core.ShallowCopySupporter<AbstractCleaner>
        Parameters:
        expand - whether to expand variables to their current values
        Returns:
        the shallow copy
      • getCleaners

        public static String[] getCleaners()
        Returns a list with classnames of filters.
        Returns:
        the filter classnames
      • forName

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

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