Ling239e: Grammar Engineering

Homework Assignment for Week 5

Due: Tuesday, February 10 (by midnight)
Submit assignments electronically to both professors (rmkaplan@stanford.edu and thking@stanford.edu)


Turn in: 1. the final grammar you end up with for the context free part (eng-week5-cfp.lfg)
2. the final grammar you end up with for the functional uncertainty part (eng-week5-funcun.lfg)
Please name your grammars with name-eng-week3-feat.lfg and name-eng-week3-mltsec.lfg
Exercises on:
PART 1: context free parsing
PART 2: functional uncertainty

There are two grammars this week; one for each part (the context free parsing part should not take long, but the functional uncertainty part may):

Do not use capital letters. You can use an ending period and some pronouns (see the lexicon).

If you put a file called .xlerc in the directory with your grammar and in .xlerc you put:

  create-parser eng-week5-cfp.lfg

then whenever you start xle in that directory, it will automatically load eng-week5-cfp.lfg (change this to eng-week5-funcun.lfg when you do that part). This will save a lot of time when making and testing changes.


PART 1: Context Free Parsing

For this part, you should use the grammar eng-week5-cfp.lfg.

This grammar is context free and contains no equations (other than the default ^=!). Parse the sentences:

  flying planes can be dangerous
  flying planes with wings of wood can be dangerous
  a flying plane with wings of wood can be dangerous
  flying a plane with wings of wood can be dangerous

Look at the types of trees you get.

Add simple equations to the lexical entries and to the rules to remove the ambiguity from the sentences:

   flying planes is dangerous
   flying planes are dangerous

You can use the following entry for flying:

  flying    VN * (^PRED)='fly<(^OBJ)>'
                 (^NUM)=sg;
             A * (^PRED)='flying'.

You do not need to add in fancy templates or lots of features, just enough to get a basic f-structure without the undesired ambiguity.

Turn in: The new version of your grammar.

PART 2: Functional Uncertainty

For this part, you should use the grammar eng-week5-funcun.lfg.

EXERCISE 1 -- Relative Clauses

The NP rule allows for an optional relative clause:

   NP --> { (D)
 	    AP*: @ADJUNCT;
 	    N
 	    PP*: @ADJUNCT;
	    (RelCL)
 	   |PRON}.

   RelCL --> "relative clause rule"
	  RelPRON
 	  S.

Add equations so that you can parse relative clauses like:

   NP: the girl who laughed
   NP: the girl who devoured the banana
   NP: the banana that the girl devoured
   NP: the banana that the monkey thought about

You will also need to modify the c-structure rules slightly to allow for the "gaps".

Do not worry about when that and when who is used.

Now expand your equations to allow for these to be embedded so that you can parse relative clauses like:

   NP: the girl who he said laughed
   NP: the girl who wanted to devour the banana
   NP: the banana that the girl reported the monkey devoured
   NP: the banana that she said that monkey wanted to think about

If relative clauses with want to in them get two parses, you can either fix this or put a comment in the grammar saying where the two parses are coming from.

Do not worry about the fact that some relative clauses are linguistically bad if you have that in the subordinate clauses.

EXERCISE 2 -- Matrix Questions

The goal of this exercise is to add basic wh questions to the grammar: subject, object, oblique object. There are two basic types of these: ones with subject-auxiliary inversion and ones without.

No subject-auxiliary inversion:

   who laughed
   who said that he laughed

Subject-auxiliary inversion:

   who did they see
   what did they devour
   
   what did they think about

   who did they say laughed
   who did they want to laugh
   what did they want to think about
This exercise will be in four steps:
  1. Add questions with no subject-auxiliary inversion
  2. Add questions with subject-auxiliary inversion but only one clause
  3. Allow subject-auxiliary questions with multiple clauses
  4. Allow question marks

Note: the goal here is not to write a grammar that captures all of English questions; you don't have to have it do any more than is indicated here.

STEP 1

Modify the grammar to allow sentences like:

   who laughed
   who said that he laughed

Make sure that you modifications do not parse (you can set up the rules so that these do not even get a valide c-structure):

   they said that who laughed
   they requested that who said that he laughed

Add a new feature to clauses called STMT-TYPE. STMT-TYPE should have a value of interrogative for questions and declarative for non-questions. This feature should appear at the same level of the f-structure as TENSE.

STEP 2

This step will require the most changes to the c-structure of the grammar. The c-structure rules need to be changed to allow subject-auxiliary inversion in questions like:

   who did they see
   what did they devour
   
   what did they think about

There is already a lexical entry for the auxiliary did. To see how it works, you can parse declaratives such as:

   he did laugh.

You will want the progressive auxiliary is to also be able to appear in questions (only the main verb will be a -ing form instead of a base form).

STEP 3

Modify the grammar to allow sentences like:

  who did they say laughed
  who did they want to laugh
  what did they say he thought about

This should not involve having to write new c-structure rules, assuming you got steps 1 and 2 to work. Do not worry about the fact that the grammar will be able to parse things like:

  who did they say that laughed

You may end up with double parses for things like:

  who did they want to laugh

If this is the case, you can either fix this or put a comment in the grammar saying where the two parses are coming from.

STEP 4

Make a lexical entry for the question mark ? and make sure that it can only occur with questions.

Turn in: The new version of your grammar.


If you have any questions, you can send us email (rmkaplan@stanford.edu and thking@stanford.edu), call us (Ron: 812-4348; Tracy: 812-4808), or talk to us during office hours.