这涉及到以下几个问题 -的UnicodeDecodeError: 'ASCII' 编解码器不能解码字节 - Python的
- Python unicode equal comparison failed
- Find word infront and behind of a Python list
- Searching for Unicode characters in Python
- NLTK Context Free Grammar Genaration
我有python应用程序执行以下任务 -
# -*- coding: utf-8 -*-
1.阅读Unicode文本文件(非英语) -
def readfile(file, access, encoding):
with codecs.open(file, access, encoding) as f:
return f.read()
text = readfile('teststory.txt','r','utf-8-sig')
这给予回报的文本文件作为字符串。
2.将文本分割成句子。
3.经过每一句话,并确定动词,名词等
参考 - Searching for Unicode characters in Python和Find word infront and behind of a Python list
4.添加他们到不同的变量如下
名词=“CAR”| “BUS”|
verbs =“DRIVES”| “命中”
5.现在我想将它们传递到NLTK背景如下自由语法 -
grammar = nltk.parse_cfg('''
S -> NP VP
NP -> N
VP -> V | NP V
N -> '''+nouns+'''
V -> '''+verbs+'''
''')
它给了我下面的错误 -
line 40, in V -> '''+verbs+''' UnicodeDecodeError: 'ascii' codec can't decode byte 0xe0 in position 114: ordinal not in range(128)
哪能克服这个问题并将变量传递给NLTK CFG?
完整代码 - https://dl.dropboxusercontent.com/u/4959382/new.zip
你可以显示错误的* full * traceback吗? – Bakuriu
我正在使用Pycharm。我如何打印完整的追溯? print_stack()不起作用。无论如何,可以找出与给定的例外问题? – ChamingaD
'输入日志;尝试:你的代码;除了:logging.exception(“ouch”)'#为了清楚起见,使用换行符和缩进代替';' –