public class FunctionExpander extends BaseAttributeExpander implements Citable
To define a function used to generate new attributes, simply write out a expression with the variables surrounded by #{}'s (e.g., (#{x} + #{y}/#{x})). This expander will substitute the all possible combinations of attributes for each of those variables. If you would like to generate all permutations of attributes in a specific formula, write out all possible orders of variables into that formula (ex: both #{x}/#{y} and #{y}/#{x})
Variables names that start with "r:" can be used to allow only certain attributes. These variables are expected to be of the format "r:[name],[regex]" where [name] is a unique name and [regex] is the regular expression used to decide whether a variable will be used to decide whether an attribute will be used in the function. This classes uses the Matcher.find() to test whether an attribute name contains a substring matching the regular expression. For example, "r:x,*" would match all attributes and "r:x,^a.*z$" would match only attributes that start with a and end with z. The formula "#{r:x,*}*#{r:y,^time$}" would multiple all attributes with the attribute named "time". Note, this will generate all permutations of attributes for each variable.
Examples
Functions should follow the syntax outlined in the Javadoc
ParsedFunction
,
Serialized FormConstructor and Description |
---|
FunctionExpander() |
Modifier and Type | Method and Description |
---|---|
void |
addNewFunction(java.lang.String function)
Add a new function to be used for expansion
|
void |
clearFunctionList()
Clear list of functions used to generate new attributes.
|
void |
expand(Dataset Data)
Generate new attributes based on the attributes already in Dataset
|
protected java.util.List<int[]> |
generateCombinations(java.lang.String[] attributeNames,
ParsedFunction function)
Compute all acceptable combinations of attributes for a
|
java.util.List<org.apache.commons.lang3.tuple.Pair<java.lang.String,Citation>> |
getCitations()
Return a list of citations for this object and any underlying objects.
|
java.lang.String |
printUsage()
Print out required format for options.
|
void |
setOptions(java.util.List<java.lang.Object> Options)
Set any options for this object.
|
public void setOptions(java.util.List<java.lang.Object> Options) throws java.lang.Exception
Options
setOptions
in interface Options
Options
- Array of options as Objects - can be null
java.lang.Exception
- if problem with inputspublic java.lang.String printUsage()
Options
printUsage
in interface Options
public void clearFunctionList()
public void addNewFunction(java.lang.String function) throws java.lang.Exception
function
- Function to be parsedjava.lang.Exception
public void expand(Dataset Data)
BaseAttributeExpander
expand
in class BaseAttributeExpander
Data
- Dataset to be expandedprotected java.util.List<int[]> generateCombinations(java.lang.String[] attributeNames, ParsedFunction function)
attributeNames
- function
- public java.util.List<org.apache.commons.lang3.tuple.Pair<java.lang.String,Citation>> getCitations()
Citable
getCitations
in interface Citable