Grail Tutorial - Debugging Grammars

When using the optimization options, it can happen that Grail fails to find a proof when you are convinced there should be one. This section lists several of the more common reasons why Grail may exclude a proof and how to modify your grammar file or the Grail invocation to deal with this.

Grail fails directly

This is usually caused by an error in the lexicon. Grail uses a property call the count check which verifies that all positive and negative atomic categories occur the same number of times.

Given that a parse is valid only if we can contract it to a tree with only lexical leaves and the Goal node as its root, this means that all positive and negative atomic formulas need to be eliminated. Since each substitution cancels a positive and a negative atomic formula of the same type, this makes the count check an easy verification to perform to exclude graphs which are sure to be invalid.

If a lexical lookup is invalid, Grail will print an error message to the terminal - indicating one of the atomic categories which occurs either too few or too many times - and continue with the next lookup and if no other lookups exist for the sentence, Grail will fail. In order to verify your grammar is correct, open the file lookup.dot which is in your current working directory. This lists all the possible lexical lookups for each word and allows you to verify there is a problem with your grammar.

A second option is that your sentence passes the count check for at least one of its lookups but that the optimization parameters specified for the grammar excludes all substitutions for your grammar. We'll deal with how to correct this next.

Grail refuses to make an atomic substitution

When Grail refuses to make an atomic substitution you think is essential for your derivation, this is an indication that your optimization settings are probably overeager. There are several ways to check where things go wrong.
  1. Restart Grail using the g3 nozeroheap command line option. This will show all possible axiom linking for the current lexical lookup even if one or more atoms have zero substitution possibilities.
  2. Comment out all optimization options in your grammar files (you can comment out a line of a Prolog program by prefixing % to it) . The declarations to comment out are:
  3. Finally, when all else fails, the log file grail_log logs all attempts at connecting axioms and indicates which of the first order labeling or the inert declarations is to blame for a connection failures.

Grail refuses to contract an auxiliary connection

There are a number of common mistakes in your grammar which can cause a contraction to fail. Look at the graph which fails to contract and verify the following.
  1. Assure yourself first that the main and the auxiliary constructor are connected at two points and that both of these points are connected to both of the constructor by a tentacle with the same label.
  2. Then check that neither of the two points which are connected by both paired links have the arrow of the auxiliary constructor pointing towards them.
  3. Finally, verify that both constructors have the same mode i indicated inside of their central circle. If node modes are indicated anywhere, your grammar is unimodal and this shouldn't be a problem.
In case one of these conditions is not respected, the contraction will fail. This can mean either that there is an error in the lexical graph (for example and error in the left/right direction of one of the connections) or that a structural rule fails to apply.

Grail complains about word order

Sometimes, Grail will manage to contract the input graph to a tree, but with the yield of this tree not corresponding to the word order of the input sentence. In this case, Grail will print out an error message and try to find another substitution which does produce the required word order.

Of course, this automatically means Grail can derive the current sentence in the word order indicated. If this is not what you want, there is probably an error in either your lexicon or your structural rules.

Similarly, if Grail fails to derive the desired word order, this can be a problem of missing graph in the lexicon or a missing structural rule in the grammar. When writing a grammar, you should always strive to strike a careful balance between lexical ambiguity and the number of structural rules in your grammar. Ideally, your grammar should both have a restricted number of lexical graphs for each word and a restricted number of structural rules.

Grail connects and contracts everything but reports failure in spite of this

Another source of errors is the absence of external modes. This is especially the case for grammars created by editing a file. When Grail has succeeded performing all contractions, it filters the resulting shared forest keeping only the modes which have been declared as external by your grammar. In case there are no trees consisting exclusively of branches of external modes, the parse is considered to have failed.

The quick fix is to add the following declarations to your grammar

external(_).
external_dia(_).

Though a powerful a commonly used tool, the use of external declarations should be used with care and their complete absence is almost certainly an error of the grammar writer.

Inspecting the log file

While executing a syntactic analysis, Grail outputs a lot of information in the file grail_log in the current working directory (the same directory where Grail puts all the output files for Graphviz and LaTeX).

Grail puts a lot of information in this file, so if you want to inspect the grail_log, it is recommended that you

  1. exit Grail,
  2. then restart Grail and reload your grammar,
  3. parse the sentence which failed to parse,
  4. exit Grail directly afterwards.

Using the Prolog debugger

The brave of heart can try the Prolog debugger in order to debug their grammars.
Last modified: Thu Apr 14 16:50:55 CEST 2011