SyntaxError:分析时出现意外的EOF…用于python 3.4和nltk
在使用Python3.4的Jupyter中使用以下代码时,我遇到了一个解析错误SyntaxError:分析时出现意外的EOF…用于python 3.4和nltk,python,nltk,jupyter,Python,Nltk,Jupyter,在使用Python3.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_to
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)
导入nltk
从nltk.corpus导入州联盟
从nltk.tokenize导入PunkSentenceTokenizer
train\u text=state\u union.raw(“2005 GWBush.txt”)
示例文本=state\u union.raw(“2006 GWBush.txt”)
自定义\u已发送\u标记器=PunkSentenceTokenizer(序列\u文本)
tokenized=自定义\u发送\u标记器。标记化(示例\u文本)
def process_content():
尝试:
对于标记化的i:
words=nltk.word\u标记化(i)
tagged=nltk.pos_标签(文字)
chunkGram=r“”“块:{**?}”
chunkParser=nltk.RegexpParser(chunkGram)
chunked=chunkParser.parse(标记)
打印(分块)
我得到以下错误:
File "<ipython-input-12-a049462ffecb>", line 26
^
SyntaxError: unexpected EOF while parsing
文件“”,第26行
^
SyntaxError:分析时出现意外的EOF
请告知我如何解决此解析错误Python正在查找的其余部分,例如
finally:
或除了:
块
由于您没有提供,Python对此表示不满。由于在较低的缩进级别上没有其他块,所以当解析器到达文件末尾时,它只能确定其余的块丢失了。因为解析器希望找到语句的另一部分,所以找不到EOF(文件结尾)。看一下and和or