Question: write a function called cky _ parsing that accepts a list of sentences to be parsed and the PCFG used for parsing. This function should
write a function called ckyparsing that accepts a list of sentences to be parsed and the PCFG used for parsing. This function should construct a set of known words present in the given productions. Initialize a viterbi parser using the pcfg Iterate over each sentence in sentences:
Tokenize the sentence.Replace any word not found in the set of known words with Parse the sentence using the Viterbi parser. Select the parse with the highest probability, or handle cases where no valid parse is found check the parseall method of the ViterbiParser object from the nltkparse library Return a list of tuples. one tuple per sentence made of the index of the sentence within the input list, the original sentence, the best parse tree found or an appropriate value indicating he grammatical structure of sentences.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
