Skip to content

Commit

Permalink
fix mutability issue with cache
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigopivi committed Apr 3, 2018
1 parent 9aaba94 commit af0567e
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 3 deletions.
61 changes: 61 additions & 0 deletions core/__snapshots__/core.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,67 @@ Object {
}
`;

exports[`test passing optional alias to two entities with opt and non opt works fine with caching 1`] = `
Object {
"rasa_nlu_data": Object {
"common_examples": Array [
Object {
"entities": Array [],
"intent": "greet",
"text": "hola botname1",
},
Object {
"entities": Array [],
"intent": "greet",
"text": "hola botname2",
},
Object {
"entities": Array [],
"intent": "greet",
"text": "hola",
},
Object {
"entities": Array [],
"intent": "greet",
"text": "buenas botname1",
},
Object {
"entities": Array [],
"intent": "greet",
"text": "buenas botname2",
},
Object {
"entities": Array [],
"intent": "greet",
"text": "buenas",
},
Object {
"entities": Array [],
"intent": "goodbye",
"text": "chao botname1",
},
Object {
"entities": Array [],
"intent": "goodbye",
"text": "chao botname2",
},
Object {
"entities": Array [],
"intent": "goodbye",
"text": "adios botname1",
},
Object {
"entities": Array [],
"intent": "goodbye",
"text": "adios botname2",
},
],
"entity_synonyms": Array [],
"regex_features": Array [],
},
}
`;

exports[`test pegjs parser output 1`] = `
"[
{
Expand Down
23 changes: 23 additions & 0 deletions core/core.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,3 +411,26 @@ test("test passing optional alias once and once not and caching works", () => {
expect(error).toBeNull();
expect(result).toMatchSnapshot();
});

test("test passing optional alias to two entities with opt and non opt works fine with caching", () => {
let error = null;
let result = null;
const input = `
%[greet]
hola ~[bot?]
buenas ~[bot?]
%[goodbye]
chao ~[bot]
adios ~[bot]
~[bot]
botname1
botname2
`;
try {
result = generator.datasetFromString(input, "rasa");
} catch (e) { error = e; }
expect(error).toBeNull();
expect(result).toMatchSnapshot();
});
2 changes: 1 addition & 1 deletion core/datasetGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ function getVariationsFromEntity(e, defs, parentEntity, isTheOnlyEntityOfASenten
}
let variations = [];
if (cache[e.type] && cache[e.type][e.id]) {
variations = cache[e.type][e.id];
variations = [].concat(cache[e.type][e.id]);
} else {
sentences.forEach(s => {
variations = variations.concat(getVariationsFromSentence(s, defs, null, e, cache));
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chatito",
"version": "1.2.1",
"version": "1.2.2",
"description": "Generate training datasets for slot filling chatbots in a breeze using a simple DSL",
"bin": {
"chatito": "./bin/chatito.js"
Expand Down

0 comments on commit af0567e

Please sign in to comment.