Namespaces#

Usually there is no problem with the order in which rules work: first all lexicons are run and then the rules will be run in the order that they require.

For example, consider my file farming.wow

lexicon: (input="stem")
{
    duck,
    pig,
    sheep,
    horse,
    pony
} = FarmAnimal;

lexicon: (input="normalized_literal")
{
    old macdonald,
    colonel sanders
}= Farmer;

//----------------------------
// old MacDonald has 3 ducks
//----------------------------
rule:
{
    Farmer
    'have'
    (
        ('\,'|'and')?
        FarmAnimalCount
    )+
} = FarmerAnimalRelation;

//-------------
// 3 ducks
//-------------
rule:
{
    Num FarmAnimal
} = FarmAnimalCount;

First the lexicons FarmAnimal and Farmer are run. The rule FarmerAnimalRelation, needs to have an annotation called FarmAnimalCount, so that one will be run first. Finally FarmerAnimalRelation will run. We will get as a result:

wow -p "english,rules" -i 'old macdonald had 2 ducks, 3 pigs and 1 horse' --tool stagger
FarmerAnimalRelation -> old macdonald had 2 ducks , 3 pigs and 1 horse
Farmer -> old macdonald
FarmAnimalCount -> 2 ducks
FarmAnimal -> ducks
FarmAnimalCount -> 3 pigs
FarmAnimal -> pigs
FarmAnimalCount -> 1 horse
FarmAnimal -> horse

But sometimes, when you are dealing with a complicated domain you want to make sure that the rules are run in the order that you intend, for example, when you want to run the filters last to remove unwanted results, or just for the sake of clarity, you want to group some rules together. For that purpose you can use namespace.

Namespaces help you to determine the order in which rules run.

the syntax is the following:

namespace namespace_name {
        rule : {... };
        rule : {... };
      ...
}

Built-in namespaces are: conjecture, grammar, entities, anaphora, in that order.

All other namespaces run in alphabetical order!! take this into account. An easy way to organize is to add a number at the end:

namespace pass_0 { ... }
namespace pass_1 { ... }