看看LemmaGen-用C#3.0编写的开源库。
测试词的结果( http://lemmatise.ijs.si/Services )
- 猫->猫
- 跑步
- 跑->跑
- 仙人掌
- 仙人掌->仙人掌
- 仙人掌->仙人掌
- 社区
- 社区->社区
0
看看LemmaGen-用C#3.0编写的开源库。
测试词的结果( http://lemmatise.ijs.si/Services )
0
我在这个滚雪球的演示站点上尝试了您的术语列表,结果看起来还不错....
词干被认为可以将词的变形形式转化为某些共同的词根。使该词根成为“适当的”字典词并不是真正的工作。为此,您需要查看形态/正交分析仪 。
我认为这个问题或多或少是同一件事,而Kaarel对这个问题的回答是我从第二个链接中获得的。
0
词干对词条还原器的争论仍在继续。这是优先考虑精度而不是效率的问题。您应该进行词形化处理以实现语言上有意义的单元,并阻止使用最少的计算汁,并且仍然在同一键下索引单词及其变体。
参见词干机与引爆机
这是python NLTK的示例:
>>> sent = "cats running ran cactus cactuses cacti community communities"
>>> from nltk.stem import PorterStemmer, WordNetLemmatizer
>>>
>>> port = PorterStemmer()
>>> " ".join([port.stem(i) for i in sent.split()])
'cat run ran cactu cactus cacti commun commun'
>>>
>>> wnl = WordNetLemmatizer()
>>> " ".join([wnl.lemmatize(i) for i in sent.split()])
'cat running ran cactus cactus cactus community community'
0
根据有关Stack Overflow的各种答案和我遇到的博客,这是我正在使用的方法,而且看起来返回的真实单词相当好。想法是将传入的文本拆分成单词数组(使用您想要的任何一种方法),然后找到这些单词的词性(POS),并使用它来帮助词干和词素化。
您上面的示例不能很好地工作,因为无法确定POS。但是,如果我们使用一个真实的句子,那么效果会更好。
import nltk
from nltk.corpus import wordnet
lmtzr = nltk.WordNetLemmatizer().lemmatize
def get_wordnet_pos(treebank_tag):
if treebank_tag.startswith('J'):
return wordnet.ADJ
elif treebank_tag.startswith('V'):
return wordnet.VERB
elif treebank_tag.startswith('N'):
return wordnet.NOUN
elif treebank_tag.startswith('R'):
return wordnet.ADV
else:
return wordnet.NOUN
def normalize_text(text):
word_pos = nltk.pos_tag(nltk.word_tokenize(text))
lemm_words = [lmtzr(sw[0], get_wordnet_pos(sw[1])) for sw in word_pos]
return [x.lower() for x in lemm_words]
print(normalize_text('cats running ran cactus cactuses cacti community communities'))
# ['cat', 'run', 'ran', 'cactus', 'cactuses', 'cacti', 'community', 'community']
print(normalize_text('The cactus ran to the community to see the cats running around cacti between communities.'))
# ['the', 'cactus', 'run', 'to', 'the', 'community', 'to', 'see', 'the', 'cat', 'run', 'around', 'cactus', 'between', 'community', '.']
0
这看起来很有趣:MIT Java WordnetStemmer: http ://projects.csail.mit.edu/jwi/api/edu/mit/jwi/morph/WordnetStemmer.html
0
http://wordnet.princeton.edu/man/morph.3WN
对于我的许多项目,我更喜欢基于词典的WordNet lemmatizer,而不是更具侵略性的porter。
http://wordnet.princeton.edu/links#PHP包含指向WN API的PHP接口的链接。
0
我使用stanford nlp进行lemmatization。最近几天,我一直在遇到类似的问题。感谢stackoverflow帮助我解决问题。
import java.util.*;
import edu.stanford.nlp.pipeline.*;
import edu.stanford.nlp.ling.*;
import edu.stanford.nlp.ling.CoreAnnotations.*;
public class example
{
public static void main(String[] args)
{
Properties props = new Properties();
props.put("annotators", "tokenize, ssplit, pos, lemma");
pipeline = new StanfordCoreNLP(props, false);
String text = /* the string you want */;
Annotation document = pipeline.process(text);
for(CoreMap sentence: document.get(SentencesAnnotation.class))
{
for(CoreLabel token: sentence.get(TokensAnnotation.class))
{
String word = token.get(TextAnnotation.class);
String lemma = token.get(LemmaAnnotation.class);
System.out.println("lemmatized version :" + lemma);
}
}
}
}
如果稍后在分类器中使用停用词来最小化输出引理,则也可能是一个好主意。请看一下John Conwell编写的coreNlp扩展。
0
Martin Porter的官方页面包含PHP以及其他语言的Porter Stemmer 。
如果您真的很想做好词干,尽管您需要从Porter Algorithm之类的东西入手,则可以通过添加规则来修复数据集常见的不正确案例来完善它,最后为规则添加很多例外。这可以通过键/值对(dbm / hash / dictionaries)轻松实现,其中键是要查找的单词,而值是要替换原始单词的词干。我曾经研究过的一个商业搜索引擎最终以800个修改后的Porter算法的例外而告终。
0
如果您了解Python, 自然语言工具包(NLTK)具有使用WordNet的非常强大的lemmatizer。
请注意,如果您是初次使用该词法分析器,则必须先下载语料库,然后再使用它。这可以通过以下方式完成:
>>> import nltk
>>> nltk.download('wordnet')
您只需要执行一次。假设您现在已经下载了语料库,它的工作方式如下:
>>> from nltk.stem.wordnet import WordNetLemmatizer
>>> lmtzr = WordNetLemmatizer()
>>> lmtzr.lemmatize('cars')
'car'
>>> lmtzr.lemmatize('feet')
'foot'
>>> lmtzr.lemmatize('people')
'people'
>>> lmtzr.lemmatize('fantasized','v')
'fantasize'
nltk.stem模块中还有其他lemmatizers ,但我自己还没有尝试过。
0
我已经尝试过PorterStemmer和Snowball,但是它们都不能在所有单词上使用,缺少一些非常常见的单词。
我的测试词是:“ 猫跑了仙人掌仙人掌社区仙人掌 ”,并且两人都获得了不到一半的权利。
也可以看看: