【问题标题】:How can I use Mahout's sequencefile API code?如何使用 Mahout 的 sequencefile API 代码?
【发布时间】:2012-07-23 14:56:47
【问题描述】:

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

【问题讨论】:

    标签: hadoop mahout sequencefile


    【解决方案1】:

    你可以这样做:

    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();
    

    您可以找到更多信息herehere

    此外,您可以使用 org.apache.mahout.text.SequenceFilesFromDirectory 调用您从 Mahout 中描述的完全相同的功能

    然后调用看起来像这样:

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

    ToolRunner 来自org.apache.hadoop.util.ToolRunner

    希望这对您有所帮助。

    【讨论】:

    • 您可能还想查看here,其中的代码同时使用了 SequenceFile Writer 和 Reader。
    • "appledata/apples"Path path = new Path("appledata/apples");here 中的路径是什么。如果这是地址目录?
    • 可能与Hadoop File System (HDFS)相关
    • 那么,我该如何设置地址呢?我没有这方面的更多信息。
    • 那你就不需要HDFS了,只要指定你想要输出写入的本地路径。
    猜你喜欢
    • 1970-01-01
    • 2012-10-20
    • 2014-09-08
    • 2013-08-31
    • 1970-01-01
    • 2014-09-05
    • 2018-04-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多