Grew main page

The examples used one this page are available on the SVN repository with the commands:

svn checkout svn://scm.gforge.inria.fr/svnroot/semagramme/grew_resources/tuto/lex_rule
cd lex_rule

Lexical rules

When a rule application should be controlled by some lexical information, it is painful to use big disjunction of atomic values (see here for an example). To deal with these kinds of cases, there are lexical rules in GREW.

Let us go on with an example: we are looking for the French verb “faire” used with a predicative “noun”. In the Lexique-Grammaire ressources, there are more than 5000 predicatives nous or noun phrases associated with faire. One of them is illustrated by the sentence “Max fait la cuisine.”:

Dep2pict

The old way

Without lexical rules, we have to write something like this:

  rule faire_old {
    match {
      V [cat=V, lemma="faire"];
      O [cat=N, phon= "carnage" | "figure" | "cuisine" | ... ];
      V -[obj]-> O;
    }
    without {
      V [tag = *];
    }
    commands {
      V.tag = "SUPPORT:C:red";
      O.tag = "PRED:C:red";
    } 
  }

and applied to our example (in the directory lex_rule).

grew -grs faire.grs -seq old -gr 01_Max_fait_la_cuisine.conll -main_feat phon 

produced the dependency structure below:

Dep2pict

Use a parameter

With a lexical rule, you can put the lexical information in a external 5000 lines long file named faire.lp:

faire.lp
carnage
figure
cuisine
...

and get the same result as before with the following rule:

  lex_rule faire_param (feature $noun; file "faire.lp") {
    match {
      V [cat=V, lemma="faire"];
      O [cat=N, phon= $noun];
      V -[obj]-> O;
    }
    without {
      V [tag = *];
    }
    commands {
      V.tag = "SUPPORT:C:red";
      O.tag = "PRED:C:red";
    }

and the command below produces the same result as before.

grew -grs faire.grs -seq param -gr 01_Max_fait_la_cuisine.conll -main_feat phon 

Use several parameters

But, looking deeper in LG data, we find some predicatives nouns that require another patterns… Consider “Max fait la grasse matinée puis fait la cuisine.” below: “grasse” and “matinée” must be matched together.

Dep2pict

In the 5000 lines associated with the French verb faire, we find:

  • fausse manoeuvre
  • grasse matinée
  • premier pas

The needed pattern refers to two different lexical items. For this, we can use more than one parameter.

Consider the file:

faire_adj_noun.lp
fausse#manoeuvre
grasse#matinée
premier#pas
...

and the following rule:

  lex_rule faire_two_param (feature $adj, $noun; file "faire_adj_noun.lp") {
    match {
      V [cat=V, lemma="faire"];
      O [cat=N, phon= $noun];
      V -[obj]-> O;
      A [cat=A, phon= $adj];
      O -[mod]-> A;
    }
    without {
      V [tag = *];
      }
    commands {
      V.tag = "SUPPORT:C:red";
      O.tag = "PRED:C:red";
      } 
   }

This rule (together with the previous rule_param) and with the command:

 grew -grs faire.grs -seq param -gr 02_Max_fait_la_grasse_matinee_puis_il_fait_la_cuisine.conll -main_feat phon 

gives the dependency structure below:

Dep2pict

Add parameters in commands

Now, we want to keep some trace about the lexical entries what were used. For instance, in LG data each lexical information is linked to an identifier. We can do this with the two following files:

faire_id.lp
carnage##N_fnpn_30
carnage##N_fs2_13
figure##N_fnpn_132
cuisine##N_f1a_13
cuisine##N_f31_33
cuisine##N_fn_96
...
faire_adj_noun_id.lp
fausse#manoeuvre##N_fna_82
grasse#matinée##N_fna_89
premier#pas##N_fna_118
...

and the two rules:

  lex_rule faire_param_id (feature $noun, @id; file "faire_id.lp") {
    match {
      V [cat=V, lemma="faire"];
      O [cat=N, phon= $noun];
      V -[obj]-> O;
    }
    without {
      V [tag = *];
      }
    commands {
      V.tag = "SUPPORT(" + @id + "):C:red";
      O.tag = "PRED(" + @id + "):C:red";
      } 
   }
  lex_rule faire_two_param_id (feature $adj, $noun, @id; file "faire_adj_noun_id.lp") {
    match {
      V [cat=V, lemma="faire"];
      O [cat=N, phon= $noun];
      V -[obj]-> O;
      A [cat=A, phon= $adj];
      O -[mod]-> A;
    }
    without {
      V [tag = *];
      }
    commands {
      V.tag = "SUPPORT(" + @id + "):C:red";
      O.tag = "PRED(" + @id + "):C:red";
      } 
   }

the command

 grew -grs faire.grs -seq param_id -gr 02_Max_fait_la_grasse_matinee_puis_il_fait_la_cuisine.conll -main_feat phon 

produces the stucture below:

Dep2pict

It is also possible to use pattern parameters in rule. For instance, we can use the command

      V.tag = "SUPPORT_" + $noun +_(" + @id + "):C:red";

to make the value of the $noun parameter to appear in the verb feature structure.

A few remarks

Parameter syntax

In a lex_rule, the parameter declaration part (with parenthesis) must always follow the syntax (with n≥1 and m≥0):

 (feature $p_1, $p_2, ..., $p_n, @c_1, @c_2, ..., @c_m; file "filename") 

File syntax

In a .lp file, blank lines and lines starting with % are ignored. All other lines must follow the syntax (where n and m are consistent with parameter declaration):

 v_1#v_2#...#v_n##w_1#w_2#...#w_m 

In rule application; values in the files and variables in the parameter declaration are linked following a linear order.

Lexical ambiguity

If there is one parameter, several lines of the parameter files can match the pattern. In this case, the returned value is a disjunction of atoms (like N_f1a_13/N_f31_33/N_fn_96 in the examples above for the predicative noun “cuisine”).

If you use more than one command parameter, the file is supposed to be non amibigous. For instance, if the file contains:

not_det.lp
cuisine##N_f1a#13
cuisine##N_f31#33
cuisine##N_fn#96

The command

 grew -grs faire.grs -seq not_det -gr 02_Max_fait_la_grasse_matinee_puis_il_fait_la_cuisine.conll -main_feat phon 

produce an error “Lexical parameter are not functionnal”.