Class PartitionedMultiFilter2

  • All Implemented Interfaces:
    Serializable, weka.core.CapabilitiesHandler, weka.core.CapabilitiesIgnorer, weka.core.CommandlineRunnable, weka.core.OptionHandler, weka.core.RevisionHandler

    public class PartitionedMultiFilter2
    extends weka.filters.SimpleBatchFilter
    A filter that applies filters on subsets of attributes and assembles the output into a new dataset. Attributes that are not covered by any of the ranges can be either retained or removed from the output.

    Valid options are:

     -D
      Turns on output of debugging information.
     
     -F <classname [options]>
      A filter to apply (can be specified multiple times).
     
     -R <range>
      An attribute range (can be specified multiple times).
      For each filter a range must be supplied. 'first' and 'last'
      are valid indices. 'inv(...)' around the range denotes an
      inverted range.
     
     -U
      Flag for leaving unused attributes out of the output, by default
      these are included in the filter output.
     
    Author:
    FracPete (fracpete at waikato dot ac dot nz)
    See Also:
    StreamableFilter, Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected weka.filters.Filter[] m_Filters
      The filters.
      protected int[] m_IndicesUnused
      the indices of the unused attributes.
      protected adams.core.base.BaseString[] m_Prefixes
      The prefixes.
      protected weka.core.Instances[] m_Processed
      temporary filter results when determining output format to avoid duplicate processing of data.
      protected weka.core.Range[] m_Ranges
      The attribute ranges.
      protected boolean m_RemoveUnused
      Whether unused attributes are left out of the output.
      • Fields inherited from class weka.filters.Filter

        m_Debug, m_DoNotCheckCapabilities, m_FirstBatchDone, m_InputRelAtts, m_InputStringAtts, m_NewBatch, m_OutputRelAtts, m_OutputStringAtts
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean allowAccessToFullInputFormat()
      Returns whether to allow the determineOutputFormat(Instances) method access to the full dataset rather than just the header.
      protected void checkDimensions()
      checks whether the dimensions of filters and ranges fit together.
      protected weka.core.Instances determineOutputFormat​(weka.core.Instances inputFormat)
      Determines the output format based only on the full input dataset and returns this otherwise null is returned.
      protected void determineUnusedIndices​(weka.core.Instances data)
      determines the indices of unused attributes (ones that are not covered by any of the range).
      String filtersTipText()
      Returns the tip text for this property.
      protected weka.core.Instances generateSubset​(weka.core.Instances data, weka.core.Range range)
      generates a subset of the dataset with only the attributes from the range (class is always added if present).
      weka.core.Capabilities getCapabilities()
      Returns the Capabilities of this filter.
      weka.filters.Filter getFilter​(int index)
      Gets a single filter from the set of available filters.
      weka.filters.Filter[] getFilters()
      Gets the list of possible filters to choose from.
      protected String getFilterSpec​(weka.filters.Filter filter)
      returns the filter classname and the options as one string.
      String[] getOptions()
      Gets the current settings of the filter.
      adams.core.base.BaseString[] getPrefixes()
      Gets the list of prefixes to use.
      weka.core.Range getRange​(int index)
      Gets a single Range from the set of available Ranges.
      weka.core.Range[] getRanges()
      Gets the list of possible Ranges to choose from.
      boolean getRemoveUnused()
      Gets whether unused attributes (ones that are not covered by any of the ranges) are removed from the output.
      String getRevision()
      Returns the revision string.
      String globalInfo()
      Returns a string describing this filter.
      Enumeration<weka.core.Option> listOptions()
      Returns an enumeration describing the available options.
      static void main​(String[] args)
      Main method for executing this class.
      String prefixesTipText()
      Returns the tip text for this property.
      protected weka.core.Instances process​(weka.core.Instances instances)
      Processes the given data (may change the provided dataset) and returns the modified version.
      String rangesTipText()
      Returns the tip text for this property.
      String removeUnusedTipText()
      Returns the tip text for this property.
      protected weka.core.Instances renameAttributes​(weka.core.Instances data, String prefix)
      renames all the attributes in the dataset (excluding the class if present) by adding the prefix to the name.
      void setFilters​(weka.filters.Filter[] filters)
      Sets the list of possible filters to choose from.
      void setOptions​(String[] options)
      Parses a list of options for this object.
      void setPrefixes​(adams.core.base.BaseString[] prefixes)
      Sets the list of prefixes to use.
      void setRanges​(weka.core.Range[] Ranges)
      Sets the list of possible Ranges to choose from.
      void setRemoveUnused​(boolean value)
      Sets whether unused attributes (ones that are not covered by any of the ranges) are removed from the output.
      protected void testInputFormat​(weka.core.Instances instanceInfo)
      tests the data whether the filter can actually handle it.
      • Methods inherited from class weka.filters.SimpleBatchFilter

        batchFinished, hasImmediateOutputFormat, input
      • Methods inherited from class weka.filters.SimpleFilter

        reset, setInputFormat
      • Methods inherited from class weka.filters.Filter

        batchFilterFile, bufferInput, copyValues, copyValues, debugTipText, doNotCheckCapabilitiesTipText, filterFile, flushInput, getCapabilities, getDebug, getDoNotCheckCapabilities, getInputFormat, getOutputFormat, initInputLocators, initOutputLocators, inputFormatPeek, isFirstBatchDone, isNewBatch, isOutputFormatDefined, makeCopies, makeCopy, mayRemoveInstanceAfterFirstBatchDone, numPendingOutput, output, outputFormatPeek, outputPeek, postExecution, preExecution, push, push, resetQueue, run, runFilter, setDebug, setDoNotCheckCapabilities, setOutputFormat, toString, useFilter, wekaStaticWrapper
    • Field Detail

      • m_Filters

        protected weka.filters.Filter[] m_Filters
        The filters.
      • m_Ranges

        protected weka.core.Range[] m_Ranges
        The attribute ranges.
      • m_Prefixes

        protected adams.core.base.BaseString[] m_Prefixes
        The prefixes.
      • m_RemoveUnused

        protected boolean m_RemoveUnused
        Whether unused attributes are left out of the output.
      • m_IndicesUnused

        protected int[] m_IndicesUnused
        the indices of the unused attributes.
      • m_Processed

        protected weka.core.Instances[] m_Processed
        temporary filter results when determining output format to avoid duplicate processing of data.
    • Constructor Detail

      • PartitionedMultiFilter2

        public PartitionedMultiFilter2()
    • Method Detail

      • globalInfo

        public String globalInfo()
        Returns a string describing this filter.
        Specified by:
        globalInfo in class weka.filters.SimpleFilter
        Returns:
        a description of the filter suitable for displaying in the explorer/experimenter gui
      • listOptions

        public Enumeration<weka.core.Option> listOptions()
        Returns an enumeration describing the available options.
        Specified by:
        listOptions in interface weka.core.OptionHandler
        Overrides:
        listOptions in class weka.filters.Filter
        Returns:
        an enumeration of all the available options.
      • setOptions

        public void setOptions​(String[] options)
                        throws Exception
        Parses a list of options for this object.
        Specified by:
        setOptions in interface weka.core.OptionHandler
        Overrides:
        setOptions in class weka.filters.Filter
        Parameters:
        options - the list of options as an array of strings
        Throws:
        Exception - if an option is not supported
      • getOptions

        public String[] getOptions()
        Gets the current settings of the filter.
        Specified by:
        getOptions in interface weka.core.OptionHandler
        Overrides:
        getOptions in class weka.filters.Filter
        Returns:
        an array of strings suitable for passing to setOptions
      • checkDimensions

        protected void checkDimensions()
                                throws Exception
        checks whether the dimensions of filters and ranges fit together.
        Throws:
        Exception - if dimensions differ
      • getCapabilities

        public weka.core.Capabilities getCapabilities()
        Returns the Capabilities of this filter.
        Specified by:
        getCapabilities in interface weka.core.CapabilitiesHandler
        Overrides:
        getCapabilities in class weka.filters.Filter
        Returns:
        the capabilities of this object
        See Also:
        Capabilities
      • testInputFormat

        protected void testInputFormat​(weka.core.Instances instanceInfo)
                                throws Exception
        tests the data whether the filter can actually handle it.
        Overrides:
        testInputFormat in class weka.filters.Filter
        Parameters:
        instanceInfo - the data to test
        Throws:
        Exception - if the test fails
      • setRemoveUnused

        public void setRemoveUnused​(boolean value)
        Sets whether unused attributes (ones that are not covered by any of the ranges) are removed from the output.
        Parameters:
        value - if true then the unused attributes get removed
      • getRemoveUnused

        public boolean getRemoveUnused()
        Gets whether unused attributes (ones that are not covered by any of the ranges) are removed from the output.
        Returns:
        true if unused attributes are removed
      • removeUnusedTipText

        public String removeUnusedTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the explorer/experimenter gui
      • setFilters

        public void setFilters​(weka.filters.Filter[] filters)
        Sets the list of possible filters to choose from. Also resets the state of the filter (this reset doesn't affect the options).
        Parameters:
        filters - an array of filters with all options set.
        See Also:
        SimpleFilter.reset()
      • getFilters

        public weka.filters.Filter[] getFilters()
        Gets the list of possible filters to choose from.
        Returns:
        the array of Filters
      • filtersTipText

        public String filtersTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the explorer/experimenter gui
      • getFilter

        public weka.filters.Filter getFilter​(int index)
        Gets a single filter from the set of available filters.
        Parameters:
        index - the index of the filter wanted
        Returns:
        the Filter
      • getFilterSpec

        protected String getFilterSpec​(weka.filters.Filter filter)
        returns the filter classname and the options as one string.
        Parameters:
        filter - the filter to get the specs for
        Returns:
        the classname plus options
      • setRanges

        public void setRanges​(weka.core.Range[] Ranges)
        Sets the list of possible Ranges to choose from. Also resets the state of the Range (this reset doesn't affect the options).
        Parameters:
        Ranges - an array of Ranges with all options set.
        See Also:
        SimpleFilter.reset()
      • getRanges

        public weka.core.Range[] getRanges()
        Gets the list of possible Ranges to choose from.
        Returns:
        the array of Ranges
      • rangesTipText

        public String rangesTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the explorer/experimenter gui
      • setPrefixes

        public void setPrefixes​(adams.core.base.BaseString[] prefixes)
        Sets the list of prefixes to use.
        Parameters:
        prefixes - an array of prefixes
        See Also:
        SimpleFilter.reset()
      • getPrefixes

        public adams.core.base.BaseString[] getPrefixes()
        Gets the list of prefixes to use.
        Returns:
        the array of prefixes
      • prefixesTipText

        public String prefixesTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the explorer/experimenter gui
      • getRange

        public weka.core.Range getRange​(int index)
        Gets a single Range from the set of available Ranges.
        Parameters:
        index - the index of the Range wanted
        Returns:
        the Range
      • allowAccessToFullInputFormat

        public boolean allowAccessToFullInputFormat()
        Returns whether to allow the determineOutputFormat(Instances) method access to the full dataset rather than just the header.
        Overrides:
        allowAccessToFullInputFormat in class weka.filters.SimpleBatchFilter
        Returns:
        whether determineOutputFormat has access to the full input dataset
      • determineUnusedIndices

        protected void determineUnusedIndices​(weka.core.Instances data)
        determines the indices of unused attributes (ones that are not covered by any of the range).
        Parameters:
        data - the data to base the determination on
        See Also:
        m_IndicesUnused
      • generateSubset

        protected weka.core.Instances generateSubset​(weka.core.Instances data,
                                                     weka.core.Range range)
                                              throws Exception
        generates a subset of the dataset with only the attributes from the range (class is always added if present).
        Parameters:
        data - the data to work on
        range - the range of attribute to use
        Returns:
        the generated subset
        Throws:
        Exception - if creation fails
      • renameAttributes

        protected weka.core.Instances renameAttributes​(weka.core.Instances data,
                                                       String prefix)
                                                throws Exception
        renames all the attributes in the dataset (excluding the class if present) by adding the prefix to the name.
        Parameters:
        data - the data to work on
        prefix - the prefix for the attributes
        Returns:
        a copy of the data with the attributes renamed
        Throws:
        Exception - if renaming fails
      • determineOutputFormat

        protected weka.core.Instances determineOutputFormat​(weka.core.Instances inputFormat)
                                                     throws Exception
        Determines the output format based only on the full input dataset and returns this otherwise null is returned. In case the output format cannot be returned immediately, i.e., immediateOutputFormat() returns false, then this method will be called from batchFinished().
        Specified by:
        determineOutputFormat in class weka.filters.SimpleFilter
        Parameters:
        inputFormat - the input format to base the output format on
        Returns:
        the output format
        Throws:
        Exception - in case the determination goes wrong
        See Also:
        SimpleBatchFilter.hasImmediateOutputFormat(), SimpleBatchFilter.batchFinished()
      • process

        protected weka.core.Instances process​(weka.core.Instances instances)
                                       throws Exception
        Processes the given data (may change the provided dataset) and returns the modified version. This method is called in batchFinished().
        Specified by:
        process in class weka.filters.SimpleFilter
        Parameters:
        instances - the data to process
        Returns:
        the modified data
        Throws:
        Exception - in case the processing goes wrong
        See Also:
        SimpleBatchFilter.batchFinished()
      • getRevision

        public String getRevision()
        Returns the revision string.
        Specified by:
        getRevision in interface weka.core.RevisionHandler
        Overrides:
        getRevision in class weka.filters.Filter
        Returns:
        the revision
      • main

        public static void main​(String[] args)
        Main method for executing this class.
        Parameters:
        args - should contain arguments for the filter: use -h for help