class_docstr: Allow chatbots to be trained with the data from the Ubuntu Dialog Corpus.
code: def train(self):
      import glob
  
      tagger = PosLemmaTagger(
          language=self.chatbot.storage.tagger.language
      )
  
      # Download and extract the Ubuntu dialog corpus if needed
      corpus_download_path = self.download(self.data_download_url)
  
      # Extract if the directory does not already exist
      if not self.is_extracted(self.extracted_data_directory):
          self.extract(corpus_download_path)
  
      extracted_corpus_path = os.path.join(
          self.extracted_data_directory, "**", "**", "*.tsv"
      )
  
      def chunks(items, items_per_chunk):
          for start_index in range(0, len(items), items_per_chunk):
              end_index = start_index + items_per_chunk
              yield items[start_index:end_index]
  
      file_list = glob.glob(extracted_corpus_path)
  
      file_groups = tuple(chunks(file_list, 10000))
  
      start_time = time.time()
  
      for tsv_files in file_groups:
          statements_from_file = []
  
          for tsv_file in tsv_files:
              with open(tsv_file, "r", encoding="utf-8") as tsv:
                  reader = csv.reader(tsv, delimiter="\t")
  
                  previous_statement_text = None
                  previous_statement_search_text = ""
  
                  for row in reader:
                      if len(row) > 0:
                          statement = Statement(
                              text=row[3],
                              in_response_to=previous_statement_text,
                              conversation="training",
                              created_at=date_parser.parse(row[0]),
                              persona=row[1],
                          )
  
                          for (
                              preprocessor
                          ) in self.chatbot.preprocessors:
                              statement = preprocessor(statement)
  
                          statement.search_text = (
                              tagger.get_text_index_string(
                                  statement.text
                              )
                          )
                          statement.search_in_response_to = (
                              previous_statement_search_text
                          )
  
                          previous_statement_text = statement.text
                          previous_statement_search_text = (
                              statement.search_text
                          )
  
                          statements_from_file.append(statement)
  
          self.chatbot.storage.create_many(statements_from_file)
  
      print("Training took", time.time() - start_time, "seconds.")
  
imports: import os
  import sys
  import csv
  import time
  from dateutil import parser
  from chatterbot.conversation import Statement
  from chatterbot.tagging import PosLemmaTagger
  from chatterbot import utils
label_desc: Use image node_id 6 for calling the UbuntuCorpusTrainer obj's underlying member method code with example usage: obj.train() without return types