Lucene 上的AnalyzerUtil 错误

发布于 2024-12-23 13:31:50 字数 2265 浏览 2 评论 0 原文

我正在学习使用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 - [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");
        }
    }
}

但出现以下错误:

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。

I'm learning to work with lucene. I wrote a simple program to test lucene analyzers like:

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");
        }
    }
}

but I got the following error:

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

I think library wordnet or AnalyzerUtils is not available. How can I install this part of lucene? Do you have any ideas? Why is that missing? I've installed lucene 3.5.0.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

倾城泪 2024-12-30 13:31:50

Lucene-wordnet contrib 模块在 Lucene 3.4.0 中被删除。 AnalyzerUtils 也不存在,因此您要么必须获取 Lucene 3.3.0,要么基于此编写自己的 3.5.0。

lucene-wordnet contrib module was removed in Lucene 3.4.0. AnalyzerUtils also doesn't exist, so you either have to get Lucene 3.3.0 or write your own for 3.5.0 based on this one.

裸钻 2024-12-30 13:31:50

对于 word-net,word-net contrib 已从 lucene 3.4.0 中删除,并且功能已与 analyzers 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

In case of word-net, the word-net contrib was removed from lucene 3.4.0 and the functionality was merged with analyzers contrib. Point number 4 at: http://apache.spinellicreations.com/lucene/java/3.4.0/changes-3.4.0/Contrib-Changes.html#3.4.0.new_features.

Java docs can be found for the same at: https://lucene.apache.org/core/old_versioned_docs/versions/3_5_0/api/all/org/apache/lucene/analysis/synonym/SynonymFilter.html

(り薆情海 2024-12-30 13:31:50

而不是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();
}

Instead of AnalyzerUtils.displayTokens(analyzer,text);

Use the function:

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();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文