One way would be to delegate the external code to handle all the replies:
+ what is the capital of *
- <call>capital <star></call>
And then your macro would look up the answer. If the user said something completely invalid (“what is the capital of Mars?”), it could just return a whole response like “I don’t think that has a capital.”
Depending on how large the data set is, this would probably be the best way to do it so far. You could write a program to generate RiveScript code for you from a database, but the more triggers your RiveScript code has the slower the bot will be able to give a reply, as it has to scan through all the triggers until it finds a match. The speed difference is negligible for most bots, but becomes pretty apparent when you try to run a large bot like Alice in RiveScript ( https://github.com/aichaos/alice-benchmarks ).
For example, I was playing with adding emoji support to one of my RiveScript bots, so I wanted to generate a substitution file in RiveScript to replace emoji unicode symbols with friendlier names (source). It was auto-generating the RiveScript file from a “database” of sorts (a large JSON file), but there was just so much data that it would slow down reply fetching by a good amount (several seconds). I ended up pruning the list of supported emojis down to just those that I think are more commonly used (emoticons and common symbols).
Soon I’ll start playing with some ideas to optimize RiveScript so it can handle larger sets of data without slowing down.
For auto-generating RiveScript source code, though, some implementations support methods to help with that. The JavaScript and Perl versions has functions like `deparse()` and `write()/stringify()`—if you give a data structure to `write()` that looks like the sort of data you got from `deparse()`, it can do all the heavy lifting of writing it as RiveScript code.