Exercise 32: Large numbers

Summary

Implement a command and control grammar to recognize large numbers so that Grace can be asked things such as "What is five hundred and ninety times forty one"?

Enhance the voice command syntax to support named rules. For example:
number_part: {group_of_ten} {digit}

What this says is that a rule named number_part consists of a group_of_ten token followed by a digit token.

Allow rules to be referenced using the following syntax:
{number_part}

Since this overlaps the syntax used to reference an entity type, we will treat entity types as an implicit rule. If there is a rule that uses the same identifier, it will override the entity type.

Use the large number translations as a basis for the voice command grammar.

Solution

It appears that voice recognition grammar rules can't contain any circular references, so the transformations that I've been using can't be directly adapted. For the time being, I'm using the following:

small_number: [{digit} | {teen_number} | {group_of_ten} | {group_of_ten} {digit}]
number: [{small_number} | {small_number} {multiplier} | {small_number} {multiplier} (and) {small_number}]

The other issue I ran into is that my approach of enumerating all entity type permutations before trying to parse a phrase isn't scalable past about 6 words. I've bumped into it before, but it's a bit more obvious when dealing with numbers since numbers tend to be very wordy.

I think I'll take a crack at trying to rewrite this part of the language parsing algorithm to see whether it is possible to enumerate on the fly. I expect it is, and this approach might make the algorithm scalable up to say 10 words, or it might make it scalable past 15, it's hard to know.