import com.rapidminer.RapidMiner;import com.rapidminer.RapidMiner.ExecutionMode;import com.rapidminer.repository.IOObjectEntry;import com.rapidminer.repository.RepositoryLocation;import com.rapidminer.Process;import com.rapidminer.example.Attribute;import com.rapidminer.example.Attributes;import com.rapidminer.example.Example;import com.rapidminer.example.ExampleSet;import com.rapidminer.operator.IOContainer;import com.rapidminer.operator.IOObject;import java.io.File;import java.util.Iterator;public class Classification { static Example exampleSet = null; public static void main(String [] args) throws Exception{ ExampleSet resultSet1 = null; // this initializes RapidMiner with your repositories available // you have to call this for all your programs, otherwise your RapidMiner integration will not work correctly RapidMiner.setExecutionMode(ExecutionMode.COMMAND_LINE); RapidMiner.init(); String xml = "<?xml version='1.0' encoding='UTF-8' standalone='no'?>" + "<process version='5.3.007'>" + "<context>" + "<input/>" + "<output/>" + "<macros/>" + "</context>" + "<operator activated='true' class='process' compatibility='5.3.007' expanded='true' name='Process'>" + "<process expanded='true'>" + "<operator activated='true' class='read_excel' compatibility='5.3.007' expanded='true' height='60' name='Read Excel' width='90' x='45' y='165'>" + "<parameter key='excel_file' value='C:\\Users\\MP-TEST\\Desktop\\Rapid_Test\\Training Data - Wieder.xls'/>" + "<parameter key='imported_cell_range' value='A1:B276'/>" + "<parameter key='first_row_as_names' value='false'/>" + "<list key='annotations'/>" + "<list key='data_set_meta_data_information'>" + "<parameter key='0' value='Bewertung.true.text.attribute'/>" + "<parameter key='1' value='Label.true.binominal.label'/>" + "</list>" + "</operator>" + "<operator activated='true' class='text:process_document_from_data' compatibility='5.3.000' expanded='true' height='76' name='Process Documents from Data' width='90' x='45' y='30'>" + "<parameter key='prune_method' value='absolute'/>" + "<parameter key='prune_below_absolute' value='5'/>" + "<parameter key='prune_above_absolute' value='9999'/>" + "<parameter key='prune_above_rank' value='0.05'/>" + "<list key='specify_weights'/>" + "<process expanded='true'>" + "<operator activated='true' class='text:tokenize' compatibility='5.3.000' expanded='true' height='60' name='Tokenize' width='90' x='44' y='30'/>" + "<operator activated='true' class='text:transform_cases' compatibility='5.3.000' expanded='true' height='60' name='Transform Cases' width='90' x='179' y='30'/>" + "<operator activated='false' class='text:filter_stopwords_german' compatibility='5.3.000' expanded='true' height='60' name='Filter Stopwords (German)' width='90' x='179' y='210'/>" + "<operator activated='false' class='text:stem_german' compatibility='5.3.000' expanded='true' height='60' name='Stem (German)' width='90' x='313' y='255'/>" + "<operator activated='true' class='text:generate_n_grams_terms' compatibility='5.3.000' expanded='true' height='60' name='Generate n-Grams (Terms)' width='90' x='447' y='30'>" + "<parameter key='max_length' value='1'/>" + "</operator>" + "<connect from_port='document' to_op='Tokenize' to_port='document'/>" + "<connect from_op='Tokenize' from_port='document' to_op='Transform Cases' to_port='document'/>" + "<connect from_op='Transform Cases' from_port='document' to_op='Generate n-Grams (Terms)' to_port='document'/>" + "<connect from_op='Generate n-Grams (Terms)' from_port='document' to_port='document 1'/>" + "<portSpacing port='source_document' spacing='0'/>" + "<portSpacing port='sink_document 1' spacing='0'/>" + "<portSpacing port='sink_document 2' spacing='0'/>" + "</process>" + "</operator>" + "<operator activated='false' class='store' compatibility='5.3.007' expanded='true' height='60' name='Store Wordlist' width='90' x='179' y='120'>" + "<parameter key='repository_entry' value='Wordlist_Wieder'/>" + "</operator>" + "<operator activated='true' class='set_role' compatibility='5.3.007' expanded='true' height='76' name='Set Role' width='90' x='313' y='75'>" + "<parameter key='attribute_name' value='Label'/>" + "<parameter key='target_role' value='label'/>" + "<list key='set_additional_roles'/>" + "</operator>" + "<operator activated='true' class='x_validation' compatibility='5.3.007' expanded='true' height='112' name='Validation' width='90' x='447' y='75'>" + "<process expanded='true'>" + "<operator activated='true' class='support_vector_machine_libsvm' compatibility='5.3.007' expanded='true' height='76' name='SVM' width='90' x='133' y='30'>" + "<parameter key='gamma' value='0.9'/>" + "<parameter key='C' value='8.0'/>" + "<parameter key='epsilon' value='0.0010'/>" + "<list key='class_weights'/>" + "</operator>" + "<connect from_port='training' to_op='SVM' to_port='training set'/>" + "<connect from_op='SVM' from_port='model' to_port='model'/>" + "<portSpacing port='source_training' spacing='0'/>" + "<portSpacing port='sink_model' spacing='0'/>" + "<portSpacing port='sink_through 1' spacing='0'/>" + "</process>" + "<process expanded='true'>" + "<operator activated='true' class='apply_model' compatibility='5.3.007' expanded='true' height='76' name='Apply Model' width='90' x='24' y='30'>" + "<list key='application_parameters'/>" + "</operator>" + "<operator activated='true' class='performance' compatibility='5.3.007' expanded='true' height='76' name='Performance' width='90' x='179' y='30'/>" + "<connect from_port='model' to_op='Apply Model' to_port='model'/>" + "<connect from_port='test set' to_op='Apply Model' to_port='unlabelled data'/>" + "<connect from_op='Apply Model' from_port='labelled data' to_op='Performance' to_port='labelled data'/>" + "<connect from_op='Performance' from_port='performance' to_port='averagable 1'/>" + "<portSpacing port='source_model' spacing='0'/>" + "<portSpacing port='source_test set' spacing='0'/>" + "<portSpacing port='source_through 1' spacing='0'/>" + "<portSpacing port='sink_averagable 1' spacing='0'/>" + "<portSpacing port='sink_averagable 2' spacing='0'/>" + "</process>" + "</operator>" + "<operator activated='false' class='store' compatibility='5.3.007' expanded='true' height='60' name='Store Model' width='90' x='581' y='165'>" + "<parameter key='repository_entry' value='Stored_Model_Wieder'/>" + "</operator>" + "<operator activated='false' class='retrieve' compatibility='5.3.007' expanded='true' height='60' name='Retrieve Wordlist' width='90' x='45' y='480'>" + "<parameter key='repository_entry' value='Wordlist_Wieder'/>" + "</operator>" + "<operator activated='false' class='retrieve' compatibility='5.3.007' expanded='true' height='60' name='Retrieve' width='90' x='380' y='435'>" + "<parameter key='repository_entry' value='Stored_Model_Wieder'/>" + "</operator>" + "<operator activated='false' class='read_excel' compatibility='5.3.007' expanded='true' height='60' name='Read Excel (2)' width='90' x='45' y='570'>" + "<parameter key='excel_file' value='C:\\Users\\MP-TEST\\Desktop\\Rapid_Test\\HaendlerRatings_neu.xls'/>" + "<parameter key='imported_cell_range' value='A1:A2000'/>" + "<parameter key='first_row_as_names' value='false'/>" + "<list key='annotations'/>" + "<list key='data_set_meta_data_information'>" + "<parameter key='0' value='A.true.text.attribute'/>" + "</list>" + "</operator>" + "<operator activated='false' class='text:process_document_from_data' compatibility='5.3.000' expanded='true' height='76' name='Process Documents from Data (2)' width='90' x='313' y='525'>" + "<parameter key='prune_method' value='absolute'/>" + "<parameter key='prune_below_absolute' value='5'/>" + "<parameter key='prune_above_absolute' value='9999'/>" + "<parameter key='prune_above_rank' value='0.05'/>" + "<list key='specify_weights'/>" + "<process expanded='true'>" + "<operator activated='false' class='text:tokenize' compatibility='5.3.000' expanded='true' height='60' name='Tokenize (2)' width='90' x='45' y='30'/>" + "<operator activated='false' class='text:transform_cases' compatibility='5.3.000' expanded='true' height='60' name='Transform Cases (2)' width='90' x='180' y='30'/>" + "<operator activated='false' class='text:filter_stopwords_german' compatibility='5.3.000' expanded='true' height='60' name='Filter Stopwords (2)' width='90' x='246' y='210'/>" + "<operator activated='false' class='text:stem_german' compatibility='5.3.000' expanded='true' height='60' name='Stem (2)' width='90' x='179' y='255'/>" + "<operator activated='false' class='text:generate_n_grams_terms' compatibility='5.3.000' expanded='true' height='60' name='Generate n-Grams (2)' width='90' x='447' y='75'>" + "<parameter key='max_length' value='1'/>" + "</operator>" + "<connect from_port='document' to_op='Tokenize (2)' to_port='document'/>" + "<connect from_op='Tokenize (2)' from_port='document' to_op='Transform Cases (2)' to_port='document'/>" + "<connect from_op='Transform Cases (2)' from_port='document' to_op='Generate n-Grams (2)' to_port='document'/>" + "<connect from_op='Generate n-Grams (2)' from_port='document' to_port='document 1'/>" + "<portSpacing port='source_document' spacing='0'/>" + "<portSpacing port='sink_document 1' spacing='0'/>" + "<portSpacing port='sink_document 2' spacing='0'/>" + "</process>" + "</operator>" + "<operator activated='false' class='apply_model' compatibility='5.3.007' expanded='true' height='76' name='Apply Model (2)' width='90' x='581' y='525'>" + "<list key='application_parameters'/>" + "</operator>" + "<connect from_op='Read Excel' from_port='output' to_op='Process Documents from Data' to_port='example set'/>" + "<connect from_op='Process Documents from Data' from_port='example set' to_op='Set Role' to_port='example set input'/>" + "<connect from_op='Process Documents from Data' from_port='word list' to_op='Store Wordlist' to_port='input'/>" + "<connect from_op='Set Role' from_port='example set output' to_op='Validation' to_port='training'/>" + "<connect from_op='Validation' from_port='model' to_port='result 1'/>" + "<connect from_op='Validation' from_port='averagable 1' to_port='result 2'/>" + "<connect from_op='Retrieve Wordlist' from_port='output' to_op='Process Documents from Data (2)' to_port='word list'/>" + "<connect from_op='Retrieve' from_port='output' to_op='Apply Model (2)' to_port='model'/>" + "<connect from_op='Read Excel (2)' from_port='output' to_op='Process Documents from Data (2)' to_port='example set'/>" + "<connect from_op='Process Documents from Data (2)' from_port='example set' to_op='Apply Model (2)' to_port='unlabelled data'/>" + "<portSpacing port='source_input 1' spacing='0'/>" + "<portSpacing port='sink_result 1' spacing='234'/>" + "<portSpacing port='sink_result 2' spacing='0'/>" + "<portSpacing port='sink_result 3' spacing='0'/>" + "</process>" + "</operator>" + "</process>"; Process pr = new Process(xml); IOContainer ioInput = null; IOContainer ioResult = pr.run(ioInput); if (ioResult.getElementAt(0) instanceof ExampleSet) { resultSet1 = (ExampleSet)ioResult.getElementAt(0); System.out.println(resultSet1); } // note: resultSet must be instanceof ExampleSet for (Example example : resultSet1) { Iterator<Attribute> allAtts = exampleSet.getAttributes().allAttributes(); while(allAtts.hasNext()) { Attribute a = allAtts.next(); if (a.isNumerical()) { double value = example.getValue(a); System.out.println(value); } else { String value = example.getValueAsString(a); System.out.println(value); } } } }}
INFO: Process finished successfully after 0 sException in thread "main" java.lang.NullPointerException at Classification.main(Classification.java:177)
operator.setParameter(ExcelExampleSource.PARAMETER_EXCEL_FILE, "HaendlerRatings_neu.xls");
A value for the parameter 'excel_file' must be specified!
operator.setParameter(ExcelExampleSource.PARAMETER_EXCEL_FILE, "C:\\Users\\MP-TEST\\Desktop\\Rapid_Test\\HaendlerRatings_neu.xls"); operator.setParameter(ExcelExampleSource.PARAMETER_IMPORTED_CELL_RANGE, "A1:A2000"); operator.setParameter(ExcelExampleSource.PARAMETER_ID_COLUMN, "0"); operator.setParameter(ExcelExampleSource.PARAMETER_SHEET_NUMBER, "1"); operator.setParameter(ExcelExampleSource.PARAMETER_DATAMANAGEMENT, "double_array"); operator.setParameter(ExcelExampleSource.PARAMETER_TIME_ZONE, "SYSTEM");
// replace "Read Excel" with the name the Read Excel operator has in your processprocess.getOperator("Read Excel").setParameter(ExcelExampleSource.PARAMETER_EXCEL_FILE, "C:\\Users\\username\\Desktop\\2.xls");
Hi,
Unfortunately, the link is broken, and I could not open the page you referred to.
Thanks,
hi @Pirehelokan - this is an old thread. Which link are you referring to?
Scott