"Select Attributes" operator parameters modifications

Aurelien
Aurelien New Altair Community Member
edited November 5 in Community Q&A
Dear All,

I want to modify the value of a parameter from my Java code. It seems I am missing something obvious because the modification is not applied.
In my case I want to modify the value of the "Attributes" parameter of the "Select Attributes" operator.

What is the good way for modifying the value of a parameter?

Thanks in advance for your help,
regards,

Aurelien.

import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.Iterator;

import com.rapidminer.RapidMiner;
import com.rapidminer.example.Attribute;
import com.rapidminer.example.Attributes;
import com.rapidminer.example.Example;
import com.rapidminer.example.ExampleReader;
import com.rapidminer.example.ExampleSet;
import com.rapidminer.operator.IOContainer;
import com.rapidminer.operator.Operator;
import com.rapidminer.operator.OperatorCreationException;
import com.rapidminer.operator.Value;
import com.rapidminer.operator.ValueDouble;
import com.rapidminer.operator.learner.igss.Result;
import com.rapidminer.tools.OperatorService;
import com.rapidminer.tools.XMLException;
import com.rapidminer.Process;

public class DescriptorModification {

// Change the subset of attributes for an existing process
public DescriptorModification(){
Process rmProcess;

RapidMiner.init();

try {
// Load an existing process
// The process contains a "Select Attributes" operator wichich select the subset "Att1|Att2"
rmProcess = new Process( new File( "MyProcess.rmp") );

// Change the subset of Attributes
Operator selectAttributesOperator = rmProcess.getOperator( "Select Attributes" );
selectAttributesOperator.setParameter("Attributes", "Att1|Att2|Att3|Att4");

// Check if the "Select Attributes" operator parameters were changed
// Yes, the display is: "Att1|Att2|Att3|Att4"
selectAttributesOperator= rmProcess.getOperator( "Select Attributes" );
System.out.println( selectAttributesOperator.getParameter("Attributes") );

// Check if the XML corresponding to the process is changed
// No, it is still the former attributes: "Att1|Att2"
System.out.print( rmProcess );


} catch (Exception e) {
e.printStackTrace();
}

}

public static void main(String[] args) {

DescriptorModification garm = new DescriptorModification();

}

}
Thanks
Tagged:

Answers

  • Aurelien
    Aurelien New Altair Community Member
    Ok it was a stupid question, the good way to modify a parameter for an operator is:
    rmProcess.getOperator( "Select Attributes" ).setParameter("attributes", "Att1|Att2|Att3|Att4");
    I simply used "Attributes" instead of "attributes"...
  • land
    land New Altair Community Member
    Hi,
    let me add, that it's the recommended way of using the parameter name constants that every operator declares. These public and static constants are mostly called <class of operator>.PARAMETER_<PARAMETER_NAME> . If we change the names, we will change this constants and your code will still work.

    Greetings,
      Sebastian