Categories

Versions

You are viewing the RapidMiner Developers documentation for version 9.8 - Check here for latest version

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 and 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 ExampleSetMetaData() ));
}

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", new ExampleSetMetaData());

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 ExampleSetPrecondition( tableInput, new String[]{"test"}, 
        Ontology.ATTRIBUTE_VALUE) );

The ExampleSetPrecondition can also check whether the regular columns are of a certain type, which special columns have to be contained, and of which type they must be. 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.