ChatterBot 1.2.16__tar.gz → 1.2.17__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {chatterbot-1.2.16 → chatterbot-1.2.17}/ChatterBot.egg-info/PKG-INFO +1 -1
- {chatterbot-1.2.16 → chatterbot-1.2.17}/PKG-INFO +1 -1
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/__init__.py +1 -1
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/chatterbot.py +22 -5
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/comparisons.py +12 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/logic/best_match.py +11 -2
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/logic/logic_adapter.py +20 -3
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/logic/mathematical_evaluation.py +15 -2
- {chatterbot-1.2.16 → chatterbot-1.2.17}/tests/test_chatbot.py +111 -1
- {chatterbot-1.2.16 → chatterbot-1.2.17}/ChatterBot.egg-info/SOURCES.txt +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/ChatterBot.egg-info/dependency_links.txt +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/ChatterBot.egg-info/requires.txt +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/ChatterBot.egg-info/top_level.txt +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/LICENSE +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/README.md +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/__main__.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/adapters.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/components.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/constants.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/conversation.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/corpus.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/exceptions.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/ext/__init__.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/ext/django_chatterbot/__init__.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/ext/django_chatterbot/abstract_models.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/ext/django_chatterbot/admin.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/ext/django_chatterbot/apps.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/ext/django_chatterbot/migrations/0001_initial.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/ext/django_chatterbot/migrations/0002_statement_extra_data.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/ext/django_chatterbot/migrations/0003_change_occurrence_default.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/ext/django_chatterbot/migrations/0004_rename_in_response_to.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/ext/django_chatterbot/migrations/0005_statement_created_at.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/ext/django_chatterbot/migrations/0006_create_conversation.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/ext/django_chatterbot/migrations/0007_response_created_at.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/ext/django_chatterbot/migrations/0008_update_conversations.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/ext/django_chatterbot/migrations/0009_tags.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/ext/django_chatterbot/migrations/0010_statement_text.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/ext/django_chatterbot/migrations/0011_blank_extra_data.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/ext/django_chatterbot/migrations/0012_statement_created_at.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/ext/django_chatterbot/migrations/0013_change_conversations.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/ext/django_chatterbot/migrations/0014_remove_statement_extra_data.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/ext/django_chatterbot/migrations/0015_statement_persona.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/ext/django_chatterbot/migrations/0016_statement_stemmed_text.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/ext/django_chatterbot/migrations/0017_tags_unique.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/ext/django_chatterbot/migrations/0018_text_max_length.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/ext/django_chatterbot/migrations/0019_alter_statement_id_alter_tag_id_and_more.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/ext/django_chatterbot/migrations/0020_alter_statement_conversation_and_more.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/ext/django_chatterbot/migrations/0021_increase_text_max_length_to_1100.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/ext/django_chatterbot/migrations/__init__.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/ext/django_chatterbot/model_admin.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/ext/django_chatterbot/models.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/ext/django_chatterbot/settings.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/ext/sqlalchemy_app/__init__.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/ext/sqlalchemy_app/models.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/filters.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/languages.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/logic/__init__.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/logic/llm_adapters.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/logic/mcp_tools.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/logic/specific_response.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/logic/time_adapter.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/logic/unit_conversion.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/parsing.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/preprocessors.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/response_selection.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/search.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/storage/__init__.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/storage/django_storage.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/storage/mongodb.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/storage/redis.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/storage/sql_storage.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/storage/storage_adapter.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/tagging.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/trainers.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/utils.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/vectorstores.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/pyproject.toml +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/setup.cfg +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/tests/test_adapter_validation.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/tests/test_benchmarks.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/tests/test_cli.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/tests/test_comparisons.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/tests/test_conversations.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/tests/test_corpus.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/tests/test_examples.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/tests/test_filters.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/tests/test_initialization.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/tests/test_languages.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/tests/test_parsing.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/tests/test_preprocessors.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/tests/test_response_selection.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/tests/test_search.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/tests/test_tagging.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/tests/test_turing.py +0 -0
- {chatterbot-1.2.16 → chatterbot-1.2.17}/tests/test_utils.py +0 -0
|
@@ -31,9 +31,13 @@ class ChatBot(object):
|
|
|
31
31
|
:type tagger: object
|
|
32
32
|
|
|
33
33
|
:param tagger_language: The language to use for the tagger.
|
|
34
|
-
Defaults to
|
|
34
|
+
Defaults to ``language`` if provided, otherwise
|
|
35
|
+
:class:`~chatterbot.languages.ENG`.
|
|
35
36
|
:type tagger_language: object
|
|
36
37
|
|
|
38
|
+
:param language: The language to use when no ``tagger_language`` is provided.
|
|
39
|
+
:type language: object
|
|
40
|
+
|
|
37
41
|
:param preprocessors: A list of preprocessor functions to use for the chat bot.
|
|
38
42
|
:type preprocessors: list
|
|
39
43
|
|
|
@@ -81,7 +85,10 @@ class ChatBot(object):
|
|
|
81
85
|
|
|
82
86
|
self.storage = utils.initialize_class(storage_adapter, **kwargs)
|
|
83
87
|
|
|
84
|
-
tagger_language = kwargs.get(
|
|
88
|
+
tagger_language = kwargs.get(
|
|
89
|
+
'tagger_language',
|
|
90
|
+
kwargs.get('language', languages.ENG)
|
|
91
|
+
)
|
|
85
92
|
|
|
86
93
|
# Check if storage adapter has a preferred tagger
|
|
87
94
|
PreferredTagger = self.storage.get_preferred_tagger()
|
|
@@ -137,6 +144,9 @@ class ChatBot(object):
|
|
|
137
144
|
self.logger.info(f'Storage adapter prefers search algorithm: {preferred_search_algorithm}')
|
|
138
145
|
kwargs.setdefault('search_algorithm_name', preferred_search_algorithm)
|
|
139
146
|
|
|
147
|
+
# NOTE: 'xx' is the language code for a multi-language model
|
|
148
|
+
self.nlp = spacy.blank(self.tagger.language.ISO_639_1)
|
|
149
|
+
|
|
140
150
|
for adapter in logic_adapters:
|
|
141
151
|
utils.validate_adapter_class(adapter, LogicAdapter)
|
|
142
152
|
logic_adapter = utils.initialize_class(adapter, self, **kwargs)
|
|
@@ -153,9 +163,6 @@ class ChatBot(object):
|
|
|
153
163
|
for preprocessor in preprocessors:
|
|
154
164
|
self.preprocessors.append(utils.import_module(preprocessor))
|
|
155
165
|
|
|
156
|
-
# NOTE: 'xx' is the language code for a multi-language model
|
|
157
|
-
self.nlp = spacy.blank(self.tagger.language.ISO_639_1)
|
|
158
|
-
|
|
159
166
|
# Allow the bot to save input it receives so that it can learn
|
|
160
167
|
self.read_only = kwargs.get('read_only', False)
|
|
161
168
|
|
|
@@ -279,6 +286,7 @@ class ChatBot(object):
|
|
|
279
286
|
results = []
|
|
280
287
|
result = None
|
|
281
288
|
max_confidence = -1
|
|
289
|
+
has_confident_response = False
|
|
282
290
|
|
|
283
291
|
for adapter in self.logic_adapters:
|
|
284
292
|
if adapter.can_process(input_statement):
|
|
@@ -295,6 +303,9 @@ class ChatBot(object):
|
|
|
295
303
|
if output.confidence > max_confidence:
|
|
296
304
|
result = output
|
|
297
305
|
max_confidence = output.confidence
|
|
306
|
+
|
|
307
|
+
if output.confidence >= adapter.maximum_similarity_threshold:
|
|
308
|
+
has_confident_response = True
|
|
298
309
|
else:
|
|
299
310
|
self.logger.info(
|
|
300
311
|
'Not processing the statement using {}'.format(adapter.class_name)
|
|
@@ -337,6 +348,12 @@ class ChatBot(object):
|
|
|
337
348
|
f'No logic adapter was able to process the statement "{input_statement.text}".'
|
|
338
349
|
)
|
|
339
350
|
|
|
351
|
+
if not has_confident_response:
|
|
352
|
+
for adapter in self.logic_adapters:
|
|
353
|
+
if adapter.default_responses:
|
|
354
|
+
result = adapter.get_default_response(input_statement)
|
|
355
|
+
break
|
|
356
|
+
|
|
340
357
|
response = Statement(
|
|
341
358
|
text=result.text,
|
|
342
359
|
in_response_to=input_statement.text,
|
|
@@ -12,6 +12,9 @@ class Comparator:
|
|
|
12
12
|
Base class establishing the interface that all comparators should implement.
|
|
13
13
|
"""
|
|
14
14
|
|
|
15
|
+
# Default maximum_similarity_threshold for search stopping and fallback acceptance.
|
|
16
|
+
default_threshold = 0.95
|
|
17
|
+
|
|
15
18
|
def __init__(self, language):
|
|
16
19
|
|
|
17
20
|
self.language = language
|
|
@@ -44,6 +47,9 @@ class LevenshteinDistance(Comparator):
|
|
|
44
47
|
based on the Levenshtein distance algorithm.
|
|
45
48
|
"""
|
|
46
49
|
|
|
50
|
+
# Default maximum_similarity_threshold for search stopping and fallback acceptance.
|
|
51
|
+
default_threshold = 0.70
|
|
52
|
+
|
|
47
53
|
def compare_text(self, text_a: str, text_b: str) -> float:
|
|
48
54
|
"""
|
|
49
55
|
Compare the two pieces of text.
|
|
@@ -97,6 +103,9 @@ class SpacySimilarity(Comparator):
|
|
|
97
103
|
|
|
98
104
|
"""
|
|
99
105
|
|
|
106
|
+
# Default maximum_similarity_threshold for search stopping and fallback acceptance.
|
|
107
|
+
default_threshold = 0.70
|
|
108
|
+
|
|
100
109
|
def __init__(self, language):
|
|
101
110
|
super().__init__(language)
|
|
102
111
|
|
|
@@ -148,6 +157,9 @@ class JaccardSimilarity(Comparator):
|
|
|
148
157
|
.. _`Jaccard similarity index`: https://en.wikipedia.org/wiki/Jaccard_index
|
|
149
158
|
"""
|
|
150
159
|
|
|
160
|
+
# Default maximum_similarity_threshold for search stopping and fallback acceptance.
|
|
161
|
+
default_threshold = 0.50
|
|
162
|
+
|
|
151
163
|
def __init__(self, language):
|
|
152
164
|
super().__init__(language)
|
|
153
165
|
|
|
@@ -105,8 +105,17 @@ class BestMatch(LogicAdapter):
|
|
|
105
105
|
additional_response_selection_parameters
|
|
106
106
|
)
|
|
107
107
|
|
|
108
|
-
|
|
109
|
-
|
|
108
|
+
exact_response_selection_parameters = dict(response_selection_parameters)
|
|
109
|
+
exact_response_selection_parameters.pop('search_text', None)
|
|
110
|
+
exact_response_selection_parameters['in_response_to'] = (
|
|
111
|
+
closest_match.in_response_to or input_statement.text
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
response_list = list(self.chatbot.storage.filter(**exact_response_selection_parameters))
|
|
115
|
+
|
|
116
|
+
if not response_list:
|
|
117
|
+
# Fall back to indexed text to support normalized variations.
|
|
118
|
+
response_list = list(self.chatbot.storage.filter(**response_selection_parameters))
|
|
110
119
|
|
|
111
120
|
if response_list:
|
|
112
121
|
response = self.select_response(
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
from copy import copy
|
|
1
2
|
from random import choice
|
|
2
3
|
|
|
3
4
|
from chatterbot.adapters import Adapter
|
|
@@ -20,8 +21,8 @@ class LogicAdapter(Adapter):
|
|
|
20
21
|
The maximum amount of similarity between two statement that is required
|
|
21
22
|
before the search process is halted. The search for a matching statement
|
|
22
23
|
will continue until a statement with a greater than or equal similarity
|
|
23
|
-
is found or the search set is exhausted.
|
|
24
|
-
|
|
24
|
+
is found or the search set is exhausted. Defaults to the selected
|
|
25
|
+
comparison function's ``default_threshold``.
|
|
25
26
|
|
|
26
27
|
:param response_selection_method:
|
|
27
28
|
The a response selection method.
|
|
@@ -47,8 +48,24 @@ class LogicAdapter(Adapter):
|
|
|
47
48
|
self.search_algorithm_name
|
|
48
49
|
]
|
|
49
50
|
|
|
51
|
+
statement_comparison_function = kwargs.get('statement_comparison_function')
|
|
52
|
+
|
|
53
|
+
if statement_comparison_function is not None and hasattr(self.search_algorithm, 'compare_statements'):
|
|
54
|
+
if isinstance(statement_comparison_function, str):
|
|
55
|
+
statement_comparison_function = utils.import_module(
|
|
56
|
+
statement_comparison_function
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
self.search_algorithm = copy(self.search_algorithm)
|
|
60
|
+
self.search_algorithm.compare_statements = statement_comparison_function(
|
|
61
|
+
language=self.chatbot.tagger.language
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
comparison_function = getattr(self.search_algorithm, 'compare_statements', None)
|
|
65
|
+
default_threshold = getattr(comparison_function, 'default_threshold', 0.95)
|
|
66
|
+
|
|
50
67
|
self.maximum_similarity_threshold = kwargs.get(
|
|
51
|
-
'maximum_similarity_threshold',
|
|
68
|
+
'maximum_similarity_threshold', default_threshold
|
|
52
69
|
)
|
|
53
70
|
|
|
54
71
|
if response_selection_method := kwargs.get('response_selection_method'):
|
|
@@ -21,11 +21,16 @@ class MathematicalEvaluation(LogicAdapter, MCPToolAdapter):
|
|
|
21
21
|
"""
|
|
22
22
|
|
|
23
23
|
def __init__(self, chatbot, **kwargs):
|
|
24
|
+
from mathparse import mathwords
|
|
25
|
+
|
|
24
26
|
super().__init__(chatbot, **kwargs)
|
|
25
27
|
|
|
26
28
|
self.language = kwargs.get('language', languages.ENG)
|
|
27
29
|
self.cache = {}
|
|
28
30
|
|
|
31
|
+
math_words = mathwords.MATH_WORDS.get(self.language.ISO_639.upper(), {})
|
|
32
|
+
self.stop_words: set = chatbot.nlp.Defaults.stop_words - set(math_words.get('scales', {}))
|
|
33
|
+
|
|
29
34
|
def can_process(self, statement) -> bool:
|
|
30
35
|
"""
|
|
31
36
|
Determines whether it is appropriate for this
|
|
@@ -58,7 +63,11 @@ class MathematicalEvaluation(LogicAdapter, MCPToolAdapter):
|
|
|
58
63
|
try:
|
|
59
64
|
response.text = '{} = {}'.format(
|
|
60
65
|
response.text,
|
|
61
|
-
mathparse.parse(
|
|
66
|
+
mathparse.parse(
|
|
67
|
+
expression,
|
|
68
|
+
language=self.language.ISO_639.upper(),
|
|
69
|
+
stopwords=self.stop_words
|
|
70
|
+
)
|
|
62
71
|
)
|
|
63
72
|
|
|
64
73
|
# The confidence is 1 if the expression could be evaluated
|
|
@@ -109,7 +118,11 @@ class MathematicalEvaluation(LogicAdapter, MCPToolAdapter):
|
|
|
109
118
|
extracted = mathparse.extract_expression(expression, language=self.language.ISO_639.upper())
|
|
110
119
|
|
|
111
120
|
# Evaluate the expression
|
|
112
|
-
result = mathparse.parse(
|
|
121
|
+
result = mathparse.parse(
|
|
122
|
+
extracted,
|
|
123
|
+
language=self.language.ISO_639.upper(),
|
|
124
|
+
stopwords=self.stop_words
|
|
125
|
+
)
|
|
113
126
|
|
|
114
127
|
return f"{extracted} = {result}"
|
|
115
128
|
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
from tests.base_case import ChatBotTestCase
|
|
2
2
|
from chatterbot import ChatBot
|
|
3
|
-
from chatterbot
|
|
3
|
+
from chatterbot import comparisons, utils
|
|
4
|
+
from chatterbot.logic import BestMatch, LogicAdapter, MathematicalEvaluation
|
|
4
5
|
from chatterbot.conversation import Statement
|
|
5
6
|
from chatterbot import languages
|
|
7
|
+
from chatterbot.tagging import NoOpTagger
|
|
6
8
|
|
|
7
9
|
|
|
8
10
|
class ChatBotInitializationTestCase(ChatBotTestCase):
|
|
@@ -45,6 +47,29 @@ class ChatBotInitializationTestCase(ChatBotTestCase):
|
|
|
45
47
|
str(exc.exception),
|
|
46
48
|
)
|
|
47
49
|
|
|
50
|
+
def test_language_is_used_as_tagger_language_default(self):
|
|
51
|
+
chatbot = ChatBot(
|
|
52
|
+
'Test Bot',
|
|
53
|
+
language=languages.GER,
|
|
54
|
+
tagger=NoOpTagger,
|
|
55
|
+
database_uri=None
|
|
56
|
+
)
|
|
57
|
+
self.addCleanup(chatbot.storage.close)
|
|
58
|
+
|
|
59
|
+
self.assertIs(chatbot.tagger.language, languages.GER)
|
|
60
|
+
|
|
61
|
+
def test_tagger_language_overrides_language(self):
|
|
62
|
+
chatbot = ChatBot(
|
|
63
|
+
'Test Bot',
|
|
64
|
+
language=languages.GER,
|
|
65
|
+
tagger_language=languages.ENG,
|
|
66
|
+
tagger=NoOpTagger,
|
|
67
|
+
database_uri=None
|
|
68
|
+
)
|
|
69
|
+
self.addCleanup(chatbot.storage.close)
|
|
70
|
+
|
|
71
|
+
self.assertIs(chatbot.tagger.language, languages.ENG)
|
|
72
|
+
|
|
48
73
|
|
|
49
74
|
class ChatterBotResponseTestCase(ChatBotTestCase):
|
|
50
75
|
|
|
@@ -401,6 +426,77 @@ class TestAdapterC(LogicAdapter):
|
|
|
401
426
|
|
|
402
427
|
class ChatBotLogicAdapterTestCase(ChatBotTestCase):
|
|
403
428
|
|
|
429
|
+
def test_adapter_comparison_functions_are_isolated(self):
|
|
430
|
+
self.chatbot.logic_adapters = [
|
|
431
|
+
utils.initialize_class(
|
|
432
|
+
{
|
|
433
|
+
'import_path': 'chatterbot.logic.BestMatch',
|
|
434
|
+
'statement_comparison_function': 'chatterbot.comparisons.JaccardSimilarity'
|
|
435
|
+
},
|
|
436
|
+
self.chatbot
|
|
437
|
+
),
|
|
438
|
+
BestMatch(
|
|
439
|
+
self.chatbot,
|
|
440
|
+
statement_comparison_function=comparisons.LevenshteinDistance
|
|
441
|
+
)
|
|
442
|
+
]
|
|
443
|
+
|
|
444
|
+
self.assertIsInstance(
|
|
445
|
+
self.chatbot.logic_adapters[0].search_algorithm.compare_statements,
|
|
446
|
+
comparisons.JaccardSimilarity
|
|
447
|
+
)
|
|
448
|
+
self.assertIsInstance(
|
|
449
|
+
self.chatbot.logic_adapters[1].search_algorithm.compare_statements,
|
|
450
|
+
comparisons.LevenshteinDistance
|
|
451
|
+
)
|
|
452
|
+
self.assertIsNot(
|
|
453
|
+
self.chatbot.logic_adapters[0].search_algorithm,
|
|
454
|
+
self.chatbot.logic_adapters[1].search_algorithm
|
|
455
|
+
)
|
|
456
|
+
self.assertIsInstance(
|
|
457
|
+
self.chatbot.search_algorithms['indexed_text_search'].compare_statements,
|
|
458
|
+
comparisons.LevenshteinDistance
|
|
459
|
+
)
|
|
460
|
+
self.assertEqual(self.chatbot.logic_adapters[0].maximum_similarity_threshold, 0.5)
|
|
461
|
+
self.assertEqual(self.chatbot.logic_adapters[1].maximum_similarity_threshold, 0.7)
|
|
462
|
+
|
|
463
|
+
spacy_adapter = BestMatch(
|
|
464
|
+
self.chatbot,
|
|
465
|
+
statement_comparison_function=comparisons.SpacySimilarity
|
|
466
|
+
)
|
|
467
|
+
self.assertEqual(spacy_adapter.maximum_similarity_threshold, 0.7)
|
|
468
|
+
|
|
469
|
+
overridden_adapter = BestMatch(
|
|
470
|
+
self.chatbot,
|
|
471
|
+
statement_comparison_function=comparisons.LevenshteinDistance,
|
|
472
|
+
maximum_similarity_threshold=0.6
|
|
473
|
+
)
|
|
474
|
+
self.assertEqual(overridden_adapter.maximum_similarity_threshold, 0.6)
|
|
475
|
+
|
|
476
|
+
def test_single_word_query_uses_comparer_default_confidence(self):
|
|
477
|
+
question = 'What is a microprocessor?'
|
|
478
|
+
answer = 'An integrated circuit that implements the functions of a central processing unit of a computer.'
|
|
479
|
+
self._create_with_search_text(text=question)
|
|
480
|
+
self._create_with_search_text(text=answer, in_response_to=question)
|
|
481
|
+
|
|
482
|
+
for comparison_function in (
|
|
483
|
+
comparisons.JaccardSimilarity,
|
|
484
|
+
comparisons.LevenshteinDistance
|
|
485
|
+
):
|
|
486
|
+
self.chatbot.logic_adapters = [
|
|
487
|
+
BestMatch(
|
|
488
|
+
self.chatbot,
|
|
489
|
+
statement_comparison_function=comparison_function,
|
|
490
|
+
default_response='I do not understand.'
|
|
491
|
+
)
|
|
492
|
+
]
|
|
493
|
+
|
|
494
|
+
response = self.chatbot.generate_response(
|
|
495
|
+
self._add_search_text(text='microprocessor')
|
|
496
|
+
)
|
|
497
|
+
|
|
498
|
+
self.assertEqual(response.text, answer)
|
|
499
|
+
|
|
404
500
|
def test_sub_adapter_agreement(self):
|
|
405
501
|
"""
|
|
406
502
|
In the case that multiple adapters agree on a given
|
|
@@ -418,6 +514,20 @@ class ChatBotLogicAdapterTestCase(ChatBotTestCase):
|
|
|
418
514
|
self.assertEqual(statement.confidence, 0.5)
|
|
419
515
|
self.assertEqual(statement.text, 'Good morning.')
|
|
420
516
|
|
|
517
|
+
def test_default_response_when_no_adapter_meets_similarity_threshold(self):
|
|
518
|
+
self.chatbot.logic_adapters = [
|
|
519
|
+
TestAdapterA(
|
|
520
|
+
self.chatbot,
|
|
521
|
+
default_response='I do not understand.',
|
|
522
|
+
maximum_similarity_threshold=0.65
|
|
523
|
+
)
|
|
524
|
+
]
|
|
525
|
+
|
|
526
|
+
response = self.chatbot.generate_response(Statement(text='Something unexpected'))
|
|
527
|
+
|
|
528
|
+
self.assertEqual(response.text, 'I do not understand.')
|
|
529
|
+
self.assertEqual(response.confidence, 0)
|
|
530
|
+
|
|
421
531
|
def test_no_adapter_can_process_statement(self):
|
|
422
532
|
"""
|
|
423
533
|
If no logic adapter can process the statement,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/ext/django_chatterbot/migrations/0001_initial.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/ext/django_chatterbot/migrations/0009_tags.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{chatterbot-1.2.16 → chatterbot-1.2.17}/chatterbot/ext/django_chatterbot/migrations/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|