def fetch_all_treebanks(ud_dir, languages, corpus, best_per_language):
all_treebanks = dict()<EOL>treebank_size = dict()<EOL>for l in languages:<EOL><INDENT>all_treebanks[l] = []<EOL>treebank_size[l] = <NUM_LIT:0><EOL><DEDENT>for treebank_dir in ud_dir.iterdir():<EOL><INDENT>if treebank_dir.is_dir():<EOL><INDENT>for txt_path in treebank_dir.iterdir():<EOL><INDENT>if txt_path.name.endswith('<STR_LIT>' + corpus + '<STR_LIT>'):<EOL><INDENT>file_lang = txt_path.name.split('<STR_LIT:_>')[<NUM_LIT:0>]<EOL>if file_lang in languages:<EOL><INDENT>gold_path = treebank_dir / txt_path.name.replace('<STR_LIT>', '<STR_LIT>')<EOL>stats_xml = treebank_dir / "<STR_LIT>"<EOL>if not _contains_blinded_text(stats_xml):<EOL><INDENT>if not best_per_language:<EOL><INDENT>all_treebanks[file_lang].append(txt_path)<EOL><DEDENT>else:<EOL><INDENT>with gold_path.open(mode='<STR_LIT:r>', encoding='<STR_LIT:utf-8>') as gold_file:<EOL><INDENT>gold_ud = conll17_ud_eval.load_conllu(gold_file)<EOL>gold_tokens = len(gold_ud.tokens)<EOL><DEDENT>if treebank_size[file_lang] < gold_tokens:<EOL><INDENT>all_treebanks[file_lang] = [txt_path]<EOL>treebank_size[file_lang] = gold_tokens<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>return all_treebanks<EOL>
Fetch the txt files for all treebanks for a given set of languages