* @throws ClassNotFoundException
*/
@Override
public void runJob(String input, String output, BayesParameters params) throws IOException {
Configurable client = new JobClient();
JobConf conf = new JobConf(BayesWeightSummerDriver.class);
conf.setJobName("TfIdf Driver running over input: " + input);
conf.setOutputKeyClass(StringTuple.class);
conf.setOutputValueClass(DoubleWritable.class);
FileInputFormat.addInputPath(conf, new Path(output + "/trainer-termDocCount"));
FileInputFormat.addInputPath(conf, new Path(output + "/trainer-wordFreq"));
FileInputFormat.addInputPath(conf, new Path(output + "/trainer-featureCount"));
Path outPath = new Path(output + "/trainer-tfIdf/");
FileOutputFormat.setOutputPath(conf, outPath);
// conf.setNumMapTasks(100);
conf.setJarByClass(BayesTfIdfDriver.class);
conf.setMapperClass(BayesTfIdfMapper.class);
conf.setInputFormat(SequenceFileInputFormat.class);
conf.setCombinerClass(BayesTfIdfReducer.class);
conf.setReducerClass(BayesTfIdfReducer.class);
conf.setOutputFormat(BayesTfIdfOutputFormat.class);
conf
.set("io.serializations",
"org.apache.hadoop.io.serializer.JavaSerialization,org.apache.hadoop.io.serializer.WritableSerialization");
// Dont ever forget this. People should keep track of how hadoop conf
// parameters and make or break a piece of code
FileSystem dfs = FileSystem.get(outPath.toUri(), conf);
if (dfs.exists(outPath)) {
dfs.delete(outPath, true);
}
Path interimFile = new Path(output + "/trainer-docCount/part-*");
Map<String,Double> labelDocumentCounts = SequenceFileModelReader.readLabelDocumentCounts(dfs,
interimFile, conf);
DefaultStringifier<Map<String,Double>> mapStringifier = new DefaultStringifier<Map<String,Double>>(conf,
GenericsUtil.getClass(labelDocumentCounts));
String labelDocumentCountString = mapStringifier.toString(labelDocumentCounts);
log.info("Counts of documents in Each Label");
Map<String,Double> c = mapStringifier.fromString(labelDocumentCountString);
log.info("{}", c);
conf.set("cnaivebayes.labelDocumentCounts", labelDocumentCountString);
log.info(params.print());
if (params.get("dataSource").equals("hbase")) {
HBaseConfiguration hc = new HBaseConfiguration(new Configuration());
HTableDescriptor ht = new HTableDescriptor(output);
HColumnDescriptor hcd = new HColumnDescriptor(BayesConstants.HBASE_COLUMN_FAMILY + ':');
hcd.setBloomfilter(true);
hcd.setInMemory(true);
hcd.setMaxVersions(1);
hcd.setBlockCacheEnabled(true);
ht.addFamily(hcd);
log.info("Connecting to hbase...");
HBaseAdmin hba = new HBaseAdmin(hc);
log.info("Creating Table {}", output);
if (hba.tableExists(output)) {
hba.disableTable(output);
hba.deleteTable(output);
hba.majorCompact(".META.");
}
hba.createTable(ht);
conf.set("output.table", output);
}
conf.set("bayes.parameters", params.toString());
client.setConf(conf);
JobClient.runJob(conf);
}