Monday 2 February 2015

new function: int-coeffs-to-word

I've been meaning to write this one for ages and ages. Finally got around to it. Had to add a new operator type in the parsers function tables, though. But I'm not in the mood to explain details. Anyway, let's explain how it works.

int-coeffs-to-word n |x> == |no plural(x)> (if int(n) == 0)
int-coeffs-to-word n |x> == |no x>             (if int(n) == 0, and plural is not defined)
int-coeffs-to-word n |x> == |1 x>               (if int(n) == 1)
int-coeffs-to-word n |x> == |n plural(x)>   (if int(n) != 1 and plural is defined)
int-coeffs-to-word n |x> == |n x>               (if int(n) != 1 and plural is not defined)

Let's load up some plurals (yeah, omitting the "word" data-type):
plural |*> #=> merge-labels(|_self> + |s>)
plural |foot> => |feet>
plural |mouse> => |mice>
plural |radius> => |radii>
plural |tooth> => |teeth>
plural |person> => |people> 
And give an example:
sa: int-coeffs-to-word (|apple> + 3|mouse> + 2|tooth> + 9|cat>)
|1 apple> + |3 mice> + |2 teeth> + |9 cats>
Now as a sentence fragment:
sa: list-to-words int-coeffs-to-word (|apple> + 3|mouse> + 2|tooth> + 9|cat>)
|1 apple, 3 mice, 2 teeth and 9 cats>
And we finish with a fun one:
sa: list-to-words int-coeffs-to-word (2|ear> + 2|eye> + |nose> + 0|tooth>)
|2 ears, 2 eyes, 1 nose and no teeth> 
And that's it for this post. Simple, fun, and slowly working towards natural language. Also, thanks to this post I found a serious bug in context.recall(). Fix was easy enough, thankfully.

No comments:

Post a Comment