NodeModel

Introduction

We start off by explaining a very simple binner. The bins are equally spaced, such that the whole range of a certain attribute is divided into n intervals. The data points with an attribute value within the k-th interval are considered to belong to the k-th bin. Therefore, the output is the original table with the binning information appended for each instance, i.e. row. The node also requires a dialog, as the user should be able to determine the number of bins and also specify the column on which the values should be binned.

Preparations

Before we start to implement the actual binning algorithm in the execute method, we have to define the fields we need in the NodeModel. (After creation the NodeModel already contains exemplary code which can be deleted). A convienent way to exchange the settings from the NodeModel to the NodeDialog is provided by the SettingsModel. As you will see later on, the NodeDialog also works with the SettingsModel, which is why we use them for the number of bins and the column on which the values should be binned:

Define the SettingsModels:

        // the settings model for the number of bins 
	private final SettingsModelIntegerBounded m_numberOfBins =
		new SettingsModelIntegerBounded(
                    NumericBinnerNodeModel.CFGKEY_NR_OF_BINS,
                    NumericBinnerNodeModel.DEFAULT_NR_OF_BINS,
                    1, Integer.MAX_VALUE);
	// the settings model storing the column to bin
	private final SettingsModelString m_column = new SettingsModelString(
            NumericBinnerNodeModel.CFGKEY_COLUMN_NAME, "");
In order to obtain the settings from the dialog, they must be written into a NodeSettings object. The NodeSettings transfer the settings from the dialog to the model and vice versa. A key is needed for each field to identify and retrieve it from the NodeSettings. It is good practice to define the static final string used as the key in the NodeModel.

Config Keys for the SettingsModels:

    /** The config key for the number of bins. */ 
    public static final String CFGKEY_NR_OF_BINS = "numberOfbins"; 
    /** The config key for the selected column. */
    public static final String CFGKEY_COLUMN_NAME = "columnName";
LinkedInTwitterShare

What are you looking for?