我使用Python NLTK标记了一些unicode文本。 问题在于文本来自严重编码的数据源,并且未指定编码。经过一番弄乱之后,我发现文本必须是UTF-8格式。 鉴于输入字符串:Python中的另一个unicode混乱
s = u"The problem isn’t getting to Huancavelica from Huancayo to the north."
我想处理它与NLTK,例如用于词性标注,但特殊字符不解决,我得到的输出,如:
The/DT problem/NN isn’t/NN getting/VBG
相反的:
The/DT problem/NN isn't/VBG getting/VBG
如何从这些特殊字符中清除文本?
感谢您的任何反馈,
Mulone
更新:如果我运行HTMLParser().unescape(s)
,我得到:
u'The problem isn\u2019t getting to Huancavelica from Huancayo to the north.'
在其他情况下,我还是得到像&
和
在文本。 我需要做些什么才能将其转化为NLTK能够理解的内容?
不,您的示例输入文本完全由您的码。我没有看到任何'....;'逃离左边。你的示例文本是什么*你的方法返回* – 2013-04-11 11:02:42
其实我将文本存储在一个文件中,写入一个XML文件,然后再次读取,所有这些都使用lxml。 – Mulone 2013-04-11 11:06:18
尝试类似'txt = lec.decode('utf8')。encode('latin9')' – 2013-04-11 11:26:15