diff --git a/core/data/en/global-resolvers/affirmation_denial.json b/core/data/en/global-resolvers/affirmation_denial.json index 38ba26691..95b5c6d58 100644 --- a/core/data/en/global-resolvers/affirmation_denial.json +++ b/core/data/en/global-resolvers/affirmation_denial.json @@ -7,7 +7,7 @@ "Yep", "Yup", "Yeah", - "Let's do it", + "Do [it|this|that]", "For sure", "Sure thing", "Of course!", @@ -30,6 +30,7 @@ "utterance_samples": [ "No", "No no don't", + "Stop it", "Nope", "Naa", "No thanks", diff --git a/scripts/train/train-resolvers-model/train-global-resolvers.js b/scripts/train/train-resolvers-model/train-global-resolvers.js index cce35fdaf..3460386fb 100644 --- a/scripts/train/train-resolvers-model/train-global-resolvers.js +++ b/scripts/train/train-resolvers-model/train-global-resolvers.js @@ -1,5 +1,6 @@ import path from 'path' import fs from 'fs' +import { composeFromPattern } from '@nlpjs/utils' import log from '@/helpers/log' @@ -28,7 +29,13 @@ export default (lang, nlp) => new Promise((resolve) => { nlp.assignDomain(lang, intent, 'system') for (let k = 0; k < intentObj.utterance_samples.length; k += 1) { - nlp.addDocument(lang, intentObj.utterance_samples[k], intent) + const utteranceSample = intentObj.utterance_samples[k] + // Achieve Cartesian training + const utteranceAlternatives = composeFromPattern(utteranceSample) + + utteranceAlternatives.forEach((utteranceAlternative) => { + nlp.addDocument(lang, utteranceAlternative, intent) + }) } } diff --git a/scripts/train/train-resolvers-model/train-skills-resolvers.js b/scripts/train/train-resolvers-model/train-skills-resolvers.js index a86012395..f2d4fb53c 100644 --- a/scripts/train/train-resolvers-model/train-skills-resolvers.js +++ b/scripts/train/train-resolvers-model/train-skills-resolvers.js @@ -1,5 +1,6 @@ import path from 'path' import fs from 'fs' +import { composeFromPattern } from '@nlpjs/utils' import log from '@/helpers/log' import domain from '@/helpers/domain' @@ -40,7 +41,12 @@ export default (lang, nlp) => new Promise(async (resolve) => { nlp.assignDomain(lang, intent, currentDomain.name) intentObj.utterance_samples.forEach((utteranceSample) => { - nlp.addDocument(lang, utteranceSample, intent) + // Achieve Cartesian training + const utteranceAlternatives = composeFromPattern(utteranceSample) + + utteranceAlternatives.forEach((utteranceAlternative) => { + nlp.addDocument(lang, utteranceAlternative, intent) + }) }) }) diff --git a/server/src/core/ner.js b/server/src/core/ner.js index a57849325..9db763d3d 100644 --- a/server/src/core/ner.js +++ b/server/src/core/ner.js @@ -49,6 +49,8 @@ class Ner { promises.push(this.injectRegexEntity(lang, entity)) } else if (entity.type === 'trim') { promises.push(this.injectTrimEntity(lang, entity)) + } else if (entity.type === 'enum') { + promises.push(this.injectEnumEntity(lang, entity)) } } @@ -140,6 +142,24 @@ class Ner { }) } + /** + * Inject enum type entities + */ + injectEnumEntity (lang, entity) { + return new Promise((resolve) => { + const { name: entityName, options } = entity + const optionKeys = Object.keys(options) + + optionKeys.forEach((optionName) => { + const { synonyms } = options[optionName] + + this.ner.addRuleOptionTexts(lang, entityName, optionName, synonyms) + }) + + resolve() + }) + } + /** * Get Microsoft builtin entities * https://github.com/axa-group/nlp.js/blob/master/packages/builtin-microsoft/src/builtin-microsoft.js diff --git a/skills/social_communication/mbti/nlu/en.json b/skills/social_communication/mbti/nlu/en.json index 0fb3b1736..09cb8ccce 100644 --- a/skills/social_communication/mbti/nlu/en.json +++ b/skills/social_communication/mbti/nlu/en.json @@ -3,10 +3,11 @@ "setup": { "type": "dialog", "utterance_samples": [ - "I want to know my MBTI personality type" + "I want to know my MBTI personality type", + "Start a personality type [quiz|questionnaire|test]" ], "answers": [ - "Alright, let's go!" + "Alright, let's go!

1/20
At a party do you:" ], "next_action": "quiz" }, @@ -34,24 +35,20 @@ "1_b": { "utterance_samples": [ "Interact with a few", - "Know to [me|you]" + "Known to [me|you]" ], "value": "1_b" }, "2_a": { "utterance_samples": [ - "Realistic than speculative", - "Not a dreamer", - "Believe in science" + "Head in the clouds", + "My head in the clouds" ], "value": "2_a" }, "2_b": { "utterance_samples": [ - "Speculative than realistic", - "Speculative", - "[like|love] to dream", - "A dreamer" + "In a rut" ], "value": "2_b" } @@ -59,5 +56,7 @@ } }, "answers": { + "2": ["%question%/20
Is it worse to:"], + "3": ["%question%/20
Is it worse to:"] } } diff --git a/skills/social_communication/mbti/src/actions/quiz.py b/skills/social_communication/mbti/src/actions/quiz.py index 41f8fc05a..1a793d6e6 100644 --- a/skills/social_communication/mbti/src/actions/quiz.py +++ b/skills/social_communication/mbti/src/actions/quiz.py @@ -2,6 +2,7 @@ # -*- coding:utf-8 -*- import utils +from ..lib import db def quiz(params): """TODO""" @@ -12,4 +13,18 @@ def quiz(params): if resolver['name'] == 'mbti_quiz': answer = resolver['value'] - print('answer', answer) + session = db.get_session() + + current_question = 1 + if session != None: + current_question = session['current_question'] + + db.upsert_session(current_question) + + current_question += 1 + + if current_question == 20: + # TODO + return utils.output('end', 'Your personality type is...', { 'isInActionLoop': False }) + + return utils.output('end', { 'key': current_question, 'data': { 'question': current_question }}) diff --git a/skills/social_communication/mbti/src/lib/db.py b/skills/social_communication/mbti/src/lib/db.py new file mode 100644 index 000000000..554b05ce5 --- /dev/null +++ b/skills/social_communication/mbti/src/lib/db.py @@ -0,0 +1,26 @@ +from time import time + +import utils + +# Skill database +db = utils.db()['db'] + +table = utils.db()['table'] + +# Session table +session_table = db.table('session') + +# Time stamp +timestamp = int(time()) + +def upsert_session(current_question): + """Save current question number""" + + session_table.upsert(table.Document({ + 'current_question': current_question + }, doc_id=0)) + +def get_session(): + """TODO""" + + return session_table.get(doc_id=0)