1

我正在学习使用 lucene。我编写了一个简单的程序来测试 lucene 分析器,例如:

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 - xyz@example.com"
        };
    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");
        }
    }
}

但我收到以下错误:

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

我认为图书馆 wordnet 或 AnalyzerUtils 不可用。如何安装 lucene 的这一部分?你有什么想法?为什么不见了?我已经安装了 lucene 3.5.0。

4

3 回答 3

2

Lucene 3.4.0 中删除了 lucene-wordnet contrib 模块。AnalyzerUtils 也不存在,因此您要么必须获得 Lucene 3.3.0,要么在此基础上为 3.5.0 编写自己的。

于 2012-01-04T11:10:44.200 回答
0

在 word-net 的情况下,word-net contrib 已从 lucene 3.4.0 中删除,并且功能与分析器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

于 2012-05-02T09:13:00.040 回答
0

而不是 AnalyzerUtils.displayTokens(analyzer,text);

使用功能:

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();
}
于 2014-01-21T06:18:58.027 回答