Data Mining: Practical Machine Learning Tools and Techniques, Second Edition

(Brent) #1

466 CHAPTER 14 | EMBEDDED MACHINE LEARNING


// Give instance access to attribute information from the dataset.
instance.setDataset(data);
return instance;
}

/**
* Main method.
*/
public static void main(String[] options) {

try {

// Read message file into string.
String messageName = Utils.getOption('m', options);
if (messageName.length() == 0) {
throw new Exception("Must provide name of message file.");
}
FileReader m = new FileReader(messageName);
StringBuffer message = new StringBuffer(); int l;
while ((l = m.read()) != -1) {
message.append((char)l);
}
m.close();

// Check if class value is given.
String classValue = Utils.getOption('c', options);

// If model file exists, read it, otherwise create new one.
String modelName = Utils.getOption('o', options);
if (modelName.length() == 0) {
throw new Exception("Must provide name of model file.");
}
MessageClassifier messageCl;
try {
ObjectInputStream modelInObjectFile =
new ObjectInputStream(new FileInputStream(modelName));
messageCl = (MessageClassifier) modelInObjectFile.readObject();
modelInObjectFile.close();
} catch (FileNotFoundException e) {
messageCl = new MessageClassifier();

Figure 14.1(continued)

Free download pdf