Categories

Versions

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

Adding Generation Rules to Output Ports

At this point, if you connect your operator with another operator that receives an ExampleSet object, it alerts that it hasn't receive the correct object. This is because your operator hasn't yet done transformation of the meta data. It makes use of the meta data to check the preconditions, but doesn't deliver it to the output port. You can change this by adding generation rules in the constructor:

public MyOwnOperator( OperatorDescription description ){

    super(description);
    exampleSetInput.addPrecondition(
        new ExampleSetPrecondition( exampleSetInput, new String[]{"test"}, 
            Ontology.ATTRIBUTE_VALUE ));

    getTransformer().addPassThroughRule(exampleSetInput, exampleSetOutput);
}

This rule simply passes the received meta data to the output port, which causes the warning to vanish. However, the meta data doesn't reflect the actual delivered data. Remember, you can add an attribute for that. This should be reflected in the meta data, which is why you must implement a special transformation rule. To do so, use an anonymous class so that it looks like this:

getTransformer().addRule(
    new ExampleSetPassThroughRule( exampleSetInput, exampleSetOutput, SetRelation.EQUAL){
        @Override
        public ExampleSetMetaData modifyExampleSet( 
            ExampleSetMetaData metaData ) throws UndefinedParameterError {
                return metaData;
        }
});

However, this only passes the received meta data to the output port, it doesn't account for changes to the meta data. By adding a hook, you can grab the meta data and change it so that it reflects the changes made on the data during operator execution. After adding the code, the method looks like this:

getTransformer().addRule(
    new ExampleSetPassThroughRule( exampleSetInput, exampleSetOutput, SetRelation.EQUAL){
        @Override
        public ExampleSetMetaData modifyExampleSet( 
            ExampleSetMetaData metaData ) throws UndefinedParameterError {
                metaData.addAttribute(
                    new AttributeMetaData("newAttribute", Ontology.REAL));
                return metaData;
        }
});

If you change the type and name of an attribute, you can also change the meta data like this:

AttributeMetaData testAMD = metaData.getAttributeByName("test");
if(testAMD!=null){
    testAMD.setType(Ontology.DATE_TIME);
    testAMD.setName( "date(" + testAMD.getName() + ")" );
    testAMD.setValueSetRelation(SetRelation.UNKNOWN);
}
return metaData;

You should change the meta data according to the changes of the data through your operator.

If you don't know the details of the outgoing data but you know the output port type, you can add a very simple generation rule that defines the type delivered at the output port.

getTransformer().addGenerationRule(exampleSetOutput, ExampleSet.class);

In the next step, you will learn how to use the PortExtender.