# Path: abkhazia/decode/_score.py
# def options():
# def format(score_opts, mkgraph_opts):
# def skip_scoring(score_opts):


import os
import abkhazia.utils as utils
import abkhazia.kaldi as kaldi
from abkhazia.decode import _score

    # link requested files to decoder.recipe_dir. final.mdl is
    # mandatory (raise if not found), others are optional and Kaldi
    # will work without
    for linked in ('final.mdl', 'cmvn_opts', 'final.mat',
                   'splice_opts', 'delta_order', 'log'):
        src = os.path.join(decoder.am_dir, linked)
        if os.path.exists(src):
            os.symlink(src, os.path.join(decoder.recipe_dir, linked))
        elif linked == 'final.mdl':
            raise IOError('acoustic model file not found: {}'.format(src))
        else:
            decoder.log.info('optional file not here %s', src)

    # TODO train_pnorm_fast script outputs a lda.mat file, is it the
    # final.mat requested by decode.sh ? -> NO
    # src = os.path.join(decoder.am_dir, 'lda.mat')
    # if os.path.isfile(src):
    #     os.symlink(src, os.path.join(decoder.recipe_dir, 'final.mat'))

    decoder._run_command((
        'steps/nnet2/decode.sh --nj {njobs} --cmd "{cmd}" {decode_opts} '
        '--parallel-opts "{paral}" '
        '{skip_scoring} --scoring-opts "{score_opts}" '
        '{graph} {data} {decode}'.format(
            njobs=decoder.njobs,
            cmd=utils.config.get('kaldi', 'decode-cmd'),
            decode_opts=decode_opts,
            paral='--num-threads {}'.format(
                decoder.decode_opts['num-threads'].value),

# Path: abkhazia/decode/_score.py
# def options():
# def format(score_opts, mkgraph_opts):
# def skip_scoring(score_opts):


# Path: abkhazia/decode/_decoder_nnet.py
import os
import abkhazia.utils as utils
import abkhazia.kaldi as kaldi
from abkhazia.decode import _score


    # link requested files to decoder.recipe_dir. final.mdl is
    # mandatory (raise if not found), others are optional and Kaldi
    # will work without
    for linked in ('final.mdl', 'cmvn_opts', 'final.mat',
                   'splice_opts', 'delta_order', 'log'):
        src = os.path.join(decoder.am_dir, linked)
        if os.path.exists(src):
            os.symlink(src, os.path.join(decoder.recipe_dir, linked))
        elif linked == 'final.mdl':
            raise IOError('acoustic model file not found: {}'.format(src))
        else:
            decoder.log.info('optional file not here %s', src)

    # TODO train_pnorm_fast script outputs a lda.mat file, is it the
    # final.mat requested by decode.sh ? -> NO
    # src = os.path.join(decoder.am_dir, 'lda.mat')
    # if os.path.isfile(src):
    #     os.symlink(src, os.path.join(decoder.recipe_dir, 'final.mat'))

    decoder._run_command((
        'steps/nnet2/decode.sh --nj {njobs} --cmd "{cmd}" {decode_opts} '
        '--parallel-opts "{paral}" '
        '{skip_scoring} --scoring-opts "{score_opts}" '
        '{graph} {data} {decode}'.format(
            njobs=decoder.njobs,
            cmd=utils.config.get('kaldi', 'decode-cmd'),
            decode_opts=decode_opts,
            paral='--num-threads {}'.format(
                decoder.decode_opts['num-threads'].value),

            skip_scoring=_score.skip_scoring(decoder.score_opts),