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 提取英语单词


- 如何使用WebFilter实现授权头检查 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01
- Java包名称中单词分隔符的约定是什么? 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01
- Eclipse 插件更新错误日志在哪里? 2022-01-01
- 从 finally 块返回时 Java 的奇怪行为 2022-01-01
- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- Jersey REST 客户端:发布多部分数据 2022-01-01
- C++ 和 Java 进程之间的共享内存 2022-01-01
- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01