@Override
public void configure(JobConf job) {
try {
log.info("Bayes Parameter {}", job.get("bayes.parameters"));
Parameters params = Parameters.fromString(job.get("bayes.parameters", ""));
log.info("{}", params.print());
Algorithm algorithm;
Datastore datastore;
if (params.get("dataSource").equals("hdfs")) {
if (params.get("classifierType").equalsIgnoreCase("bayes")) {
log.info("Testing Bayes Classifier");
algorithm = new BayesAlgorithm();
datastore = new InMemoryBayesDatastore(params);
} else if (params.get("classifierType").equalsIgnoreCase("cbayes")) {
log.info("Testing Complementary Bayes Classifier");
algorithm = new CBayesAlgorithm();
datastore = new InMemoryBayesDatastore(params);
} else {
throw new IllegalArgumentException("Unrecognized classifier type: " + params.get("classifierType"));
}
} else if (params.get("dataSource").equals("hbase")) {
if (params.get("classifierType").equalsIgnoreCase("bayes")) {
log.info("Testing Bayes Classifier");
algorithm = new BayesAlgorithm();
datastore = new HBaseBayesDatastore(params.get("basePath"), params);
} else if (params.get("classifierType").equalsIgnoreCase("cbayes")) {
log.info("Testing Complementary Bayes Classifier");
algorithm = new CBayesAlgorithm();
datastore = new HBaseBayesDatastore(params.get("basePath"), params);
} else {
throw new IllegalArgumentException("Unrecognized classifier type: " + params.get("classifierType"));
}
} else {
throw new IllegalArgumentException("Unrecognized dataSource type: " + params.get("dataSource"));
}
classifier = new ClassifierContext(algorithm, datastore);
classifier.initialize();
defaultCategory = params.get("defaultCat");
gramSize = Integer.valueOf(params.get("gramSize"));
} catch (IOException ex) {
log.warn(ex.toString(), ex);
} catch (InvalidDatastoreException e) {
log.error(e.toString(), e);
}