

3. Usage

First, start the swi-prolog CLI.
$swi-pl

Than, compile and load the program

?- ['grammar.pl'].
%  transducer compiled into transducer 0.00 sec, 10,916 bytes
% grammar.pl compiled 0.03 sec, 98,280 bytes

Yes
?-

Loading the grammar is done using the 'load_grammar' predicate. This predicate 
loads all grammar files included by the main grammar file, lexicon files, and
builds affix domains and lexicon sets.

?- load_grammar('meko.gra').
Loading grammar from file meko.gra
The End
Loading lexicon smallex.dat
The End
Building affix domains
Finished creating lexsets

Yes
?-

There is one single important predicate used to generate a phrase matching a
nonterminal: 'generate_nonterminal'. It takes 3 parameters: the name of the
nonterminal, the variable that takes the generated string and a list of affix
values for this nonterminal. 

Suppose we have the following definitions:

NUMB :: sing | plur.
PERS :: first | second | third.

verbpart(NUMB, PERS): ....

To generate a phrase that matches verbpart of any number and first or second person
we issue the following predicate call:

?- generate_nonterminal(verbpart, I, ['NUMB', [first,second]]).

To generate a phrase that matches any combination of affix values:

?- generate_nonterminal(verbpart, I, ['NUMB', 'PERS']).

To generate a singular verbpart for the first or third person:

?- generate_nonterminal(verbpart, I, [[sing],[first,third]]).

To generate a complete sentence we could use the generate_nonterminal predicate
if we know the root nonterminal, or use the generate_sentence predicate, that
takes only one argument, the variable that will take the generate string.

?- generate_sentence(I).

To control the ammount of information displayed during generation we use a number
of globally declared clauses, named attributes. To change the value of an attribute
issue the following call:

?- set_attribute(<Name>, <Value>).

Current attributes values are:

stepbystep - it allows the user to watch closely every step of the generation process.
	It requires the user to press Enter for the next step to occur. The user can 
	exit the stepbystep mode by pressing space. Values accepted: true, false. 
	Default value: false.

show_trace - it activates/deactivates the printing of the generation trace. 
	Accepted values: true, false. Default: true.

step_on_backtrack - it allows the user to specify that when a rule can't be satisfied 
	with the current affix values, the generator should automatically turn into
	stepbystep mode, so that the process of backtracking to other alternatives
	can be inspected.
	Accepted values: true, false. Default: false.

