improv
improv copied to clipboard
Filtering tags fails on submodels
Attempting to apply filters or any options that look at the tags of a model seems to fail in the context of submodels. Here I try using submodels to make different characters in a sentence speak consistently:
const Improv = require('improv');
const spec = {
name: {
bind: true,
groups: [
{
tags: [['nationality', 'spanish']],
phrases: ['Carmen', 'Miguel', 'Jose']
},
{
tags: [['nationality', 'french']],
phrases: ['Guy', 'Pierre', 'Wes']
}
]
},
say_hello: {
groups: [
{
tags: [['nationality', 'spanish']],
phrases: ['[:name] says "Hola!"']
},
{
tags: [['nationality', 'french']],
phrases: ['[:name] says "Bonjour!"']
}
]
},
root: {
groups: [
{
tags: [],
phrases: [
'[>actorA:name] walks up to [>actorB:name]. [>actorA:say_hello] and [>actorB:say_hello].'
]
}
]
}
};
const improv = new Improv(spec, {
filters: [Improv.filters.mismatchFilter()],
reincorporate: true
});
const myModel = {};
const text = improv.gen('root', myModel);
console.log(myModel);
console.log(text);
Running this results in the following error:
G:\Code\textgen\node_modules\improv\dist\filters.js:41
var matched = model.tags.find(function (modelTag) {
^
TypeError: Cannot read property 'find' of undefined
at G:\Code\textgen\node_modules\←[4mimprov←[24m\dist\filters.js:41:30
at Array.find (<anonymous>)
at Improv.mismatchFilterSub (G:\Code\textgen\node_modules\←[4mimprov←[24m\dist\filters.js:39:27)
at Improv.applyFilterToGroup (G:\Code\textgen\node_modules\←[4mimprov←[24m\dist\index.js:191:27)
at Array.forEach (<anonymous>)
at Improv.applyFiltersToGroup (G:\Code\textgen\node_modules\←[4mimprov←[24m\dist\index.js:210:20)
at G:\Code\textgen\node_modules\←[4mimprov←[24m\dist\index.js:232:22
at Array.map (<anonymous>)
at Improv.applyFilters (G:\Code\textgen\node_modules\←[4mimprov←[24m\dist\index.js:231:21)
at Improv.__gen (G:\Code\textgen\node_modules\←[4mimprov←[24m\dist\index.js:83:66)
I tried putting a console.log in the filter function and it seems to think model
is a string for some reason instead of an object.