2012-01-01 9 views
1

私はluceneで作業することを学んでいます。私は次のようにLuceneのアナライザをテストするための簡単なプログラムを書いた:LuceneのAnalyzerUtilエラー

import org.apache.lucene.analysis.standard.StandardAnalyzer; 
import org.apache.lucene.analysis.WhitespaceAnalyzer; 
import org.apache.lucene.analysis.SimpleAnalyzer; 
import org.apache.lucene.analysis.StopAnalyzer; 
import org.apache.lucene.analysis.Analyzer; 
import org.apache.lucene.util.Version; 
import org.apache.lucene.wordnet.AnalyzerUtils; 
import java.io.IOException; 
public class AnalyzerDemo { 
    private static final String[] examples = { 
     "The quick brown fox jumped over the lazy dog", 
     "XY&Z Corporation - [email protected]" 
     }; 
    private static final Analyzer[] analyzers = new Analyzer[] { 
     new WhitespaceAnalyzer(), 
     new SimpleAnalyzer(), 
     new StopAnalyzer(Version.LUCENE_30), 
     new StandardAnalyzer(Version.LUCENE_30) 
    }; 
    public static void main(String[] args) throws IOException { 
     String[] strings = examples; 
     if (args.length > 0) { 
      strings = args; 
     } 
     for (String text : strings) { 
      analyze(text); 
     } 
    } 
    private static void analyze(String text) throws IOException { 
     System.out.println("Analyzing \"" + text + "\""); 
     for (Analyzer analyzer : analyzers) { 
      String name = analyzer.getClass().getSimpleName(); 
      System.out.println(" " + name + ":"); 
      System.out.print("   "); 
      AnalyzerUtils.displayTokens(analyzer, text); 
      System.out.println("\n"); 
     } 
    } 
} 

が、私は次のエラーました:私は図書館WordNetのかAnalyzerUtilsが利用できないと思う

AnalyzerDemo.java:7: package org.apache.lucene.wordnet does not exist 
import org.apache.lucene.wordnet.AnalyzerUtils; 
           ^
AnalyzerDemo.java:35: cannot find symbol 
symbol : variable AnalyzerUtils 
location: class AnalyzerDemo 
      AnalyzerUtils.displayTokens(analyzer, text); 
      ^
Note: AnalyzerDemo.java uses or overrides a deprecated API. 
Note: Recompile with -Xlint:deprecation for details. 
2 errors 

を。どのようにしてこの部分のluceneをインストールできますか?あなたはなにか考えはありますか?なぜそれが欠けているのですか?私はlucene 3.5.0をインストールしました。

答えて

2

Lucene 3.4.0でlucene-wordnet投稿モジュールが削除されました。 AnalyzerUtilsも存在しないので、Lucene 3.3.0を入手するか、またはこれに基づいて3.5.0用に独自に記述する必要があります。

+0

私はドキュメント(文書の用語ベクトル)と単語の出現頻度の単語リストを必要とするのであれば、私は何をすべきでしょうか? – orezvani

+0

新しい質問を作成する、同じことをしたい他の人がいるかもしれない – milan

0

word-netの場合、word-net contribはlucene 3.4.0から削除され、機能はanalyzer contribとマージされました。ポイント番号4:http://apache.spinellicreations.com/lucene/java/3.4.0/changes-3.4.0/Contrib-Changes.html#3.4.0.new_features

のJavaドキュメントの位置は同じのために見つけることができる:https://lucene.apache.org/core/old_versioned_docs/versions/3_5_0/api/all/org/apache/lucene/analysis/synonym/SynonymFilter.html

0

代わりのAnalyzerUtils.displayTokens(分析、テキスト)。

機能を使用します。

private static void displayTokens(Analyzer analyzer,String text) throws IOException 
{ 
    TokenStream stream=analyzer.tokenStream(null,new StringReader(text)); 
    CharTermAttribute cattr = stream.addAttribute(CharTermAttribute.class); 
    stream.reset(); 
    while (stream.incrementToken()){ 
     System.out.print(cattr.toString()+" "); 
    } 
    stream.end(); 
    stream.close(); 
}