【问题标题】:Rake error while getting stop words list in python在python中获取停用词列表时出现错误
【发布时间】:2021-06-27 09:52:41
【问题描述】:

我正在运行以下代码

from rake_nltk import rake
import operator
stoppath = 'data/stoplists/SmartStoplist.txt'
rake_object = rake.Rake("SmartStopList.txt",5,3,2)

但是当我运行最后一行时,我得到以下错误

rake_object = rake.Rake("SmartStopList.txt",5,3,2)
Traceback (most recent call last):

  File "<ipython-input-12-595e49e89adb>", line 1, in <module>
    rake_object = rake.Rake("SmartStopList.txt",5,3,2)

  File "C:\Users\kris\Anaconda3\lib\site-packages\rake_nltk\rake.py", line 64, in __init__
    self.to_ignore = set(chain(self.stopwords, self.punctuations))

TypeError: 'int' object is not iterable

我不确定为什么会出现此错误。需要帮助

【问题讨论】:

    标签: python rake-task


    【解决方案1】:

    看看__init__

    def __init__(
        self,
        stopwords=None,
        punctuations=None,
        language="english",
        ranking_metric=Metric.DEGREE_TO_FREQUENCY_RATIO,
        max_length=100000,
        min_length=1,
    )
    

    5 将指向punctuations 参数,该参数应该是一个列表,而不是ranking_metric。使用参数名称

    rake_object = rake.Rake("SmartStopList.txt", ranking_metric=5, max_length=3, min_length=2)
    

    顺便说一下stopwords也应该是一个列表,你正在发送字符串。

    【讨论】:

    • 非常感谢这有帮助,但是当我运行下一行时,我得到一个属性错误```keywords = rake_object.run(df['Customer_Log']) ```我得到的错误是``` Traceback(最近一次调用最后):文件“”,第 1 行,在 关键字 = rake_object.run(df['Customer_Log']) AttributeError: 'Rake' object没有属性'run'```在这个方向上也有任何帮助
    • @Krishnamurthy Rake 它没有 run。您可以查看source code 以查看可用的功能和作用。
    • 那么我如何在数据帧上运行 rake_object?
    • @Krishnamurthy run 函数属于python-rake,而不是rake_nltk。如果你使用这个库,你可以做df['Customer_Log'].apply(rake_object.run)
    • 我已经在我的 spyder 中安装了 python-rake 库,但是当我尝试使用此代码 import Rake 导入时,它给我一个错误提示 no such module exists 我做错了什么?跨度>
    猜你喜欢
    • 1970-01-01
    • 2019-05-18
    • 2019-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-16
    • 1970-01-01
    相关资源
    最近更新 更多