Question
Modify your generator so that it can pick rules with unequal probabilities. The number before a rule now denotes the relative odds of picking that
Modify your generator so that it can pick rules with unequal probabilities. The number before a rule now denotes the relative odds of picking that rule. For example, in the grammar:
1 NP DT Noun 1 NP NP PP
bothNPrules have equal chance of being picked. However:2 NP DT Noun
1 NP NP PP
the firstNPrule has32chance of being picked, while the second has only13chance of being picked.
Name your programrandpsent.pyand have it be run as the previous program you wrote.
3 More Complex Sentences
Modify the grammar so it can also generate the types of phenomena illustrated in the following sentences. You want to end up with a single grammar that can generate all of the following sentences as well as grammatically similar sentences.
1Do not assume any file extension. Assume the contents are text like the one exemplified in the grammar above
2
1. Sally ate a sandwich . 2. Sally and the president wanted and ate a sandwich . 3. the president sighed . 4. the president thought that a sandwich sighed . 5. it perplexed the president that a sandwich ate Sally . 6. that a sandwich ate Sally perplexed the president . 7. the very very very perplexed president ate a sandwich . 8. the president worked on every proposal on the desk .
Note: Yes, (6) is grammatically correct in standard written English. It means the same thing as (5).
While your new grammar may generate some very silly sentences, it should not generate any that are obviously ungrammatical. For example, your grammar must be able to generate (4) but not
*the president thought that a sandwich sighed a pickle . Please pay attention to the following:
While the sentences should be okay structurally, they don't need to really make sense. You don't need to distinguish between classes of nouns that can eat, want, or think and those that can't.
however, there are verbs that need a direct object to effect the action and verbs that do not. For example,eat,put,drop need a noun or pronoun to beeaten,putordropped, as in "he eats cake," "she put it on" and "they dropped the class." Conversely, verbs likesleep, fall, andsighdo not need a direct object as they do not perform an action on a noun. People do notsleepan object, orfallsomething.
Have your grammar be calledgrammar2and it should work on both the first and second programs.
4
1. 2.
Conceptual Questions
For the first program: Why does it generate so many long sentences? What grammar rule is responsible?
Howmanywaysaretheretoanalyzethefollowingnounphraseundertheoriginal grammar? (That is, how many ways are there to derive this string if you start from the NP symbol of grammar?)every sandwich with a pickle on the floor under the chief of staffExplainyouranswer.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started