The same script is used for either testing or cleaning data. A script used for testing returns the boolean variable "aimReturnStatus" as either True or False depending on whether the data passed the test. The same script returns a string variable "aimReturnValue" containing the cleaned data. When applied as a testing script, Analyzer looks at "aimReturnStatus". When applied as a cleaning script, Analyzer looks at "aimReturnValue" and, if different, modifies the data value. "aimReturnValue" is returned with the original value ("aimValue") if no data modification is to take place. The modified value appears in the Data Browser highlighted in yellow with a pencil icon just as if it had been modified individually.
aimValue - the current value being tested aimArrayValue - array of all values in the current cell aim_<attrName> - the value of each attribute in the dataset aimArray_<attrName> - array of values for each attribute aimReturnStatus - boolean variable. Set to true if value passed test, false if failed. aimReturnValue - the new data value. Return with original value to leave unmodified.
aimReturnStatus = true;
aimReturnValue = aimValue;
if (aimValue != null)
{
lower = aimValue.toLowerCase();
if ( !aimValue.equals(lower) )
{
aimReturnStatus = false;
aimReturnValue = lower;
}
}
When applied as a test script, the following script flags strings
longer than 16 characters as failed. When applied as a cleaning script,
it truncates the string and replaces the last 3 characters with "...".
limit = 16;
aimReturnStatus = true;
aimReturnValue = aimValue;
if (aimValue != null)
{
len = aimValue.length;
if ( len > limit)
{
aimReturnStatus = false;
aimReturnValue = aimValue.substring(0,limit-3) + "...";
}
}
To see what values the cleaning script modifies, you can simply apply it with the "Apply Metric to column" option in the right-click menu. To clean the data, you can apply it as a cleaning script with the "Apply Cleaner Script to column" option.
aimReturnStatus = true;
aimReturnValue = aimValue;
if (aimValue == null)
{
aimReturnValue = "Some Default Value";
}
else
{ //...
}
Similarly, a script can delete a value by setting "aimReturnValue" to null. Scripts should always initialize "aimReturnValue" to "aimValue" so it does not appear to Analyzer as a null.