【问题标题】:Python NLTK LazyPython NLTK 懒惰
【发布时间】:2022-01-09 11:21:49
【问题描述】:

我正在尝试使用 NLTK 分析 Python 中的文本,但是当我运行程序时,我收到一个错误,提示 TypeError: 'LazyCorpusLoader' object is not callable。我不确定为什么会出现这个错误。

import re
import csv
import nltk



class project:



    def __init__(self):
        self.ReadDoc()


    def ReadDoc(self):

        PPV = nltk.corpus.words('/Users/documents/project/docs/txt/file.txt')
        PPV = ' '.join(PPV)

【问题讨论】:

    标签: python nltk corpus


    【解决方案1】:

    这是由于没有定义语料库变量。

    应该是这样的:

    import re
    import csv
    import nltk
    
    
    
    class project:
    
    
    
        def __init__(self):
            self.ReadDoc()
    
    
        def ReadDoc(self):
    
            corpus_root = os.getcwd() + "/docs/txt/"
            file_ids = ".*.txt"
            corpus = PlaintextCorpusReader(corpus_root, file_ids)
    
            PPV = nltk.corpus.words('file.txt')
            PPV = ' '.join(PPV)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-04-01
      • 2012-06-02
      • 2015-09-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-06
      相关资源
      最近更新 更多