Integration of RapidMiner in Java application -
i have text classification process in rapidminer. reads test data specified excel ssheet , classification. have small java application running process. want make file input part in aplication, everytime able specify excel file application (not rapidminer). hints?
this code:
import com.rapidminer.rapidminer; import com.rapidminer.process; import com.rapidminer.example.attribute; import com.rapidminer.example.example; import com.rapidminer.example.exampleset; import com.rapidminer.operator.iocontainer; import com.rapidminer.operator.operator; import com.rapidminer.operator.operatorexception; import java.io.file; import java.io.ioexception; import java.util.iterator; import com.rapidminer.operator.io.excelexamplesource; import com.rapidminer.tools.xmlexception; public class classification { public static void main(string [] args) throws exception{ exampleset resultset1 = null; iocontainer ioinput = null; iocontainer ioresult; try { rapidminer.setexecutionmode(rapidminer.executionmode.command_line); rapidminer.init(); process pr = new process(new file("c:\\users\\mp-test\\desktop\\rapid_test\\wieder_model.rmp")); operator op = pr.getoperator("read excel"); op.setparameter(excelexamplesource.parameter_excel_file, "c:\\users\\mp-test\\desktop\\rapid_test\\haendlerratings_neu.xls"); ioresult = pr.run(ioinput); if (ioresult.getelementat(0) instanceof exampleset) { resultset1 = (exampleset)ioresult.getelementat(0); (example example : resultset1) { iterator<attribute> allatts = example.getattributes().allattributes(); while(allatts.hasnext()) { attribute = allatts.next(); if (a.isnumerical()) { double value = example.getvalue(a); system.out.println(value); } else { string value = example.getvalueasstring(a); system.out.println(value); } } } } } catch (ioexception | xmlexception | operatorexception e) { // todo auto-generated catch block e.printstacktrace(); } } }
this error:
apr 09, 2013 9:06:05 com.rapidminer.process run info: process c:\users\mp-test\desktop\rapid_test\wieder_model.rmp starts com.rapidminer.operator.usererror: value parameter 'excel_file' must specified! @ com.rapidminer.operator.nio.model.excelresultsetconfiguration.makedataresultset(excelresultsetconfiguration.java:316) @ com.rapidminer.operator.nio.model.abstractdataresultsetreader.createexampleset(abstractdataresultsetreader.java:127) @ com.rapidminer.operator.io.abstractexamplesource.read(abstractexamplesource.java:52) @ com.rapidminer.operator.io.abstractexamplesource.read(abstractexamplesource.java:1) @ com.rapidminer.operator.io.abstractreader.dowork(abstractreader.java:126) @ com.rapidminer.operator.operator.execute(operator.java:855) @ com.rapidminer.operator.execution.simpleunitexecutor.execute(simpleunitexecutor.java:51) @ com.rapidminer.operator.executionunit.execute(executionunit.java:711) @ com.rapidminer.operator.operatorchain.dowork(operatorchain.java:379) @ com.rapidminer.operator.operator.execute(operator.java:855) @ com.rapidminer.process.run(process.java:949) @ com.rapidminer.process.run(process.java:873) @ com.rapidminer.process.run(process.java:832) @ com.rapidminer.process.run(process.java:827) @ classification.main(classification.java:29)
best regards
armen
i see 2 ways that.
the first 1 change programatically xml definition of process. rapidminer processes specified xml file .rmp
extension. in file find definition of operator wish change. excerpt simple process specifiing read excel operator:
<operator activated="true" class="read_excel" compatibility="5.3.005" expanded="true" height="60" name="read excel" width="90" x="313" y="75"> <parameter key="excel_file" value="d:\file.xls"/> <!-- here file path --> <parameter key="sheet_number" value="1"/> <parameter key="imported_cell_range" value="a1"/> <parameter key="encoding" value="system"/> <parameter key="first_row_as_names" value="true"/> <list key="annotations"/> <parameter key="date_format" value=""/> <parameter key="time_zone" value="system"/> <parameter key="locale" value="english (united states)"/> <list key="data_set_meta_data_information"/> <parameter key="read_not_matching_values_as_missings" value="true"/> <parameter key="datamanagement" value="double_array"/> </operator>
i highlighted part path excel file is. can overwrite in application. careful not break xml file.
the other way modify operator after load process in java application. can reference operator process#getoperator(string name)
or process#getalloperators()
. guess should of 1 of these classes:
com.rapidminer.operator.io.excelexamplesource com.rapidminer.operator.nio.excelexamplesource
when find correct operator modify path operator#setparameter(string key, string value)
.
this code works me rapidminer 5.3: (the process read excel operator , write csv operator)
package sorapid; import com.rapidminer.process; import com.rapidminer.rapidminer; import com.rapidminer.operator.operator; import com.rapidminer.operator.operatorexception; import com.rapidminer.operator.io.excelexamplesource; import com.rapidminer.tools.xmlexception; import java.io.file; import java.io.ioexception; public class sorapid { public static void main(string[] args) { try { rapidminer.setexecutionmode(rapidminer.executionmode.command_line); rapidminer.init(); process process = new process(new file("c:\\users\\matlab\\.rapidminer5\\repositories\\local repository\\processes\\test.rmp")); operator op = process.getoperator("read excel"); op.setparameter(excelexamplesource.parameter_excel_file, "d:\\excel.xls"); process.run(); } catch (ioexception | xmlexception | operatorexception ex) { ex.printstacktrace(); } } }
Comments
Post a Comment