Lab for week 5: Recursive Descent Parser -- Answers

Author: Henry S. Thompson
Date: 2015-10-20, updated 2016-10-17
Copyright: This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License: You may re-use, redistribute, or modify this work for non-commercial purposes provided you retain attribution to any previous author(s).

Adding productions to the grammar

Ungrammatical sentences

Number agreement (optional)

Change the grammar to handle number agreement and parse the following sentences:

Use grammar2 in

Exploring a treebank grammar

Distribution of Productions

  • What are the 10 most frequent and least frequent lexical and grammatical productions ?

    First download the answer code and look at the definition of production_distribution

Then do


lex_prods, nonlex_prods = production_distribution(psents)

For the 10 most frequent productions

sorted(lex_prods.items(), key=lambda x : x[1], reverse=True)[:10]

sorted(nonlex_prods.items(), key=lambda x : x[1], reverse=True)[:10]

10 least frequent productions

sorted(lex_prods.items(), key=lambda x : x[1])[:10]

sorted(nonlex_prods.items(), key=lambda x : x[1])[:10]