Ling187/287: Grammar Engineering

Homework Assignment for Week 3

Due: Friday, February 6 (by noon)
Submit assignments electronically to all three teachers (ron.kaplan "at" microsoft.com, tracy.king "at" microsoft.com, mforst "at" parc.com)


Turn in: 1. the final grammar you end up with (eng-week3.lfg); each part uses the same grammar
2. your new testsuite eng-week3-test.lfg
One again, please name your grammar with name-eng-week3.lfg
Exercises on:
PART 1: coordination
PART 2: finite subordinate clauses
PART 3: infinitives
PART 4: relative clauses

There is one grammar this week; try to do Part 1 before the others since otherwise the grammar will have too much spurious ambiguity (Parts 2 and 3 are not crucially ordered):

Until you do Part 3, if you load the generator you will see warnings like: Some disjuncts have a PRED value and some do not. Too many of these will cause a performance problem for the generator. You can ignore these.

Do not use capital letters; in later grammars we will add these in. 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-week3.lfg

then whenever you start xle in that directory, it will automatically load eng-week3.lfg. This will save a lot of time when making and testing changes.


PART 1: Coordination

For this part, you should use the grammar you got as a result of doing Part 1. This grammar has two basic coordination macros already defined:

   SC-COORD(_CAT)
   NP-COORD(_CAT)

EXERCISE 1 -- Calling the coordination rule

Put in a call to NP-COORD in the NP rule. To do this, you will need to create a disjunction between what the rule currently has as its right hand side and the call. The call will look like:

  @(NP-COORD NP)

The value NP is passed in because this is the category you are going to be coordinating at this level. If you had been putting this in another nominal rule, like Nbar (no, there is not one in this grammar), then the call would have been:

  @(NP-COORD Nbar)

Your grammar should be able to parse:

  the monkey and the girl devoured a banana.

Note: Do not get over-zealous and start putting this in for all the nominals; the third exercise will have you do this via the METARULEMACRO. The same goes for SC-COORD.

Put in a call to SC-COORD in the PP rule. As with the NP coordination, you will need to create a disjunction in the PP rule. Your grammar should be able to parse:

   they laughed in the park and in the garden.

Make sure you can still parse non-coordinated PPs like:

  they laughed in the park.

EXERCISE 2 -- Adding in COORD-LEVEL

Many meaning oriented applications want to know what c-structure level the coordination occurred at. This information can be stored as a feature in the f-structure (instead of having to look back at the c-structure to derive it).

Alter NP-COORD and SC-COORD so that they assign a feature COORD-LEVEL to every coordination. This feature should appear at the same level as the CONJ-FORM feature. So, a sentence like:

   the girl and the monkey devoured the banana.

Should look roughly like:

[ PRED   'devour'
  SUBJ   [ { [ PRED 'girl'
               SPEC def ]
             [ PRED 'monkey'
               SPEC def ] }
             CONJ-FORM and
             COORD-LEVEL NP 
             NUM pl ] ]

EXERCISE 3 -- METARULEMACRO

As discussed last week, METARULEMACRO is a predefined macro that applies to all of the rules in the grammar. Currently, it is set to just give back the right hand side of the rule that you already defined.

Add a disjunct to METARULEMACRO that calls SC-COORD. You will need to pass in _CAT to the template:

   @(SC-COORD _CAT)

Comment out the call to SC-COORD that is currently in the PP rule. (Don't remove it since we want to make sure you got the call right for exercise 1.)

Parse the following sentences to see if things are working right (the second one will have two parses):

  the monkey ate in the park and in the garden.

  the monkey ate and devours a banana.

  the monkey ate a banana and devours a orange.

With this formulation, NPs will be affected by both NP-COORD which is called in the NP and by SC-COORD which is called by METARULEMACRO. It is also applying to N, which should be going through NP-COORD. This can be constrained in METARULEMACRO by adding a constraint in the disjunct:

  e: _CAT ~$ { N NP };
  @(SC-COORD _CAT)

Finally, add another disjunct into METARULEMACRO for NP-COORD. This should be restricted to only apply to NP and N. To do this, you need set notation similar to that above only instead of a negative condition, this is positive condition with $ (instead of ~$ for SCCOORD).

Parse the testsuite eng-week3-test.lfg with your grammar. Make sure that everything parses. If you look at the comments in the grammar, you will see that some of the examples will get more than one parse (it is possible that the way you did the assignment will result in slightly different parse statistics).

EXERCISE 4 --- PERS feature in NP coordination

When you coordinate NPs, the PERS of the coordinated NP depends on the PERS feature of the conjuncts. The rules are basically:

  1. If any conjunct is first person, than the coordinate NP is first person.
       Mary and I saw ourselves in the mirror.
    
  2. If no conjunct is first person and one of the conjuncts is second person, then the coordinate NP is second person.
      You are Mary saw yourselves in the mirror.
    
  3. Otherwise the coordinate NP is third person.
       John and Mary saw themselves in the mirror.
    

The goal of this task is to encode this in the grammar in the NP-COORD macro so that the coordinated NP has a PERS feature with the correct value. What you are going to want to do is have a set of equations on the _CAT in NP-COORD (you will want to keep the @IN-SET part as is). These equations will look down into the _CAT (!) to determine its PERS and then sometimes assign a PERS feature to the coordinated NP (^). You will probably need a combination of constraining and defining equations to do this properly. The same set of equations can go on both instances of _CAT; you can put these in a template (NP-COORD-PERS) and call it from NP-COORD so that you don't have to keep retyping the equations in both places.

Some NPs to try:

   NP: the girl and the monkey

   NP: the girl and I

   NP: you and the girl

   NP: you and I

Note: The equations are likely to be quite ugly. Don't worry about this.
Also don't worry about getting the constraints on why it is the girl and I instead of I and the girl (it is unclear whether this should be done in the syntax at all).

PART 2: Subordinate Clauses

The goal of this part is to add in that clauses like:

    the girl knows that the monkey slept.

Verbs like this take a SUBJ and COMP; there is a template V-COMP for this. The f-structure you want should look roughly like:

  [ PRED  'know'
    SUBJ  [ PRED  'girl' ]
    COMP  [ PRED  'slept'
            COMP-FORM that
            SUBJ  [ PRED 'monkey' ] ] ]

To do this, you will need to:

You should be able to put any sentence you could parse before as the complement of the that. Put in a comment in your new rule a couple of sentences you can now parse. You should also be able to have nested versions such as:

   the girl knows that the girl knows that the monkey slept

If you rule does not already account for them, make sure that you can parse sentences like:

the girl know the monkey slept

where the that has been dropped (you'll need this in the next part on relative clauses)

PART 3: Infinitives

In Part 2, you added in finite clauses as COMP to parse things like:

  the girl knows that the monkey ate a banana.

This exercise adds in infinitival complements. First, create a rule VPinf which take the initival marker to followed by a VP. There is already an entry for the infinitival marker in the lexicon. Try parsing:

  VPinf: to laugh

You should not get a well-formed f-structure because the verb is missing its SUBJ, but make sure there is no TENSE feature and that there is an INF feature.

Alter the VP rule to allow VPinf as an XCOMP. At this point, the c-structure should be all set for parsing things like:

   he wants to laugh.

although the f-structure will not be built correctly because the template for V-XCOMP and V-OBJ-XCOMP goes to TRUE instead of having the appropriate equations associated with it.

Create templates for these verbs. First do V-XCOMP. This should take a SUBJ and an XCOMP. In addition, it needs to state that the verb's SUBJ is its XCOMP SUBJ. You want an f-structure roughly like:

    [ PRED  'want'
      SUBJ  [ PRED 'he' ]=1
      XCOMP [ PRED 'laugh'
              SUBJ [ ]=1 ] ]

where the =1 indicate that the SUBJ are identical. You should be able to parse things like:

  he wants to laugh.
  he want to eat a banana.
  he wants to want to laugh.
  I know that he wants to laugh.

Now do the same thing for V-OBJ-XCOMP. For these verbs, it is the OBJ that controls the XCOMP SUBJ. You should be able to parse things like:

   I want her to laugh.
   he knows that I want her to eat a banana.

Note that the case on the pronouns will reflect the surface form even when playing the role of SUBJ in the infinitive.

PART 4: Relatives Clauses

For this part, you should use the grammar you created for Part I. If you did not get the infinitives to work quite right, some of the sentences in the examples may not parse correctly.

The NP rule allows for an optional relative clause:

  NP --> { (D)
 	    AP*: @(ADJUNCT NP); 
 	    Nmod*: @MOD; "noun noun compounds"
 	    N
 	    PP*: @(ADJUNCT NP);
	    (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.

You want to have an f-structure that looks roughly like:

[ PRED 'girl'
  ADJUNCT { [ PRED 'laugh'
              SUBJ [PRED 'who'] ] } ]

Note that there is no overt connection (for example, no functional control) between the head noun girl and the relative pronoun who.

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 the monkey wanted to think about

If relative clauses with want to in them get two parses, 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.


Turn in: The new version of your grammar.
The .new version of your testsuite from the coordination section.


If you have any questions, you can send us email (ron.kaplan "at" microsoft.com, tracy.king "at" microsoft.com, mforst "at" parc.com), call us (Ron: 650-245-6865; Tracy: 415-8487276, Martin: 650-812-4788), or set up office hours with us.