【发布时间】:2012-07-23 14:56:47
【问题描述】:
在 Mahout 中有一个命令用于创建序列文件为bin/mahout seqdirectory -c UTF-8
-i <input address> -o <output address>。我想将此命令用作代码 API。
【问题讨论】:
标签: hadoop mahout sequencefile
在 Mahout 中有一个命令用于创建序列文件为bin/mahout seqdirectory -c UTF-8
-i <input address> -o <output address>。我想将此命令用作代码 API。
【问题讨论】:
标签: hadoop mahout sequencefile
你可以这样做:
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.SequenceFile;
import org.apache.hadoop.io.Text;
Configuration conf = new Configuration();
FileSystem fs = FileSystem.get(conf);
Path outputPath = new Path("c:\\temp");
Text key = new Text(); // Example, this can be another type of class
Text value = new Text(); // Example, this can be another type of class
SequenceFile.Writer writer = new SequenceFile.Writer(fs, conf, outputPath, key.getClass(), value.getClass());
while(condition) {
key = Some text;
value = Some text;
writer.append(key, value);
}
writer.close();
此外,您可以使用 org.apache.mahout.text.SequenceFilesFromDirectory 调用您从 Mahout 中描述的完全相同的功能
然后调用看起来像这样:
ToolRunner.run(new SequenceFilesFromDirectory(), String[] args //your parameters);
ToolRunner 来自org.apache.hadoop.util.ToolRunner
希望这对您有所帮助。
【讨论】: