def compact_hyp(hyp_path, comp_hyp_path): d = DefaultOrderedDict(list) with open(hyp_path, 'rb') as hyp: for line in hyp: tmp = line.split() name, dec = tmp[0], tmp[1:] d[name].extend(dec) with open(comp_hyp_path, 'wb') as w: for wav, dec_list in d.iteritems(): w.write('%s %s\n' % (wav, ' '.join(dec_list)))
def compact_hyp(hyp_path, comp_hyp_path): """Converts transcriptions of single hypotheses on multiple lines to one hypothesis per line. Read from hyp_path file and save the results to comp_hyp_path Args: hyp_path(str): path to file with hypotheses on multiple lines comp_hyp_path(str): path to save the hypotheses one on each line """ d = DefaultOrderedDict(list) with open(hyp_path, 'rb') as hyp: for line in hyp: tmp = line.split() name, dec = tmp[0], tmp[1:] d[name].extend(dec) with open(comp_hyp_path, 'wb') as w: for wav, dec_list in d.iteritems(): w.write('%s %s\n' % (wav, ' '.join(dec_list)))