In this lab you will be writing grammars that can generate a subset of sentences that are grammatical in Standard American English (SAE), while ensuring that these grammars do not generate sentences that are ungrammatical in SAE.
By completing this lab, you will demonstrate that you:
grammar1.txt
grammar2.txt
for the grammar in Part 2grammar3.txt
for the grammar in Part 3grammar4.txt
for the grammar in Part 4Lab3.py
with the added functions and tests for each
grammar.Before starting each lab, get the latest version of the
NLPScholar
repo by first navigating to the folder on
terminal and then executing:
git pull
Additionally, a package is missing that you need for today. With the nlp environment activated run:
conda install nltk
In this part familiarize yourself with the provided grammar in
grammar1.txt
. The main function in Lab3.py
generates 10 random sentences from the grammar, and also generates the
parses for two sentences.
Answer the following questions in the google doc template.
Lab3.py
you will see that the sentence
“the panda saw my friend in her pajamas” has two different parses.
Describe the difference between these parses.Next, complete the function is_grammatical
in
Lab3.py
, which determines if a given sentence is
grammatical under a given grammar.
Create a new file grammar2.txt
which is a copy of
grammar1.txt
. Add the following verbs to the grammar:
existed, gave, died, vanished, lent, sent
.
Confirm whether the following sentences are deemed grammatical by your grammar:
Note, all of these sentences are actually ungrammatical in SAE. In considering this, answer the following question in the google doc template:
Finally, update your grammar in grammar2.txt
so that you
don’t generate these sentences (by generate sentences with those verbs
that are grammatical). Write test cases for your new grammar in the
test_grammar2
function in Lab3.py
.
Make a copy of your grammar2.txt
called
grammar3.txt
. You will improve this grammar by adding in
adverbs and adjectives. Here are some examples of sentences that this
grammar should be able to generate (these are also grammatical in
SAE):
Here are examples of sentences that should be ungrammatical under your grammar (these are also ungrammatical in SAE):
Start by answering the following questions in the google doc template:
How does adjective modification in SAE work?
How does adverb modification in SAE work?
You should modify grammar3.txt
to capture these
processes. You should minimally include the following adjectives and
adverbs:
Write test cases for your new grammar in the
test_grammar3
function in Lab3.py
.
Make a copy of grammar3.txt
called
grammar4.txt
. You will add another structure to your
grammar: fronted sentential complements. Here are some examples of
sentences that this grammar should be able to generate (these are also
grammatical in SAE):
Start by answering the following question in the google doc template:
Next, create a new file grammar4.txt
and modify the
grammar from the previous step to accept these new sentences. Write test
cases for your new grammar in the test_grammar4
function in
Lab3.py
.