#!/usr/bin/env python import sys import os scripts = ( ('CRFsuite 0.12', './bench_crfsuite.py'), ('CRFsuite 0.11', './bench_crfsuite-0.11.py'), ('Wapiti v1.1.3', './bench_wapiti.py'), ('sgd 1.3', './bench_crfsgd.py'), ('CRF++ 0.54', './bench_crfpp.py'), ('MALLET 2.0.6', './bench_mallet.py'), ) fields = ( ('# Features', 'num_features'), ('Time', 'time'), ('# Iters', 'iterations'), ('Update', 'update'), ('Loss', 'loss'), ('Log', 'log'), ) def number(x): y = '' p = x.find('.') if p == -1: p = len(x) for i in range(p): if i % 3 == 0 and i != 0: y = ' ' + y y = x[p-i-1] + y return y + x[p:] def read(): R = {} for name, script in scripts: fi = os.popen(script, 'r') R[name] = eval(fi.read()) return R def output_update(fo, R): for name, script in scripts: for param, result in R[name].iteritems(): fo.write('%s\t%s\t%f\n' % (name, param, result.get('update', 0.))) def output_table(fo, R): for name, script in scripts: for param, result in R[name].iteritems(): fo.write('\n') fo.write('%s\n' % name) fo.write('%s\n' % param) fo.write('\n') fo.write('%s\n' % number('%d' % result['num_features'])) fo.write('%s\n' % number('%.1f' % result['time'])) fo.write('%s\n' % number('%d' % result['iterations'])) fo.write('%s\n' % number('%.1f' % result['update'])) fo.write('%s\n' % number('%.1f' % result['loss'])) fo.write('%.3f\n' % (100. * result['accuracy'])) fo.write('Log\n' % result['logfile']) fo.write('\n') fo.write('\n') if __name__ == '__main__': R = read() output_table(sys.stdout, R)