org.knime.core.node.port.pmml
Class PMMLPortObject

java.lang.Object
  extended by org.knime.core.node.port.pmml.PMMLPortObject
All Implemented Interfaces:
PortObject

public final class PMMLPortObject
extends Object
implements PortObject

Author:
Fabian Dill, University of Konstanz, Dominik Morent, KNIME.com AG, Zurich, Switzerland

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.knime.core.node.port.PortObject
PortObject.PortObjectSerializer<T extends PortObject>
 
Field Summary
static String CDATA
          Constant for CDATA.
static String DATA_DICT
          Constant for DataDictionary.
static String DATA_FIELD
          Constant for DataField.
static String EXTENSION_ELEMENT
          Constant for Extension element.
static Integer[] KNIME_V_2_3_3
          Version array for KNIME v.2.3.3.
static Integer[] KNIME_V_2_4
          Version array for KNIME v.2.4.
protected static String LOCAL_TRANS
          Constant for the LocalTransformations tag.
static String PMML_ELEMENT
          Constant for PMML Element.
static String PMML_V3_0
          Constant for version 3.0.
static String PMML_V3_1
          Constant for version 3.1.
static String PMML_V3_2
          Constant for version 3.2.
static String PMML_V4_0
          Constant for version 4.0.
static PortType TYPE
          Convenience accessor for the port type.
protected static String VALUE
          Constant for Value.
 
Constructor Summary
PMMLPortObject()
          Default constructor necessary for loading.
PMMLPortObject(PMMLPortObjectSpec spec)
          Creates a new PMML port object.
PMMLPortObject(PMMLPortObjectSpec spec, PMMLContentHandler handler)
          Deprecated. 
PMMLPortObject(PMMLPortObjectSpec spec, org.dmg.pmml40.PMMLDocument pmmlDoc)
          Creates a new PMML port object baed on the spec and the PMML document after it has been validated.
PMMLPortObject(PMMLPortObjectSpec spec, PMMLPortObject port)
          Creates a new PMML port based on the PMMLPortObjectSpec and the PMMLPortObject.
PMMLPortObject(PMMLPortObjectSpec spec, PMMLPortObject port, DataTableSpec inData)
          Creates a new PMML port based on the PMMLPortObjectSpec and the PMMLPortObject.
 
Method Summary
 void addGlobalTransformations(org.dmg.pmml40.TransformationDictionaryDocument.TransformationDictionary dictionary)
          Adds global transformations to the PMML document.
 void addModelTranslater(PMMLTranslator modelTranslator)
          Adds the model of the content translater to the PMML document.
 void addPMMLModelFromHandler(PMMLContentHandler handler)
          Deprecated. 
 org.dmg.pmml40.DerivedFieldDocument.DerivedField[] getDerivedFields()
           
 PMMLValue getPMMLValue()
          Returns the PMML value.
static PortObject.PortObjectSerializer<PMMLPortObject> getPortObjectSerializer()
          Static serializer as demanded from PortObject framework.
 PMMLPortObjectSpec getSpec()
          Get specification to this port object.
 String getSummary()
          Get a short summary of this PortObject.
 JComponent[] getViews()
          The returned views are displayed in the out port view of the referring node.
 void initializeModelTranslator(PMMLTranslator translator)
           
static boolean isKnimeProducedAndOlderThanVersion(org.dmg.pmml40.PMMLDocument.PMML pmml, Integer[] version)
           
 void loadFrom(PMMLPortObjectSpec spec, InputStream is)
          Initializes the pmml port object based on the xml input stream.
 void loadFrom(PMMLPortObjectSpec spec, InputStream in, String version)
          Deprecated. 
 void moveGlobalTransformationsToModel()
          Moves the content of the transformation dictionary to local transformations of the model if a model exists.
 void save(OutputStream out)
          Writes the port object to valid PMML.
 void validate()
          Validates that this PMMLPortObject contains a valid PMML document.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TYPE

public static final PortType TYPE
Convenience accessor for the port type.


CDATA

public static final String CDATA
Constant for CDATA.

See Also:
Constant Field Values

DATA_DICT

public static final String DATA_DICT
Constant for DataDictionary.

See Also:
Constant Field Values

DATA_FIELD

public static final String DATA_FIELD
Constant for DataField.

See Also:
Constant Field Values

PMML_ELEMENT

public static final String PMML_ELEMENT
Constant for PMML Element.

See Also:
Constant Field Values

EXTENSION_ELEMENT

public static final String EXTENSION_ELEMENT
Constant for Extension element.

See Also:
Constant Field Values

VALUE

protected static final String VALUE
Constant for Value.

See Also:
Constant Field Values

LOCAL_TRANS

protected static final String LOCAL_TRANS
Constant for the LocalTransformations tag.

See Also:
Constant Field Values

KNIME_V_2_3_3

public static final Integer[] KNIME_V_2_3_3
Version array for KNIME v.2.3.3.


KNIME_V_2_4

public static final Integer[] KNIME_V_2_4
Version array for KNIME v.2.4.


PMML_V3_0

public static final String PMML_V3_0
Constant for version 3.0.

See Also:
Constant Field Values

PMML_V3_1

public static final String PMML_V3_1
Constant for version 3.1.

See Also:
Constant Field Values

PMML_V3_2

public static final String PMML_V3_2
Constant for version 3.2.

See Also:
Constant Field Values

PMML_V4_0

public static final String PMML_V4_0
Constant for version 4.0.

See Also:
Constant Field Values
Constructor Detail

PMMLPortObject

PMMLPortObject()
Default constructor necessary for loading. Derived classes also must provide a default constructor, otherwise loading will fail. Calling this constructor is discouraged. It is only available for internal calls.


PMMLPortObject

public PMMLPortObject(PMMLPortObjectSpec spec)
Creates a new PMML port object. Models can be added later by calling addModelTranslater(PMMLTranslator).

Parameters:
spec - the referring PMMLPortObjectSpec

PMMLPortObject

public PMMLPortObject(PMMLPortObjectSpec spec,
                      org.dmg.pmml40.PMMLDocument pmmlDoc)
Creates a new PMML port object baed on the spec and the PMML document after it has been validated.

Parameters:
spec - the PMMLPortObjectSpec
pmmlDoc - a PMML document

PMMLPortObject

public PMMLPortObject(PMMLPortObjectSpec spec,
                      PMMLPortObject port)
Creates a new PMML port based on the PMMLPortObjectSpec and the PMMLPortObject. If port is null it has the same effect as calling PMMLPortObject(PMMLPortObjectSpec).

Parameters:
spec - the referring PMMLPortObjectSpec
port - the existing PMML port
See Also:
PMMLPortObject(PMMLPortObjectSpec)

PMMLPortObject

public PMMLPortObject(PMMLPortObjectSpec spec,
                      PMMLPortObject port,
                      DataTableSpec inData)
Creates a new PMML port based on the PMMLPortObjectSpec and the PMMLPortObject. If port is null the inData is used for initialization, otherwise inData is ignored.

Parameters:
spec - the referring PMMLPortObjectSpec
port - the existing PMML port
inData - the incoming data table spec
See Also:
PMMLPortObject(PMMLPortObjectSpec)

PMMLPortObject

@Deprecated
public PMMLPortObject(PMMLPortObjectSpec spec,
                                 PMMLContentHandler handler)
Deprecated. 

Parameters:
spec - the port object spec
handler - the pmml content handler that adds the model content
Method Detail

getPortObjectSerializer

public static final PortObject.PortObjectSerializer<PMMLPortObject> getPortObjectSerializer()
Static serializer as demanded from PortObject framework.

Returns:
serializer for PMML (reads and writes PMML files)

addPMMLModelFromHandler

@Deprecated
public void addPMMLModelFromHandler(PMMLContentHandler handler)
                             throws SAXException
Deprecated. 

Appends the pmml model of the content handler by invoking its PMMLContentHandler.addPMMLModel(DocumentFragment, PMMLPortObjectSpec) method. Only PMMLModelType elements can be added.

Parameters:
model - the model fragment to add
Throws:
SAXException - if the pmml model could not be added

save

public final void save(OutputStream out)
                throws IOException
Writes the port object to valid PMML.

Parameters:
out - stream which reads the PMML file
Throws:
IOException - if the file cannot be written to the stream

initializeModelTranslator

public void initializeModelTranslator(PMMLTranslator translator)
Parameters:
translator - the model translator to be initialized

addModelTranslater

public void addModelTranslater(PMMLTranslator modelTranslator)
Adds the model of the content translater to the PMML document.

Parameters:
modelTranslator - the model translator containing the model to be added

moveGlobalTransformationsToModel

public void moveGlobalTransformationsToModel()
Moves the content of the transformation dictionary to local transformations of the model if a model exists.


getSummary

public String getSummary()
Get a short summary of this PortObject. The return value will be shown in a node port's tooltip, for instance.

Specified by:
getSummary in interface PortObject
Returns:
Summary of the object's content, suitable for a tooltip. Empty strings and null result values are ok (though not encouraged).

loadFrom

@Deprecated
public void loadFrom(PMMLPortObjectSpec spec,
                                InputStream in,
                                String version)
              throws IOException,
                     ParserConfigurationException,
                     SAXException
Deprecated. 

This method should no longer be used. The version parameter is ignored. Use loadFrom(PMMLPortObjectSpec, InputStream) instead.

Parameters:
spec - the referring spec of this object
in - the input stream to write to
version - the version (3.0 - 3.2)
Throws:
SAXException - if something goes wrong during writing
ParserConfigurationException - if the parser cannot be instantiated
IOException - if the file cannot be found

loadFrom

public void loadFrom(PMMLPortObjectSpec spec,
                     InputStream is)
              throws IOException,
                     org.apache.xmlbeans.XmlException
Initializes the pmml port object based on the xml input stream.

Parameters:
spec - the referring spec of this object
is - the pmml input stream
Throws:
IOException - if the file cannot be found
org.apache.xmlbeans.XmlException - if something goes wrong during reading

getSpec

public PMMLPortObjectSpec getSpec()
Get specification to this port object. That is, the corresponding PortObjectSpec which is used to configure any successor node after execution, e.g. a BufferedDataTable can return a DataTableSpec.

Subclasses should narrow the return type if possible.

Specified by:
getSpec in interface PortObject
Returns:
underlying PortObjectSpec or any derived spec, never null.

getViews

public JComponent[] getViews()
The returned views are displayed in the out port view of the referring node. Each component is displayed in an extra tab. The name of the component is used as the title for the tab. It is important that no external members are kept in the component so it can be deleted, when the port object is deleted. If the port object has no view return an empty array.

Specified by:
getViews in interface PortObject
Returns:
an array of views for the port object, each displayed as a tab in the out port view

addGlobalTransformations

public void addGlobalTransformations(org.dmg.pmml40.TransformationDictionaryDocument.TransformationDictionary dictionary)
Adds global transformations to the PMML document. Only DerivedField elements are supported so far. If no global transformations are set so far the dictionary is set as new transformation dictionary, otherwise all contained transformations are appended to the existing one.

Parameters:
dictionary - the transformation dictionary that contains the transformations to be added

getDerivedFields

public org.dmg.pmml40.DerivedFieldDocument.DerivedField[] getDerivedFields()
Returns:
the derived fields defined in the transformation dictionary and local transformations or an empty array if no derived fields are defined.

getPMMLValue

public PMMLValue getPMMLValue()
Returns the PMML value.

Returns:
the pmml value

validate

public void validate()
              throws IllegalStateException
Validates that this PMMLPortObject contains a valid PMML document.

Throws:
IllegalStateException - if this PMMLPortObject does not contain a valid PMML document

isKnimeProducedAndOlderThanVersion

public static boolean isKnimeProducedAndOlderThanVersion(org.dmg.pmml40.PMMLDocument.PMML pmml,
                                                         Integer[] version)
Parameters:
pmml - the PMML document
version - the KNIME version to check
Returns:
true, if the passed PMML document was produced with KNIME in a version older than the passed version.


Copyright, 2003 - 2012. 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.