本文整理汇总了Python中chatterbot.conversation.Statement.add_tags方法的典型用法代码示例。如果您正苦于以下问题:Python Statement.add_tags方法的具体用法?Python Statement.add_tags怎么用?Python Statement.add_tags使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类chatterbot.conversation.Statement
的用法示例。
在下文中一共展示了Statement.add_tags方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: StatementIntegrationTestCase
# 需要导入模块: from chatterbot.conversation import Statement [as 别名]
# 或者: from chatterbot.conversation.Statement import add_tags [as 别名]
class StatementIntegrationTestCase(TestCase):
"""
Test case to make sure that the Django Statement model
and ChatterBot Statement object have a common interface.
"""
def setUp(self):
super().setUp()
from datetime import datetime
from pytz import UTC
now = datetime(2020, 2, 15, 3, 14, 10, 0, UTC)
self.object = StatementObject(text='_', created_at=now)
self.model = StatementModel(text='_', created_at=now)
# Simulate both statements being saved
self.model.save()
self.object.id = self.model.id
def test_text(self):
self.assertTrue(hasattr(self.object, 'text'))
self.assertTrue(hasattr(self.model, 'text'))
def test_in_response_to(self):
self.assertTrue(hasattr(self.object, 'in_response_to'))
self.assertTrue(hasattr(self.model, 'in_response_to'))
def test_conversation(self):
self.assertTrue(hasattr(self.object, 'conversation'))
self.assertTrue(hasattr(self.model, 'conversation'))
def test_tags(self):
self.assertTrue(hasattr(self.object, 'tags'))
self.assertTrue(hasattr(self.model, 'tags'))
def test__str__(self):
self.assertTrue(hasattr(self.object, '__str__'))
self.assertTrue(hasattr(self.model, '__str__'))
self.assertEqual(str(self.object), str(self.model))
def test_add_tags(self):
self.object.add_tags('a', 'b')
self.model.add_tags('a', 'b')
self.assertIn('a', self.object.get_tags())
self.assertIn('a', self.model.get_tags())
def test_serialize(self):
object_data = self.object.serialize()
model_data = self.model.serialize()
self.assertEqual(object_data, model_data)
示例2: train
# 需要导入模块: from chatterbot.conversation import Statement [as 别名]
# 或者: from chatterbot.conversation.Statement import add_tags [as 别名]
def train(self, *corpus_paths):
from chatterbot.corpus import load_corpus, list_corpus_files
data_file_paths = []
# Get the paths to each file the bot will be trained with
for corpus_path in corpus_paths:
data_file_paths.extend(list_corpus_files(corpus_path))
for corpus, categories, file_path in load_corpus(*data_file_paths):
statements_to_create = []
# Train the chat bot with each statement and response pair
for conversation_count, conversation in enumerate(corpus):
if self.show_training_progress:
utils.print_progress_bar(
'Training ' + str(os.path.basename(file_path)),
conversation_count + 1,
len(corpus)
)
previous_statement_text = None
previous_statement_search_text = ''
for text in conversation:
statement_search_text = self.stemmer.get_bigram_pair_string(text)
statement = Statement(
text=text,
search_text=statement_search_text,
in_response_to=previous_statement_text,
search_in_response_to=previous_statement_search_text,
conversation='training'
)
statement.add_tags(*categories)
statement = self.get_preprocessed_statement(statement)
previous_statement_text = statement.text
previous_statement_search_text = statement_search_text
statements_to_create.append(statement)
self.chatbot.storage.create_many(statements_to_create)
示例3: ChatterBotResponseTestCase
# 需要导入模块: from chatterbot.conversation import Statement [as 别名]
# 或者: from chatterbot.conversation.Statement import add_tags [as 别名]
#.........这里部分代码省略.........
def test_get_response_emoji(self):
"""
Test the case that the input string contains an emoji.
"""
response = self.chatbot.get_response(u'💩 ')
self.assertGreater(len(response.text), 0)
def test_get_response_non_whitespace(self):
"""
Test the case that a non-whitespace C1 control string is passed in.
"""
response = self.chatbot.get_response(u'')
self.assertGreater(len(response.text), 0)
def test_get_response_two_byte_characters(self):
"""
Test the case that a string containing two-byte characters is passed in.
"""
response = self.chatbot.get_response(u'田中さんにあげて下さい')
self.assertGreater(len(response.text), 0)
def test_get_response_corrupted_text(self):
"""
Test the case that a string contains "corrupted" text.
"""
response = self.chatbot.get_response(u'Ṱ̺̺̕h̼͓̲̦̳̘̲e͇̣̰̦̬͎ ̢̼̻̱̘h͚͎͙̜̣̲ͅi̦̲̣̰̤v̻͍e̺̭̳̪̰-m̢iͅn̖̺̞̲̯̰d̵̼̟͙̩̼̘̳.̨̹͈̣')
self.assertGreater(len(response.text), 0)
def test_response_with_tags_added(self):
"""
If an input statement has tags added to it,
that data should saved with the input statement.
"""
self.test_statement.add_tags('test')
self.chatbot.get_response(
self.test_statement
)
results = self.chatbot.storage.filter(text=self.test_statement.text)
self.assertIsLength(results, 1)
self.assertIn('test', results[0].get_tags())
def test_get_response_with_text_and_kwargs(self):
self.chatbot.get_response('Hello', conversation='greetings')
results = self.chatbot.storage.filter(text='Hello')
self.assertIsLength(results, 1)
self.assertEqual(results[0].conversation, 'greetings')
def test_get_response_missing_text(self):
with self.assertRaises(self.chatbot.ChatBotException):
self.chatbot.get_response()
def test_get_response_missing_text_with_conversation(self):
with self.assertRaises(self.chatbot.ChatBotException):
self.chatbot.get_response(conversation='test')
def test_generate_response(self):
statement = Statement(text='Many insects adopt a tripedal gait for rapid yet stable walking.')
response = self.chatbot.generate_response(statement)
self.assertEqual(response, statement)
self.assertEqual(response.confidence, 1)