mirror of
https://github.com/leon-ai/leon.git
synced 2024-11-27 16:16:48 +03:00
feat: add Cartesian sample training on resolvers + enum entities
This commit is contained in:
parent
eb5ade7684
commit
6ed88a5946
@ -7,7 +7,7 @@
|
|||||||
"Yep",
|
"Yep",
|
||||||
"Yup",
|
"Yup",
|
||||||
"Yeah",
|
"Yeah",
|
||||||
"Let's do it",
|
"Do [it|this|that]",
|
||||||
"For sure",
|
"For sure",
|
||||||
"Sure thing",
|
"Sure thing",
|
||||||
"Of course!",
|
"Of course!",
|
||||||
@ -30,6 +30,7 @@
|
|||||||
"utterance_samples": [
|
"utterance_samples": [
|
||||||
"No",
|
"No",
|
||||||
"No no don't",
|
"No no don't",
|
||||||
|
"Stop it",
|
||||||
"Nope",
|
"Nope",
|
||||||
"Naa",
|
"Naa",
|
||||||
"No thanks",
|
"No thanks",
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import path from 'path'
|
import path from 'path'
|
||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
|
import { composeFromPattern } from '@nlpjs/utils'
|
||||||
|
|
||||||
import log from '@/helpers/log'
|
import log from '@/helpers/log'
|
||||||
|
|
||||||
@ -28,7 +29,13 @@ export default (lang, nlp) => new Promise((resolve) => {
|
|||||||
nlp.assignDomain(lang, intent, 'system')
|
nlp.assignDomain(lang, intent, 'system')
|
||||||
|
|
||||||
for (let k = 0; k < intentObj.utterance_samples.length; k += 1) {
|
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)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import path from 'path'
|
import path from 'path'
|
||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
|
import { composeFromPattern } from '@nlpjs/utils'
|
||||||
|
|
||||||
import log from '@/helpers/log'
|
import log from '@/helpers/log'
|
||||||
import domain from '@/helpers/domain'
|
import domain from '@/helpers/domain'
|
||||||
@ -40,7 +41,12 @@ export default (lang, nlp) => new Promise(async (resolve) => {
|
|||||||
nlp.assignDomain(lang, intent, currentDomain.name)
|
nlp.assignDomain(lang, intent, currentDomain.name)
|
||||||
|
|
||||||
intentObj.utterance_samples.forEach((utteranceSample) => {
|
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)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -49,6 +49,8 @@ class Ner {
|
|||||||
promises.push(this.injectRegexEntity(lang, entity))
|
promises.push(this.injectRegexEntity(lang, entity))
|
||||||
} else if (entity.type === 'trim') {
|
} else if (entity.type === 'trim') {
|
||||||
promises.push(this.injectTrimEntity(lang, entity))
|
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
|
* Get Microsoft builtin entities
|
||||||
* https://github.com/axa-group/nlp.js/blob/master/packages/builtin-microsoft/src/builtin-microsoft.js
|
* https://github.com/axa-group/nlp.js/blob/master/packages/builtin-microsoft/src/builtin-microsoft.js
|
||||||
|
@ -3,10 +3,11 @@
|
|||||||
"setup": {
|
"setup": {
|
||||||
"type": "dialog",
|
"type": "dialog",
|
||||||
"utterance_samples": [
|
"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": [
|
"answers": [
|
||||||
"Alright, let's go!"
|
"Alright, let's go!<br><br>1/20<br>At a party do you:<ul><li>a. Interact with many, including strangers</li><li>b. Interact with a few, known to you</li></ul>"
|
||||||
],
|
],
|
||||||
"next_action": "quiz"
|
"next_action": "quiz"
|
||||||
},
|
},
|
||||||
@ -34,24 +35,20 @@
|
|||||||
"1_b": {
|
"1_b": {
|
||||||
"utterance_samples": [
|
"utterance_samples": [
|
||||||
"Interact with a few",
|
"Interact with a few",
|
||||||
"Know to [me|you]"
|
"Known to [me|you]"
|
||||||
],
|
],
|
||||||
"value": "1_b"
|
"value": "1_b"
|
||||||
},
|
},
|
||||||
"2_a": {
|
"2_a": {
|
||||||
"utterance_samples": [
|
"utterance_samples": [
|
||||||
"Realistic than speculative",
|
"Head in the clouds",
|
||||||
"Not a dreamer",
|
"My head in the clouds"
|
||||||
"Believe in science"
|
|
||||||
],
|
],
|
||||||
"value": "2_a"
|
"value": "2_a"
|
||||||
},
|
},
|
||||||
"2_b": {
|
"2_b": {
|
||||||
"utterance_samples": [
|
"utterance_samples": [
|
||||||
"Speculative than realistic",
|
"In a rut"
|
||||||
"Speculative",
|
|
||||||
"[like|love] to dream",
|
|
||||||
"A dreamer"
|
|
||||||
],
|
],
|
||||||
"value": "2_b"
|
"value": "2_b"
|
||||||
}
|
}
|
||||||
@ -59,5 +56,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"answers": {
|
"answers": {
|
||||||
|
"2": ["%question%/20<br>Is it worse to:<ul><li>a. Have your \"head in the clouds\"</li><li>b. Be \"in a rut\"</li></ul>"],
|
||||||
|
"3": ["%question%/20<br>Is it worse to:<ul><li>a. Have your \"head in the clouds\"</li><li>b. Be \"in a rut\"</li></ul>"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
# -*- coding:utf-8 -*-
|
# -*- coding:utf-8 -*-
|
||||||
|
|
||||||
import utils
|
import utils
|
||||||
|
from ..lib import db
|
||||||
|
|
||||||
def quiz(params):
|
def quiz(params):
|
||||||
"""TODO"""
|
"""TODO"""
|
||||||
@ -12,4 +13,18 @@ def quiz(params):
|
|||||||
if resolver['name'] == 'mbti_quiz':
|
if resolver['name'] == 'mbti_quiz':
|
||||||
answer = resolver['value']
|
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 }})
|
||||||
|
26
skills/social_communication/mbti/src/lib/db.py
Normal file
26
skills/social_communication/mbti/src/lib/db.py
Normal file
@ -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)
|
Loading…
Reference in New Issue
Block a user