org.knime.base.node.mine.decisiontree2
Class PMMLPredicate

java.lang.Object
  extended by org.knime.base.node.mine.decisiontree2.PMMLPredicate
Direct Known Subclasses:
PMMLCompoundPredicate, PMMLFalsePredicate, PMMLSimplePredicate, PMMLSimpleSetPredicate, PMMLTruePredicate

public abstract class PMMLPredicate
extends Object

Base class for Predicate as specified in PMML (http://www.dmg.org/v4-0/TreeModel.html).

Author:
Dominik Morent, KNIME.com, Zurich, Switzerland

Nested Class Summary
(package private) static class PMMLPredicate.PMMLPredicates
          Enumeration of all subclasses of PMMLPredicate.
 
Field Summary
protected static String ATTRIBUTE_KEY
          The key to store the attribute in configurations.
protected static String CDATA
          Constant for CDATA.
protected static NumberFormat NUMBERFORMAT
          For formatting the predicates toString output.
protected static String OPERATOR_KEY
          The key to store the operator in configurations.
protected static String TYPE_KEY
          The key to store the predicate type in configurations.
 
Constructor Summary
PMMLPredicate()
           
 
Method Summary
protected  void cacheSpec(DataTableSpec spec)
          Store the spec and index position to speedup subsequent evaluations.
abstract  Boolean evaluate(DataRow row, DataTableSpec spec)
          Evaluates the predicate for the passed parameters and returns the result.
abstract  String getName()
          Returns the name of the predicate.
 PMMLOperator getOperator()
           
static PMMLPredicate getPredicateForConfig(Config conf)
          Returns the correct PMMLPredicate for a config object.
static PMMLPredicate getPredicateForType(String type)
          Returns the correct PMMLPredicate for its string representation.
protected  int getPreviousIndex()
           
protected  DataTableSpec getPreviousSpec()
           
protected  String getSplitAttribute()
          Returns the name of the field the predicate operates on, an empty String if it works on multiple attributes, or null if not applicable.
abstract  void loadFromPredParams(Config conf)
          Load internal predicate settings from a config object.
abstract  void saveToPredParams(Config conf)
          Save internal predicate settings to a config object.
 void setOperator(PMMLOperator op)
           
 void setOperator(String op)
           
protected  void setPreviousIndex(int previousIndex)
           
protected  void setPreviousSpec(DataTableSpec previousSpec)
           
 void setSplitAttribute(String splitAttribute)
           
abstract  String toString()
          
abstract  void writePMML(TransformerHandler handler)
          Writes the PMML XML object for the predicate.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NUMBERFORMAT

protected static NumberFormat NUMBERFORMAT
For formatting the predicates toString output.


TYPE_KEY

protected static final String TYPE_KEY
The key to store the predicate type in configurations.

See Also:
Constant Field Values

ATTRIBUTE_KEY

protected static final String ATTRIBUTE_KEY
The key to store the attribute in configurations.

See Also:
Constant Field Values

OPERATOR_KEY

protected static final String OPERATOR_KEY
The key to store the operator in configurations.

See Also:
Constant Field Values

CDATA

protected static final String CDATA
Constant for CDATA.

See Also:
Constant Field Values
Constructor Detail

PMMLPredicate

public PMMLPredicate()
Method Detail

getOperator

public PMMLOperator getOperator()
Returns:
the operator used for this predicate

setOperator

public void setOperator(String op)
Parameters:
op - the op to set

setOperator

public void setOperator(PMMLOperator op)
Parameters:
op - the op to set

getSplitAttribute

protected String getSplitAttribute()
Returns the name of the field the predicate operates on, an empty String if it works on multiple attributes, or null if not applicable.

Returns:
the name of the field the predicate operates on, "" if working on multiple attributes or null if not applicable

setSplitAttribute

public void setSplitAttribute(String splitAttribute)
Parameters:
splitAttribute - the splitAttribute to set

getPreviousSpec

protected DataTableSpec getPreviousSpec()
Returns:
the previousSpec

setPreviousSpec

protected void setPreviousSpec(DataTableSpec previousSpec)
Parameters:
previousSpec - the previousSpec to set

getPreviousIndex

protected int getPreviousIndex()
Returns:
the previousIndex

setPreviousIndex

protected void setPreviousIndex(int previousIndex)
Parameters:
previousIndex - the previousIndex to set

evaluate

public abstract Boolean evaluate(DataRow row,
                                 DataTableSpec spec)
Evaluates the predicate for the passed parameters and returns the result. If values are missing and an evaluation is not possible null is returned.

Parameters:
row - The data row containing the data cells to be evaluated.
spec - The spec for the row.
Returns:
true if the the predicates evaluates to true, false if it evaluates to false, null on missing values

cacheSpec

protected void cacheSpec(DataTableSpec spec)
Store the spec and index position to speedup subsequent evaluations.

Parameters:
spec - the spec to be stored

toString

public abstract String toString()

Overrides:
toString in class Object

getName

public abstract String getName()
Returns the name of the predicate.

Returns:
the name of the predicate

writePMML

public abstract void writePMML(TransformerHandler handler)
                        throws SAXException
Writes the PMML XML object for the predicate.

Parameters:
handler - TransformerHandler for parsing and transforming events
Throws:
SAXException - - any SAX exception, possibly wrapping another exception

saveToPredParams

public abstract void saveToPredParams(Config conf)
Save internal predicate settings to a config object.

Parameters:
conf - the config object to write into

loadFromPredParams

public abstract void loadFromPredParams(Config conf)
                                 throws InvalidSettingsException
Load internal predicate settings from a config object.

Parameters:
conf - the config object to load from
Throws:
InvalidSettingsException - - if invalid settings are provided

getPredicateForConfig

public static PMMLPredicate getPredicateForConfig(Config conf)
                                           throws InvalidSettingsException
Returns the correct PMMLPredicate for a config object. Based on the config it determines the correct PMMLPredicate type, creates a new predicate instance and initializes it with the settings from the configuration.

Parameters:
conf - the config to get a predicate for
Returns:
the initialized predicate
Throws:
InvalidSettingsException - - if no predicate can be instantiated with the provided settings

getPredicateForType

public static PMMLPredicate getPredicateForType(String type)
                                         throws InstantiationException,
                                                IllegalAccessException
Returns the correct PMMLPredicate for its string representation.

Parameters:
type - the string representation of the predicate
Returns:
the predicate
Throws:
InstantiationException - - if the instantiation fails for some reason
IllegalAccessException - - if the class or its nullary constructor is not accessible.


Copyright, 2003 - 2010. All rights reserved.
University of Konstanz, Germany.
Chair for Bioinformatics and Information Mining, Prof. Dr. Michael R. Berthold.
You may not modify, publish, transmit, transfer or sell, reproduce, create derivative works from, distribute, perform, display, or in any way exploit any of the content, in whole or in part, except as otherwise expressly permitted in writing by the copyright owner or as specified in the license file distributed with this product.