我试过了,但没有用
from nltk.corpus import stopwords
stopwords_list = stopwords.words('arabic')
print(stopwords_list)2018年1月更新nltk数据存储库自2017年10月起就包含阿拉伯语停止语,因此这个问题不再出现。上述代码将如预期的那样工作。
发布于 2017-03-06 13:45:45
截至2017年10月,nltk收录了一批阿拉伯语词组。如果您在该日期之后运行nltk.download(),则不会出现此问题。如果您已经使用nltk有一段时间了,而您现在缺少阿拉伯语停止词,请使用nltk.download()更新您的停止语语料库。
nltk.download(),您会发现stopwords语料库显示为“过期”(红色)。下载包含阿拉伯语的当前版本。注:
在列表中查找单词是非常缓慢的。使用集合,而不是列表。例如,
arb_stopwords = set(nltk.corpus.stopwords.words("arabic"))原文(仍适用于不包括在内的语文)
为什么不直接检查一下stopwords集合包含什么:
>>> from nltk.corpus import stopwords
>>> stopwords.fileids()
['danish', 'dutch', 'english', 'finnish', 'french', 'german', 'hungarian',
'italian', 'norwegian', 'portuguese', 'russian', 'spanish', 'swedish',
'turkish']所以没有阿拉伯语的名单。我不知道你所说的“添加它”是什么意思,但是停止词列表只是单词的列表。他们甚至不做形态学分析,或其他你可能希望在一种屈折的语言。因此,如果您有(或可以将)阿拉伯语停止词的列表,只需将它们放在一个set()中,那么如果代码工作的话,您就领先了一步。
发布于 2017-03-06 16:03:28
这里有一张阿拉伯语停止词列表:
https://github.com/mohataher/arabic-stop-words/blob/master/list.txt
如果您使用文件名nltk_data将该文件保存在您的arabic目录中,那么您将能够使用上面的代码使用nltk调用它,即:
from nltk.corpus import stopwords
stopwords_list = stopwords.words('arabic')(请注意,可以通过在nltk_data解释器中键入nltk.data.path来查看您的nltk.data.path目录的可能位置)。
您也可以使用alexis的建议来检查是否找到它。
请注意他的建议,将停止词列表转换为一个集合:stopwords_set = set(stopwords.words('arabic')),因为它会对性能产生真正的影响。
发布于 2022-07-26 18:01:06
您应该使用这个名为“阿拉伯语停止词”的库,这里是它的要点:
pip install Arabic-Stopwords只需安装它,应该在输入以下内容之后导入:
import arabicstopwords.arabicstopwords as stp它比nltk的要好得多
https://stackoverflow.com/questions/42625084
复制相似问题