Skip to content

Commit

Permalink
Logic adapers set confidence value on statement
Browse files Browse the repository at this point in the history
  • Loading branch information
gunthercox committed Jan 10, 2017
1 parent 4ab0d07 commit f22a075
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 6 deletions.
5 changes: 5 additions & 0 deletions chatterbot/conversation/statement.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ def __init__(self, text, **kwargs):

self.extra_data = kwargs.pop('extra_data', {})

# This is the confidence with which the chat bot believes
# this is an accurate response. This value is set when the
# statement is returned by the chat bot.
self.confidence = 0

self.storage = None

def __str__(self):
Expand Down
5 changes: 5 additions & 0 deletions chatterbot/ext/django_chatterbot/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ class Statement(models.Model):

extra_data = models.CharField(max_length=500)

# This is the confidence with which the chat bot believes
# this is an accurate response. This value is set when the
# statement is returned by the chat bot.
confidence = 0

def __str__(self):
if len(self.text.strip()) > 60:
return '{}...'.format(self.text[:57])
Expand Down
1 change: 1 addition & 0 deletions chatterbot/logic/best_match.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,5 @@ def process(self, input_statement):
# Set confidence to zero because a random response is selected
confidence = 0

response.confidence = confidence
return confidence, response
5 changes: 4 additions & 1 deletion chatterbot/logic/low_confidence.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,7 @@ def process(self, input_statement):
else:
confidence = 0

return confidence, Statement(self.default_response)
response = Statement(self.default_response)
response.confidence = confidence

return confidence, response
11 changes: 8 additions & 3 deletions chatterbot/logic/mathematical_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,19 @@ def process(self, statement):

# Returning important information
try:
expression += "= " + str(
expression += '= ' + str(
eval(expression, {f: getattr(numpy, f) for f in self.functions})
)

response = Statement(expression)
response.confidence = 1

# return a confidence of 1 if the expression could be evaluated
return 1, Statement(expression)
return 1, response
except:
return 0, Statement(expression)
response = Statement(expression)
response.confidence = 0
return 0, response

def simplify_chunks(self, input_text):
"""
Expand Down
6 changes: 4 additions & 2 deletions chatterbot/logic/no_knowledge_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ def process(self, statement):
"""

if self.chatbot.storage.count():
return 0, statement
statement.confidence = 0
else:
statement.confidence = 1

return 1, statement
return statement.confidence, statement
1 change: 1 addition & 0 deletions chatterbot/logic/specific_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ def process(self, statement):
if statement == self.input_text:
confidence = 1

self.response_statement.confidence = confidence
return confidence, self.response_statement
1 change: 1 addition & 0 deletions chatterbot/logic/time_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,5 @@ def process(self, statement):
confidence = self.classifier.classify(time_features)
response = Statement('The current time is ' + now.strftime('%I:%M %p'))

response.confidence = confidence
return confidence, response

0 comments on commit f22a075

Please sign in to comment.