Skip to content

Commit

Permalink
Complete elemental structure of QAbase.
Browse files Browse the repository at this point in the history
  • Loading branch information
zake7749 committed Nov 3, 2016
1 parent c142ec4 commit b01872a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
37 changes: 34 additions & 3 deletions Chatbot/QuestionAnswering/qaBase.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,36 @@
from . import match
from . import responsesEvaluate
import json

from .match import *
from .responsesEvaluate import Evaluator

class QABase(object):
pass

def __init__(self, data_path):

"""
Args:
data_path: 指出 data 資料夾位在哪個位置
"""
self.general_questions = []
self.data_path = data_path

self.matcher = getMatcher(matcherType="Fuzzy")
self.evaluator = Evaluator()

def getResponse(self, sentence, api_key=None):

if api_key is not None:
response = self.getCustomQA(sentence,api_key)
else:
response = self._getGeneralQA(sentence)
return response

def getGeneralQA(self, sentence):

pass

def getCustomQA(self, sentence, api_key):

#TODO GET USER'S QA BY api_key
#customqa_list = json.loads(getUserQA(api_key))
pass
2 changes: 1 addition & 1 deletion Chatbot/QuestionAnswering/responsesEvaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def evaluateByGrade(self,topk,debug=False):
meanful += math.log(wordWeight,10)
cur_grade += wordWeight

cur_grade = cur_grade * meanful / math.log(len(self.segResponses[i])+1,avgWords)
cur_grade = cur_grade * meanful / (math.log(len(self.segResponses[i])+1,avgWords) + 1)
candiates.append([self.responses[i],cur_grade])

if debug:
Expand Down
Empty file removed Chatbot/log/exception_log
Empty file.

0 comments on commit b01872a

Please sign in to comment.