Error in nodemodel.java while implementing new node

Hello,

I am trying to generate my new node similar to the punctuation erasure node, i have copied the source code from the org.knime.base dependencies. What to write in configure() and execute() methods in nodemodel class?

My code for Pp.java (containing same code as PunctuationErasure.class) is:

package org.Pp;

import java.util.ArrayList;
import java.util.List;

import org.knime.ext.textprocessing.data.Term;
import org.knime.ext.textprocessing.data.Word;
import org.knime.ext.textprocessing.nodes.preprocessing.StringPreprocessing;
import org.knime.ext.textprocessing.nodes.preprocessing.TermPreprocessing;

public class Pp implements TermPreprocessing, StringPreprocessing {
    private static String punctMarks = "[!#$%&'\"()*+,./\\:;<=>?@^_`{|}~\\[\\]]+";
    private static String replacement = "";
    public Pp() { }
    @Override
    public Term preprocessTerm(Term term) {
        // TODO Auto-generated method stub
        List<Word> words = term.getWords();
        List<Word> newWords = new ArrayList<Word>();
        for (Word w : words) {
            newWords.add(new Word(punctuationFilter(w.getWord()), w.getWhitespaceSuffix()));
        }
        return new Term(newWords, term.getTags(), term.isUnmodifiable());
    }
     private String punctuationFilter(final String str) {
            return str.replaceAll(punctMarks, replacement);
        }
     @Override
        public String preprocessString(String str) {
            return punctuationFilter(str);
        }
}

 

Hi Jasleen,

if you are using the Textprocessing framework the NodeModel is easy to implement. I assume that you don't need an dialog, as well as view. All you need to implement in the NodeModel is the following:

public final class MyCustomPpNodeModel extends StreamableFunctionPreprocessingNodeModel {
    protected TermPreprocessing createPreprocessing() throws Exception {
        return new Pp();
    }

}

In the NodeFactory set dialog to true and create an instance of PreprocessingNodeSettingsPane2.

public final class MyCustomPpNodeFactory extends NodeFactory<MyCustomPpNodeModel> {

    public PunctuationErasureNodeModel2 createNodeModel() {
        return new MyCustomPpNodeModel();
    }

...

    protected boolean hasDialog() {
        return true;
    }

    protected NodeDialogPane createNodeDialogPane() {
        return new PreprocessingNodeSettingsPane2();
    }
}

The rest will be done by the framework. The node will be automatically streamable.

I hope this helps.

Cheers, Kilian