现在的位置: 首页 > 综合 > 正文

Mahout0.6-PrepareTwentyNewsgroups bug修复

2018年02月20日 ⁄ 综合 ⁄ 共 1011字 ⁄ 字号 评论关闭
文章目录

PrepareTwentyNewsgroups(Mahout0.6)

在第三部分的1.1.2中执行如下命令对20Newsgroups预处理

$MAHOUT0P6_HOME/bin/mahoutprepare20newsgroups –p 20_newsgroups -o 20news-train -aorg.apache.lucene.analysis.standard.StandardAnalyzer -c UTF-8

会报出无法找到org.apache.lucene.analysis.standard.StandardAnalyzer类的错误,而在Mahout0.5中可以正常执行,对照0.6版本和0.5版本查找差异,发现代码如下

Mahout0.5中为:

Analyzer analyzer;

      try {

        analyzer =Class.forName(analyzerName).asSubclass(Analyzer.class).newInstance();

      } catch(InstantiationException e) {

        analyzer =(Analyzer)Class.forName(analyzerName).getConstructor(Version.class).newInstance(Version.LUCENE_30);

      }

Mahout0.6中为:

Analyzer analyzer analyzer = ClassUtils.instantiateAs(analyzerName, Analyzer.class);

修改方法为:

1)将Mahout0.6中代码改为如下,重新打包

      try{

      analyzer = ClassUtils.instantiateAs(analyzerName,Analyzer.class);

      }catch(InstantiationException e){

      analyzer = (Analyzer) Class.forName(analyzerName).getConstructor(Version.class).newInstance(Version.LUCENE_30);

      }

2)将Mahout0.6中的PrepareTwentyNewsgroups的class文件拷贝到Mahout0.6中覆盖相应文件。

抱歉!评论已关闭.