Ling239e: Grammar Engineering

Homework Assignment for Week 3

Due: Tuesday, January 27 (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 feature part (eng-week3-feat.lfg)
2. the final grammar you end up with for the multiple sections part (eng-week3-mltsec.lfg)
3. a rough estimate of how long this took so that we can (again) adjust future assignments as needed
(this should not take as long as last time)
One again, please name your grammars with name-eng-week3-feat.lfg and name-eng-week3-mltsec.lfg
Exercises on:
PART 1: feature declarations
PART 2: multiple lexicon and grammar sections

There are two grammars this week; one for each part (the two parts are unrelated and so if you get stuck, you might want to switch to the other part for a bit):

Do not use punctuation or capital letters; in later grammars we will add these in.

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

  create-parser eng-week3-feat.lfg

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

Like with changes to the rules and templates, if you change anything in the CONFIG or the feature declaration, you must restart XLE.


PART 1: Feature Declarations

EXERCISE 1 -- Create a Feature Declaration

You need to create a feature declaration for eng-week3-feat.lfg. Do this in the following steps:

  1. In the CONFIG, add a line:
         FEATURES (DEMO ENGLISH).
    

    Make sure to include the ending period.

  2. Create a feature section just after the ---- that end the CONFIG
    (all sections start with the name and version number and end with four hyphens):
      DEMO ENGLISH FEATURES (1.0)
    
    
      ----
    
  3. Start XLE. At this point it will load and allow you to parse things you could parse before.
  4. As soon as you start adding features, it will not load the grammar until you have them all correct. XLE only checks the grammar, not the lexicon. So, features that are triggered only by the lexicon will not cause problems until you try to parse them; the next step will tell you how to systematically trigger these feature warnings.
    As a first step, list each feature in the feature section, ending it with just a period. For example, after you add NUM it should look like:
      DEMO ENGLISH FEATURES (1.0)
    
      NUM.
      ----
    

    You can either examine the grammar to figure out the list of features or you can read them off of the XLE warnings.
    Remember to restart XLE after any changes to the feature declaration.

    Note: You do not need to add features that are listed as GOVERNABLERELATIONS or SEMANTICFUNCTIONS. You also do not need to list PRED (this is a system declared feature).

  5. To make sure you got all the features in the lexicon, on the XLE command line type:
      regenerate "a girl laughed"
    

    Keep adding features until XLE has no more warnings and returns (the number of CPU seconds will depend on your machine):

      A girl laughed
    
      regeneration took 0.2 CPU seconds.
    
  6. Once you get the grammar back to where you can load it and parse, fill in the values of the features. For example, after you add NUM it should look like (only with a lot of other features that just end in a period):
      DEMO ENGLISH FEATURES (1.0)
    
      NUM: -> $ { sg pl }.
      ----
    

    There will be two basic formats. Features with atomic values will look like the NUM example above with the basic format:

      FEAT: -> $ { val1 val2 val3 }.
    

    Some features may only have a single value; you still need to include the {}.

    Features that take f-structures as values will have the basic format:

      FEAT: -> << [ FEAT1  FEAT2  FEAT3 ].
    

    Every feature should have its values listed.

    Once again, keep going until when you do:

      regenerate "a girl laughed"
    

    you get back:

      A girl laughed
    
      regeneration took 0.2 CPU seconds.
    

EXERCISE 2 - Adding New Features

Adding ADJUNCT-TYPE

For every ADJUNCT, we want to know what type of adjunct it is. Modify the ADJUNCT template so that it takes one parameter. This parameter should be the value of a new feature ADJUNCT-TYPE. So, when called in the VP, the call to ADJUNCT should be:

  @(ADJUNCT VP)

And when called in the NP, the call should be:

  @(ADJUNCT NP)

And when called in S, the call should be:

  @(ADJUNCT S)

The f-structure for an ADJUNCT (PP or ADV) should now look roughly like the following for yesterday in yesterday the girl laughed:

  [ PRED    'laugh<(^ SUBJ)>'
    SUBJ    [ ... ]
    ADJUNCT { [ PRED 'yesterday'
                ADJUNCT-TYPE S ] } ]

Make sure to update the feature table as well as the template.

Adding TNS-ASP

Currently there are two features TENSE and ASPECT which can occur in the f-structures of verbs. Create a new feature TNS-ASP which takes the current TENSE and ASPECT features as its values. So, the f-structure of the girl is devouring a banana should look roughly like:

  [ PRED   'devour<(^SUBJ)(^OBJ)>'
    SUBJ   [...]
    OBJ    [...]
    TNS-ASP  [ TENSE pres
               ASPECT prog ] ]

In addition to modifying the templates, you will need to create a new entry in the feature declaration for TNS-ASP (note that you should not need to modify the TENSE and ASPECT declarations).

Turn in: Your new grammar with the feature declaration and the new ADJUNCT-TYPE and TNS-ASP features.


PART 2: Multiple Sections

For this part, you should use the grammar eng-week3-mltsec.lfg. This grammar has two additional lexicon and rule sections in it:

  DEMO-PLUS ENGLISH RULES (1.0)

  ----

occurs just after the DEMO ENGLISH RULES and:

  DEMO-PLUS ENGLISH LEXICON (1.0)

  ----

occurs just after the DEMO ENGLISH LEXICON section at the very end of the file.

As a first step, you need to modify the RULES and LEXENTRIES listings in the CONFIG so that the DEMO-PLUS sections are more highly ranked than the DEMO ones that are already there. If you don't remember how to do this, either look in the XLE documentation or at the slides for week3.

EXERCISE 1: Lexicons

Add an entry for orange in the DEMO-PLUS lexicon so that orange is now both a noun and an adjective (see the entry for purple for a sample adjective entry). You should now be able to parse:

  the girl devoured a orange orange

Add entries for ate and eats in the DEMO-PLUS lexicon so that they are both transitive (V-TRANS) and intransitive (V-INTRANS). You should now be able to parse:

  the girl ate

  the girl ate a banana

Now add a new noun of your choice to the DEMO-PLUS lexicon and make sure you can parse it.

EXERCISE 2: Rules

The DEMO rules are set up to allow an AP (adjective phrase) inside the NP. This allows you to parse things like:

  a orange monkey devoured a purple banana

However, the AP rule simply goes to A. In the DEMO-PLUS rules, create a new AP rule that allows very to optionally appear in front of the A.
(Hint: make very some new c-structure category such as AMOD and then make a lexical entry for it that looks similar to that of adverbs like today only with this new c-structure category.)

Make sure you can parse:

  a very purple monkey laughed

Write a rule in your DEMO-PLUS rules that says:

  VPaux --> FALSE

Figure out what effect this has on your grammar. In XLE, you can use:

  print-rule VP

  print-rule VPaux

to see what the rules expand to.

In a comment after the new VPaux rule, state what this basic affect was and list one sentence whose behaviour has changed with the addition of this rule.

Comments in the grammar are anything between "" (these have to be the straight up and down, non-directional quotes). There are some sample comments in the templates. Comments can be many lines long. An example from eng-week3-mltsec.lfg:

   NOUN-SG(_P) = "template for singular nouns"
	  @(PRED _P)
	  @(NUM sg).

Turn in: The new version of your grammar with the new lexicon and rule sections and the comment about the VPaux rule in it.


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.