本文整理汇总了Python中chatterbot.conversation.Statement.serialize方法的典型用法代码示例。如果您正苦于以下问题:Python Statement.serialize方法的具体用法?Python Statement.serialize怎么用?Python Statement.serialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类chatterbot.conversation.Statement
的用法示例。
在下文中一共展示了Statement.serialize方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: StatementTests
# 需要导入模块: from chatterbot.conversation import Statement [as 别名]
# 或者: from chatterbot.conversation.Statement import serialize [as 别名]
class StatementTests(TestCase):
def setUp(self):
self.statement = Statement(text="A test statement.")
def test_string_equality(self):
"""
It should be possible to check if a statement
is the same as the statement text that another
statement lists as a response.
"""
self.assertEqual(self.statement, "A test statement.")
def test_string_equality_unicode(self):
"""
Test that it is possible to check if a statement
is in a list of other statements when the
statements text is unicode.
"""
self.statement.text = "我很好太感谢"
self.assertEqual(self.statement, "我很好太感谢")
def test_serializer(self):
data = self.statement.serialize()
self.assertEqual(self.statement.text, data["text"])
示例2: StatementTests
# 需要导入模块: from chatterbot.conversation import Statement [as 别名]
# 或者: from chatterbot.conversation.Statement import serialize [as 别名]
class StatementTests(TestCase):
def setUp(self):
self.statement = Statement(text='A test statement.')
def test_serializer(self):
data = self.statement.serialize()
self.assertEqual(self.statement.text, data['text'])
示例3: StatementIntegrationTestCase
# 需要导入模块: from chatterbot.conversation import Statement [as 别名]
# 或者: from chatterbot.conversation.Statement import serialize [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)
示例4: StatementTests
# 需要导入模块: from chatterbot.conversation import Statement [as 别名]
# 或者: from chatterbot.conversation.Statement import serialize [as 别名]
class StatementTests(TestCase):
def setUp(self):
self.statement = Statement("A test statement.")
def test_equality(self):
"""
It should be possible to check if a statement
exists in the list of statements that another
statement has been issued in response to.
"""
self.statement.add_response(Statement("Yo"))
self.assertEqual(len(self.statement.in_response_to), 1)
self.assertIn(
Statement("Yo"),
self.statement.in_response_to
)
def test_occurrence_count(self):
self.statement.update_occurrence_count()
self.assertTrue(
self.statement.get_occurrence_count(),
2
)
def test_update_response_list_new(self):
new_statement = Statement("Hello")
self.statement.add_response(new_statement)
self.assertTrue(
len(self.statement.in_response_to),
1
)
def test_update_response_list_existing(self):
previous_statement = Statement("Hello")
self.statement.add_response(previous_statement)
self.statement.add_response(previous_statement)
self.assertTrue(
len(self.statement.in_response_to),
1
)
def test_add_signature(self):
signature = Signature("Gunther Cox")
self.statement.add_signature(signature)
self.assertIn(signature, self.statement.signatures)
def test_serializer(self):
data = self.statement.serialize()
self.assertEqual(self.statement.text, data["text"])
示例5: StatementTests
# 需要导入模块: from chatterbot.conversation import Statement [as 别名]
# 或者: from chatterbot.conversation.Statement import serialize [as 别名]
class StatementTests(TestCase):
def setUp(self):
self.statement = Statement("A test statement.")
def test_equality(self):
"""
It should be possible to check if a statement
exists in the list of statements that another
statement has been issued in response to.
"""
self.statement.add_response(Response("Yo"))
self.assertEqual(len(self.statement.in_response_to), 1)
self.assertIn(Response("Yo"), self.statement.in_response_to)
def test_update_response_list_new(self):
self.statement.add_response(Response("Hello"))
self.assertTrue(len(self.statement.in_response_to), 1)
def test_update_response_list_existing(self):
response = Response("Hello")
self.statement.add_response(response)
self.statement.add_response(response)
self.assertTrue(len(self.statement.in_response_to), 1)
def test_remove_response_exists(self):
self.statement.add_response(Response("Testing"))
removed = self.statement.remove_response("Testing")
self.assertTrue(removed)
def test_remove_response_does_not_exist(self):
self.statement.add_response(Response("Testing"))
removed = self.statement.remove_response("Test")
self.assertFalse(removed)
def test_serializer(self):
data = self.statement.serialize()
self.assertEqual(self.statement.text, data["text"])
def test_occurrence_count_for_new_statement(self):
"""
When the occurrence is updated for a statement that
previously did not exist as a statement that the current
statement was issued in response to, then the new statement
should be added to the response list and the occurence count
for that response should be set to 1.
"""
response = Response("This is a test.")
self.statement.add_response(response)
self.assertTrue(self.statement.get_response_count(response), 1)
def test_occurrence_count_for_existing_statement(self):
self.statement.add_response(Response("ABC"))
self.statement.add_response(Response("ABC"))
self.assertTrue(
self.statement.get_response_count(Response("ABC")),
2
)
def test_occurrence_count_incremented(self):
self.statement.add_response(Response("ABC"))
self.statement.add_response(Response("ABC"))
self.assertEqual(len(self.statement.in_response_to), 1)
self.assertEqual(self.statement.in_response_to[0].occurrence, 2)
示例6: StatementIntegrationTestCase
# 需要导入模块: from chatterbot.conversation import Statement [as 别名]
# 或者: from chatterbot.conversation.Statement import serialize [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(StatementIntegrationTestCase, self).setUp()
self.object = StatementObject(text='_')
self.model = StatementModel(text='_')
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_extra_data(self):
self.assertTrue(hasattr(self.object, 'extra_data'))
self.assertTrue(hasattr(self.model, 'extra_data'))
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_extra_data(self):
self.object.add_extra_data('key', 'value')
self.model.add_extra_data('key', 'value')
def test_add_response(self):
self.assertTrue(hasattr(self.object, 'add_response'))
self.assertTrue(hasattr(self.model, 'add_response'))
def test_remove_response(self):
self.object.add_response(ResponseObject('Hello'))
model_response_statement = StatementModel.objects.create(text='Hello')
self.model.save()
self.model.in_response.create(statement=self.model, response=model_response_statement)
object_removed = self.object.remove_response('Hello')
model_removed = self.model.remove_response('Hello')
self.assertTrue(object_removed)
self.assertTrue(model_removed)
def test_get_response_count(self):
self.object.add_response(ResponseObject('Hello', occurrence=2))
model_response_statement = StatementModel.objects.create(text='Hello')
self.model.save()
ResponseModel.objects.create(
statement=self.model, response=model_response_statement
)
ResponseModel.objects.create(
statement=self.model, response=model_response_statement
)
object_count = self.object.get_response_count(StatementObject(text='Hello'))
model_count = self.model.get_response_count(StatementModel(text='Hello'))
self.assertEqual(object_count, 2)
self.assertEqual(model_count, 2)
def test_serialize(self):
object_data = self.object.serialize()
model_data = self.model.serialize()
self.assertEqual(object_data, model_data)
def test_response_statement_cache(self):
self.assertTrue(hasattr(self.object, 'response_statement_cache'))
self.assertTrue(hasattr(self.model, 'response_statement_cache'))