[英]Non-ASCII character error using nltk in Python
I'm trying to use the solution code given in the following link: Unicode Tagging in Python NLTK 我正在尝试使用以下链接中提供的解决方案代码: Python NLTK中的Unicode标记
In the solution given by omerbp : 在由omerbp给出的解决方案中:
from nltk.corpus import indian
from nltk.tag import tnt
train_data = indian.tagged_sents('hindi.pos')
tnt_pos_tagger = tnt.TnT()
tnt_pos_tagger.train(train_data) #Training the tnt Part of speech tagger with hindi data
print tnt_pos_tagger.tag(nltk.word_tokenize(word_to_be_tagged))
I'm getting the following error: 我收到以下错误:
'SyntaxError: Non-ASCII character '\\xe0' in file q12.py on line 1, but no encoding declared; 'SyntaxError:第1行的文件q12.py中的非ASCII字符'\\ xe0',但未声明编码; see http://www.python.org/peps/pep-0263.html for details' in line 1. 有关详情,请参见http://www.python.org/peps/pep-0263.html第1行。
Add these two lines on the top of your file: 将这两行添加到文件顶部:
#!/usr/bin/python
# -*- coding: utf-8 -*-
They will instruct the interpreter to encode every charater as UTF-8 instead of ASCII. 他们将指示解释器将每个字符编码为UTF-8而不是ASCII。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.