Pages: [1]
  Print  
Author Topic: Iterate ExampleSet and extract WordList (Java API)  (Read 627 times)
totihue
Newbie
*
Posts: 2


« on: May 04, 2014, 05:50:19 PM »

Hi,

Use the java platform and took a while trying to go a IOContainer as FAQs should I do it this way:

FAQ >> http://rapid-i.com/rapidforum/index.php/topic,5807.0.html

Code:
IOContainer ioResult = myProcess.run(ioInput);
if (ioResult.getElementAt(0) instanceof ExampleSet) {
    ExampleSet resultSet = (ExampleSet)ioResult.getElementAt(0);
}

But it does not work, I think it may be the version of RapidMiner, I using version 5.3.013, but I've also tested with version 5.2.008 and 5.1.017. Which version of RapidMiner is the previous block of code? (Currently I using version 5.2.008)

On the other hand, if I extract the code into a IOObject [3], in the first position meeting the performance vector, in the second meeting a model (MultiModelByRegression) and in the third I find a WordList, the description of that object says com.rapidminer.operator.text.WordList but I can not create that kind of object, on which version of RapidMiner find the WordList object? (This is the code):

Code:
            IOContainer ioContainer = process.run();
            IOObject[] ioObject = new IOObject[3];
            ioObject[0] = ioContainer.getElementAt(0); //the created model
            ioObject[1] = ioContainer.getElementAt(1); //the performance vector created by a self test
            ioObject[2] = ioContainer.getElementAt(2); //the WordList
           
            MultiModelByRegression multiModel = (MultiModelByRegression) ioObject[0];
            PerformanceVector performance = (PerformanceVector) ioObject[1];
            Object exampleSetWordList =  ioObject[2]; //Here I extract the object information

Please Help me!
Thanks!!
« Last Edit: August 15, 2014, 09:48:01 PM by totihue » Logged
Marco Boeck
Administrator
Hero Member
*****
Posts: 905


WWW
« Reply #1 on: May 05, 2014, 09:24:14 AM »

Hi,

the code is from 5.3.x, however it should work with slightly older and any newer versions as well. Can't say what might be wrong without an actual error message though.
WordList is a class from the Text Processing extension.See here for sources.

Regards,
Marco
Logged

totihue
Newbie
*
Posts: 2


« Reply #2 on: August 15, 2014, 10:07:40 PM »

This is the error:

This

java.lang.ClassCastException: com.rapidminer.operator.learner.meta.MultiModelByRegression cannot be cast to com.rapidminer.example.ExampleSet

The problem is the "if" block:

Code:
if (ioResult.getElementAt(0) instanceof ExampleSet) {
    ExampleSet resultSet = (ExampleSet)ioResult.getElementAt(0);
}

This instanceof is not running ok, this happens because there (on port "0") is not an exampleset, port 0 is a MultiModelByRegression, only on port 2 exists something similar to exampleset, there is a wordList, then it can not interpret the object. I've tried changing ioResult.getElementAt(0) by ioResult.getElementAt(2), but also not, I need to rescue the word, its frequency in the text and the predicted label.

Could you tell me the conditions for the method you mention in the FAQs section, run ok? (Java version, RapidMiner version, some other library)

I really need help with this!!

Thank you!!!
« Last Edit: August 15, 2014, 11:54:15 PM by totihue » Logged
Marco Boeck
Administrator
Hero Member
*****
Posts: 905


WWW
« Reply #3 on: August 18, 2014, 07:44:41 AM »

Hi,

let's clarify a couple of things:

1) The result of a RapidMiner Studio process is an IOContainer. This container can contain any number of results (including none at all). This depends on the number of connections to the process output ports. Essentially, you get the same number of results in the IOContainer as the number of connected process result ports (the ones on the top right corner of a process in RapidMiner Studio GUI). Caveat: If one or more of the lines results in a null result, it is omitted from the result IOContainer by default. Iterate over all results of a process like so:
Code:
IOContainer container = process.run();
for (int i = 0; i < container.size(); i++) {
IOObject ioObject = container.getElementAt(i);
// do something
}

2) All results contained in an IOContainer implement the interface "IOObject". You can detect what they really are by simply checking for expected results or calling ioObject.getClass() to find out. The most common result would be an ExampleSet (wich is the main data class of RapidMiner Studio). However you can also get a Model or a FileObject or many, many others (see the implementations of the IOObject interface by selecting it in Eclipse and pressing Ctrl+T).

3) Extensions can define their own IOObject implementations. This is what you are faced with, because the Text Extension adds things like com.rapidminer.operator.text.Document or com.rapidminer.operator.text.WorldList to the mix. To use them programatically, you need to have the text extension sources available in your IDE. See my previous reply for a link. Once you have these sources available, you can work with the results and use them like you would for RapidMiner core IOObjects.

Regards,
Marco
« Last Edit: August 18, 2014, 10:12:00 AM by Marco Boeck » Logged

Pages: [1]
  Print  
 
Jump to: