Skip to content

Commit

Permalink
Merge pull request #244 from gunthercox/confidence
Browse files Browse the repository at this point in the history
Return a confidence of zero if a random response is selected
  • Loading branch information
gunthercox authored Aug 20, 2016
2 parents ea2baad + 46ae032 commit 915f4e3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions chatterbot/adapters/logic/base_match.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,7 @@ def process(self, input_statement):
else:
response = self.context.storage.get_random()

# Set confidence to zero if a random response is selected
confidence = 0

return confidence, response
19 changes: 19 additions & 0 deletions tests/logic_adapter_tests/test_closest_match.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,22 @@ def test_confidence_no_match(self):
confidence, match = self.adapter.get(statement)

self.assertEqual(confidence, 0)

def test_no_known_responses(self):
"""
In the case that a match is selected which has no known responses.
In this case a random response will be returned, but the confidence
should be zero because it is a random choice.
"""
self.adapter.context.storage.update = MagicMock()
self.adapter.context.storage.filter = MagicMock(
return_value=[]
)
self.adapter.context.storage.get_random = MagicMock(
return_value=Statement("Random")
)

confidence, match = self.adapter.process(Statement("Blah"))

self.assertEqual(confidence, 0)
self.assertEqual(match.text, "Random")

0 comments on commit 915f4e3

Please sign in to comment.