A statement represents a single spoken entity, sentence or phrase that someone can say.
| 60 | |
| 61 | |
| 62 | class Statement(StatementMixin): |
| 63 | """ |
| 64 | A statement represents a single spoken entity, sentence or |
| 65 | phrase that someone can say. |
| 66 | """ |
| 67 | |
| 68 | __slots__ = ( |
| 69 | 'id', |
| 70 | 'text', |
| 71 | 'search_text', |
| 72 | 'conversation', |
| 73 | 'persona', |
| 74 | 'tags', |
| 75 | 'in_response_to', |
| 76 | 'search_in_response_to', |
| 77 | 'created_at', |
| 78 | 'confidence', |
| 79 | 'storage', |
| 80 | ) |
| 81 | |
| 82 | def __init__(self, text: str, in_response_to=None, **kwargs): |
| 83 | |
| 84 | self.id = kwargs.get('id') |
| 85 | self.text = str(text) |
| 86 | self.search_text = kwargs.get('search_text', '') |
| 87 | self.conversation = kwargs.get('conversation', '') |
| 88 | self.persona = kwargs.get('persona', '') |
| 89 | self.tags = kwargs.pop('tags', []) |
| 90 | self.in_response_to = in_response_to |
| 91 | self.search_in_response_to = kwargs.get('search_in_response_to', '') |
| 92 | self.created_at = kwargs.get('created_at', datetime.now()) |
| 93 | |
| 94 | if not isinstance(self.created_at, datetime): |
| 95 | self.created_at = date_parser.parse(self.created_at) |
| 96 | |
| 97 | # Set timezone to UTC if no timezone was provided |
| 98 | if not self.created_at.tzinfo: |
| 99 | self.created_at = self.created_at.replace(tzinfo=timezone.utc) |
| 100 | |
| 101 | # This is the confidence with which the chat bot believes |
| 102 | # this is an accurate response. This value is set when the |
| 103 | # statement is returned by the chat bot. |
| 104 | self.confidence = kwargs.get('confidence', 0) |
| 105 | |
| 106 | self.storage = None |
| 107 | |
| 108 | def __str__(self): |
| 109 | return self.text |
| 110 | |
| 111 | def __repr__(self): |
| 112 | return '<Statement text:%s>' % (self.text) |
| 113 | |
| 114 | def save(self): |
| 115 | """ |
| 116 | Save the statement in the database. |
| 117 | """ |
| 118 | self.storage.update(self) |
no outgoing calls