1

I want to execute a Rapidminer process from Java to use the output ExampleSet (Process Result) for subsequent operations (with Java).

I managed the process execution with the code below, but I don't have a clue how to obtain the process Result Example Set.

Ideally, I want to get any Example Set independent of the variables, but if you need to generate the metadata beforehand, will have to be.

package com.companyname.rm;

import com.rapidminer.Process;
import com.rapidminer.RapidMiner;
import com.rapidminer.operator.OperatorException;
import com.rapidminer.tools.XMLException;

import java.io.File;
import java.io.IOException;

public class RunProcess {
    public static void main(String[] args) {
        try {
            RapidMiner.setExecutionMode(RapidMiner.ExecutionMode.COMMAND_LINE);
            RapidMiner.init();

            Process process = new Process(new File("//my_path/..../test_JAVA.rmp"));
            process.run();

        } catch (IOException | XMLException | OperatorException ex) {
            ex.printStackTrace();
        }
    }
}
Mickäel A.
  • 9,012
  • 5
  • 54
  • 71
Gerardo A.
  • 13
  • 5

2 Answers2

1

To obtain the ExampleSet of the process you need add

IOContainer ioResult = process.run();

A shortened example taken from http://allinoneat.blogspot.de/2013/04/integrate-rapidminer-wtih-java.html

IOContainer ioResult = process.run();
if (ioResult.getElementAt(0) instanceof ExampleSet) {
    ExampleSet resultSet = (ExampleSet) ioResult.getElementAt(0);

    for (Example example : resultSet) {
        Iterator<Attribute> allAtts = example.getAttributes().allAttributes();
            while (allAtts.hasNext()) {
                Attribute a = allAtts.next();
                if (a.isNumerical()) {
                    double value = example.getValue(a);
                    System.out.print(value + " ");
                } else {
                    String value = example.getValueAsString(a);
                    System.out.print(value + " ");
                }
            }
            System.out.println("\n");
     }
}
Kristjan Liiva
  • 9,069
  • 3
  • 25
  • 26
0

Option 1: Click on context, and save process output to files. Then, read from files.

Option2:

Use the WriteAsText to save what you want. Then read from the file.

I just run the rapidminer as a script:

http://rapid-i.com/rapidforum/index.php?topic=3009.0

Eduardo Santana
  • 5,780
  • 3
  • 19
  • 21
  • Thanks for the answer. The solution covers all I want, but I need something more restrained, thinking about an externalized production process. – Gerardo A. Jun 18 '14 at 20:01