我有3个数据集:
patterns=[
"[foo] is a [bar]",
"[foo] is not a [bar]",
"[foo] could be a [bar]"
]
fooSet=[
"a","b", "c"
]
barSet = [
"d", "e", "f"
]
这些数据集将是动态的,它可能是5种不同的模式和4种数据集,我已经尝试过每次使用lodash和各种循环,但我所拥有的只是这样的东西:
{{country}}中的{{cost}}“
{{country}}中的“{{cost}}”狗
“{{animal}} in mex for {{cost}}”
{{cost}}“
在美国的”{{animal}} {p}} {{country}}中的{{animal}}便宜“ {p}} {{country}}中的{{animal}}代价昂贵的“使用此数据集:
{{animal}} in {{country}} for {{cost}}
cat
dog
iguana
bird
usa
mexico
denmark
cheap
expensive
good price
这是我的代码:
generateKeywords() {
//first get an array of patterns
var patternArray = this.patterns.split(',');
_this = this;
newArrayOfPatterns = [];
_.each(this.elements, function(element) {
_.each(patternArray, function(pattern) {
subset = element.list_of_variations.split('\n');
_.each(subset, function(val) {
result = pattern.replace(element.element_caught, val);
newArrayOfPatterns.push(result);
})
});
})
}
其中,元素是包含单词和模式的对象,是模式数组