RM integration to Java (Text Mining) - Repository Problem
shioshio
New Altair Community Member
I'm new to integrating RM to Java. I have a process that applies the model and word list I have stored using the Naive Bayes classification. I want to integrate that process to my Java application.
But I keep getting this problem with the repository:
I am following this http://rapid-i.com/rapidforum/index.php/topic,3862.msg14364.html#msg14364.
This is my code.
But I keep getting this problem with the repository:
Process run
INFO: Process starts
com.rapidminer.operator.UserError: Cannot resolve relative repository location 'Model'. Process is not associated with a repository.
at com.rapidminer.Process.resolveRepositoryLocation(Process.java:1210)
at com.rapidminer.operator.Operator.getParameterAsRepositoryLocation(Operator.java:1383)
at com.rapidminer.operator.io.RepositorySource.getRepositoryEntry(RepositorySource.java:91)
at com.rapidminer.operator.io.RepositorySource.read(RepositorySource.java:105)
at com.rapidminer.operator.io.AbstractReader.doWork(AbstractReader.java:123)
at com.rapidminer.operator.Operator.execute(Operator.java:834)
at com.rapidminer.operator.execution.SimpleUnitExecutor.execute(SimpleUnitExecutor.java:51)
at com.rapidminer.operator.ExecutionUnit.execute(ExecutionUnit.java:711)
at com.rapidminer.operator.OperatorChain.doWork(OperatorChain.java:379)
at com.rapidminer.operator.Operator.execute(Operator.java:834)
at com.rapidminer.Process.run(Process.java:925)
at com.rapidminer.Process.run(Process.java:848)
at com.rapidminer.Process.run(Process.java:807)
at com.rapidminer.Process.run(Process.java:802)
at com.rapidminer.Process.run(Process.java:792)
at RapidMinerPrototype.RMPrototype.btnClassifyActionPerformed(RMPrototype.java:286)
at RapidMinerPrototype.RMPrototype.access$000(RMPrototype.java:53)
at RapidMinerPrototype.RMPrototype$1.actionPerformed(RMPrototype.java:86)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6505)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:723)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:682)
at java.awt.EventQueue$3.run(EventQueue.java:680)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:696)
at java.awt.EventQueue$4.run(EventQueue.java:694)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:693)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:244)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:147)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:139)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:97)
I am following this http://rapid-i.com/rapidforum/index.php/topic,3862.msg14364.html#msg14364.
This is my code.
try {
RapidMiner.setExecutionMode(RapidMiner.ExecutionMode.COMMAND_LINE);
RapidMiner.init();
RepositoryLocation location = new RepositoryLocation("//NewLocalRepository/TrendClass(70%)/Apply Model (Oct Data)");
ProcessEntry pEntry = (ProcessEntry) location.locateEntry();
String xmlprocess = pEntry.retrieveXML();
Process process = new Process(xmlprocess);
RepositoryLocation objectsLoc = new RepositoryLocation("//NewLocalRepository/TrendClass(70%)/WordList");
IOObjectEntry entry = (IOObjectEntry) objectsLoc.locateEntry();
IOObject myObject;
myObject = entry.retrieveData(null);
IOContainer ioInput = new IOContainer(new IOObject[] {myObject});
IOContainer ioResult = process.run();
IOObject result = ioResult.getElementAt(0);
if (ioResult.getElementAt(0) instanceof ExampleSet) {
ExampleSet resultSet = (ExampleSet)ioResult.getElementAt(0);
System.out.println(result);
int i=0;
for (Example example : resultSet) {
Iterator<Attribute> allAtts = example.getAttributes().allAttributes();
while(allAtts.hasNext()) {
Attribute a = allAtts.next();
if(i<=3)
System.out.print(a.getName()+ " ");
i++;
}
}
System.out.println("\n");
for (Example example : resultSet) {
Iterator<Attribute> allAtts = example.getAttributes().allAttributes();
while(allAtts.hasNext()) {
Attribute a = allAtts.next();
if (a.isNumerical()) {
double value = example.getValue(a);
System.out.print(value+ " " );
//System.out.println("\n");
} else {
String value = example.getValueAsString(a);
System.out.print(value+ " ");
//System.out.println("\n");
}
}
System.out.println("\n");
}
}
} catch (IOException | XMLException | OperatorException ex) {
ex.printStackTrace();
} catch (RepositoryException ex) {
Logger.getLogger(RMPrototype.class.getName()).log(Level.SEVERE, null, ex);
}
0
Answers
-
Hi,
I'm afraid the example I posted there is not working in case your process makes use of parameters resolving local repository locations. Because the process itself is not linked to a repository location if created that way, it does not know where to find the specified files. To fix this, add
after you have created your process.
process.setProcessLocation(new RepositoryProcessLocation(location));
Regards,
Marco0