Grail Tutorial - Editing Grammar Files Directly

For the more advanced user, using the user interface to edit your lexicon is a bit laborious. In addition, it doesn't allow you to specify the lexical semantics. This section of the tutorial discusses how to edit your Grail grammar files directly. It assumes a basic familiarity with formulas for the multimodal Lambek calculus for the syntactic part, such as used in Moortgat (1997) or as described in the section on the relation between Grail's graphs and multimodal formulas.

Given that Grail and its grammar files are written in Prolog, some basic familiarity with Prolog and its syntax will be useful, though the fundamentals will be explained in the text. An introduction to Prolog can be found here (offsite).

The Lexicon

The most frequently used edits are done to the lexicon of a file. A grammar's lexicon is stored in the form of a number of lex(Word, Formula, Semantics) triples. Where Word is the orthographical form of the lexical entry, Formula is the formula assigned to this word and Semantics the corresponding lambda-term semantics.

The simplest possible lexical entry is then.

lex(arthur, np, arthur).

which states "Arthur" (note the lowercase letter in the lexical entry: unquoted Prolog constants need to start with a lowercase letter) is of category np and has arthur as its semantics. Remark that a Prolog fact like the lexical entry above has to be terminated by a period.

Multimodal formulas in Prolog

Complex formulas are translated by Prolog terms. The table below lists the terms corresponding to the different formulas. In all inductive cases I is the Prolog atom corresponding to the mode i, A is the Prolog term corresponding to the formula A and B is the Prolog term corresponding to the formula B.

The mnemonics for the term constructors are `division right' for dr, `product' for p, `division left' for dl, `diamond' for dia and `box' box.

Grail's representation of formulas

After having edited a file, remember that you can select [File/Reload Grammar] from the menu bar to reload your edited grammar into Grail.

The Macro Facilities

As there tend to be many formulas which are used quite frequently, Grail allows you to give names to complex formulas. This is done by adding macro declarations to your grammar. A macro is a Prolog fact of the form macro(Term, Formula) indicating that Term should be replaced by Formula. This term occur anywhere a formula can occur and Grail will recursively expand the macro definitions until a normal form is reached.

As an example, two frequently occurring macro's are the following.

macro(iv, dl(0,np,s)).
macro(tv, dr(0,iv,np)).

The first macro indicates that the atom iv, for intransitive verb, corresponds to the formula np \0 s, ie. the formula which looks for a noun phrase to its left in order to produce a sentence.

The second macro indicates that the atom tv corresponds to a formula which is looking to its right for a noun phrase in order to produce an intransitive verb, as defined by the first macro.

Grail makes the tacit assumption that your macro definitions will terminate and produce a unique normal form for any term using them. The macro facilities are meant as a simply way to factorize your grammars and not as a tool to perform complex computations. Changing macro definitions is a way to quickly make global changes to your grammar.

Typed lambda-term semantics in Prolog

Grail's representation of lambda term semantics

Richard.Moot@labri.fr
Last modified: Sat Feb 21 00:28:15 CET 2009