gpt4 book ai didi

python - 雪球词干提取器 : poor french stemming

转载 作者:太空宇宙 更新时间:2023-11-04 09:42:34 24 4
gpt4 key购买 nike

我正在处理一些 nlp 任务。我的输入是法语文本,因此在我的上下文中只能使用 Snowball Stemmer。但是,不幸的是,它一直给我糟糕的词干,因为它甚至不会删除 plural "s"silent e。下面是一些例子:

from nltk.stem import SnowballStemmer
SnowballStemmer("french").stem("pommes, noisettes dorées & moelleuses, la boîte de 350g")
Output: 'pommes, noisettes dorées & moelleuses, la boîte de 350g'

最佳答案

词干提取器提取单词而不是句子,因此对句子进行分词并分别对标记进行提取。

>>> from nltk import word_tokenize
>>> from nltk.stem import SnowballStemmer

>>> fr = SnowballStemmer('french')

>>> sent = "pommes, noisettes dorées & moelleuses, la boîte de 350g"
>>> word_tokenize(sent)
['pommes', ',', 'noisettes', 'dorées', '&', 'moelleuses', ',', 'la', 'boîte', 'de', '350g']

>>> [fr.stem(word) for word in word_tokenize(sent)]
['pomm', ',', 'noiset', 'dor', '&', 'moelleux', ',', 'la', 'boît', 'de', '350g']

>>> ' '.join([fr.stem(word) for word in word_tokenize(sent)])
'pomm , noiset dor & moelleux , la boît de 350g'

关于python - 雪球词干提取器 : poor french stemming,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51097463/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com