SyntaxError: unexpected EOF while parsing...for python 3.4 and nltk
SyntaxError: unexpected EOF while parsing...for python 3.4 and nltk
当我使用 python 3.4
在 Jupyter 中使用以下代码时出现解析错误
import nltk
from nltk.corpus import state_union
from nltk.tokenize import PunktSentenceTokenizer
train_text = state_union.raw("2005-GWBush.txt")
sample_text = state_union.raw("2006-GWBush.txt")
custom_sent_tokenizer = PunktSentenceTokenizer(train_text)
tokenized = custom_sent_tokenizer.tokenize(sample_text)
def process_content():
try:
for i in tokenized:
words = nltk.word_tokenize(i)
tagged = nltk.pos_tag(words)
chunkGram = r"""Chunk: {<RB.?>*<VB.?>*<NNP><NN>?}"""
chunkParser = nltk.RegexpParser(chunkGram)
chunked = chunkParser.parse(tagged)
print(chunked)
我收到以下错误:
File "<ipython-input-12-a049462ffecb>", line 26
^
SyntaxError: unexpected EOF while parsing
请告诉我如何解决这个解析错误
Python 正在寻找 compound try:
statement 的其余部分,例如finally:
或 except:
块。
由于您没有提供,Python 对此进行了投诉。由于没有其他块处于较低的缩进级别,它只能在解析器到达文件末尾时确定其余部分丢失了。因为解析器期望找到语句的另一部分,所以找到 EOF(文件结尾)是意外的。
当我使用 python 3.4
在 Jupyter 中使用以下代码时出现解析错误import nltk
from nltk.corpus import state_union
from nltk.tokenize import PunktSentenceTokenizer
train_text = state_union.raw("2005-GWBush.txt")
sample_text = state_union.raw("2006-GWBush.txt")
custom_sent_tokenizer = PunktSentenceTokenizer(train_text)
tokenized = custom_sent_tokenizer.tokenize(sample_text)
def process_content():
try:
for i in tokenized:
words = nltk.word_tokenize(i)
tagged = nltk.pos_tag(words)
chunkGram = r"""Chunk: {<RB.?>*<VB.?>*<NNP><NN>?}"""
chunkParser = nltk.RegexpParser(chunkGram)
chunked = chunkParser.parse(tagged)
print(chunked)
我收到以下错误:
File "<ipython-input-12-a049462ffecb>", line 26
^
SyntaxError: unexpected EOF while parsing
请告诉我如何解决这个解析错误
Python 正在寻找 compound try:
statement 的其余部分,例如finally:
或 except:
块。
由于您没有提供,Python 对此进行了投诉。由于没有其他块处于较低的缩进级别,它只能在解析器到达文件末尾时确定其余部分丢失了。因为解析器期望找到语句的另一部分,所以找到 EOF(文件结尾)是意外的。