import/export PMML model

this is my first post here, so thanks in advance for your help.

I need to import/export a PMML model for my plugins developing. I have a node with two outputs and one of them is a PMML outport. I’ve created the class PMMLMyNodePortObject as extension of PMMLPortObject class and, through the overriding of the method writePMMLModel(…), I’ve realized MyPMML structure successfully visible as output, but now I’ve two problems:

  1. although I can see MyPMML structure as output after the node execution, an error occurs on developing console: “Could not save model”. How can I save the model and fix this problem?

  2. (maybe related to first one) How can I read the previous PMML structure in a new node through a PMML inport?

Follow the code of writePMMLModel(…) method:

protected void writePMMLModel(final TransformerHandler handler) throws SAXException {
    AttributesImpl atts = new AttributesImpl();
    handler.startElement(null, null, “WScorer”, null);
    String scName = m_ConfusionMatrix.getName();
    Integer nrHypo = m_ConfusionMatrix.getNrHypo();
    atts.addAttribute(null, null, “name”, CDATA, scName);
    atts.addAttribute(null, null, “nrHypo”, CDATA, nrHypo.toString());
    handler.startElement(null, null, “classifier”, atts);
    handler.endElement(null, null, “classifier”);
    handler.endElement(null, null, “WScorer”);

Thanks again and sorry for my bad english.

Best regards,

Wow! That’s cool. Nice to hear that you implement PMML support for your model.
Which PMML model do you implement?

Regarding your question:
So far, you managed to write your model with the writePMMLModel method (that’s why you can see it in the ouport view, since it is written to an JTree).
Now you also have to take care of reading your model. Hence you have to implement an PMMLContentHandler - which is actually an XML ContentHandler - and restore your model as a Java object from the XML.

Once you are done with that you have to override the loadFrom method in your PMMLPortObject, register your handler call the super implementation and retrieve the parsed values from your handler:

/** {@inheritDoc} */
    public void loadFrom(final PMMLPortObjectSpec spec, 
            final InputStream in, final String version) 
        throws ParserConfigurationException, SAXException, IOException {
        MyPMMLHandler hdl = new MyPMMLHandler();
        super.addPMMLContentHandler("myModel", hdl);
        super.loadFrom(spec, in, version);
	hdl = (PMMLClusterHandler)super.getPMMLContentHandler(
	int nrHypo = hdl.getNrHypo();

Please also refer to the PMML specification if you have any questions about the PMML standard.

And if you want the PMML Reader node to support your model (i.e. instantiate your PMMLPortObject implementation if it discovers your model in the incoming PMML file) you have to extend the extension point org.knime.base.pmmlports, where you have to link to your PMMLPortObject class. In this way you can read in PMML models of different PMML producers.

Let us know if you have any further questions.

Thanks a lot for your helpful answer. I’ve implemented all the methods requested. Although it works fine, an error still occurs during its execution: “PMMLErrorHandler - Error during validation of PMML port object”.
It should be an error due a wrong parsing of PMML code, but until now I haven’t find the solution yet.