The Altair Community is migrating to a new platform to provide a better experience for you. In preparation for the migration, the Altair Community is on read-only mode from October 28 - November 6, 2024. Technical support via cases will continue to work as is. For any urgent requests from Students/Faculty members, please submit the form linked here
Using IOO object in java
jaya_darne
Member Posts: 8 Contributor I
I have written a process in RM and and running it using a JAVA progarm. Please find code attached.
package com.tcs.RM;
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.IOObject;
import com.rapidminer.operator.Operator;
import com.rapidminer.operator.OperatorException;
import com.rapidminer.operator.nio.ExcelExampleSource;
import com.rapidminer.tools.XMLException;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Iterator;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
public class Demo {
public static void main(String [] args) throws Exception{
ExampleSet resultSet1 = null;
IOObject result = null;
IOContainer ioResult;
Logger logger = Logger.getLogger(Demo.class);
PrintWriter writer = new PrintWriter("L2_test_result.txt", "UTF-8");
String log4jConfigFile = System.getProperty("user.dir")
+ File.separator + "log4j.properties";
PropertyConfigurator.configure(log4jConfigFile);
logger.info("This is my first log4j's statement");
try {
RapidMiner.setExecutionMode(RapidMiner.ExecutionMode.COMMAND_LINE);
RapidMiner.init();
Process pr = new Process(new File("C:\\Users\\1026445\\.RapidMiner\\repositories\\Local Repository\\processes\\L2_Test.rmp"));
System.out.println("================End=====================");
ioResult = pr.run();
System.out.println("Result Size"+ioResult.size());
result = ioResult.getElementAt(0);
System.out.println("RESULT"+'\t'+result);
if (ioResult.getElementAt(0) instanceof ExampleSet) {
System.out.println("=======================Getting example Set==========================");
ExampleSet resultSet = (ExampleSet)ioResult.getElementAt(0);
writer.println(result);
System.out.println(result);
int i=0;
for (Example example : resultSet) {
System.out.println("===================Getting attributes===============");
Iterator<Attribute> allAtts = example.getAttributes().allAttributes();
while(allAtts.hasNext()) {
Attribute a = allAtts.next();
if(i<=3)
writer.println(a.getName()+ " ");
//System.out.print(a.getName()+ " ");
i++;
}
}
/* if (ioResult.getElementAt(0) instanceof ExampleSet) {
resultSet1 = (ExampleSet)ioResult.getElementAt(0);
for (Example example : resultSet1) {
Iterator<Attribute> allAtts = example.getAttributes().allAttributes();
while(allAtts.hasNext()) {
System.out.println("===================Getting attributes===============");
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);
}
}
}
//Operator op = pr.getOperator("Read Excel");
//op.setParameter(ExcelExampleSource.PARAMETER_EXCEL_FILE, "C:\\Users\\MP-TEST\\Desktop\\Rapid_Test\\HaendlerRatings_neu.xls");
*/
}
}
catch (IOException e) {
// TODO Auto-generated catch block
/*StringWriter stack = new StringWriter();
e.printStackTrace(new PrintWriter(stack));
logger.debug("Caught exception; decorating with appropriate status template : " + stack.toString());*/
logger.error("Error description",e);
}
finally
{
writer.close();
}
}
}
<!-- My RM Process -->
<?xml version="1.0" encoding="UTF-8"?><process version="7.6.001">
<context>
<input/>
<output/>
<macros/>
</context>
<operator activated="true" class="process" compatibility="7.6.001" expanded="true" name="Process">
<parameter key="logverbosity" value="init"/>
<parameter key="logfile" value="C:\Users\1026445\.RapidMiner\repositories\Local Repository\logs\08_09_2017_logs.log"/>
<parameter key="resultfile" value="C:\Users\1026445\.RapidMiner\repositories\ResultSet\L2_test.res"/>
<parameter key="random_seed" value="2001"/>
<parameter key="send_mail" value="never"/>
<parameter key="notification_email" value=""/>
<parameter key="process_duration_for_mail" value="30"/>
<parameter key="encoding" value="SYSTEM"/>
<process expanded="true">
<operator activated="true" class="pdf_table_extraction:pdf2exampleset_operator" compatibility="0.1.004" expanded="true" height="68" name="Read PDF Table" width="90" x="45" y="34">
<parameter key="resource_type" value="file"/>
<parameter key="filename" value="C:\Users\1026445\Documents\Cisco_L2_CY14V101LA-BA45XI.pdf"/>
</operator>
<operator activated="true" class="loop_collection" compatibility="7.6.001" expanded="true" height="82" name="Loop Collection" width="90" x="179" y="34">
<parameter key="set_iteration_macro" value="false"/>
<parameter key="macro_name" value="iteration"/>
<parameter key="macro_start_value" value="1"/>
<parameter key="unfold" value="false"/>
<process expanded="true">
<operator activated="true" class="handle_exception" compatibility="7.6.001" expanded="true" height="82" name="Handle Exception" width="90" x="45" y="34">
<process expanded="true">
<operator activated="true" class="branch" compatibility="7.6.001" expanded="true" height="82" name="Branch (3)" width="90" x="45" y="34">
<parameter key="condition_type" value="attribute_available"/>
<parameter key="condition_value" value="Device Supplier Contact Name"/>
<parameter key="expression" value="if(contains([Stress Test],"Convection"),TRUE,FALSE)"/>
<parameter key="io_object" value="ANOVAMatrix"/>
<parameter key="return_inner_output" value="true"/>
<process expanded="true">
<connect from_port="condition" to_port="input 1"/>
<portSpacing port="source_condition" spacing="0"/>
<portSpacing port="source_input 1" spacing="0"/>
<portSpacing port="sink_input 1" spacing="0"/>
<portSpacing port="sink_input 2" spacing="0"/>
</process>
<process expanded="true">
<portSpacing port="source_condition" spacing="0"/>
<portSpacing port="source_input 1" spacing="0"/>
<portSpacing port="sink_input 1" spacing="0"/>
<portSpacing port="sink_input 2" spacing="0"/>
</process>
<description align="center" color="transparent" colored="false" width="126">Parameter exists</description>
</operator>
<connect from_port="in 1" to_op="Branch (3)" to_port="condition"/>
<connect from_op="Branch (3)" from_port="input 1" to_port="out 1"/>
<portSpacing port="source_in 1" spacing="0"/>
<portSpacing port="source_in 2" spacing="0"/>
<portSpacing port="sink_out 1" spacing="0"/>
<portSpacing port="sink_out 2" spacing="0"/>
</process>
<process expanded="true">
<connect from_port="in 1" to_port="out 1"/>
<portSpacing port="source_in 1" spacing="0"/>
<portSpacing port="source_in 2" spacing="0"/>
<portSpacing port="sink_out 1" spacing="0"/>
<portSpacing port="sink_out 2" spacing="0"/>
</process>
</operator>
<operator activated="true" class="handle_exception" compatibility="7.6.001" expanded="true" height="82" name="Handle Exception (3)" width="90" x="313" y="34">
<process expanded="true">
<operator activated="true" class="filter_examples" compatibility="7.6.001" expanded="true" height="103" name="Filter Examples" width="90" x="179" y="34">
<parameter key="parameter_expression" value=""/>
<parameter key="condition_class" value="custom_filters"/>
<parameter key="invert_filter" value="false"/>
<list key="filters_list">
<parameter key="filters_entry_key" value="Device Supplier Contact Name.contains.Body Size"/>
<parameter key="filters_entry_key" value="Device Supplier Contact Name.contains.Number of Solder Joints/Interconnects"/>
<parameter key="filters_entry_key" value="Device Supplier Contact Name.equals.Supplier"/>
<parameter key="filters_entry_key" value="Device Supplier Contact Name.contains.Cypress Marketing Part #"/>
<parameter key="filters_entry_key" value="Device Supplier Contact Name.contains.Package Manufacturer"/>
<parameter key="filters_entry_key" value="Device Supplier Contact Name.contains.Package Type"/>
<parameter key="filters_entry_key" value="Device Supplier Contact Name.contains.Die Size"/>
<parameter key="filters_entry_key" value="Device Supplier Contact Name.contains.Silicon Technology (Line Pitch)"/>
<parameter key="filters_entry_key" value="Device Supplier Contact Name.contains.2nd Level Interconnect Pitch"/>
</list>
<parameter key="filters_logic_and" value="false"/>
<parameter key="filters_check_metadata" value="true"/>
<description align="center" color="transparent" colored="false" width="126">Stress Test contains Convection and Temperature and High Temp</description>
</operator>
<connect from_port="in 1" to_op="Filter Examples" to_port="example set input"/>
<connect from_op="Filter Examples" from_port="example set output" to_port="out 1"/>
<portSpacing port="source_in 1" spacing="0"/>
<portSpacing port="source_in 2" spacing="0"/>
<portSpacing port="sink_out 1" spacing="0"/>
<portSpacing port="sink_out 2" spacing="0"/>
</process>
<process expanded="true">
<connect from_port="in 1" to_port="out 1"/>
<portSpacing port="source_in 1" spacing="0"/>
<portSpacing port="source_in 2" spacing="0"/>
<portSpacing port="sink_out 1" spacing="0"/>
<portSpacing port="sink_out 2" spacing="0"/>
</process>
</operator>
<operator activated="true" class="handle_exception" compatibility="7.6.001" expanded="true" height="82" name="Handle Exception (4)" width="90" x="447" y="34">
<process expanded="true">
<operator activated="true" class="branch" compatibility="7.6.001" expanded="true" height="82" name="Branch (5)" width="90" x="112" y="34">
<parameter key="condition_type" value="min_examples"/>
<parameter key="condition_value" value="1"/>
<parameter key="expression" value=""/>
<parameter key="io_object" value="ANOVAMatrix"/>
<parameter key="return_inner_output" value="true"/>
<process expanded="true">
<connect from_port="condition" to_port="input 1"/>
<portSpacing port="source_condition" spacing="0"/>
<portSpacing port="source_input 1" spacing="0"/>
<portSpacing port="sink_input 1" spacing="0"/>
<portSpacing port="sink_input 2" spacing="0"/>
</process>
<process expanded="true">
<portSpacing port="source_condition" spacing="0"/>
<portSpacing port="source_input 1" spacing="0"/>
<portSpacing port="sink_input 1" spacing="0"/>
<portSpacing port="sink_input 2" spacing="0"/>
</process>
<description align="center" color="transparent" colored="false" width="126">Number of Examples is &#8805;1</description>
</operator>
<connect from_port="in 1" to_op="Branch (5)" to_port="condition"/>
<connect from_op="Branch (5)" from_port="input 1" to_port="out 1"/>
<portSpacing port="source_in 1" spacing="0"/>
<portSpacing port="source_in 2" spacing="0"/>
<portSpacing port="sink_out 1" spacing="0"/>
<portSpacing port="sink_out 2" spacing="0"/>
</process>
<process expanded="true">
<connect from_port="in 1" to_port="out 1"/>
<portSpacing port="source_in 1" spacing="0"/>
<portSpacing port="source_in 2" spacing="0"/>
<portSpacing port="sink_out 1" spacing="0"/>
<portSpacing port="sink_out 2" spacing="0"/>
</process>
</operator>
<connect from_port="single" to_op="Handle Exception" to_port="in 1"/>
<connect from_op="Handle Exception" from_port="out 1" to_op="Handle Exception (3)" to_port="in 1"/>
<connect from_op="Handle Exception (3)" from_port="out 1" to_op="Handle Exception (4)" to_port="in 1"/>
<connect from_op="Handle Exception (4)" from_port="out 1" to_port="output 1"/>
<portSpacing port="source_single" spacing="0"/>
<portSpacing port="sink_output 1" spacing="0"/>
<portSpacing port="sink_output 2" spacing="0"/>
</process>
</operator>
<connect from_op="Read PDF Table" from_port="collection of pdf data tables as example sets" to_op="Loop Collection" to_port="collection"/>
<connect from_op="Loop Collection" from_port="output 1" to_port="result 1"/>
<portSpacing port="source_input 1" spacing="0"/>
<portSpacing port="sink_result 1" spacing="0"/>
<portSpacing port="sink_result 2" spacing="0"/>
</process>
</operator>
</process>
I want to be able to print only the result that is generated post process run. My process reads a PDF file and does table extraction based on certain conditions.In RM Studio it gives me a single table as output while in my java code the entire PDF file is getting printed.
Tagged:
0