2

我正在尝试将词频值转换为 mahout 向量表示,以便我可以在给定向量上使用 LDA。我正在关注 mahout wiki,其中代码片段建议如何将现有向量转换为 Mahout 向量。

https://cwiki.apache.org/MAHOUT/creating-vectors-from-text.html

这是我的代码,我得到一个 NullPointerException 来代替创建 VectorWriter。apache cwiki 建议使用,

VectorWriter vectorWriter = SequenceFile.createWriter(filesystem, configuration, outfile, LongWritable.class, SparseVector.class);

但是,我在 org.apache.hadoop.io.SequenceFile 中看不到 SequenceFile.createWriter;

这是完整的代码段。

        fs = FileSystem.get(conf);
        //I"m using SeqeunceFile.Writer because SequenceFile.createWriter is not available.
        VectorWriter vectorWriter = (VectorWriter) new SequenceFile.Writer(fs, conf, path, LongWritable.class, RandomAccessSparseVector.class);

        ArrayList<Vector> weights = new ArrayList<Vector>();
        BufferedReader buffer = new BufferedReader(new FileReader("/home/hadoop/LDATest/LDAData/test"));
        String line = null;

        while((line = buffer.readLine()) != null)
        {    
            String[] data = line.split(" "); // split the term,weight data
            Vector weightVector = new RandomAccessSparseVector(1,1);
            weightVector.setQuick(0, Double.parseDouble(data[1])); // add the weight
            weights.add(weightVector);
        }


        vectorWriter.write(new VectorIterable(weights));

这是错误,

org.apache.hadoop.io.SequenceFile$Writer.init(SequenceFile.java) 的 org.apache.hadoop.io.serializer.SerializationFactory.getSerializer(SerializationFactory.java:73) 的线程“主”java.lang.NullPointerException 中的异常:910) 在 org.apache.hadoop.io.SequenceFile$Writer.(SequenceFile.java:843) 在 org.apache.hadoop.io.SequenceFile$Writer.(SequenceFile.java:831) 在 org.apache.hadoop。 io.SequenceFile$Writer.(SequenceFile.java:823) 在 kbsi.ideal.LDATest.iterableTest(LDATest.java:161) 在 kbsi.ideal.LDATest.main(LDATest.java:194)

我真的很感谢你在这方面的帮助。谢谢

4

0 回答 0