pennyworth
a natural language templating engine
usage
// build a template from a template stringvar template = pennyworth; // the template is a function that can be called with data at// any time and multiple times;
spec
variables
template: hello, $who.
- for
hello, alfred
=> $who =alfred
- for
hello, alfred. how are you?
=> $who =alfred how are you
- for
hello, how are you?
=> $who =how are you
template: hello, $who. how are you?
- for
hello, alfred.
=> $who =alfred
- for
hello, alferd. how are you?
=> $who =alfred
- for
hello, how are you?
=> $who = ``
variable filters
template: i am $x years old.
- for
i am 18 years old.
=> $x = "18"
template: i am $x:int years old.
- for
i am 18 years old
=> $x = 18
Supported filters: string, int, float, word.
Adding a new filter:
pennyworth; var template = pennyworth;who === 'alfred!'; // true
For asynchronous filters, grab a callback using this.async():
pennyworth;
named entities
pennyworth uses the Stanford NER for named entity filters.
Supported filters (from the 7 class model): Location, Person, Organization, Money, Percent, Date, Time
To use any, just use the entity type as the filter name:
For instance, for the input string My name is Alfred Pennyworth not Wayne Mansion.
, if you use the filter
'string': My name is $name:string
then the resolved name will be "Alfred Pennyworth not Wayne Mansion". But
if you use the filter 'person', the output will be "Alfred Pennyworth".
expander
to expand a set of arguments, use curly braces:
{hey, hi, hello}, there
will expand to:- hey, there.
- hi, there.
- hello, there.
conditional
to make a part of the expansion conditional, use a question mark:
i am $age {years?}
expands to:- i am $age
- i am $age years