OutputPortExtender - How to add a precondition

radoneradone RapidMiner Certified Expert, Member Posts: 74  Guru
edited November 2018 in Help
I have input port extender defined as folows:
private OutputPortExtender innerOut1 = new OutputPortExtender(
"Example Set", getSubprocess(0).getInnerSources());
The code is generated from operator and therefore it is not possible to use any passthrough rule.

How can I add a Metadata precodndition to the innerOut1 port?

This approach failed:
innerOut1.deliverMetaData(getMetadata());
private List<MetaData> getMetadata() {
List<MetaData> metadata = new Vector<MetaData>();
metadata.add(new MetaData(ExampleSet.class));
return metadata;
}
Thanks in advance for any help.
Tagged:

Answers

  • fischerfischer Member Posts: 439  Guru
    Hi,

    output ports don't have preconditions. For InputPortExtenders, you either pass it a desiredMetaData in the constuctor if your precondition is as simple as requiring an IOObject of a certain type, or you override makePrecondition.

    The rules for the output ports are handeled just as those of any other port.

    Best,
    Simon
  • StaryVenaStaryVena Member Posts: 126  Maven
    Hi,
    I can't figure out, how to add generation rule for OutputPortExtender.
    Simon Fischer wrote:


    The rules for the output ports are handeled just as those of any other port.

    This is defined only for OutputPort.
    getTransformer().addGenerationRule(port, IOObject.class);
    How can I do same thing for OutputPortExtender?

    Thanks for your answers.
  • StaryVenaStaryVena Member Posts: 126  Maven
    I made small work around by modifying OneToManyPassThroughRule class:

    public class ManyGenerationRule implements MDTransformationRule {

    private final Collection<OutputPort> outputPorts;
    MetaData metaData;

    public ManyGenerationRule(OutputPorts outputPorts, MetaData metaData) {
    this(outputPorts.getAllPorts(), metaData);
    }

    public ManyGenerationRule(Collection<OutputPort> outputPorts, MetaData metaData) {
    this.outputPorts = outputPorts;
    this.metaData = metaData;
    }

    @Override
    public void transformMD() {
    int i = 0;
    for (OutputPort outputPort : outputPorts) {
    if (metaData != null) {
    metaData = metaData.clone();
    metaData.addToHistory(outputPort);
    outputPort.deliverMD(metaData);
    } else {
    outputPort.deliverMD(null);
    }
    i++;
    }
    }
    }
    But I'm not sure if it is good solution of this problem. Is there better way to solve it?
  • IngoRMIngoRM Administrator, Moderator, Employee, RapidMiner Certified Analyst, RapidMiner Certified Expert, Community Manager, RMResearcher, Member, University Professor Posts: 1,643  RM Founder
    Hi,

    Simon is out of office right now but I am sure he will come back to you later.

    Cheers,
    Ingo
  • fischerfischer Member Posts: 439  Guru
    Hi StaryVena,

    I think your solution is perfect. To be honest, I don't know why we don't have a ready-made class like the one you posted, but I also can't think of an operator that would use it - why would an operator produce several identical objects? May I ask what your application is, maybe I can make a better proposal then.

    Best,
    Simon
  • StaryVenaStaryVena Member Posts: 126  Maven
    Simon Fischer wrote:

    ..., but I also can't think of an operator that would use it - why would an operator produce several identical objects? May I ask what your application is, maybe I can make a better proposal then.
    It is inner output port of OperatorChain. Segmented image comes to outer input port  and to inner operators is sent only one segment per one subprocess run. Segmented image and one segment have different IOObject class. It could be used Multiply operator and single output port, but almost always will be used several inner operators. Thats why I prefer output port extender instead of single port.

    Thank you for your answer.
    Ciao
    StaryVena
  • fischerfischer Member Posts: 439  Guru
    Hi,

    then I think your solution is fine.

    Best,
    Simon
Sign In or Register to comment.