auto-guessing node settings

Hi,

as auto-guessing of settings is prefered if possible, I wanted to implement that for one node (within the configure() method). Just to make sure: I need to update the model settings after that step, no?

I tried to look it up in one of the KNIME nodes. But I did not find the right node doing auto-guessing.

I looked at 'Naive Bayes Learner' and the 'Value Counter' but both nodes are not executable without opening+closing the configuration dialog...

Do you have any better example?

There is an example here showing how to do this:

https://tech.knime.org/configure-0

Steve

Hmm, I not really happy with that code. The answer to my question might be somewhere in the remaining code of the node model?

	protected DataTableSpec[] configure(
        throws InvalidSettingsException {
    // check spec with selected column
    DataColumnSpec columnSpec =
            inSpecs[DATA_INPORT].getColumnSpec(m_classifyColumn);
    if (columnSpec == null
            || !columnSpec.getType().isCompatible(NominalValue.class)) {
        // if no useful column is selected guess one
        // get the first useful one starting at the end of the table
        for (int i = inSpecs[DATA_INPORT].getNumColumns() - 1; i >= 0; i--) {
            if (inSpecs[DATA_INPORT].getColumnSpec(i).getType()
                    .isCompatible(NominalValue.class)) {
                m_classifyColumn =
                        inSpecs[DATA_INPORT].getColumnSpec(i).getName();
            break;
        }
        throw new InvalidSettingsException("Table contains no nominal"
                + " attribute for classification.");
        }
    }

    return new DataTableSpec[]{};
}

So, the variable m_classifyColumn is a String and member of the node model as far as I can see. That might work if I directly execute the node after configuration. But if I open the dialog and did not put that string into a setting model before, the dialog component might not reflect that auto-guess as selection in the 'column chooser'.

So where is the corresponding settings model updated?

I'm still struggling with my implementation. I had a look at the DecisionTreeLearner Node, which does auto-guessing but it also uses DefaultDialogComponents (which I do not use).

In my developer training manual (which is from 2011), I thought NodeModel#saveSettingsTo is called before the dialog opens but it does not seem to be the case? Would I have to call that explicitly to save the settings? Or how does settings guessed by the configure-method reach the dialog? After opening the dialog (after configure did its autoguessing) NodeDialog#loadSettingsFrom still reflects the 'old' settings.

I'm a bit confused at this point. Which is the missing link?

Hi,

in our nodes, we always update the settings models for the column after a column was guessed (this step is obviously missing in the above example). Then the value is available and selected in the dialog, as expected.

As the guessing logic gets pretty repetitive, I've moved some common functionality to a helper class (which I can share, if you are interested). But I feel it would be great, if the KNIME framework would provide some more existing functionality for the guessing.

we always update the settings models

Do you mean, that you set the value for the settings model, no? That's what I did, but obviously it is not transfered to the dialog.

Do you work with DialogComponents?

Yes, I am interested in your helper class. As I need to polish our nodes, I might need to implement the autoguessing for other nodes too.

Do you mean, that you set the value for the settings model, no? That's what I did, but obviously it is not transfered to the dialog.

Exactly.

Do you work with DialogComponents?

Yes.

Yes, I am interested in your helper class. As I need to polish our nodes, I might need to implement the autoguessing for other nodes too.

Guess it would be the easiest way if I give you access to our Git repository, then I can give you a pointer to a working example. Can you contact me via mail: mail@palladian.ws?