Stemming English words with Lucene(使用 Lucene 提取英语单词)
问题描述
我正在一个 Java 应用程序中处理一些英文文本,我需要对它们进行词干处理.例如,从文本amenities/amenity"我需要得到amenit".
I'm processing some English texts in a Java application, and I need to stem them. For example, from the text "amenities/amenity" I need to get "amenit".
函数如下:
String stemTerm(String term){
...
}
我找到了 Lucene Analyzer,但它看起来太复杂了,无法满足我的需要.http://lucene.apache.org/java/2_2_0/api/org/apache/lucene/analysis/PorterStemFilter.html
I've found the Lucene Analyzer, but it looks way too complicated for what I need. http://lucene.apache.org/java/2_2_0/api/org/apache/lucene/analysis/PorterStemFilter.html
有没有办法在不构建分析器的情况下使用它来词干?我不了解所有 Analyzer 业务...
Is there a way to use it to stem words without building an Analyzer? I don't understand all the Analyzer business...
编辑:我实际上需要词干提取+词形还原.Lucene 可以做到这一点吗?
EDIT: I actually need a stemming + lemmatization. Can Lucene do this?
推荐答案
import org.apache.lucene.analysis.PorterStemmer;
...
String stemTerm (String term) {
PorterStemmer stemmer = new PorterStemmer();
return stemmer.stem(term);
}
参见这里 了解更多详情.如果您只想使用词干提取,那么您应该使用 this 而不是 Lucene.
See here for more details. If stemming is all you want to do, then you should use this instead of Lucene.
您应该在将 term
传递给 stem()
之前将其小写.
You should lowercase term
before passing it to stem()
.
这篇关于使用 Lucene 提取英语单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 Lucene 提取英语单词


基础教程推荐
- Java 实例变量在两个语句中声明和初始化 2022-01-01
- 在 Java 中创建日期的正确方法是什么? 2022-01-01
- Java Swing计时器未清除 2022-01-01
- 如何在 JFrame 中覆盖 windowsClosing 事件 2022-01-01
- 从 python 访问 JVM 2022-01-01
- 不推荐使用 Api 注释的描述 2022-01-01
- 多个组件的复杂布局 2022-01-01
- 大摇大摆的枚举 2022-01-01
- 如何在 Spring @Value 注解中正确指定默认值? 2022-01-01
- 验证是否调用了所有 getter 方法 2022-01-01