Skip to content

Commit

Permalink
forget命令完成
Browse files Browse the repository at this point in the history
  • Loading branch information
gutrse3321 committed Jun 30, 2018
1 parent ab9df0b commit 8b48aba
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 12 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "marisa",
"productName": "marisa",
"version": "0.0.001",
"version": "0.0.1",
"author": "gutrse3321 <[email protected]>",
"description": "大家的老朋友,莎莎",
"license": "",
Expand All @@ -20,6 +20,7 @@
"pack": "npm run pack:main && npm run pack:renderer",
"pack:main": "cross-env NODE_ENV=production webpack --progress --colors --config .electron-vue/webpack.main.config.js",
"pack:renderer": "cross-env NODE_ENV=production webpack --progress --colors --config .electron-vue/webpack.renderer.config.js",
"packorder": "npm run pack && electron-packager . --overwrite --asar=true --icon=./src/renderer/assets/icon.ico",
"postinstall": "npm run lint:fix"
},
"dependencies": {
Expand Down
30 changes: 26 additions & 4 deletions src/renderer/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ segment.useDefault()

export default class MarisaCore {
/**
* 魔理沙与你的说话格式
* 魔理沙与你的说话格式,以及处理You的说话格式
* @param {String} name
* @param {String} content
*/
Expand All @@ -28,7 +28,7 @@ export default class MarisaCore {
let keywords = []

// 处理获取的_content到数据库去遍历查询
// 大于80%就回复对应回答
// 大于60%就回复对应回答
for (let i = 0; i < memorise.length; i++) {
let ratio = 0
keywords = memorise[i].keyword
Expand All @@ -38,7 +38,7 @@ export default class MarisaCore {
ratio++
}
})
if ((ratio / keywords.length) >= 0.5) {
if ((ratio / keywords.length) >= 0.6) {
answer = memorise[i].answer
break
}
Expand Down Expand Up @@ -70,7 +70,7 @@ export default class MarisaCore {
ratio++
}
})
if ((ratio / keywords.length) >= 0.5) {
if ((ratio / keywords.length) >= 0.6) {
keywords.concat(toPpl)
// 去除重复的关键词或字
keywords = Array.from(new Set(keywords.filter((x, i, self) => self.indexOf(x) === i)))
Expand All @@ -90,4 +90,26 @@ export default class MarisaCore {
}
return memorey
}

/**
* 魔理沙记忆消除中枢
* @param {Array} list
*/
static forget (list) {
let answers = []
list.forEach((item) => {
if (item.name === '白絲魔理沙') {
answers.push(item)
}
})
if (answers.length > 1) {
let finder = db.get('memorise').find({answer: answers[answers.length - 1].content}).value()
if (finder !== undefined) {
db.get('memorise').remove({answer: finder.answer}).write()
return true
} else {
return false
}
}
}
}
23 changes: 16 additions & 7 deletions src/renderer/views/Home/chatroom.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@
<span class="marisa-cmd">teach</span>&nbsp;进入内容教学模式
</span>
<span class="system-cmd cmd-collect">
<del>
<span class="marisa-cmd">forget</span>&nbsp;忘记最后所说的内容</del>
<span class="marisa-cmd">forget</span>&nbsp;忘记最后所说的内容
</span>
<span class="system-cmd cmd-collect">
<del>
<span class="marisa-cmd">application</span>&nbsp;管理外部应用接口</del>
<del><span class="marisa-cmd">application</span>&nbsp;管理外部应用接口</del>
</span>
<span class="system-cmd cmd-collect">
<span class="marisa-cmd">status</span>&nbsp;查看目前知识所掌握情况
Expand Down Expand Up @@ -75,6 +73,9 @@ export default {
this.talk_list.push(MarisaCore.speak(MARISA, '要教给魔里沙什么 ..? 现在只能学习语句.. 如"问`答".. 中止教学输入 exit ..'))
this.cmd_flag = 1
break
case 'forget':
this._marisaForget()
break
case 'status':
this._marisaStatus()
break
Expand All @@ -87,11 +88,11 @@ export default {
if (answer !== '') {
this.talk_list.push(MarisaCore.speak(MARISA, answer))
} else {
this.talk_list.push(MarisaCore.speak(MARISA, '唔嗯...不懂你在说什么呢...'))
this.talk_list.push(MarisaCore.speak(MARISA, '唔嗯...不懂你在说什么呢...教教我吧~'))
}
},
_teachMarisa (_content) {
if (_content === 'exit') {
if (_content === 'exit' || _content === 'teach' || _content === 'forget' || _content === 'status') {
this.talk_list.push(MarisaCore.speak(YOU, '白丝魔理沙,退出学习模式'))
this.cmd_flag = 0
return
Expand All @@ -104,6 +105,14 @@ export default {
this.talk_list.push(MarisaCore.speak(MARISA, '行,我知道了'))
this.cmd_flag = 0
},
_marisaForget () {
let flag = MarisaCore.forget(this.talk_list)
if (flag) {
this.talk_list.push(MarisaCore.speak(MARISA, '这句话魔理沙说错了么 ... 呜呜呜对不起 ...'))
} else {
this.talk_list.push(MarisaCore.speak(MARISA, '魔理沙这阵子不太想忘记东西的样子……'))
}
},
_marisaStatus () {
let memorise = this.$db.get('memorise').value().length
let weight = 0.00011 * parseFloat(memorise)
Expand All @@ -120,7 +129,7 @@ export default {
this._scrollBottom()
},
created () {
let _startTalk = MarisaCore.speak(MARISA, '白絲魔理沙 Type 0.005,还在继续升级DA☆ZE!')
let _startTalk = MarisaCore.speak(MARISA, '白絲魔理沙 Type 0.01,还在继续升级DA☆ZE!')
this.talk_list.push(_startTalk)
}
}
Expand Down

0 comments on commit 8b48aba

Please sign in to comment.