区块.draw()未在python空闲模式下工作

2024-10-06 16:26:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我无法在Python IDLE中绘制分块数据,我正在Python cmd中成功打印它,我正在使用Python 2.7,并且我正在youtube上遵循教程,我找到了this tutorial,但是我无法通过使用draw()函数获得所需的结果。 这是我的密码,如果我做错了什么,请告诉我

import nltk
from nltk.corpus import state_union
from nltk import PunktSentenceTokenizer
'''
POS tag list:

CC  Coordinating conjunction
CD  Cardinal number
DT  Determiner
EX  Existential there
FW  Foreign word
IN  Preposition or subordinating conjunction
JJ  Adjective
JJR Adjective, comparative
JJS Adjective, superlative
LS  List item marker
MD  Modal
NN  Noun, singular or mass
NNS Noun, plural
NNP Proper noun, singular
NNPS    Proper noun, plural
PDT Predeterminer
POS Possessive ending
PRP Personal pronoun
PRP$    Possessive pronoun
RB  Adverb
RBR Adverb, comparative
RBS Adverb, superlative
RP  Particle
SYM Symbol
TO  to
UH  Interjection
VB  Verb, base form
VBD Verb, past tense
VBG Verb, gerund or present participle
VBN Verb, past participle
VBP Verb, non-3rd person singular present
VBZ Verb, 3rd person singular present
WDT Wh-determiner
WP  Wh-pronoun
WP$ Possessive wh-pronoun
WRB Wh-adverb
'''
train_text = state_union.raw("2005-GWBush.txt")
sample_text = state_union.raw("2006-GWBush.txt")

custom_sent_tokenizer = PunktSentenceTokenizer(train_text) #A

tokenized = custom_sent_tokenizer.tokenize(sample_text)   #B

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)

        chunked.draw()

except Exception as e:
        print(str(e))

process_content()

Tags: ortextimportstateadjectiveuniondrawverb