-
-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* nlp * split nodes * entity node * language drop down * save and load model * cleanup * cleanup and language guess * xleanup * tests for entity * test intent * test nlp train and process * cleanup * update docs * refactor language node * language rule * rule isLanguage * lint * fix text language * update docs
- Loading branch information
Showing
31 changed files
with
3,240 additions
and
336 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
const _ = require('underscore'); | ||
const assert = require('chai').assert; | ||
const RED = require('../lib/red-stub')(); | ||
const NLPEntityBlock = require('../nodes/chatbot-nlp-entity'); | ||
|
||
require('../lib/platforms/telegram'); | ||
require('../lib/platforms/slack'); | ||
|
||
describe('Chat nlp entity node', () => { | ||
|
||
it('set the entity payload', () => { | ||
const msg = RED.createMessage(); | ||
RED.node.config({ | ||
name: 'fruits', | ||
language: 'en', | ||
entities: [ | ||
{ name: 'orange' }, | ||
{ name: 'apple', aliases: ['golden apple', 'granny smith apple'] } | ||
] | ||
}); | ||
NLPEntityBlock(RED); | ||
RED.node.get().emit('input', msg); | ||
return RED.node.get().await() | ||
.then(() => { | ||
const payload = RED.node.message().payload; | ||
assert.isObject(payload); | ||
assert.isObject(payload.entities); | ||
assert.isObject(payload.entities.en); | ||
assert.isArray(payload.entities.en.fruits); | ||
assert.lengthOf(payload.entities.en.fruits, 2); | ||
assert.equal(payload.entities.en.fruits[0].name, 'orange'); | ||
assert.equal(payload.entities.en.fruits[1].name, 'apple'); | ||
assert.isArray(payload.entities.en.fruits[1].aliases); | ||
assert.lengthOf(payload.entities.en.fruits[1].aliases, 2); | ||
assert.equal(payload.entities.en.fruits[1].aliases[0], 'golden apple'); | ||
assert.equal(payload.entities.en.fruits[1].aliases[1], 'granny smith apple'); | ||
}); | ||
|
||
}); | ||
|
||
it('set the entity payload from message', () => { | ||
const msg = RED.createMessage({ | ||
name: 'fruits', | ||
language: 'en', | ||
entities: [ | ||
{ name: 'orange' }, | ||
{ name: 'apple', aliases: ['golden apple', 'granny smith apple'] } | ||
] | ||
}); | ||
RED.node.config({}); | ||
NLPEntityBlock(RED); | ||
RED.node.get().emit('input', msg); | ||
return RED.node.get().await() | ||
.then(() => { | ||
const payload = RED.node.message().payload; | ||
assert.isObject(payload); | ||
assert.isObject(payload.entities); | ||
assert.isObject(payload.entities.en); | ||
assert.isArray(payload.entities.en.fruits); | ||
assert.lengthOf(payload.entities.en.fruits, 2); | ||
assert.equal(payload.entities.en.fruits[0].name, 'orange'); | ||
assert.equal(payload.entities.en.fruits[1].name, 'apple'); | ||
assert.isArray(payload.entities.en.fruits[1].aliases); | ||
assert.lengthOf(payload.entities.en.fruits[1].aliases, 2); | ||
assert.equal(payload.entities.en.fruits[1].aliases[0], 'golden apple'); | ||
assert.equal(payload.entities.en.fruits[1].aliases[1], 'granny smith apple'); | ||
}); | ||
|
||
}); | ||
|
||
it('set the entity payload from message and append to previous', () => { | ||
const msg = RED.createMessage({ | ||
entities: { | ||
en: { | ||
fruits: [ | ||
{ name: 'banana' } | ||
] | ||
} | ||
} | ||
}); | ||
RED.node.config({ | ||
name: 'fruits', | ||
language: 'en', | ||
entities: [ | ||
{ name: 'orange' }, | ||
{ name: 'apple', aliases: ['golden apple', 'granny smith apple'] } | ||
] | ||
}); | ||
NLPEntityBlock(RED); | ||
RED.node.get().emit('input', msg); | ||
return RED.node.get().await() | ||
.then(() => { | ||
const payload = RED.node.message().payload; | ||
assert.isObject(payload); | ||
assert.isObject(payload.entities); | ||
assert.isObject(payload.entities.en); | ||
assert.isArray(payload.entities.en.fruits); | ||
assert.lengthOf(payload.entities.en.fruits, 3); | ||
assert.equal(payload.entities.en.fruits[0].name, 'banana'); | ||
assert.equal(payload.entities.en.fruits[1].name, 'orange'); | ||
assert.equal(payload.entities.en.fruits[2].name, 'apple'); | ||
assert.isArray(payload.entities.en.fruits[2].aliases); | ||
assert.lengthOf(payload.entities.en.fruits[2].aliases, 2); | ||
assert.equal(payload.entities.en.fruits[2].aliases[0], 'golden apple'); | ||
assert.equal(payload.entities.en.fruits[2].aliases[1], 'granny smith apple'); | ||
}); | ||
}); | ||
|
||
}); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
const _ = require('underscore'); | ||
const assert = require('chai').assert; | ||
const RED = require('../lib/red-stub')(); | ||
const NLPEntityBlock = require('../nodes/chatbot-nlp-intent'); | ||
|
||
require('../lib/platforms/telegram'); | ||
require('../lib/platforms/slack'); | ||
|
||
describe('Chat nlp intent node', () => { | ||
|
||
it('set the intent payload', () => { | ||
const msg = RED.createMessage(); | ||
RED.node.config({ | ||
intent: 'switch.on', | ||
language: 'en', | ||
utterances: [ | ||
'switch on the lights', | ||
'turn on the lights' | ||
] | ||
}); | ||
NLPEntityBlock(RED); | ||
RED.node.get().emit('input', msg); | ||
return RED.node.get().await() | ||
.then(() => { | ||
const payload = RED.node.message().payload; | ||
assert.isObject(payload); | ||
assert.isObject(payload.intents); | ||
assert.isObject(payload.intents.en); | ||
assert.isArray(payload.intents.en['switch.on']); | ||
assert.lengthOf(payload.intents.en['switch.on'], 2); | ||
assert.equal(payload.intents.en['switch.on'][0], 'switch on the lights'); | ||
assert.equal(payload.intents.en['switch.on'][1], 'turn on the lights'); | ||
|
||
}); | ||
}); | ||
|
||
it('set the intent payload from message', () => { | ||
const msg = RED.createMessage({ | ||
intent: 'switch.on', | ||
language: 'en', | ||
utterances: [ | ||
'switch on the lights', | ||
'turn on the lights' | ||
] | ||
}); | ||
RED.node.config({}); | ||
NLPEntityBlock(RED); | ||
RED.node.get().emit('input', msg); | ||
return RED.node.get().await() | ||
.then(() => { | ||
const payload = RED.node.message().payload; | ||
assert.isObject(payload); | ||
assert.isObject(payload.intents); | ||
assert.isObject(payload.intents.en); | ||
assert.isArray(payload.intents.en['switch.on']); | ||
assert.lengthOf(payload.intents.en['switch.on'], 2); | ||
assert.equal(payload.intents.en['switch.on'][0], 'switch on the lights'); | ||
assert.equal(payload.intents.en['switch.on'][1], 'turn on the lights'); | ||
|
||
}); | ||
}); | ||
|
||
it('set the intent payload and append to previous', () => { | ||
const msg = RED.createMessage({ | ||
intents: { | ||
en: { | ||
'switch.on': ['switch on all the lights'] | ||
}, | ||
it: { | ||
'switch.on': ['appiccia la luce'] | ||
} | ||
} | ||
}); | ||
RED.node.config({ | ||
intent: 'switch.on', | ||
language: 'en', | ||
utterances: [ | ||
'switch on the lights', | ||
'turn on the lights' | ||
] | ||
}); | ||
NLPEntityBlock(RED); | ||
RED.node.get().emit('input', msg); | ||
return RED.node.get().await() | ||
.then(() => { | ||
const payload = RED.node.message().payload; | ||
assert.isObject(payload); | ||
assert.isObject(payload.intents); | ||
assert.isObject(payload.intents.en); | ||
assert.isArray(payload.intents.en['switch.on']); | ||
assert.lengthOf(payload.intents.en['switch.on'], 3); | ||
assert.equal(payload.intents.en['switch.on'][0], 'switch on all the lights'); | ||
assert.equal(payload.intents.en['switch.on'][1], 'switch on the lights'); | ||
assert.equal(payload.intents.en['switch.on'][2], 'turn on the lights'); | ||
assert.isArray(payload.intents.it['switch.on']); | ||
assert.lengthOf(payload.intents.it['switch.on'], 1); | ||
assert.equal(payload.intents.it['switch.on'][0], 'appiccia la luce'); | ||
}); | ||
}); | ||
}); | ||
|
Oops, something went wrong.