3

Mahout 中存在用于将序列文件创建为bin/mahout seqdirectory -c UTF-8 -i <input address> -o <output address>. 我想将此命令用作代码 API。

4

1 回答 1

3

你可以这样做:

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

然后调用看起来像这样:

ToolRunner.run(new SequenceFilesFromDirectory(), String[] args //your parameters);

ToolRunner来自_org.apache.hadoop.util.ToolRunner

希望这有帮助。

于 2012-07-25T08:16:19.420 回答