Hello everybody,
Does anyone knows how can I save the output generated by my code. This is the sample of very simple process, I'm trying to learn how to write RM process from the scratch without use of GUI.From the sample it can be seen that I connected the result to a result file using GUI options, so the output is being saved in a Result.md file.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<process version="5.1.006">
<context>
<input>
<location>//NewLocalRepository/Project/Golf</location>
</input>
<output>
<location>result</location>
</output>
<macros/>
</context>
<operator activated="true" class="process" compatibility="5.1.006" expanded="true" name="Process">
<process expanded="true" height="440" width="625">
<operator activated="true" class="retrieve" compatibility="5.1.006" expanded="true" height="60" name="Retrieve" width="90" x="64" y="183">
<parameter key="repository_entry" value="Golf"/>
</operator>
<operator activated="true" class="naive_bayes" compatibility="5.1.006" expanded="true" height="76" name="Naive Bayes" width="90" x="249" y="164"/>
<connect from_op="Retrieve" from_port="output" to_op="Naive Bayes" to_port="training set"/>
<connect from_op="Naive Bayes" from_port="model" to_port="result 1"/>
<portSpacing port="source_input 1" spacing="0"/>
<portSpacing port="sink_result 1" spacing="0"/>
<portSpacing port="sink_result 2" spacing="0"/>
</process>
</operator>
</process>
And now this is the code I wrote for this process (actually I found some snippets in this forum and used them for my process):
import com.rapidminer.Process;
import com.rapidminer.RapidMiner;
import com.rapidminer.RapidMiner.ExecutionMode;
import com.rapidminer.operator.Operator;
import com.rapidminer.operator.io.RepositorySource;
import com.rapidminer.operator.learner.bayes.NaiveBayes;
import com.rapidminer.operator.ports.InputPort;
import com.rapidminer.operator.ports.InputPorts;
import com.rapidminer.operator.ports.OutputPort;
import com.rapidminer.repository.RepositoryLocation;
import com.rapidminer.tools.OperatorService;
public class Test {
private static Operator createRetrievalOperator(Process parentProcess)
throws Exception {
RepositoryLocation location = new RepositoryLocation(
"//NewLocalRepository/Project/Golf");
String loc = parentProcess.makeRelativeRepositoryLocation(location);
// create input operator
Operator retrieve = OperatorService
.createOperator(RepositorySource.class);
/*
* Set the parameter of the operator to the location of the repository
* entry
*/
retrieve.setParameter("repository_entry", loc);
return retrieve;
}
/**
* Connect the output-port <code>fromPortName</code> from Operator
* <code>from</code> with the input-port <code>toPortName</code> of Operator
* <code>to</code>.
*/
private static void connect(Operator from, String fromPortName,
Operator to, String toPortName) {
from.getOutputPorts().getPortByName(fromPortName).connectTo(
to.getInputPorts().getPortByName(toPortName));
}
/**
* Connect the output-port <code>fromPortName</code> from Subprocess
* <code>from</code> with the input-port <code>toPortName</code> of Operator
* <code>to</code>.
*/
public static void main (String[] argv) throws Exception {
// init rapidminer
RapidMiner.setExecutionMode(ExecutionMode.COMMAND_LINE);
RapidMiner.init();
// Create a process
final Process process = new Process();
// all operators from "left to right"
final Operator retrieve = createRetrievalOperator(process);
final NaiveBayes naivebayes=OperatorService.createOperator(NaiveBayes.class);
// add operators to the main process and connect them
process.getRootOperator().getSubprocess(0).addOperator(retrieve);
process.getRootOperator().getSubprocess(0).addOperator(naivebayes);
connect(retrieve, "output", naivebayes, "training set");
// print process setup
System.out.println(process.getRootOperator().createProcessTree(0));
// perform process
process.run();
}
}
And the question is should I connect the "training set" port to "result 1" port like it in XML file, if yes how can I do it? (It's very stupid question but I'm learning at least ;D)And how can I save the output of this process to somewhere so I can use or read the data from that file?
Thanks in advance.
best regards, Fire