我正在尝试导入文本文件,然后使用:
import codecs
import re
from nltk.tree import Tree
string1=codecs.open(r'C:\Users\User\Desktop\Tree2.txt','r','utf-8')
txt2=string1.read()
ptree = ParentedTree.fromstring (txt2)
但我收到以下错误:
Tree.read(): expected u')' but got u'end-of-string'
注意:由于程序有效,此文件的内容没有错误 当我将其视为字符串时正确地说:
txt2=unicode("""(S (w) (VP (VERB_PERFECT g) ))""",'utf-8')
ptree = ParentedTree.fromstring (txt2)
任何帮助?