Mahout 中有一个用于创建序列文件的命令,如下所示bin/mahout seqdirectory -c UTF-8
-i <input address> -o <output address>
。我想使用这个命令作为代码 API。
你可以这样做:
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();
您可以找到更多信息here and here
此外,您可以使用 Mahout 调用与您描述的完全相同的功能org.apache.mahout.text.SequenceFilesFromDirectory
然后调用看起来像这样:
ToolRunner.run(new SequenceFilesFromDirectory(), String[] args //your parameters);
The ToolRunner
来自org.apache.hadoop.util.ToolRunner
希望这有帮助。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)