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


« 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:

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!!
Logged
Marco Boeck
Administrator
Hero Member
*****
Posts: 879


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

Join us in Boston for the RapidMiner World conference!

RapidMiner Studio 6 | RapidMiner Studio 6 Q&A
totihue
Newbie
*
Posts: 3


« Reply #2 on: May 05, 2014, 02:35:24 PM »

It work!!

So.. yes! I needed download the Text Processing extension API, this API contains WordList class, thereby solved my problem and I can forget the ExampleSet. The code looks like this:

Code:

            Process process = new Process(new File("/your_path/your_file.rmp"));

            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); //WordList Result
           
            MultiModelByRegression multiModel = (MultiModelByRegression) ioObject[0];
            PerformanceVector performance = (PerformanceVector) ioObject[1];
            WordList wordList =  (WordList) ioObject[2];

            List<WordListEntry> wordListEntry = wordList.getEntries();
            for (WordListEntry wordListEntry1 : wordListEntry) {
               
                int documentFrequency = wordListEntry1.getDocumentFrequency();
                String word = wordListEntry1.getWord();
                float totalFrequency = wordListEntry1.getTotalFrequency();
               
                System.out.println("Word: "+word+"\n"+"Document-Frequency: "
                        +documentFrequency +"\n"+"Total-Frequency: "+totalFrequency);
               
            }


hopefully this will help others...
Thank you!!!!!!
Logged
totihue
Newbie
*
Posts: 3


« Reply #3 on: July 07, 2014, 02:09:19 AM »

Since I can only get the "word", "document frequency" and  "total frequency" from WordList, but not the "predicted label". Apparently the predicted label can only get from an ExampleSet, but I can not perform: IOContainer instanceof ExampleSet. Can someone tell me what am I doing wrong? this is my code:

Code:

            RapidMiner.setExecutionMode(RapidMiner.ExecutionMode.COMMAND_LINE);
            RapidMiner.init();

            Process myProcess = new Process(new File("/my_path/my_file.rmp"));
            IOContainer ioResult = myProcess.run();

            if (ioResult.getElementAt(0) instanceof ExampleSet) {
                ExampleSet resultSet = (ExampleSet)ioResult.getElementAt(0);
                Attributes attributes = resultSet.getAttributes();
                for (Attribute attribute : attributes) {
                }
            }


I tried with the following versions: rapidminer 5.3.013, rapidminer 5.2.008, rapidminer 5.1.017, rapidminer 5.0.010. With no I found it.

Can help me? any ideas?
Regards
« Last Edit: July 07, 2014, 03:10:11 AM by totihue » Logged
Pages: [1]
  Print  
 
Jump to: