我熟悉R中tm包中的单词词干和完成。
我试图想出一种快速而肮脏的方法来查找给定单词的所有变体(在某个语料库中)。例如,如果我的输入是“白细胞”,我想得到“白细胞”和“白血病”。
如果我现在必须这么做的话,我很可能会做这样的事情:
library(tm)
library(RWeka)
dictionary <- unique(unlist(lapply(crude, words)))
grep(pattern = LovinsStemmer("company"),
ignore.case = T, x = dictionary, value = T)我使用洛文斯是因为斯诺波尔的波特似乎不够好斗。
我对其他词干器、脚本语言(Python?)或完全不同的方法的建议持开放态度。
发布于 2017-04-04 12:21:23
此解决方案需要对您的语料库进行预处理。但一旦完成,就会快速查找字典。
from collections import defaultdict
from stemming.porter2 import stem
with open('/usr/share/dict/words') as f:
words = f.read().splitlines()
stems = defaultdict(list)
for word in words:
word_stem = stem(word)
stems[word_stem].append(word)
if __name__ == '__main__':
word = 'leukocyte'
word_stem = stem(word)
print(stems[word_stem])对于/usr/share/dict/words语料库,这将产生结果
['leukocyte', "leukocyte's", 'leukocytes']它使用可以安装在
pip install stemminghttps://stackoverflow.com/questions/31596476
复制相似问题