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

Method get_random

chatterbot/storage/sql_storage.py:428–447  ·  view source on GitHub ↗

Returns a random statement from the database.

(self)

Source from the content-addressed store, hash-verified

426 session.close()
427
428 def get_random(self):
429 """
430 Returns a random statement from the database.
431 """
432 Statement = self.get_model('statement')
433
434 session = self.Session()
435 try:
436 count = self.count()
437 if count < 1:
438 raise self.EmptyDatabaseException()
439
440 random_index = random.randrange(0, count)
441 random_statement = session.query(Statement)[random_index]
442
443 statement = self.model_to_object(random_statement)
444
445 return statement
446 finally:
447 session.close()
448
449 def drop(self):
450 """

Callers

nothing calls this directly

Calls 4

countMethod · 0.95
model_to_objectMethod · 0.95
get_modelMethod · 0.80
closeMethod · 0.45

Tested by

no test coverage detected