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
"Code error: Could not call com.rapidminer.example.SimpleAttributes.readResolve()"
Hi Everyone,
I have written a java code for text classification in netbeans. When I run the code, I get following error.
Can someone please help me. I have to submit the code and would really appreciate quick help.
The code is given below.
Thanks in advance
I have written a java code for text classification in netbeans. When I run the code, I get following error.
I have added all the libraries (including rapidminer.jar and text plugin) to project. I can verify that the model file exists. Surprisingly, when I save the output from the process using process.getRootOperator().getXML(true) (Given in the code below), and run the output .rmp file, it runs smoothly in rapidminer IDE, and gives out the classification result.
2011-03-15 02:34:55 INFO: Process starts (Process.run())
Could not read file 'C:/oneill_scripts/models/Medical_NonMedical.mod': java.io.IOException: Cannot read from XML stream, wrong format: Could not call com.rapidminer.example.SimpleAttributes.readResolve() : Duplicate attribute name: ?
---- Debugging information ----
message : Could not call com.rapidminer.example.SimpleAttributes.readResolve() : Duplicate attribute name: ?
cause-exception : com.thoughtworks.xstream.converters.reflection.ObjectAccessException
cause-message : Could not call com.rapidminer.example.SimpleAttributes.readResolve() : Duplicate attribute name: ?
class : com.rapidminer.operator.learner.functions.kernel.JMySVMModel
required-type : com.rapidminer.example.SimpleAttributes
line number : 642097
-------------------------------.
Can someone please help me. I have to submit the code and would really appreciate quick help.
The code is given below.
Thanks in advance
public String classifyText(String modelPath, String category) {
String result = "";
try {
// Create a process
final Process process = new Process();
// all operators from "left to right"
Operator readModel = OperatorService.createOperator(ModelLoader.class);
readModel.setParameter("model_file", modelPath);
Operator applyModel = OperatorService.createOperator(ModelApplier.class);
Operator document = OperatorService.createOperator(SingleDocumentInputOperator.class);
System.out.println(document.getOutputPorts().toString());
document.setParameter("text", this.TextString);
Operator document2data = OperatorService.createOperator(Document2ExampleSet.class);
document2data.setParameter("text_attribute", "text");
// add operators to the main process and connect them
process.getRootOperator().getSubprocess(0).addOperator(readModel);
process.getRootOperator().getSubprocess(0).addOperator(document);
process.getRootOperator().getSubprocess(0).addOperator(document2data);
process.getRootOperator().getSubprocess(0).addOperator(applyModel);
document.getOutputPorts().getPortByName("output").connectTo(
document2data.getInputPorts().getPortByIndex(0));//.getPortByName("documents 1"));
//connect(document, "output", document2data, "documents 1");
connect(document2data, "example set", applyModel, "unlabelled data");
connect(readModel, "output", applyModel, "model");
// print process setup
System.out.println(process.getRootOperator().createProcessTree(0));
//System.out.println(process.getRootOperator().getXML(true));
this.processAndWriteResults(process.getRootOperator().getXML(true));
String a = applyModel.getOutputPorts().getPortByIndex(0).toString();
System.out.println(a);
// perform process
process.run();
ExampleSet obj = applyModel.getOutputPorts().getPortByIndex(0).getData();
//obj.write(new FileOutputStream("/home/naurang/Desktop/output-text.txt"));
//obj.write(System.out);
ExampleTable et = obj.getExampleTable();
DataRowReader drr = et.getDataRowReader();
System.out.println(obj.getAttributes().toString());
Attribute aid = obj.getAttributes().get("prediction(label)");
Attribute pred = obj.getAttributes().get("prediction");
while (drr.hasNext()) {
DataRow rw = (DataRow) drr.next();
System.out.println(rw.get(aid) + " " + rw.get(pred));
result = Double.toString(rw.get(obj.getAttributes().get("prediction(label)")));
}
DataRowReader dr = obj.getExampleTable().getDataRowReader();
while (dr.hasNext()) {
System.out.println(obj.getAttributes().get("prediction(label)").getValue(dr.next()));
}
System.out.println(obj.getAttributes().get("prediction(label)").toString());
System.out.println(applyModel.getParameter("labelled_data"));
} catch (Exception ex) {
System.err.println(ex.getMessage());
}
return result;
}
Tagged:
0
Answers
well, I hope you aren't surprised nobody answered your post. Here in a forum for RapidNet...
Actually I doubt it is still a relevant question to you, so I save the effort of posting an answer.
Greetings,
Sebastian