Skip to content

Commit

Permalink
Change the matcher of Custom QA to Fuzzy matching.
Browse files Browse the repository at this point in the history
  • Loading branch information
zake7749 committed Dec 6, 2016
1 parent c72c135 commit 227a86e
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions Chatbot/QuestionAnswering/qaBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ def __init__(self):
self.path = os.path.dirname(__file__)

self.matcher = getMatcher(matcherType="bm25")
self.fuzzy_matcher = getMatcher(matcherType="Fuzzy")

self.evaluator = Evaluator()
self.moduleTest()

Expand Down Expand Up @@ -69,9 +71,12 @@ def getCustomQA(self, sentence, api_key, threshold=50):

# Load question to a 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()

#TODO 1. customized threshold.

#NOTICE: Always choose fuzzy matcher for custom matching.
title,index = self.fuzzy_matcher.match(sentence,custom_title=q_list)
sim = self.fuzzy_matcher.getSimilarity()
if sim < threshold:
return None,0
return customqa_list[index]["answers"][random.randrange(0,len(customqa_list[index]["answers"]))],sim

0 comments on commit 227a86e

Please sign in to comment.