code: def assemble_corpus(corpus_reader: CorpusReader,
                      types_requested: List[str],
                      type_dirs: Dict[str, List[str]] = None,
                      type_files: Dict[str, List[str]] = None) -> CorpusReader:
      
      fileid_names = []  # type: List[str]
      try:
          all_file_ids = list(corpus_reader.fileids())
          clean_ids_types = []  # type: List[Tuple[str, str]]
          if type_files:
              for key, valuelist in type_files.items():
                  if key in types_requested:
                      for value in valuelist:
                          if value in all_file_ids:
                              if key:
                                  clean_ids_types.append((value, key))
          if type_dirs:
              for key, valuelist in type_dirs.items():
                  if key in types_requested:
                      for value in valuelist:
                          corrected_dir = value.replace('./', '')
                          corrected_dir = '{}/'.format(corrected_dir)
                          for name in all_file_ids:
                              if name and name.startswith(corrected_dir):
                                  clean_ids_types.append((name, key))
          clean_ids_types.sort(key=lambda x: x[0])
          fileid_names, categories = zip(*clean_ids_types)  # type: ignore
          corpus_reader._fileids = fileid_names
          return corpus_reader
      except Exception:
          LOG.exception('failure in corpus building')
docs: Create a filtered corpus.
      :param corpus_reader: This get mutated
      :param types_requested: a list of string types, which are to be found in the type_dirs and
      type_files mappings
      :param type_dirs: a dict of corpus types to directories
      :param type_files: a dict of corpus types to files
      :return: a CorpusReader object containing only the mappings desired