MCPcopy
hub / github.com/gunthercox/ChatterBot / update

Method update

chatterbot/storage/mongodb.py:207–240  ·  view source on GitHub ↗
(self, statement)

Source from the content-addressed store, hash-verified

205 self.statements.insert_many(create_statements)
206
207 def update(self, statement):
208 data = statement.serialize()
209 data.pop('id', None)
210 data.pop('tags', None)
211
212 update_data = {
213 '$set': data
214 }
215
216 if statement.tags:
217 update_data['$addToSet'] = {
218 'tags': {
219 '$each': statement.tags
220 }
221 }
222
223 search_parameters = {}
224
225 if statement.id is not None:
226 search_parameters['_id'] = statement.id
227 else:
228 search_parameters['text'] = statement.text
229 search_parameters['conversation'] = statement.conversation
230
231 update_operation = self.statements.update_one(
232 search_parameters,
233 update_data,
234 upsert=True
235 )
236
237 if update_operation.acknowledged:
238 statement.id = update_operation.upserted_id
239
240 return statement
241
242 def get_random(self):
243 """

Calls 1

serializeMethod · 0.80