log_path.flush()
# 	sys.exit()

	p = sub.Popen(cmd.split(), stderr=sub.PIPE, stdout=sub.PIPE)
	
	while p.poll() == None:
		out = p.stdout.read(1)
		
		log_path.write(out.decode('utf-8'))
		
		log_path.flush()
		
	log_path.close()


if __name__ == '__main__':
	p = argparse.ArgumentParser()
	p.add_argument('-c', '--conf', help='Configuration file.')
	
	args = p.parse_args()
	
	c = ConfigFile(args.conf)
	
	log_f = sys.stdout
	if c.get('log_path'):
		log_f = open(c.get('log_path'), 'w', encoding='utf-8')
	
	train(c['train_path'], c['test_path'], c['constraint_path'], c['model_path'], log_f)
	
	write_and_eval(c['test_path'], c['model_path'], c['output_path'])
		
Beispiel #2
0
    pt = StanfordPOSTagger(tagger_model, tagger_jar)
    return pt.tag(string)


if __name__ == '__main__':

    p = OptionParser()
    p.add_option('-c', '--conf', help='configuration file')
    opts, args = p.parse_args(sys.argv)

    errors = require_opt(opts.conf, "You must specify a configuration file with -c or --conf", True)
    if errors:
        p.print_help()
        sys.exit()

    c = ConfigFile(opts.conf)

    # Set up the log path
    logpath = c.get('log_path')
    log_f = sys.stdout
    if logpath:
        logdir = os.makedirs(os.path.dirname(logpath), exist_ok=True)
        log_f = open(c.get('log_path'), 'w', encoding='utf-8')

    # Now do the testing and training
    train_postagger(c['train_file'],
                    c['model'],
                    c['delimeter'])
    test_postagger(c['test_file'],
                   c['model'],
                   c['out_file'],
Beispiel #3
0
    for name, featlist in combos:

        # RESET
        for other_title, other_feat in other_feats:
            c[other_feat] = False

        # Add combo features
        for feat in featlist:
            c[feat] = True

        train, test = test_feature(**c)
        performance[name] = (train, test)

    for feat in performance:
        print('%s,%s,%s' % (feat, performance[feat][0], performance[feat][1]))


if __name__ == '__main__':
    c = ConfigFile('/Users/rgeorgi/Dropbox/code/eclipse/dissertation/conf/classification/feature_ablation.conf')

    if c.get('posdict'):
        c['posdict'] = pickle.load(open(c.get('posdict'), 'rb'))


    m = MalletMaxentTrainer()
    c['maxent_model'] = m

    ablation(**c)

    #c['feat_align'] = True
    #print(test_feature(**c))