Adding Preconditions to Input Ports
As you saw after starting RapidMiner Studio, the operator works. However, it does not alert the user if nothing is connected or an object of wrong type is connected to the input port. To change this behavior and improve operator usability, you can add preconditions to the ports. These preconditions will register errors, if they are not fulfilled. Preconditions are registered at the time of operator construction. To do so, add a few code fragments to the constructor. For example, this precondition checks whether a compatible IOObject is delivered:
public MyOwnOperator( OperatorDescription description ){
super(description);
tableInput.addPrecondition(
new SimplePrecondition(tableInput, new TableMetaData()));
}
Since this is one of the most common cases, you can use a shortcut to achieve it. Specify the target meta data class when constructing the input port:
private InputPort tableInput =
getInputPorts().createPort("example set", IOTable.class);
There are many more special preconditions. Some test whether a table satisfies specific conditions, whether it contains a special column of a specific role, whether a column with a specific name is inserted, and others. For example, you could add a precondition that tests if the column test is part of the input table. The column can have any type.
tableInput.addPrecondition(
new ColumnSetPrecondition(tableInput, "test"));
If the user inserts the operator into a process without connecting an example set output port with the input port, an error is shown. If the user attaches an example set without the test column, a warning is shown.
The next step is to define generation rules for output ports.