Index: branches/apertium-tagger/experiments/run_experiment.py =================================================================== --- branches/apertium-tagger/experiments/run_experiment.py (revision 72050) +++ branches/apertium-tagger/experiments/run_experiment.py (revision 72052) @@ -16,7 +16,7 @@ import asyncio from experiments import (experiment_groups, has_needs_tsx, run_experiment, spec_to_str, str_to_spec) -from shell_utils import cd, check_run +from shell_utils import MissingLanguageDataException, check_run, mk_built_lab from shell_wrappers import (cg_conv_clean, cg_proc, copy_blanks, extract_src, fix_dix, split_n_r, strip_blanks, strip_cg_comments, strip_unknown_sent) @@ -215,11 +215,6 @@ } -class MissingLanguageDataException(Exception): - def __init__(self, fn): - self.fn = fn - - class LanguageTaggerLab: def __init__(self, lang, lang_root, texts, folds, sent_seg=False, use_cg_src=False, @@ -387,15 +382,9 @@ lang, lang_root, texts, args.folds, sent_seg=args.sent_seg, use_cg_src=args.use_cg_src, reuse=args.reuse, reuse_dic=args.reuse_dic) - try: - lab = mk_lab() - except MissingLanguageDataException as e: - print("Missing {}... Trying to build it for you.".format(e.fn)) - with cd(lang_root): - check_run(['./autogen.sh']) - check_run(['make']) - lab = mk_lab() + lab = mk_built_lab(mk_lab, lang_root) + lang_accuracies = {} def run_spec(spec): Index: branches/apertium-tagger/experiments/grid_search.py =================================================================== --- branches/apertium-tagger/experiments/grid_search.py (revision 72050) +++ branches/apertium-tagger/experiments/grid_search.py (revision 72052) @@ -4,7 +4,7 @@ from copy import deepcopy from os import mkdir from os.path import join as pjoin -from os.path import isdir, splitext +from os.path import isdir import lxml.etree @@ -11,6 +11,7 @@ from experiments import percep_experiment, str_to_spec from run_experiment import (DEFAULT_TEXTS, WORK_DIR, LanguageTaggerLab, add_common_args) +from shell_utils import mk_built_lab class GridSearchLab(LanguageTaggerLab): @@ -50,11 +51,14 @@ spec_str = args.tagger spec = str_to_spec(spec_str) - lab = LanguageTaggerLab( + def mk_lab(): + return LanguageTaggerLab( args.language, lang_root, texts, args.folds, sent_seg=args.sent_seg, use_cg_src=args.use_cg_src, reuse=args.reuse, reuse_dic=args.reuse_dic) + lab = mk_built_lab(mk_lab, lang_root) + if not lab.can_run_experiment(spec): raise Exception("mtx needs a tsx") Index: branches/apertium-tagger/experiments/shell_utils.py =================================================================== --- branches/apertium-tagger/experiments/shell_utils.py (revision 72050) +++ branches/apertium-tagger/experiments/shell_utils.py (revision 72052) @@ -4,6 +4,11 @@ import subprocess +class MissingLanguageDataException(Exception): + def __init__(self, fn): + self.fn = fn + + @contextmanager def cd(newdir): prevdir = os.getcwd() @@ -178,3 +183,14 @@ kwargs['check'] = True print("RUNNING: ", ' '.join(cmd)) return subprocess.run(cmd, *args, **kwargs) + + +def mk_built_lab(mk_lab, lang_root): + try: + return mk_lab() + except MissingLanguageDataException as e: + print("Missing {}... Trying to build it for you.".format(e.fn)) + with cd(lang_root): + check_run(['./autogen.sh']) + check_run(['make']) + return mk_lab()