weka.gui.beans

## Class SubstringLabelerRules

- java.lang.Object
- - weka.gui.beans.SubstringLabelerRules

- All Implemented Interfaces:
    java.io.Serializable, EnvironmentHandler

      public class SubstringLabelerRules
      extends java.lang.Object
      implements EnvironmentHandler, java.io.Serializable

  Manages a list of match rules for labeling strings. Also has methods for determining the output structure with respect to a set of rules and for constructing output instances that have been labeled according to the rules.
  Version:
    $Revision: 12232 $
  Author:
    Mark Hall (mhall{[at]}pentaho{[dot]}com)
  See Also:
    Serialized Form

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `SubstringLabelerRules.SubstringLabelerMatchRule` Inner class encapsulating the logic for matching

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static java.lang.String` | `MATCH_RULE_SEPARATOR` Separator for match rules in the internal representation

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `SubstringLabelerRules(java.lang.String matchDetails, java.lang.String newAttName, boolean consumeNonMatching, boolean nominalBinary, Instances inputStructure, java.lang.String statusMessagePrefix, Logger log, Environment env)` Constructor
    `SubstringLabelerRules(java.lang.String matchDetails, java.lang.String newAttName, Instances inputStructure)` Constructor.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `getConsumeNonMatching()` Get whether to consume non matching instances.
    `Instances` | `getInputStructure()` Get the input structure
    `java.lang.String` | `getNewAttributeName()` Get the name to use for the new attribute that is added
    `boolean` | `getNominalBinary()` Get whether to create a nominal binary attribute in the case when the user has not supplied an explicit label to use for each rule.
    `Instances` | `getOutputStructure()` Get the output structure
    `Instance` | `makeOutputInstance(Instance inputI, boolean batch)` Process and input instance and return an output instance
    `static java.util.List<SubstringLabelerRules.SubstringLabelerMatchRule>` | `matchRulesFromInternal(java.lang.String matchDetails, Instances inputStructure, java.lang.String statusMessagePrefix, Logger log, Environment env)` Get a list of match rules from an internally encoded match specification
    `void` | `setConsumeNonMatching(boolean n)` Set whether to consume non matching instances.
    `void` | `setEnvironment(Environment env)` Set environment variables to use.
    `void` | `setNewAttributeName(java.lang.String newName)` Set the name to use for the new attribute that is added
    `void` | `setNominalBinary(boolean n)` Set whether to create a nominal binary attribute in the case when the user has not supplied an explicit label to use for each rule.

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### MATCH_RULE_SEPARATOR

          public static final java.lang.String MATCH_RULE_SEPARATOR

      Separator for match rules in the internal representation
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### SubstringLabelerRules

          public SubstringLabelerRules(java.lang.String matchDetails,
                                       java.lang.String newAttName,
                                       boolean consumeNonMatching,
                                       boolean nominalBinary,
                                       Instances inputStructure,
                                       java.lang.String statusMessagePrefix,
                                       Logger log,
                                       Environment env)
                                throws java.lang.Exception

      Constructor
      Parameters:
        `matchDetails` - the internally encoded match details string
        `newAttName` - the name of the new attribute that will be the label
        `consumeNonMatching` - true if non-matching instances should be consumed
        `nominalBinary` - true if, in the case where no user labels have been supplied, the new attribute should be a nominal binary one rather than numeric
        `inputStructure` - the incoming instances structure
        `statusMessagePrefix` - an optional status message prefix string for logging
        `log` - the log to use (may be null)
        `env` - environment variables
      Throws:
        `java.lang.Exception`

    - #### SubstringLabelerRules

          public SubstringLabelerRules(java.lang.String matchDetails,
                                       java.lang.String newAttName,
                                       Instances inputStructure)
                                throws java.lang.Exception

      Constructor. Sets consume non matching to false and nominal binary to false. Initializes with system-wide environment variables. Initializes with no status message prefix and no log.
      Parameters:
        `matchDetails` - the internally encoded match details string.
        `newAttName` - the name of the new attribute that will be the label
        `inputStructure` - the incoming instances structure
      Throws:
        `java.lang.Exception`

  - ### Method Detail

    - #### setConsumeNonMatching

          public void setConsumeNonMatching(boolean n)

      Set whether to consume non matching instances. If false, then they will be passed through unaltered.
      Parameters:
        `n` - true then non-matching instances will be consumed (and only matching, and thus labelled, instances will be output)

    - #### getConsumeNonMatching

          public boolean getConsumeNonMatching()

      Get whether to consume non matching instances. If false, then they will be passed through unaltered.
      Returns:
        true then non-matching instances will be consumed (and only matching, and thus labelled, instances will be output)

    - #### setNominalBinary

          public void setNominalBinary(boolean n)

      Set whether to create a nominal binary attribute in the case when the user has not supplied an explicit label to use for each rule. If no labels are provided, then the output attribute is a binary indicator one (i.e. a rule matched or it didn't). This option allows that binary indicator to be coded as nominal rather than numeric
      Parameters:
        `n` - true if a binary indicator attribute should be nominal rather than numeric

    - #### getNominalBinary

          public boolean getNominalBinary()

      Get whether to create a nominal binary attribute in the case when the user has not supplied an explicit label to use for each rule. If no labels are provided, then the output attribute is a binary indicator one (i.e. a rule matched or it didn't). This option allows that binary indicator to be coded as nominal rather than numeric
      Returns:
        true if a binary indicator attribute should be nominal rather than numeric

    - #### getOutputStructure

          public Instances getOutputStructure()

      Get the output structure
      Returns:
        the structure of the output instances

    - #### getInputStructure

          public Instances getInputStructure()

      Get the input structure
      Returns:
        the structure of the input instances

    - #### setNewAttributeName

          public void setNewAttributeName(java.lang.String newName)

      Set the name to use for the new attribute that is added
      Parameters:
        `newName` - the name to use

    - #### getNewAttributeName

          public java.lang.String getNewAttributeName()

      Get the name to use for the new attribute that is added
      Returns:
        the name to use

    - #### setEnvironment

          public void setEnvironment(Environment env)

      Description copied from interface: `EnvironmentHandler`
      Set environment variables to use.
      Specified by:
        `setEnvironment` in interface `EnvironmentHandler`
      Parameters:
        `env` - the environment variables to use

    - #### matchRulesFromInternal

          public static java.util.List<SubstringLabelerRules.SubstringLabelerMatchRule> matchRulesFromInternal(java.lang.String matchDetails,
                                                                                                               Instances inputStructure,
                                                                                                               java.lang.String statusMessagePrefix,
                                                                                                               Logger log,
                                                                                                               Environment env)

      Get a list of match rules from an internally encoded match specification
      Parameters:
        `matchDetails` - the internally encoded specification of the match rules
        `inputStructure` - the input instances structure
        `statusMessagePrefix` - an optional status message prefix for logging
        `log` - the log to use
        `env` - environment variables
      Returns:
        a list of match rules

    - #### makeOutputInstance

          public Instance makeOutputInstance(Instance inputI,
                                             boolean batch)
                                      throws java.lang.Exception

      Process and input instance and return an output instance
      Parameters:
        `inputI` - the incoming instance
        `batch` - whether this is being processed as part of a batch of instances
      Returns:
        the output instance
      Throws:
        `java.lang.Exception` - if the output structure has not yet been determined