Twenty Newsgroups Classification实例任务之TrainNaiveBayesJob(一)(二)
ception {
// readFromFile(fPath);
readFromFile(trainPath);
}
/**
* 读取LabelIndex文件
* @param fPath
* @return
* @throws IOException
*/
public static Map readFromFile(String fPath) throws IOException{
FileSystem fs = FileSystem.get(URI.create(fPath), conf);
Path path = new Path(fPath);
Map map=new HashMap();
SequenceFile.Reader reader = null;
try {
reader = new SequenceFile.Reader(fs, path, conf);
Writable key = (Writable)
ReflectionUtils.newInstance(reader.getKeyClass(), conf);
Writable value = (Writable)
ReflectionUtils.newInstance(reader.getValueClass(), conf);
while (reader.next(key, value)) {
// Writable k=; // 如何实现Writable的深度复制?
// map.put(key, value);
System.out.println(key.toString()+", "+value.toString());
System.exit(-1);// 只打印第一条记录
}
} finally {
IOUtils.closeStream(reader);
}
return map;
}
}
这里在写的时候想做一个通用的,所以需要对Writable深度复制,但是一时间还没有想到办法,所以这里留个问题,有时间解决。