Recording what was said for further use

This is the documentation for 3.0.2 version, which is not the latest version. Consider upgrading to 4.3.0.

recordSaid, hasSaid and deleteSaid

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 recordSaid and hasSaid. They basically only are accessors to an internal map, which is properly rollbacked when necessary.

This will only output brand is …​ once.

Reference:

  • 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.

  • dumpHasSaid to 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 recordSaid('BRAND') or - recordSaid('BRAND'); - it is the same.

recordValue, getValue and deleteValue

Behind the scenes, recordSaid, hasSaid and 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.