How to make the program return the list of words not covered by the grammar? For example, consider the code below:
import nltk
# Define the cfg grammar.
grammar = nltk.CFG.fromstring("""
S -> NP VP
VP -> V NP
NP -> det N | N
V -> "eats" | "drinks"
N -> "President" | "apple"
det -> "The" | "a" | "an"
""")
sentence = "The President Michel eats banana"
# Load the grammar into the ChartParser.
cp = nltk.ChartParser(grammar)
# Generate and print the parse from the grammar given the sentence tokens.
for tree in cp.parse(sentence.split()):
print(tree)
it just displays the error message: ValueError: Grammar does not cover some of the input words: "'Michel','banana'".
However, I want to get these words not covered by the grammar to use them elsewhere in the program.