def run_baseline_sim(language, viol, mgain, nconstraints, mb, gam, parameters,
                     reducemem):
    '''
    this function runs the baseline simulation with a default (segmental) projection
    if it does not succeed, it does not fail gracefully, so be forwarned
    '''
    basepath = os.getcwd().split('code')[0]
    lgfullpath = os.path.join(basepath, 'data', language)
    simfunc.cleanUpWorkdir(basepath)
    if parameters:
        params.move_params(os.path.join(lgfullpath, 'params.txt'))
        viol, mgain, nconstraints, gam = params.read_params()
    else:
        params.makeParams(consize=nconstraints,
                          violable=viol,
                          mingain=mgain,
                          gamma=gam,
                          predefault=False)
    simfunc.makeSimFiles(lgfullpath)
    try:
        simfunc.runBaselineSim(basepath, reducemem=reducemem)
        #language=language.split('../data/')[1].replace('/','_')
        wrapstring = os.path.join(
            'sims',
            language.replace(os.sep, "_") + '_baseline' + '_gain' + mgain +
            '_con' + nconstraints)
        simfunc.wrapSims(wrapstring)
    except CalledProcessError:
        print("Done")
def run_agree_disagree_sim(language, viol, mgain, nconstraints, mb, gam,
                           parameters, reducemem):
    '''
    this is not described anywhere, is work in progress
    makes a bunch of constraints on the basis of the natural classes structure of the language
    they have the form +f +f, +f [+wb] +f, +f [-wb] +f, and ditto for every combination of + and - for f 
    (in other words, it makes agree constraints and disagree constraints for every feature and nat class in the language)
    it then runs a simulation with this premade constraint set.

    the early results in testing this have not been encouraging
    '''
    basepath = os.getcwd().split('code')[0]
    lgfullpath = os.path.join(basepath, 'data', language)
    simfunc.cleanUpWorkdir(basepath)
    simfunc.makeSimFiles(lgfullpath, ag_disag=True)
    if parameters:
        params.move_params(lgfullpath, 'params.txt')
        viol, mgain, nconstraints, gam = params.read_params()
    else:
        params.makeParams(consize=nconstraints,
                          violable=viol,
                          mingain=mgain,
                          gamma=gam,
                          ag_disag=True)
    simfunc.runBaselineSim(basepath, reducemem=reducemem)
    wrapstring = os.path.join(
        'sims', '_'.join([
            language.replace(os.sep, "_"), 'baseline', 'AG', viol[:2], 'gain',
            mingain, 'ncons', nconstraints
        ]))
    return simfunc.wrapSims(wrapstring, ret=True)
def run_wb_sim(language, viol, mgain, nconstraints, mb, gam, parameters,
               reducemem):
    '''
    this learning simulation is described in Gouskova and Gallagher (NLLT). The learner starts with a baseline
    grammar; if this grammar contains placeholder trigrams, it creates projections for each distinct trigram and runs a final simulation with those projections available.
    '''
    basepath = os.getcwd().split('code')[0]
    simfunc.cleanUpWorkdir(basepath)
    if parameters:
        params.move_params(
            os.path.join(basepath, 'data', language, 'params.txt'))
        viol, mgain, nconstraints, gamma = params.read_params()
    else:
        params.makeParams(consize=nconstraints,
                          violable=viol,
                          mingain=mgain,
                          gamma=gam,
                          predefault=False)
    simfunc.makeSimFiles(language)
    #baseline simulation
    simfunc.runBaselineSim(basepath, reducemem=reducemem)
    #analyze resulting grammar.txt file, make projections for each wb-mentioning constraint
    simfunc.makeProjection(basepath, 'wb', mb)
    if len(os.listdir('projections')) == 0:
        print(
            '\nNo projections were found because there were no placeholder constraints in the baseline grammar.'
        )
    else:
        simfunc.runCustomSim(reducemem=reducemem, simtype='wb')
    vio = viol[0:2]
    wrapstring = os.path.join('sims', language.replace(
        os.sep, "_")) + "_" + '_'.join(
            ['wb', vio, 'gain' + str(mgain), 'con' + str(nconstraints)])
    return simfunc.wrapSims(wrapstring, ret=True)
def run_handmade_projection_sim(language, viol, mgain, nconstraints, gam,
                                parameters, feature, reducemem):
    '''
    this either creates a projection file based on the value of "feature" (e.g., "-son") or runs a simulation with a custom projection file. To do the latter, supply a full path to the projection file as the last argument.
    '''
    basepath = os.getcwd().split('code')[0]
    lgfullpath = os.path.join(basepath, 'data', language)
    simfunc.cleanUpWorkdir(basepath)
    simfunc.makeSimFiles(language)
    if parameters:
        params.move_params(lgfullpath, 'params.txt')
        viol, mgain, nconstraints, gam = params.read_params()
    else:
        params.makeParams(consize=nconstraints,
                          violable=viol,
                          mingain=mgain,
                          gamma=gam)
    simfunc.handmakeProjection(basepath, feature)
    simfunc.runCustomSim(feature, reducemem=reducemem)
    if 'output_baseline' in os.listdir(basepath):
        shutil.rmtree(basepath + 'output_baseline')
    simfunc.wrapSims(os.path.join(
        'sims', '_'.join(language.replace(os.sep, "_"), 'custom')),
                     cust=True)