雪球茎干:糟糕的法语词干

2024-10-06 11:47:29 发布

您现在位置:Python中文网/ 问答频道 /正文

NLM正在处理一些任务。我的输入是法语文本,所以在我的上下文中,只有Snowball词干分析器可用。但是,不幸的是,它总是给我可怜的茎,因为它连plural "s"或{}都不能去掉。下面是一些例子:

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'

Tags: 文本esnlmdelabotestem
1条回答
网友
1楼 · 发布于 2024-10-06 11:47:29

词干分析器的词干是单词而不是句子,所以要对句子进行标记,并对标记进行单独的词干处理。在

>>> 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'

相关问题 更多 >