NLP初心者です。CFG について読み、トップダウン解析とボトムアップ解析に適用したいと考えています。トップダウンの解析から始めました。nltkとpython 36でトップダウンの解析木を描きたいです。以下のコードを書いたのですが動きません。何が間違っていますか?コードを強化するのを手伝ってくれる人はいますか?
import nltk
from nltk.tag import pos_tag
from nltk.tokenize import word_tokenize
from nltk.tree import *
from nltk.draw import tree
from nltk import Nonterminal, nonterminals, Production, CFG
from nltk.parse import RecursiveDescentParser
text = input('Please enter a sentence: ')
words = text.split()
sentence = pos_tag(words)
grammar1 = nltk.CFG.fromstring("""
S -> NP VP
S -> VP
VP -> V NP | V NP PP
NP -> Det N | Det N PP
PP -> P NP
V -> "saw" | "ate" | "walked" | "book" | "prefer" | "sleeps"
Det -> "a" | "an" | "the" | "my" | "that"
N -> "man" | "dog" | "cat" | "telescope" | "park" | "flight" | "apple"
P -> "in" | "on" | "by" | "with"
""")
rd = nltk.RecursiveDescentParser(grammar1, "Input")
result = rd.parse(sentence)
result.draw()
「book that flight」を解析するためにこのテキストを入力しました。