Skip to content

Commit

Permalink
Add the offline-testing for custom rules matching.
Browse files Browse the repository at this point in the history
  • Loading branch information
zake7749 committed Nov 11, 2016
1 parent 4dfd6b7 commit 33f5e32
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
9 changes: 6 additions & 3 deletions Chatbot/RuleMatcher/customRuleBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,17 @@ def buildCustomRules(self, rules):
if domain not in self.rules:
rule = Rule(domain, concepts_list, children_list, response, self.model)
self.rules[domain] = rule
if is_root:
self.forest_base_roots.append(rule)
else:
#TODO Block invalided rule type on front end.
print("[Rules]: Detect a duplicate domain name '%s'." % domain)

def getCustomDomainRules(self, key):
"""
依照 apiKey 取得該用戶的規則集
"""
#TODO
return None
#FIXME 採用正規方式驗證

data = '[{"domain": "TESTING","response": ["這是個測試客製化規則的回覆1","這是個測試客製化規則的回覆2"],"concepts": ["測試"],"children": []}]'

return data
5 changes: 3 additions & 2 deletions Chatbot/chatbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ def listen(self, sentence, target=None, api_key=None, qa_threshold=50, qa_block_
return qa_response,None,None,None,None

# matching on custom rules.
response = self.getResponseOnCustomDomain(sentence, api_key)
# FIXME Remove api_key TESTING VALUE
response = self.getResponseOnCustomDomain(sentence, api_key="TESTING")
if response is not None:
return response,None,None,None

Expand Down Expand Up @@ -182,7 +183,7 @@ def getResponseOnCustomDomain(self, sentence, api_key):
return None

#TODO 調適為能夠進行「多段式對話」
return customMatch(sentence, api_key)
return self.custom_rulebase.customMatch(sentence, api_key)

def getResponseForQA(self, sentence, api_key, threshold):
"""
Expand Down

0 comments on commit 33f5e32

Please sign in to comment.