简体   繁体   中英

Integration of Rapidminer with Java: Obtaining the output Example Set (Process Result)

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();
        }
    }
}

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");
     }
}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM