configure

The configure method has two responsibilities:

  1. check incoming data table specs and validate settings against them, if necessary, and
  2. based on the incoming data table specs create the resulting output specs

User settings may influence the structure of the outgoing data tables. Construct the data table specs according to the current values. If required values are missing, throw an InvalidSettingsException with a user message. In this method you also check the user settings against the incoming DataTableSpec (for example, if the entered column name exists in the input table). Here is also a good place to set default values for user settings (if possible). For example, if you expect the user to select a column with nominal values, and the incoming table has only one column that fits this criteria, you could just set the name of that column in the corresponding member variable. If a ColumnRearranger is used, typically a private method is used to create it. Then the configure method would look like:

Example #1:

	protected DataTableSpec[] configure(final DataTableSpec[] inSpecs)
        throws InvalidSettingsException {
    ColumnRearranger c = createColumnRearranger(inSpecs[INPORT]);
    return new DataTableSpec[]{c.createSpec()};
}

The example below demonstrates how a default value for a nominal column is found if no settings are available:

Example #2:

	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[]{};
}