The Altair Community is migrating to a new platform to provide a better experience for you. In preparation for the migration, the Altair Community is on read-only mode from October 28 - November 6, 2024. Technical support via cases will continue to work as is. For any urgent requests from Students/Faculty members, please submit the form linked here
"Select Attributes" operator parameters modifications
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.
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.
Thanks
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();
}
}
0
Contributor I
Answers
rmProcess.getOperator( "Select Attributes" ).setParameter("attributes", "Att1|Att2|Att3|Att4");I simply used "Attributes" instead of "attributes"...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