Recording what was said for further use
Sometimes you need to record what you just said to keep that information for the upcoming texts. For instance you mention the brand of the product in some mixin, and you have another mixin which can also trigger the brand: you might only want to output the brand once.
You might wonder why you can not just use global variables to record what was said. The problem is that RosaeNLG needs to go back and forth in the text generation (typically to predict which synonymic alternatives are empty), and this means that you must not use global variables to record what was said, because RosaeNLG will not be able to rollback after a synonym simulation.
Thus you should use
hasSaid. They basically only are accessors to an internal map, which is properly rollbacked when necessary.
This will only output brand is … once.
recordSaid(key): to record that something was said.
hasSaid(key): returns a boolean indicating if something was said.
deleteSaid(key): forget that something was said.
dumpHasSaidto console output what is in the internal map.
getDumpHasSaid: returns a string containing the JSON serialized map
getHasSaidCopy: returns a copy of the map as an object
You can use
Behind the scenes,
deleteSaid store booleans in a managed hashmap. You can use the same hashmap to store values. Typically you could count how many times you have talked about something.
recordValue(key, val)records a value for a given key
getValue(key)returns the stored value for a key
deleteValue(key)to delete a key
This will only output product twice.
|You can only store numbers or strings, but not complex objects.|