我已经通过 pip 安装了 textstat。 (我已经卸载并重新安装,同样失败)。
C:\Anaconda>pip install textstat
Collecting textstat
Using cached textstat-0.3.1.tar.gz
Installing collected packages: textstat
Running setup.py install for textstat ... done
Successfully installed textstat-0.3.1
当我尝试从 textstat 运行任何函数时:ipython(和 python)报告找不到该模块。
您能建议解决问题的方法吗?
In [1]: from textstat import textstat
In [2]: print textstat.syllable_count("Here is some text. Here is some more.")
AttributeError Traceback (most recent call last)
<ipython-input-2-7ac2bb0cb31e> in <module>()
----> 1 print textstat.syllable_count("Here is some text. Here is some more.")
AttributeError: 'module' object has no attribute 'syllable_count'
此外,ipython 报告该模块存在:
In [3]: ??textstat
Type: module
String form: <module 'textstat.textstat' from 'C:\Anaconda\lib\site-packages\textstat\textstat.pyc'>
File: c:\anaconda\lib\site-packages\textstat\textstat.py
Source:
from __future__ import print_function
import pkg_resources
import string
import re
import math
import operator
exclude = list(string.punctuation)
easy_word_set = set([ln.strip() for ln in pkg_resources.resource_stream('textstat', 'easy_words.txt')])
...
class textstatistics:
...
def syllable_count(self, text):
"""
Function to calculate syllable words in a text.
I/P - a text
O/P - number of syllable words
"""
...
请您参考如下方法:
出现了textstat的结构模块不是很清楚。 syllable_count 函数可以在 textstat.textstat.textstat.syllable_count 中找到:
import textstat
textstat.textstat.textstat.syllable_count()
projects readme 中的用法部分显示以下用法示例:
from textstat.textstat import textstat if __name__ == '__main__': test_data = """Playing games has always been thought to be etc..""" print textstat.flesch_reading_ease(test_data) print textstat.smog_index(test_data) #etc
为什么?
textstat 模块具有以下结构,解释了完整的from textstat.textstat import textstat:
.
+-- textstat < from textstat #folder
+-- textstat.py < .textstat #file
=FILE CONTENTS=
class textstatistics:
def syllable_count
textstat = textstatistics() < import textstat #intialised object
