ChatterBot 1.2.8__tar.gz → 1.2.9__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.8 → chatterbot-1.2.9}/ChatterBot.egg-info/PKG-INFO +14 -4
- {chatterbot-1.2.8 → chatterbot-1.2.9}/ChatterBot.egg-info/requires.txt +3 -3
- {chatterbot-1.2.8 → chatterbot-1.2.9}/PKG-INFO +14 -4
- {chatterbot-1.2.8 → chatterbot-1.2.9}/README.md +10 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/__init__.py +1 -1
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/components.py +3 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/logic/specific_response.py +13 -3
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/parsing.py +25 -15
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/storage/sql_storage.py +24 -2
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/tagging.py +44 -7
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/trainers.py +116 -49
- {chatterbot-1.2.8 → chatterbot-1.2.9}/pyproject.toml +3 -3
- {chatterbot-1.2.8 → chatterbot-1.2.9}/tests/test_chatbot.py +5 -4
- {chatterbot-1.2.8 → chatterbot-1.2.9}/tests/test_parsing.py +197 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/ChatterBot.egg-info/SOURCES.txt +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/ChatterBot.egg-info/dependency_links.txt +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/ChatterBot.egg-info/top_level.txt +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/LICENSE +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/__main__.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/adapters.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/chatterbot.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/comparisons.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/constants.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/conversation.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/corpus.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/exceptions.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/ext/__init__.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/ext/django_chatterbot/__init__.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/ext/django_chatterbot/abstract_models.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/ext/django_chatterbot/admin.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/ext/django_chatterbot/apps.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/ext/django_chatterbot/migrations/0001_initial.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/ext/django_chatterbot/migrations/0002_statement_extra_data.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/ext/django_chatterbot/migrations/0003_change_occurrence_default.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/ext/django_chatterbot/migrations/0004_rename_in_response_to.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/ext/django_chatterbot/migrations/0005_statement_created_at.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/ext/django_chatterbot/migrations/0006_create_conversation.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/ext/django_chatterbot/migrations/0007_response_created_at.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/ext/django_chatterbot/migrations/0008_update_conversations.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/ext/django_chatterbot/migrations/0009_tags.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/ext/django_chatterbot/migrations/0010_statement_text.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/ext/django_chatterbot/migrations/0011_blank_extra_data.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/ext/django_chatterbot/migrations/0012_statement_created_at.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/ext/django_chatterbot/migrations/0013_change_conversations.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/ext/django_chatterbot/migrations/0014_remove_statement_extra_data.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/ext/django_chatterbot/migrations/0015_statement_persona.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/ext/django_chatterbot/migrations/0016_statement_stemmed_text.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/ext/django_chatterbot/migrations/0017_tags_unique.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/ext/django_chatterbot/migrations/0018_text_max_length.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/ext/django_chatterbot/migrations/0019_alter_statement_id_alter_tag_id_and_more.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/ext/django_chatterbot/migrations/0020_alter_statement_conversation_and_more.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/ext/django_chatterbot/migrations/__init__.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/ext/django_chatterbot/model_admin.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/ext/django_chatterbot/models.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/ext/django_chatterbot/settings.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/ext/sqlalchemy_app/__init__.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/ext/sqlalchemy_app/models.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/filters.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/languages.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/llm.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/logic/__init__.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/logic/best_match.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/logic/logic_adapter.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/logic/mathematical_evaluation.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/logic/time_adapter.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/logic/unit_conversion.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/preprocessors.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/response_selection.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/search.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/storage/__init__.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/storage/django_storage.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/storage/mongodb.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/storage/redis.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/storage/storage_adapter.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/utils.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/chatterbot/vectorstores.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/setup.cfg +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/tests/test_adapter_validation.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/tests/test_benchmarks.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/tests/test_cli.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/tests/test_comparisons.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/tests/test_conversations.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/tests/test_corpus.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/tests/test_examples.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/tests/test_filters.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/tests/test_initialization.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/tests/test_languages.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/tests/test_preprocessors.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/tests/test_response_selection.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/tests/test_search.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/tests/test_tagging.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/tests/test_turing.py +0 -0
- {chatterbot-1.2.8 → chatterbot-1.2.9}/tests/test_utils.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ChatterBot
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.9
|
|
4
4
|
Summary: ChatterBot is a machine learning, conversational dialog engine
|
|
5
5
|
Author: Gunther Cox
|
|
6
6
|
License-Expression: BSD-3-Clause
|
|
@@ -47,16 +47,16 @@ Provides-Extra: dev
|
|
|
47
47
|
Requires-Dist: pint>=0.8.1; extra == "dev"
|
|
48
48
|
Requires-Dist: pyyaml<7.0,>=6.0; extra == "dev"
|
|
49
49
|
Requires-Dist: chatterbot-corpus<1.3.0,>=1.2.2; extra == "dev"
|
|
50
|
-
Requires-Dist: ollama<1.0,>=0.
|
|
50
|
+
Requires-Dist: ollama<1.0,>=0.6.0; extra == "dev"
|
|
51
51
|
Requires-Dist: openai; extra == "dev"
|
|
52
52
|
Provides-Extra: redis
|
|
53
|
-
Requires-Dist: redis[hiredis]<
|
|
53
|
+
Requires-Dist: redis[hiredis]<7.0; extra == "redis"
|
|
54
54
|
Requires-Dist: langchain-redis<=0.2.5; extra == "redis"
|
|
55
55
|
Requires-Dist: langchain-huggingface<=0.1.2; extra == "redis"
|
|
56
56
|
Requires-Dist: accelerate<=1.6.0; extra == "redis"
|
|
57
57
|
Requires-Dist: sentence-transformers<=4.0.2; extra == "redis"
|
|
58
58
|
Provides-Extra: mongodb
|
|
59
|
-
Requires-Dist: pymongo<4.
|
|
59
|
+
Requires-Dist: pymongo<4.16,>=4.11; extra == "mongodb"
|
|
60
60
|
Dynamic: license-file
|
|
61
61
|
|
|
62
62
|

|
|
@@ -164,6 +164,16 @@ See release notes for changes https://github.com/gunthercox/ChatterBot/releases
|
|
|
164
164
|
5. Use the projects [built-in automated testing](https://docs.chatterbot.us/testing/).
|
|
165
165
|
to help make sure that your contribution is free from errors.
|
|
166
166
|
|
|
167
|
+
# Sponsors
|
|
168
|
+
|
|
169
|
+
ChatterBot is sponsored by:
|
|
170
|
+
|
|
171
|
+
<p style="font-size:21px; color:black;">Browser testing via
|
|
172
|
+
<a href="https://www.lambdatest.com/?utm_source=chatterbot&utm_medium=sponsor" target="_blank">
|
|
173
|
+
<img src="https://www.lambdatest.com/blue-logo.png" style="vertical-align: middle;" width="250" height="45" />
|
|
174
|
+
</a>
|
|
175
|
+
</p>
|
|
176
|
+
|
|
167
177
|
# License
|
|
168
178
|
|
|
169
179
|
ChatterBot is licensed under the [BSD 3-clause license](https://opensource.org/licenses/BSD-3-Clause).
|
|
@@ -8,14 +8,14 @@ tqdm
|
|
|
8
8
|
pint>=0.8.1
|
|
9
9
|
pyyaml<7.0,>=6.0
|
|
10
10
|
chatterbot-corpus<1.3.0,>=1.2.2
|
|
11
|
-
ollama<1.0,>=0.
|
|
11
|
+
ollama<1.0,>=0.6.0
|
|
12
12
|
openai
|
|
13
13
|
|
|
14
14
|
[mongodb]
|
|
15
|
-
pymongo<4.
|
|
15
|
+
pymongo<4.16,>=4.11
|
|
16
16
|
|
|
17
17
|
[redis]
|
|
18
|
-
redis[hiredis]<
|
|
18
|
+
redis[hiredis]<7.0
|
|
19
19
|
langchain-redis<=0.2.5
|
|
20
20
|
langchain-huggingface<=0.1.2
|
|
21
21
|
accelerate<=1.6.0
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ChatterBot
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.9
|
|
4
4
|
Summary: ChatterBot is a machine learning, conversational dialog engine
|
|
5
5
|
Author: Gunther Cox
|
|
6
6
|
License-Expression: BSD-3-Clause
|
|
@@ -47,16 +47,16 @@ Provides-Extra: dev
|
|
|
47
47
|
Requires-Dist: pint>=0.8.1; extra == "dev"
|
|
48
48
|
Requires-Dist: pyyaml<7.0,>=6.0; extra == "dev"
|
|
49
49
|
Requires-Dist: chatterbot-corpus<1.3.0,>=1.2.2; extra == "dev"
|
|
50
|
-
Requires-Dist: ollama<1.0,>=0.
|
|
50
|
+
Requires-Dist: ollama<1.0,>=0.6.0; extra == "dev"
|
|
51
51
|
Requires-Dist: openai; extra == "dev"
|
|
52
52
|
Provides-Extra: redis
|
|
53
|
-
Requires-Dist: redis[hiredis]<
|
|
53
|
+
Requires-Dist: redis[hiredis]<7.0; extra == "redis"
|
|
54
54
|
Requires-Dist: langchain-redis<=0.2.5; extra == "redis"
|
|
55
55
|
Requires-Dist: langchain-huggingface<=0.1.2; extra == "redis"
|
|
56
56
|
Requires-Dist: accelerate<=1.6.0; extra == "redis"
|
|
57
57
|
Requires-Dist: sentence-transformers<=4.0.2; extra == "redis"
|
|
58
58
|
Provides-Extra: mongodb
|
|
59
|
-
Requires-Dist: pymongo<4.
|
|
59
|
+
Requires-Dist: pymongo<4.16,>=4.11; extra == "mongodb"
|
|
60
60
|
Dynamic: license-file
|
|
61
61
|
|
|
62
62
|

|
|
@@ -164,6 +164,16 @@ See release notes for changes https://github.com/gunthercox/ChatterBot/releases
|
|
|
164
164
|
5. Use the projects [built-in automated testing](https://docs.chatterbot.us/testing/).
|
|
165
165
|
to help make sure that your contribution is free from errors.
|
|
166
166
|
|
|
167
|
+
# Sponsors
|
|
168
|
+
|
|
169
|
+
ChatterBot is sponsored by:
|
|
170
|
+
|
|
171
|
+
<p style="font-size:21px; color:black;">Browser testing via
|
|
172
|
+
<a href="https://www.lambdatest.com/?utm_source=chatterbot&utm_medium=sponsor" target="_blank">
|
|
173
|
+
<img src="https://www.lambdatest.com/blue-logo.png" style="vertical-align: middle;" width="250" height="45" />
|
|
174
|
+
</a>
|
|
175
|
+
</p>
|
|
176
|
+
|
|
167
177
|
# License
|
|
168
178
|
|
|
169
179
|
ChatterBot is licensed under the [BSD 3-clause license](https://opensource.org/licenses/BSD-3-Clause).
|
|
@@ -103,6 +103,16 @@ See release notes for changes https://github.com/gunthercox/ChatterBot/releases
|
|
|
103
103
|
5. Use the projects [built-in automated testing](https://docs.chatterbot.us/testing/).
|
|
104
104
|
to help make sure that your contribution is free from errors.
|
|
105
105
|
|
|
106
|
+
# Sponsors
|
|
107
|
+
|
|
108
|
+
ChatterBot is sponsored by:
|
|
109
|
+
|
|
110
|
+
<p style="font-size:21px; color:black;">Browser testing via
|
|
111
|
+
<a href="https://www.lambdatest.com/?utm_source=chatterbot&utm_medium=sponsor" target="_blank">
|
|
112
|
+
<img src="https://www.lambdatest.com/blue-logo.png" style="vertical-align: middle;" width="250" height="45" />
|
|
113
|
+
</a>
|
|
114
|
+
</p>
|
|
115
|
+
|
|
106
116
|
# License
|
|
107
117
|
|
|
108
118
|
ChatterBot is licensed under the [BSD 3-clause license](https://opensource.org/licenses/BSD-3-Clause).
|
|
@@ -29,6 +29,9 @@ def chatterbot_bigram_indexer(document):
|
|
|
29
29
|
token for token in document if not (token.is_punct)
|
|
30
30
|
]
|
|
31
31
|
|
|
32
|
+
# Pairs consist of the part-of-speech of the first token and the
|
|
33
|
+
# lemma of the second token in the bigram. This provides a good
|
|
34
|
+
# balance of generalization and specificity for matching.
|
|
32
35
|
bigram_pairs = [
|
|
33
36
|
f"{tokens[i - 1].pos_}:{tokens[i].lemma_.lower()}"
|
|
34
37
|
for i in range(1, len(tokens))
|
|
@@ -20,7 +20,19 @@ class SpecificResponseAdapter(LogicAdapter):
|
|
|
20
20
|
def __init__(self, chatbot, **kwargs):
|
|
21
21
|
super().__init__(chatbot, **kwargs)
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
try:
|
|
24
|
+
self.input_text = kwargs['input_text']
|
|
25
|
+
except KeyError:
|
|
26
|
+
raise chatbot.ChatBotException(
|
|
27
|
+
'The SpecificResponseAdapter requires an input_text parameter.'
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
try:
|
|
31
|
+
self._output_text = kwargs['output_text']
|
|
32
|
+
except KeyError:
|
|
33
|
+
raise chatbot.ChatBotException(
|
|
34
|
+
'The SpecificResponseAdapter requires an output_text parameter.'
|
|
35
|
+
)
|
|
24
36
|
|
|
25
37
|
self.matcher = None
|
|
26
38
|
|
|
@@ -33,8 +45,6 @@ class SpecificResponseAdapter(LogicAdapter):
|
|
|
33
45
|
|
|
34
46
|
self.matcher.add('SpecificResponse', [self.input_text])
|
|
35
47
|
|
|
36
|
-
self._output_text = kwargs.get('output_text')
|
|
37
|
-
|
|
38
48
|
def _initialize_nlp(self, language):
|
|
39
49
|
model = get_model_for_language(language)
|
|
40
50
|
|
|
@@ -503,7 +503,7 @@ regex = [
|
|
|
503
503
|
]
|
|
504
504
|
|
|
505
505
|
|
|
506
|
-
def convert_string_to_number(value):
|
|
506
|
+
def convert_string_to_number(value: str) -> int:
|
|
507
507
|
"""
|
|
508
508
|
Convert strings to numbers
|
|
509
509
|
"""
|
|
@@ -517,7 +517,7 @@ def convert_string_to_number(value):
|
|
|
517
517
|
return sum(num_list)
|
|
518
518
|
|
|
519
519
|
|
|
520
|
-
def convert_time_to_hour_minute(hour, minute, convention):
|
|
520
|
+
def convert_time_to_hour_minute(hour: str, minute: str, convention: str) -> dict:
|
|
521
521
|
"""
|
|
522
522
|
Convert time to hour, minute
|
|
523
523
|
"""
|
|
@@ -532,12 +532,19 @@ def convert_time_to_hour_minute(hour, minute, convention):
|
|
|
532
532
|
minute = int(minute)
|
|
533
533
|
|
|
534
534
|
if convention.lower() == 'pm':
|
|
535
|
-
|
|
535
|
+
# Handle 12 PM (noon) - it stays as 12
|
|
536
|
+
# Handle 1-11 PM - add 12
|
|
537
|
+
if hour != 12:
|
|
538
|
+
hour += 12
|
|
539
|
+
else:
|
|
540
|
+
# Handle 12 AM (midnight) - convert to 0
|
|
541
|
+
if hour == 12:
|
|
542
|
+
hour = 0
|
|
536
543
|
|
|
537
544
|
return {'hours': hour, 'minutes': minute}
|
|
538
545
|
|
|
539
546
|
|
|
540
|
-
def date_from_quarter(base_date, ordinal, year):
|
|
547
|
+
def date_from_quarter(base_date: datetime, ordinal: int, year: int) -> list[datetime]:
|
|
541
548
|
"""
|
|
542
549
|
Extract date from quarter of a year
|
|
543
550
|
"""
|
|
@@ -554,7 +561,7 @@ def date_from_quarter(base_date, ordinal, year):
|
|
|
554
561
|
]
|
|
555
562
|
|
|
556
563
|
|
|
557
|
-
def date_from_relative_day(base_date, time, dow):
|
|
564
|
+
def date_from_relative_day(base_date: datetime, time: str, dow: str) -> datetime:
|
|
558
565
|
"""
|
|
559
566
|
Converts relative day to time
|
|
560
567
|
Ex: this tuesday, last tuesday
|
|
@@ -577,7 +584,7 @@ def date_from_relative_day(base_date, time, dow):
|
|
|
577
584
|
return next_week_day(base_date, num)
|
|
578
585
|
|
|
579
586
|
|
|
580
|
-
def date_from_relative_week_year(base_date, time, dow, ordinal=1):
|
|
587
|
+
def date_from_relative_week_year(base_date: datetime, time: str, dow: str, ordinal: int = 1) -> datetime:
|
|
581
588
|
"""
|
|
582
589
|
Converts relative day to time
|
|
583
590
|
Eg. this tuesday, last tuesday
|
|
@@ -608,7 +615,10 @@ def date_from_relative_week_year(base_date, time, dow, ordinal=1):
|
|
|
608
615
|
day = min(relative_date.day, calendar.monthrange(year, month)[1])
|
|
609
616
|
return datetime(year, month, day)
|
|
610
617
|
else:
|
|
611
|
-
|
|
618
|
+
# Base the day to valid range on the target month
|
|
619
|
+
target_month = relative_date.month + ord
|
|
620
|
+
day = min(relative_date.day, calendar.monthrange(relative_date.year, target_month)[1])
|
|
621
|
+
return datetime(relative_date.year, target_month, day)
|
|
612
622
|
elif time == 'end of the':
|
|
613
623
|
return datetime(
|
|
614
624
|
relative_date.year,
|
|
@@ -636,7 +646,7 @@ def date_from_relative_week_year(base_date, time, dow, ordinal=1):
|
|
|
636
646
|
return datetime(relative_date.year, relative_date.month, relative_date.day, 23, 59, 59)
|
|
637
647
|
|
|
638
648
|
|
|
639
|
-
def date_from_adverb(base_date, name):
|
|
649
|
+
def date_from_adverb(base_date: datetime, name: str) -> datetime:
|
|
640
650
|
"""
|
|
641
651
|
Convert Day adverbs to dates
|
|
642
652
|
Tomorrow => Date
|
|
@@ -645,14 +655,14 @@ def date_from_adverb(base_date, name):
|
|
|
645
655
|
# Reset date to start of the day
|
|
646
656
|
adverb_date = datetime(base_date.year, base_date.month, base_date.day)
|
|
647
657
|
if name == 'today' or name == 'tonite' or name == 'tonight':
|
|
648
|
-
return adverb_date
|
|
658
|
+
return adverb_date
|
|
649
659
|
elif name == 'yesterday':
|
|
650
660
|
return adverb_date - timedelta(days=1)
|
|
651
661
|
elif name == 'tomorrow' or name == 'tom':
|
|
652
662
|
return adverb_date + timedelta(days=1)
|
|
653
663
|
|
|
654
664
|
|
|
655
|
-
def date_from_duration(base_date, number_as_string, unit, duration, base_time=None):
|
|
665
|
+
def date_from_duration(base_date: datetime, number_as_string: str, unit: str, duration: str, base_time: str = None) -> datetime:
|
|
656
666
|
"""
|
|
657
667
|
Find dates from duration
|
|
658
668
|
Eg: 20 days from now
|
|
@@ -682,7 +692,7 @@ def date_from_duration(base_date, number_as_string, unit, duration, base_time=No
|
|
|
682
692
|
return base_date + timedelta(**args)
|
|
683
693
|
|
|
684
694
|
|
|
685
|
-
def this_week_day(base_date, weekday):
|
|
695
|
+
def this_week_day(base_date: datetime, weekday: int) -> datetime:
|
|
686
696
|
"""
|
|
687
697
|
Finds coming weekday
|
|
688
698
|
"""
|
|
@@ -698,7 +708,7 @@ def this_week_day(base_date, weekday):
|
|
|
698
708
|
return day
|
|
699
709
|
|
|
700
710
|
|
|
701
|
-
def previous_week_day(base_date, weekday):
|
|
711
|
+
def previous_week_day(base_date: datetime, weekday: int) -> datetime:
|
|
702
712
|
"""
|
|
703
713
|
Finds previous weekday
|
|
704
714
|
"""
|
|
@@ -708,9 +718,9 @@ def previous_week_day(base_date, weekday):
|
|
|
708
718
|
return day
|
|
709
719
|
|
|
710
720
|
|
|
711
|
-
def next_week_day(base_date, weekday):
|
|
721
|
+
def next_week_day(base_date: datetime, weekday: int) -> datetime:
|
|
712
722
|
"""
|
|
713
|
-
Finds next weekday
|
|
723
|
+
Finds the next weekday.
|
|
714
724
|
"""
|
|
715
725
|
day_of_week = base_date.weekday()
|
|
716
726
|
end_of_this_week = base_date + timedelta(days=6 - day_of_week)
|
|
@@ -720,7 +730,7 @@ def next_week_day(base_date, weekday):
|
|
|
720
730
|
return day
|
|
721
731
|
|
|
722
732
|
|
|
723
|
-
def datetime_parsing(text, base_date=datetime.now()):
|
|
733
|
+
def datetime_parsing(text: str, base_date: datetime = datetime.now()) -> list[tuple[str, datetime, tuple[int, int]]]:
|
|
724
734
|
"""
|
|
725
735
|
Extract datetime objects from a string of text.
|
|
726
736
|
"""
|
|
@@ -41,8 +41,30 @@ class SQLStorageAdapter(StorageAdapter):
|
|
|
41
41
|
|
|
42
42
|
@event.listens_for(Engine, 'connect')
|
|
43
43
|
def set_sqlite_pragma(dbapi_connection, connection_record):
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
"""
|
|
45
|
+
Set SQLite PRAGMA settings.
|
|
46
|
+
|
|
47
|
+
This function is called when a new connection is created.
|
|
48
|
+
WAL mode must be set outside of a transaction because it cannot
|
|
49
|
+
change into wal mode from within a transaction.
|
|
50
|
+
"""
|
|
51
|
+
cursor = dbapi_connection.cursor()
|
|
52
|
+
|
|
53
|
+
# Check current journal mode
|
|
54
|
+
cursor.execute('PRAGMA journal_mode')
|
|
55
|
+
current_mode = cursor.fetchone()[0]
|
|
56
|
+
|
|
57
|
+
# Only change if not already in WAL mode
|
|
58
|
+
if current_mode.lower() != 'wal':
|
|
59
|
+
# Set isolation_level to None to execute outside transaction
|
|
60
|
+
old_isolation = dbapi_connection.isolation_level
|
|
61
|
+
dbapi_connection.isolation_level = None
|
|
62
|
+
cursor.execute('PRAGMA journal_mode=WAL')
|
|
63
|
+
dbapi_connection.isolation_level = old_isolation
|
|
64
|
+
|
|
65
|
+
# Set synchronous mode (can be done normally)
|
|
66
|
+
cursor.execute('PRAGMA synchronous=NORMAL')
|
|
67
|
+
cursor.close()
|
|
46
68
|
|
|
47
69
|
if not inspect(self.engine).has_table('statement'):
|
|
48
70
|
self.create_database()
|
|
@@ -23,17 +23,37 @@ class LowercaseTagger(object):
|
|
|
23
23
|
|
|
24
24
|
def get_text_index_string(self, text: Union[str, List[str]]):
|
|
25
25
|
if isinstance(text, list):
|
|
26
|
-
documents = self.nlp.pipe(text)
|
|
26
|
+
documents = self.nlp.pipe(text, batch_size=1000, n_process=1)
|
|
27
27
|
return [document._.search_index for document in documents]
|
|
28
28
|
else:
|
|
29
29
|
document = self.nlp(text)
|
|
30
30
|
return document._.search_index
|
|
31
31
|
|
|
32
|
-
def as_nlp_pipeline(
|
|
32
|
+
def as_nlp_pipeline(
|
|
33
|
+
self,
|
|
34
|
+
texts: Union[List[str], Tuple[str, dict]],
|
|
35
|
+
batch_size: int = 1000,
|
|
36
|
+
n_process: int = 1
|
|
37
|
+
):
|
|
38
|
+
"""
|
|
39
|
+
Process texts through the spaCy NLP pipeline with optimized batching.
|
|
40
|
+
|
|
41
|
+
:param texts: Text strings or tuples of (text, context_dict)
|
|
42
|
+
:param batch_size: Number of texts per batch (default 1000)
|
|
43
|
+
:param n_process: Number of worker processes for spaCy's pipe (set >1 to use multiprocessing)
|
|
33
44
|
|
|
45
|
+
Usage:
|
|
46
|
+
documents = tagger.as_nlp_pipeline(texts)
|
|
47
|
+
documents = tagger.as_nlp_pipeline(texts, batch_size=2000, n_process=4)
|
|
48
|
+
"""
|
|
34
49
|
process_as_tuples = texts and isinstance(texts[0], tuple)
|
|
35
50
|
|
|
36
|
-
documents = self.nlp.pipe(
|
|
51
|
+
documents = self.nlp.pipe(
|
|
52
|
+
texts,
|
|
53
|
+
as_tuples=process_as_tuples,
|
|
54
|
+
batch_size=batch_size,
|
|
55
|
+
n_process=n_process
|
|
56
|
+
)
|
|
37
57
|
return documents
|
|
38
58
|
|
|
39
59
|
|
|
@@ -58,20 +78,37 @@ class PosLemmaTagger(object):
|
|
|
58
78
|
Return a string of text containing part-of-speech, lemma pairs.
|
|
59
79
|
"""
|
|
60
80
|
if isinstance(text, list):
|
|
61
|
-
documents = self.nlp.pipe(text)
|
|
81
|
+
documents = self.nlp.pipe(text, batch_size=1000, n_process=1)
|
|
62
82
|
return [document._.search_index for document in documents]
|
|
63
83
|
else:
|
|
64
84
|
document = self.nlp(text)
|
|
65
85
|
return document._.search_index
|
|
66
86
|
|
|
67
|
-
def as_nlp_pipeline(
|
|
87
|
+
def as_nlp_pipeline(
|
|
88
|
+
self,
|
|
89
|
+
texts: Union[List[str], Tuple[str, dict]],
|
|
90
|
+
batch_size: int = 1000,
|
|
91
|
+
n_process: int = 1
|
|
92
|
+
) -> spacy.tokens.Doc:
|
|
68
93
|
"""
|
|
69
94
|
Accepts a single string or a list of strings, or a list of tuples
|
|
70
95
|
where the first element is the text and the second element is a
|
|
71
96
|
dictionary of context to return alongside the generated document.
|
|
72
|
-
"""
|
|
73
97
|
|
|
98
|
+
:param texts: Text strings or tuples of (text, context_dict)
|
|
99
|
+
:param batch_size: Number of texts per batch (default 1000)
|
|
100
|
+
:param n_process: Number of worker processes for spaCy's pipe (set >1 to use multiprocessing)
|
|
101
|
+
|
|
102
|
+
Usage:
|
|
103
|
+
documents = tagger.as_nlp_pipeline(texts)
|
|
104
|
+
documents = tagger.as_nlp_pipeline(texts, batch_size=2000, n_process=4)
|
|
105
|
+
"""
|
|
74
106
|
process_as_tuples = texts and isinstance(texts[0], tuple)
|
|
75
107
|
|
|
76
|
-
documents = self.nlp.pipe(
|
|
108
|
+
documents = self.nlp.pipe(
|
|
109
|
+
texts,
|
|
110
|
+
as_tuples=process_as_tuples,
|
|
111
|
+
batch_size=batch_size,
|
|
112
|
+
n_process=n_process
|
|
113
|
+
)
|
|
77
114
|
return documents
|
|
@@ -90,28 +90,38 @@ class ListTrainer(Trainer):
|
|
|
90
90
|
"""
|
|
91
91
|
previous_statement_text = None
|
|
92
92
|
previous_statement_search_text = ''
|
|
93
|
-
|
|
94
93
|
statements_to_create = []
|
|
95
94
|
|
|
96
|
-
#
|
|
97
|
-
|
|
98
|
-
|
|
95
|
+
# Preprocess all text before NLP analysis
|
|
96
|
+
preprocessed_texts = conversation
|
|
97
|
+
for preprocessor in self.chatbot.preprocessors:
|
|
98
|
+
preprocessed_texts = [
|
|
99
|
+
preprocessor(Statement(text=text)).text
|
|
100
|
+
for text in preprocessed_texts
|
|
101
|
+
]
|
|
102
|
+
|
|
103
|
+
# Batch process with NLP
|
|
104
|
+
documents = list(self.chatbot.tagger.as_nlp_pipeline(
|
|
105
|
+
preprocessed_texts,
|
|
106
|
+
batch_size=2000,
|
|
107
|
+
# NOTE: Not all spaCy models support multi-processing
|
|
108
|
+
n_process=1
|
|
109
|
+
))
|
|
110
|
+
|
|
111
|
+
# Create statements from processed documents
|
|
99
112
|
for document in tqdm(documents, desc='List Trainer', disable=self.disable_progress):
|
|
100
113
|
statement_search_text = document._.search_index
|
|
101
114
|
|
|
102
|
-
statement =
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
conversation='training'
|
|
109
|
-
)
|
|
115
|
+
statement = Statement(
|
|
116
|
+
text=document.text,
|
|
117
|
+
search_text=statement_search_text,
|
|
118
|
+
in_response_to=previous_statement_text,
|
|
119
|
+
search_in_response_to=previous_statement_search_text,
|
|
120
|
+
conversation='training'
|
|
110
121
|
)
|
|
111
122
|
|
|
112
123
|
previous_statement_text = statement.text
|
|
113
124
|
previous_statement_search_text = statement_search_text
|
|
114
|
-
|
|
115
125
|
statements_to_create.append(statement)
|
|
116
126
|
|
|
117
127
|
self.chatbot.storage.create_many(statements_to_create)
|
|
@@ -134,21 +144,45 @@ class ChatterBotCorpusTrainer(Trainer):
|
|
|
134
144
|
|
|
135
145
|
for corpus, categories, _file_path in tqdm(
|
|
136
146
|
load_corpus(*data_file_paths),
|
|
137
|
-
desc='
|
|
147
|
+
desc='Training corpus',
|
|
138
148
|
disable=self.disable_progress
|
|
139
149
|
):
|
|
140
150
|
statements_to_create = []
|
|
141
151
|
|
|
142
|
-
#
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
# Run the pipeline in bulk to improve performance
|
|
146
|
-
documents = self.chatbot.tagger.as_nlp_pipeline(conversation)
|
|
152
|
+
# Collect all texts from all conversations for batch processing
|
|
153
|
+
all_texts = []
|
|
154
|
+
conversation_lengths = []
|
|
147
155
|
|
|
156
|
+
for conversation in corpus:
|
|
157
|
+
conversation_lengths.append(len(conversation))
|
|
158
|
+
all_texts.extend(conversation)
|
|
159
|
+
|
|
160
|
+
# Preprocess all texts
|
|
161
|
+
preprocessed_texts = all_texts
|
|
162
|
+
for preprocessor in self.chatbot.preprocessors:
|
|
163
|
+
preprocessed_texts = [
|
|
164
|
+
preprocessor(Statement(text=text)).text
|
|
165
|
+
for text in preprocessed_texts
|
|
166
|
+
]
|
|
167
|
+
|
|
168
|
+
# Batch process all texts with NLP
|
|
169
|
+
documents = list(self.chatbot.tagger.as_nlp_pipeline(
|
|
170
|
+
preprocessed_texts,
|
|
171
|
+
batch_size=2000,
|
|
172
|
+
# NOTE: Not all spaCy models support multi-processing
|
|
173
|
+
n_process=1
|
|
174
|
+
))
|
|
175
|
+
|
|
176
|
+
# Reconstruct conversations from batch-processed documents
|
|
177
|
+
doc_index = 0
|
|
178
|
+
for conversation_length in conversation_lengths:
|
|
148
179
|
previous_statement_text = None
|
|
149
180
|
previous_statement_search_text = ''
|
|
150
181
|
|
|
151
|
-
for
|
|
182
|
+
for _ in range(conversation_length):
|
|
183
|
+
document = documents[doc_index]
|
|
184
|
+
doc_index += 1
|
|
185
|
+
|
|
152
186
|
statement_search_text = document._.search_index
|
|
153
187
|
|
|
154
188
|
statement = Statement(
|
|
@@ -161,11 +195,8 @@ class ChatterBotCorpusTrainer(Trainer):
|
|
|
161
195
|
|
|
162
196
|
statement.add_tags(*categories)
|
|
163
197
|
|
|
164
|
-
statement = self.get_preprocessed_statement(statement)
|
|
165
|
-
|
|
166
198
|
previous_statement_text = statement.text
|
|
167
199
|
previous_statement_search_text = statement_search_text
|
|
168
|
-
|
|
169
200
|
statements_to_create.append(statement)
|
|
170
201
|
|
|
171
202
|
if statements_to_create:
|
|
@@ -283,18 +314,28 @@ class GenericFileTrainer(Trainer):
|
|
|
283
314
|
|
|
284
315
|
text_row = self.field_map['text']
|
|
285
316
|
|
|
317
|
+
# Collect all rows first to avoid re-reading file
|
|
318
|
+
rows_list = [row for row in data if len(row) > 0]
|
|
319
|
+
|
|
320
|
+
# Extract text and metadata for each row
|
|
321
|
+
text_values = []
|
|
322
|
+
contexts = []
|
|
323
|
+
|
|
286
324
|
try:
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
row[
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
325
|
+
for row in rows_list:
|
|
326
|
+
context = {
|
|
327
|
+
key: row[value]
|
|
328
|
+
for key, value in self.field_map.items()
|
|
329
|
+
if key != text_row
|
|
330
|
+
}
|
|
331
|
+
contexts.append(context)
|
|
332
|
+
|
|
333
|
+
# Preprocess text
|
|
334
|
+
text = row[text_row]
|
|
335
|
+
for preprocessor in self.chatbot.preprocessors:
|
|
336
|
+
text = preprocessor(Statement(text=text)).text
|
|
337
|
+
|
|
338
|
+
text_values.append((text, context))
|
|
298
339
|
except KeyError as e:
|
|
299
340
|
raise KeyError(
|
|
300
341
|
f'{e}. Please check the field_map parameter used to initialize '
|
|
@@ -302,21 +343,50 @@ class GenericFileTrainer(Trainer):
|
|
|
302
343
|
f'Current mapping: {self.field_map}'
|
|
303
344
|
)
|
|
304
345
|
|
|
346
|
+
# Batch process with NLP
|
|
347
|
+
documents = self.chatbot.tagger.as_nlp_pipeline(
|
|
348
|
+
text_values,
|
|
349
|
+
batch_size=2000,
|
|
350
|
+
# NOTE: Not all spaCy models support multi-processing
|
|
351
|
+
n_process=1
|
|
352
|
+
)
|
|
353
|
+
|
|
354
|
+
# Convert to list for processing
|
|
355
|
+
documents_list = list(documents)
|
|
356
|
+
|
|
305
357
|
response_to_search_index_mapping = {}
|
|
306
358
|
|
|
307
359
|
if 'in_response_to' in self.field_map.keys():
|
|
308
|
-
#
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
360
|
+
# Process response references for search indexing
|
|
361
|
+
in_response_to_field = self.field_map['in_response_to']
|
|
362
|
+
response_texts = [
|
|
363
|
+
row[in_response_to_field]
|
|
364
|
+
for row in rows_list
|
|
365
|
+
if row[in_response_to_field] is not None
|
|
366
|
+
]
|
|
367
|
+
|
|
368
|
+
if response_texts:
|
|
369
|
+
# Preprocess response texts
|
|
370
|
+
preprocessed_response_texts = response_texts
|
|
371
|
+
for preprocessor in self.chatbot.preprocessors:
|
|
372
|
+
preprocessed_response_texts = [
|
|
373
|
+
preprocessor(Statement(text=text)).text
|
|
374
|
+
for text in preprocessed_response_texts
|
|
375
|
+
]
|
|
376
|
+
|
|
377
|
+
# Batch process response texts
|
|
378
|
+
response_documents = self.chatbot.tagger.as_nlp_pipeline(
|
|
379
|
+
preprocessed_response_texts,
|
|
380
|
+
batch_size=2000,
|
|
381
|
+
# NOTE: Not all spaCy models support multi-processing
|
|
382
|
+
n_process=1
|
|
383
|
+
)
|
|
384
|
+
|
|
385
|
+
for document in response_documents:
|
|
386
|
+
response_to_search_index_mapping[document.text] = document._.search_index
|
|
387
|
+
|
|
388
|
+
# Create statements from processed documents
|
|
389
|
+
for document, context in tqdm(documents_list, desc='Creating statements', disable=self.disable_progress, leave=False):
|
|
320
390
|
statement = Statement(
|
|
321
391
|
text=document.text,
|
|
322
392
|
conversation=context.get('conversation', 'training'),
|
|
@@ -342,9 +412,6 @@ class GenericFileTrainer(Trainer):
|
|
|
342
412
|
statement.in_response_to = previous_statement_text
|
|
343
413
|
statement.search_in_response_to = previous_statement_search_text
|
|
344
414
|
|
|
345
|
-
for preprocessor in self.chatbot.preprocessors:
|
|
346
|
-
statement = preprocessor(statement)
|
|
347
|
-
|
|
348
415
|
previous_statement_text = statement.text
|
|
349
416
|
previous_statement_search_text = statement.search_text
|
|
350
417
|
|
|
@@ -80,16 +80,16 @@ dev = [
|
|
|
80
80
|
"pint>=0.8.1",
|
|
81
81
|
"pyyaml>=6.0,<7.0",
|
|
82
82
|
"chatterbot-corpus>=1.2.2,<1.3.0",
|
|
83
|
-
"ollama>=0.
|
|
83
|
+
"ollama>=0.6.0,<1.0",
|
|
84
84
|
"openai"
|
|
85
85
|
]
|
|
86
86
|
redis = [
|
|
87
|
-
"redis[hiredis]<
|
|
87
|
+
"redis[hiredis]<7.0",
|
|
88
88
|
"langchain-redis<=0.2.5",
|
|
89
89
|
"langchain-huggingface<=0.1.2",
|
|
90
90
|
"accelerate<=1.6.0",
|
|
91
91
|
"sentence-transformers<=4.0.2",
|
|
92
92
|
]
|
|
93
93
|
mongodb = [
|
|
94
|
-
"pymongo>=4.11,<4.
|
|
94
|
+
"pymongo>=4.11,<4.16",
|
|
95
95
|
]
|
|
@@ -16,7 +16,7 @@ class ChatBotInitializationTestCase(ChatBotTestCase):
|
|
|
16
16
|
does not exist for a language.
|
|
17
17
|
"""
|
|
18
18
|
with self.assertRaises(KeyError) as exc:
|
|
19
|
-
|
|
19
|
+
ChatBot(
|
|
20
20
|
'Test Bot',
|
|
21
21
|
tagger_language=languages.LAT
|
|
22
22
|
)
|
|
@@ -32,7 +32,7 @@ class ChatBotInitializationTestCase(ChatBotTestCase):
|
|
|
32
32
|
has not been installed for the specified language.
|
|
33
33
|
"""
|
|
34
34
|
with self.assertRaises(ChatBot.ChatBotException) as exc:
|
|
35
|
-
|
|
35
|
+
ChatBot(
|
|
36
36
|
'Test Bot',
|
|
37
37
|
tagger_language=languages.NOR
|
|
38
38
|
)
|
|
@@ -208,8 +208,9 @@ class ChatterBotResponseTestCase(ChatBotTestCase):
|
|
|
208
208
|
response = self.chatbot.get_response(
|
|
209
209
|
statement,
|
|
210
210
|
additional_response_selection_parameters={
|
|
211
|
-
|
|
212
|
-
|
|
211
|
+
'conversation': 'test_2'
|
|
212
|
+
}
|
|
213
|
+
)
|
|
213
214
|
|
|
214
215
|
self.assertEqual(response.text, 'C')
|
|
215
216
|
self.assertEqual(response.conversation, 'test_3')
|
|
@@ -387,3 +387,200 @@ class DateTimeParsingTestCases(TestCase):
|
|
|
387
387
|
result = parsing.this_week_day(base_date, weekday)
|
|
388
388
|
|
|
389
389
|
self.assertEqual(result, datetime(2016, 12, 14, 10, 10, 52, 85280))
|
|
390
|
+
|
|
391
|
+
def test_today_at_time_uses_base_date(self):
|
|
392
|
+
"""
|
|
393
|
+
The string 'today at [time]' should respect the base_date parameter.
|
|
394
|
+
"""
|
|
395
|
+
base_date = datetime(2018, 7, 14, 8, 52, 21) # July 14, 2018 at 8:52:21 AM
|
|
396
|
+
input_text = 'Your dental appointment is scheduled today at 9:00pm.'
|
|
397
|
+
parser = parsing.datetime_parsing(input_text, base_date)
|
|
398
|
+
|
|
399
|
+
self.assertEqual(len(parser), 1)
|
|
400
|
+
self.assertIn('today at 9:00pm', parser[0])
|
|
401
|
+
|
|
402
|
+
parsed_datetime = parser[0][1]
|
|
403
|
+
# Should be July 14, 2018 at 9:00 PM
|
|
404
|
+
self.assertEqual(parsed_datetime.year, 2018)
|
|
405
|
+
self.assertEqual(parsed_datetime.month, 7)
|
|
406
|
+
self.assertEqual(parsed_datetime.day, 14)
|
|
407
|
+
self.assertEqual(parsed_datetime.hour, 21) # 9 PM
|
|
408
|
+
self.assertEqual(parsed_datetime.minute, 0)
|
|
409
|
+
|
|
410
|
+
def test_next_month_from_january_31st(self):
|
|
411
|
+
"""
|
|
412
|
+
Test 'next month' from Jan 31 handles February correctly
|
|
413
|
+
"""
|
|
414
|
+
base_date = datetime(2025, 1, 31, 12, 0, 0)
|
|
415
|
+
input_text = 'next month'
|
|
416
|
+
parser = parsing.datetime_parsing(input_text, base_date)
|
|
417
|
+
|
|
418
|
+
self.assertEqual(len(parser), 1)
|
|
419
|
+
# February only has 28 days in 2025, should clamp to last valid day
|
|
420
|
+
self.assertEqual(parser[0][1].year, 2025)
|
|
421
|
+
self.assertEqual(parser[0][1].month, 2)
|
|
422
|
+
self.assertEqual(parser[0][1].day, 28)
|
|
423
|
+
|
|
424
|
+
def test_next_3_months_crosses_year_boundary(self):
|
|
425
|
+
"""
|
|
426
|
+
Test 'next 3 months' crossing year boundary
|
|
427
|
+
"""
|
|
428
|
+
base_date = datetime(2025, 11, 15, 12, 0, 0)
|
|
429
|
+
input_text = 'next 3 months'
|
|
430
|
+
parser = parsing.datetime_parsing(input_text, base_date)
|
|
431
|
+
|
|
432
|
+
self.assertEqual(len(parser), 1)
|
|
433
|
+
self.assertEqual(parser[0][1].year, 2026)
|
|
434
|
+
self.assertEqual(parser[0][1].month, 2)
|
|
435
|
+
self.assertEqual(parser[0][1].day, 15)
|
|
436
|
+
|
|
437
|
+
def test_next_month_from_march_31st(self):
|
|
438
|
+
"""
|
|
439
|
+
Test 'next month' from March 31 handles April correctly
|
|
440
|
+
"""
|
|
441
|
+
base_date = datetime(2025, 3, 31, 12, 0, 0)
|
|
442
|
+
input_text = 'next month'
|
|
443
|
+
parser = parsing.datetime_parsing(input_text, base_date)
|
|
444
|
+
|
|
445
|
+
self.assertEqual(len(parser), 1)
|
|
446
|
+
# April only has 30 days, should pick the last valid day
|
|
447
|
+
self.assertEqual(parser[0][1].year, 2025)
|
|
448
|
+
self.assertEqual(parser[0][1].month, 4)
|
|
449
|
+
self.assertEqual(parser[0][1].day, 30)
|
|
450
|
+
|
|
451
|
+
def test_next_month_from_may_31st(self):
|
|
452
|
+
"""
|
|
453
|
+
Test 'next month' from May 31 handles June correctly
|
|
454
|
+
"""
|
|
455
|
+
base_date = datetime(2025, 5, 31, 12, 0, 0)
|
|
456
|
+
input_text = 'next month'
|
|
457
|
+
parser = parsing.datetime_parsing(input_text, base_date)
|
|
458
|
+
|
|
459
|
+
self.assertEqual(len(parser), 1)
|
|
460
|
+
# June only has 30 days, should pick the last valid day
|
|
461
|
+
self.assertEqual(parser[0][1].year, 2025)
|
|
462
|
+
self.assertEqual(parser[0][1].month, 6)
|
|
463
|
+
self.assertEqual(parser[0][1].day, 30)
|
|
464
|
+
|
|
465
|
+
def test_multiple_datetime_expressions(self):
|
|
466
|
+
"""
|
|
467
|
+
Test parsing text with multiple date/time references
|
|
468
|
+
"""
|
|
469
|
+
base_date = datetime(2025, 10, 18, 12, 0, 0)
|
|
470
|
+
input_text = 'Meeting today at 2pm and tomorrow at 3pm'
|
|
471
|
+
parser = parsing.datetime_parsing(input_text, base_date)
|
|
472
|
+
|
|
473
|
+
self.assertEqual(len(parser), 2)
|
|
474
|
+
# First: today at 2pm
|
|
475
|
+
self.assertEqual(parser[0][1].year, 2025)
|
|
476
|
+
self.assertEqual(parser[0][1].month, 10)
|
|
477
|
+
self.assertEqual(parser[0][1].day, 18)
|
|
478
|
+
self.assertEqual(parser[0][1].hour, 14)
|
|
479
|
+
# Second: tomorrow at 3pm
|
|
480
|
+
self.assertEqual(parser[1][1].year, 2025)
|
|
481
|
+
self.assertEqual(parser[1][1].month, 10)
|
|
482
|
+
self.assertEqual(parser[1][1].day, 19)
|
|
483
|
+
self.assertEqual(parser[1][1].hour, 15)
|
|
484
|
+
|
|
485
|
+
def test_duration_from_yesterday(self):
|
|
486
|
+
"""
|
|
487
|
+
Test '2 days after yesterday' using base_time
|
|
488
|
+
"""
|
|
489
|
+
base_date = datetime(2025, 10, 18, 12, 0, 0)
|
|
490
|
+
input_text = '2 days after yesterday'
|
|
491
|
+
parser = parsing.datetime_parsing(input_text, base_date)
|
|
492
|
+
|
|
493
|
+
self.assertEqual(len(parser), 1)
|
|
494
|
+
# Yesterday = Oct 17, + 2 days = Oct 19
|
|
495
|
+
self.assertEqual(parser[0][1].year, 2025)
|
|
496
|
+
self.assertEqual(parser[0][1].month, 10)
|
|
497
|
+
self.assertEqual(parser[0][1].day, 19)
|
|
498
|
+
|
|
499
|
+
def test_duration_from_tomorrow(self):
|
|
500
|
+
"""
|
|
501
|
+
Test '3 days after tomorrow'
|
|
502
|
+
"""
|
|
503
|
+
base_date = datetime(2025, 10, 18, 12, 0, 0)
|
|
504
|
+
input_text = '3 days after tomorrow'
|
|
505
|
+
parser = parsing.datetime_parsing(input_text, base_date)
|
|
506
|
+
|
|
507
|
+
self.assertEqual(len(parser), 1)
|
|
508
|
+
# Tomorrow = Oct 19, + 3 days = Oct 22
|
|
509
|
+
self.assertEqual(parser[0][1].year, 2025)
|
|
510
|
+
self.assertEqual(parser[0][1].month, 10)
|
|
511
|
+
self.assertEqual(parser[0][1].day, 22)
|
|
512
|
+
|
|
513
|
+
def test_duration_from_today(self):
|
|
514
|
+
"""
|
|
515
|
+
Test '5 days before today'
|
|
516
|
+
"""
|
|
517
|
+
base_date = datetime(2025, 10, 18, 12, 0, 0)
|
|
518
|
+
input_text = '5 days before today'
|
|
519
|
+
parser = parsing.datetime_parsing(input_text, base_date)
|
|
520
|
+
|
|
521
|
+
self.assertEqual(len(parser), 1)
|
|
522
|
+
# Today = Oct 18, - 5 days = Oct 13
|
|
523
|
+
self.assertEqual(parser[0][1].year, 2025)
|
|
524
|
+
self.assertEqual(parser[0][1].month, 10)
|
|
525
|
+
self.assertEqual(parser[0][1].day, 13)
|
|
526
|
+
|
|
527
|
+
def test_noon_without_convention(self):
|
|
528
|
+
"""
|
|
529
|
+
Test '12:00' without AM/PM defaults to AM convention (midnight = 0)
|
|
530
|
+
"""
|
|
531
|
+
base_date = datetime(2025, 10, 18, 0, 0, 0)
|
|
532
|
+
input_text = 'Meeting at 12:00'
|
|
533
|
+
parser = parsing.datetime_parsing(input_text, base_date)
|
|
534
|
+
|
|
535
|
+
self.assertEqual(len(parser), 1)
|
|
536
|
+
# No convention defaults to 'am', so 12:00 becomes 0 (midnight)
|
|
537
|
+
self.assertEqual(parser[0][1].hour, 0)
|
|
538
|
+
self.assertEqual(parser[0][1].minute, 0)
|
|
539
|
+
|
|
540
|
+
def test_twelve_pm(self):
|
|
541
|
+
"""
|
|
542
|
+
Test '12:00 pm' is noon (stays as 12)
|
|
543
|
+
"""
|
|
544
|
+
base_date = datetime(2025, 10, 18, 0, 0, 0)
|
|
545
|
+
input_text = 'Meeting at 12:00 pm'
|
|
546
|
+
parser = parsing.datetime_parsing(input_text, base_date)
|
|
547
|
+
|
|
548
|
+
self.assertEqual(len(parser), 1)
|
|
549
|
+
self.assertEqual(parser[0][1].hour, 12)
|
|
550
|
+
self.assertEqual(parser[0][1].minute, 0)
|
|
551
|
+
|
|
552
|
+
def test_twelve_am(self):
|
|
553
|
+
"""
|
|
554
|
+
Test '12:00 am' is midnight (converted to 0)
|
|
555
|
+
"""
|
|
556
|
+
base_date = datetime(2025, 10, 18, 0, 0, 0)
|
|
557
|
+
input_text = 'Meeting at 12:00 am'
|
|
558
|
+
parser = parsing.datetime_parsing(input_text, base_date)
|
|
559
|
+
|
|
560
|
+
self.assertEqual(len(parser), 1)
|
|
561
|
+
self.assertEqual(parser[0][1].hour, 0)
|
|
562
|
+
self.assertEqual(parser[0][1].minute, 0)
|
|
563
|
+
|
|
564
|
+
def test_one_am(self):
|
|
565
|
+
"""
|
|
566
|
+
Test '1:00 am' is 1:00
|
|
567
|
+
"""
|
|
568
|
+
base_date = datetime(2025, 10, 18, 0, 0, 0)
|
|
569
|
+
input_text = 'Meeting at 1:00 am'
|
|
570
|
+
parser = parsing.datetime_parsing(input_text, base_date)
|
|
571
|
+
|
|
572
|
+
self.assertEqual(len(parser), 1)
|
|
573
|
+
self.assertEqual(parser[0][1].hour, 1)
|
|
574
|
+
self.assertEqual(parser[0][1].minute, 0)
|
|
575
|
+
|
|
576
|
+
def test_one_pm(self):
|
|
577
|
+
"""
|
|
578
|
+
Test '1:00 pm' is 13:00
|
|
579
|
+
"""
|
|
580
|
+
base_date = datetime(2025, 10, 18, 0, 0, 0)
|
|
581
|
+
input_text = 'Meeting at 1:00 pm'
|
|
582
|
+
parser = parsing.datetime_parsing(input_text, base_date)
|
|
583
|
+
|
|
584
|
+
self.assertEqual(len(parser), 1)
|
|
585
|
+
self.assertEqual(parser[0][1].hour, 13)
|
|
586
|
+
self.assertEqual(parser[0][1].minute, 0)
|
|
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.8 → chatterbot-1.2.9}/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.8 → chatterbot-1.2.9}/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
|
{chatterbot-1.2.8 → chatterbot-1.2.9}/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
|