External Model import in KNIME

 

Good morning , I'm trying to import an external model KNIME . The model to be imported is generated by an external software KNIME and my goal is to import the node (thus indicate somehow the path where is the model) and write the model in another node. So I have to create a Learner node that take the model input and send it to a Predictor. I am attaching the code used , but the model is not imported it read . Forgive me if my English is wrong .

public class PROVA_MODELNodeModel extends NodeModel {

private FISModel m_model;

 protected PROVA_MODELNodeModel() {
    
        // TODO: Specify the amount of input and output ports needed.
        super(new PortType[] { BufferedDataTable.TYPE }, new PortType[] { PMMLPortObject.TYPE });
    
    }

 

  protected PortObject[] execute(final PortObject[] inData,
            final ExecutionContext exec) throws Exception {
        
    //    logger.info("Node Model Stub... this is not yet implemented !");

        return new PortObject[] {(PortObject) m_model};
        
    }

 

    @Override
    protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs)
            throws InvalidSettingsException {

            return new PortObjectSpec[] { null };
        }

 

        /**
         * Solo il metodo saveModelContent deve essere sovrascritto, poiché non vi è 
         * Solo ModelOutport.
         * 
         * @see De.unikn.knime.core.node.NodeModel # saveModelContent (int, 
         * De.unikn.knime.core.node.ModelContentWO)
         */
    protected void saveModelContent(final int index, 
            final ModelContentWO modelContent) throws InvalidSettingsException {
        m_model.saveTo(modelContent);
    }

---------------------------------------------------------------------------------------------------------------------------------------------------------------------

import org.knime.core.node.ModelContentWO;

public class FISModel {
    
    public void saveTo(final ModelContentWO modelContent)
    {
    
        modelContent.addModelContent("C:/Users/Antonio/Desktop/WM_PERF615/Learner/LearnerFis.txtwm.fis");
        
        
    }
    
    

}

 

 

 

I don't see any line that actually assign an object to m_model. Therefore it's always null. In addition m_model, which is a FISModel, is casted to PortObject but it clearly doesn't inherit from PortObject. So even if m_model wasn't null you would get a ClassCastException.

I suggest you have a look at some existing nodes that output PortObjects. There are plenty in the base distribution.

 

Sorry for the stupid question but that I assign object m_model ? I might have a link to some examples?

So the type of output port is FISModel.TYPE and FisModel class call :

public class extends FisModelPortObject AbstractSimplePortObject {
public static final PortType TYPE = new PortType ( FisModelPortObject.class ) ;