Send throw PMML port new XML content

Hi everybody, I have a situation, I have define a Node with an inputPort (that recive a conventional DataTable) and an outputModelPort. The point is that I have define a new XMLObject (whith a specific XML estructure) and I don't know how to send throw the outputPortModel. The next step will be to connect with the PMMLWriter Node to export it. Please I need help with this.
Rene

Hello Rene,

you need to create a PMMLPortObject. Using the constructor

PMMLPortObject(final PMMLPortObjectSpec spec,
            final PMMLDocument pmmlDoc)

you can initialize one and output it as a PortObject in your execute method.

Regards,

Alexander

Hi Alexander I take your advice, but when I try to return the PMMLPortObject, occurs an error related with the compatibility with the PMML version. 

Here is a fragment of the code:

 protected PortObject[] execute(PortObject[] data,
            final ExecutionContext exec) throws Exception {

        BufferedDataTable dataTable = (BufferedDataTable) data[0];
         ....
        //creating DataTableSpec
        DataTableSpec outputSpec = new DataTableSpec(allColSpecs);
        .... 
        BufferedDataContainer container = exec.createDataContainer(outputSpec);
        for (int i = 1; i <= dataTable.getRowCount(); i++) {
            RowKey key = new RowKey("Row " + i);
              ....
            }
            DataRow row = new DefaultRow(key, cells_1);
            container.addRowToTable(row);
            
            // check if the execution monitor was canceled
            exec.checkCanceled();
            exec.setProgress(i / (double)m_count.getIntValue(),
                "Adding row " + i);
        }
        container.close();
        BufferedDataTable outData = container.getTable();
        
        //PMML Section
        PMMLPortObjectSpec inPMMLSpec = null;
        PMMLPortObjectSpec pmmlOutSpec = createPMMLSpec(inPMMLSpec,
                  outData.getSpec());
        
        //Creating a PMMLDocument
        PMMLDocument pmmlDoc = null;
        
        //This method generate the new XML document that is save on disk (D:\file.xml)
        saveXML_PMML_Extension_JDOM(headers,states);
        
        //Parsing document
        FileInputStream Fst = new FileInputStream(new File("D:" + File.separator + "file.xml"));
        pmmlDoc = PMMLDocument.Factory.parse(Fst);
       
        //Creating PMML output object
        PMMLPortObject outPMMLPort = new PMMLPortObject(pmmlOutSpec, pmmlDoc);
    
        return new PortObject[] {outPMMLPort};
    }

 I dont know if this could be a good way, I appreciate any example to better this.

thank's for your time

Rene.

Hi,

I think saving the document on disk is not necessary. THe best way to go is to create an own PMMLTranslator by extending the class and then adding the necessary code in the exportTo(final PMMLDocument pmmlDoc, final PMMLPortObjectSpec spec) method. Then you create an instance of your translator and pass it to the PMMLPortObject using the method addModelTranslater(PMMLTranslator t).

Could you please also post the error you are getting here?

Regards,

Alexander

Hello Alexander, till now I just had throw across the PMMLObject port this section of the PMML:

<PMML version="4.0" xmlns="http://www.dmg.org/PMML-4_0">
    <Header copyright="None">
        <Application name="FuzzyPred System" version="1.0"/>
        <Annotation>Exported whith PMML format.</Annotation>
    </Header>
    <DataDictionary numberOfFields="4">
    <DataField name="cost.low" optype="continuous" dataType="double">
        <Interval closure="openOpen" leftMargin="0.0" rightMargin="1"/>
    </DataField>
    <DataField name="cost.medium" optype="continuous" dataType="double">
        <Interval closure="openOpen" leftMargin="0.0" rightMargin="1"/>
    </DataField><DataField name="cost.high" optype="continuous" dataType="double">
        <Interval closure="openOpen" leftMargin="0.0" rightMargin="1"/>
    </DataField>
    <DataField name="entity.REDSA" optype="continuous" dataType="double">
        <Interval closure="openOpen" leftMargin="0.0" rightMargin="1"/>
    </DataField>
    </DataDictionary>

</PMML>

... the problem is with the model. The error in the eclipse_knime console is:

ERROR  FuzzyPMMLWriteExtension Execute failed: The passed PMML document is not valid.
ERROR  KNIME-Worker-0 FuzzyPMMLWriteExtension Execute failed: The passed PMML document is not valid.

Using a new PMMLModelTranslator, I could include this section (the model):

    <Extension name="FuzzyPredicateModel" funtionName="fuzzyPredicate" algorithmName="HillClimbing">
        <MiningSchema>
            <MiningFiled name="cost.low"/>
            <MiningFiled name="cost.medium"/>
            <MiningFiled name="cost.high"/>
            <MiningFiled name="entity.REDSA"/>
        </MiningSchema>    
        <PredicateSet>
            <CompoundPredicate booleanOperator="and">
                <Extension evaluation="0.0"/>
                <SimplePredicate field="cost.low" operator="equal">
                    <Extension modificator="VERY"/>
                </SimplePredicate>
                <SimplePredicate field="cost.medium" operator="equal">
                    <Extension modificator="HYPER"/>
                </SimplePredicate>
                <SimplePredicate field="cost.high" operator="equal">
                    <Extension modificator="NONE"/>
                </SimplePredicate>
                <SimplePredicate field="entity.REDSA" operator="equal">
                    <Extension modificator="VERY"/>
                </SimplePredicate>
            </CompoundPredicate>
        </PredicateSet>
    </Extension>
</PMML>

Once again thank's for your time.

Rene.

Hi Rene,

Have you tried running your PMML document through a schema validator to make sure it conforms to it? It seems it is somehow invalid, but unfortunately I cannot see where that could be in the code you posted.

Regards,

Alexander

Hi Alexander, I really not tried to validate it using a shema validator, but after read a little is probably that not fit as valid cause I'm trying to generate a PMML document for a different kind of model (FuzzyPredicates) and I' not sure that exist a schema for this model.

Well one more time thank's for the help, 

Regards

Rene     

Hi,

since you wrap your custom model in an Extension element, this should be considered valid by a schema validator. I suspect that there is an error in another part of your PMML. Could that be?

Regards,

Alexander