如何在NLTK 3.0中生成随机文本?

时间:2014-10-03 16:42:57

标签: python nlp nltk

nltk.text.Text的generate方法似乎已在NLTK 3.0中删除。

例如:

>>> bible = nltk.corpus.gutenberg.words(u'bible-kjv.txt')
>>> bibleText = nltk.Text(bible)
>>> bibleText.generate()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'Text' object has no attribute 'generate'

可能只是因为我错误地记得如何做到这一点,但我在网上找到的所有内容似乎都支持上述方法。我有什么想法吗?

1 个答案:

答案 0 :(得分:23)

first online chapter of the NLTK book中的注释说:

  

generate()方法在NLTK 3.0中不可用,但会是   在后续版本中恢复。