Package 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 Description static classSubstringLabelerRules.SubstringLabelerMatchRuleInner class encapsulating the logic for matching
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringMATCH_RULE_SEPARATORSeparator for match rules in the internal representation
-
Constructor Summary
Constructors Constructor Description SubstringLabelerRules(java.lang.String matchDetails, java.lang.String newAttName, boolean consumeNonMatching, boolean nominalBinary, Instances inputStructure, java.lang.String statusMessagePrefix, Logger log, Environment env)ConstructorSubstringLabelerRules(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 Description booleangetConsumeNonMatching()Get whether to consume non matching instances.InstancesgetInputStructure()Get the input structurejava.lang.StringgetNewAttributeName()Get the name to use for the new attribute that is addedbooleangetNominalBinary()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.InstancesgetOutputStructure()Get the output structureInstancemakeOutputInstance(Instance inputI, boolean batch)Process and input instance and return an output instancestatic 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 specificationvoidsetConsumeNonMatching(boolean n)Set whether to consume non matching instances.voidsetEnvironment(Environment env)Set environment variables to use.voidsetNewAttributeName(java.lang.String newName)Set the name to use for the new attribute that is addedvoidsetNominalBinary(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.
-
-
-
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.ExceptionConstructor- Parameters:
matchDetails- the internally encoded match details stringnewAttName- the name of the new attribute that will be the labelconsumeNonMatching- true if non-matching instances should be consumednominalBinary- true if, in the case where no user labels have been supplied, the new attribute should be a nominal binary one rather than numericinputStructure- the incoming instances structurestatusMessagePrefix- an optional status message prefix string for logginglog- 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.ExceptionConstructor. 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 labelinputStructure- 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:EnvironmentHandlerSet environment variables to use.- Specified by:
setEnvironmentin interfaceEnvironmentHandler- 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 rulesinputStructure- the input instances structurestatusMessagePrefix- an optional status message prefix for logginglog- the log to useenv- 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 instancebatch- 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
-
-