Skip to content

Commit

Permalink
Add validation module.
Browse files Browse the repository at this point in the history
  • Loading branch information
zake7749 committed Nov 19, 2016
1 parent ff39bc7 commit 97e4d5d
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 4 deletions.
6 changes: 3 additions & 3 deletions Chatbot/QuestionAnswering/qaBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ def getCustomQA(self, sentence, api_key, threshold=50):
#i.e IMPLEMENT getUserQA(api_key)
#customqa_list = json.loads(getUserQA(api_key))

data = '[{"Question":"你媽長得像魚人","Answers":["你媽也長得像魚人","你比痲瘋地精還臭"]}]'
data = '[{"question": "你好嗎?","answers": ["很好","不太好"]},{"question": "吃飽了沒?","answers": ["正要吃","剛吃飽"]}]'
customqa_list = json.loads(data)

# Load question to a list.
q_list = [qa["Question"] for qa in customqa_list]
q_list = [qa["question"] for qa in customqa_list]
#TODO customized threshold.
title,index = self.matcher.match(sentence,custom_title=q_list)
sim = self.matcher.getSimilarity()
if sim < threshold:
return None,0
return customqa_list[index]["Answers"][random.randrange(0,len(customqa_list[index]["Answers"]))],sim
return customqa_list[index]["answers"][random.randrange(0,len(customqa_list[index]["answers"]))],sim
3 changes: 3 additions & 0 deletions Chatbot/Validation/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import os
import sys
sys.path.append(os.path.dirname(__file__))
44 changes: 44 additions & 0 deletions Chatbot/Validation/validate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

class Validator(object):

"""
用於驗證預設匹配結果與實際匹配結果是否有不同
"""

def __init__(self):
self.paths = []
self.sentences = []

def loadValiadationData(self, paths_datapath, sentences_datapath):

self.loadPaths(paths_datapath)
self.loadSentences(sentences_datapath)

def loadPaths(self, path):
with open(path,'r',encoding='utf-8') as input:
self.paths = [line.strip('\n') for line in input]

def loadSentences(self, path):
with open(path,'r',encoding='utf-8') as input:
self.sentences = [line.strip('\n') for line in input]

def valiate(self, match):

"""
驗證預設分類結果與實際分類結果
Args:
# match:用於比對的函式,建議採用 console.match,該函式
# 需要回傳匹配路徑與匹配相似度
Return : 誤分點的表列
"""

miss = 0

for i in range(0,len(self.sentences)):
for sentence in self.sentences:
sim,path = match(sentence)
if path != self.paths[i]:
miss += 1
print("在'%s'中,預期為 %s,實際為 %s" % (sentence,self.paths[i],path))
2 changes: 2 additions & 0 deletions Chatbot/task_modules/medicine/medicine.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ def pattern_match(self, subject, description):
return "胃痛"
elif subject=="腹部" and description == "痛推理":
return "腹痛"
elif subject=="腹部" and description == "不舒服推理":
return "腹脹"
elif subject=="腹部" and description == "瀉推理":
return "腹瀉"
elif subject=="心臟" and description == "痛推理":
Expand Down
2 changes: 1 addition & 1 deletion Chatbot/task_modules/other/stock.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Stock(object):
def __init__(self, console):
self.console = console
self.is_close = False
def get_response(self,user_input, domain, target):
"""
Return:
Expand Down

0 comments on commit 97e4d5d

Please sign in to comment.