"Very basic use in Java question"
I have basically implemented this below in the next code section. It is working, passes all the unit tests I wrote. Thanks for the advice which I will try and add since this solution is not perfect, but working.
I have fixed this so it is working. Not quite what I wanted but it passes all the unit tests I wrote. Good enough to move on. It expects one pattern, if it gets more it uses the last pattern. It deletes the resultset from the container and keeps the models which need to be loaded one time.
<?xml version="1.0" encoding="UTF-8"?>
<process version="4.0beta2">
<operator name="Root" class="Process">
<description text="hope this will work"/>
<operator name="TestExampleSource" class="ExampleSource">
<parameter key="attributes" value="2011-05_34.aml"/>
</operator>
<operator name="ModelLoader" class="ModelLoader">
<parameter key="model_file" value="2011-04_34_DecisionTree.mod"/>
</operator>
`
<operator name="ModelApplier" class="ModelApplier">
<list key="application_parameters">
</list>
</operator>
<operator name="ExampleSetWriter" class="ExampleSetWriter">
<parameter key="example_set_file" value="2011-05_34_DecisionTree.out"/>
<parameter key="format" value="special_format"/>
<parameter key="special_format" value="$l $p"/>
</operator>
</operator>
</process>
I have fixed this so it is working. Not quite what I wanted but it passes all the unit tests I wrote. Good enough to move on. It expects one pattern, if it gets more it uses the last pattern. It deletes the resultset from the container and keeps the models which need to be loaded one time.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package dataMine;
import com.rapidminer.RapidMiner;
import com.rapidminer.example.Example;
import com.rapidminer.example.ExampleSet;
import com.rapidminer.operator.IOContainer;
import com.rapidminer.operator.Operator;
import com.rapidminer.operator.OperatorCreationException;
import com.rapidminer.operator.OperatorException;
import com.rapidminer.tools.OperatorService;
import java.io.File;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author ron
*/
public class rapidUtil {
public static final String database_url = "jdbc:mysql://192.168.0.15:3306/mng";
public static final String username = "ibt";
public static final String password = "88bitz";
HashMap<String, IOContainer> container = new HashMap<String, IOContainer>();
public void rapidUtil() {
String pluginDirString = new File("/home/ats/machineLearning/rapidminer-4.6/lib/plugins").getAbsolutePath();
System.setProperty(RapidMiner.PROPERTY_RAPIDMINER_INIT_PLUGINS_LOCATION, pluginDirString);
// set properties - rapid miner home
String path = "/home/ats/machineLearning/rapidminer-4.6/";
System.setProperty("rapidminer.home", path);
RapidMiner.init(false, false, true, false);
}
public void AddModel(String containerName, String modelPath) {
try {
if (!container.containsKey(containerName)) {
container.put(containerName, new IOContainer());
}
Operator modelLoader = OperatorService.createOperator("ModelLoader");
modelLoader.setParameter("model_file", new File(modelPath).getAbsolutePath());
container.put(containerName, modelLoader.apply(container.get(containerName)));
} catch (OperatorException ex) {
Logger.getLogger(rapidUtil.class.getName()).log(Level.SEVERE, null, ex);
} catch (OperatorCreationException ex) {
Logger.getLogger(rapidUtil.class.getName()).log(Level.SEVERE, null, ex);
}
}
public int ApplyModel(String containerName, String sqlQuery) {
int result = 999;
try {
Operator exampleSource;
exampleSource = OperatorService.createOperator("DatabaseExampleSource");
exampleSource.setParameter("database_url", database_url);
exampleSource.setParameter("username", username);
exampleSource.setParameter("password", password);
exampleSource.setParameter("query", sqlQuery);
container.put(containerName,exampleSource.apply(container.get(containerName)));
Operator modelApplier = OperatorService.createOperator("ModelApplier");
modelApplier.setParameter("keep_model", "true");
container.put(containerName, modelApplier.apply(container.get(containerName)));
ExampleSet resultSet = container.get(containerName).get(ExampleSet.class);
Example e = resultSet.getExample(resultSet.size() -1);
result = (int) e.getPredictedLabel();
container.get(containerName).remove(ExampleSet.class);
} catch (OperatorException ex) {
Logger.getLogger(rapidUtil.class.getName()).log(Level.SEVERE, null, ex);
} catch (OperatorCreationException ex) {
Logger.getLogger(rapidUtil.class.getName()).log(Level.SEVERE, null, ex);
}
return result;
}
}