def get_perfo(filename):
'''
work around for using a PERL script in python
dirty but still works.
'''
tempfile = str(random.randint(1,numpy.iinfo('i').max)) + '.txt'
if not isfile(PREFIX + 'conlleval.pl'):
os.system('wget https://www.comp.nus.edu.sg/%7Ekanmy/courses/practicalNLP_2008/packages/conlleval.pl')
#download('http://www-etud.iro.umontreal.ca/~mesnilgr/atis/conlleval.pl')
chmod('conlleval.pl', stat.S_IRWXU) # give the execute permissions
if len(PREFIX) > 0:
chmod(PREFIX + 'conlleval.pl', stat.S_IRWXU) # give the execute permissions
cmd = PREFIX + 'conlleval.pl < %s | grep accuracy > %s'%(filename,tempfile)
else:
cmd = './conlleval.pl < %s | grep accuracy > %s'%(filename,tempfile)
print(cmd)
out = os.system(cmd)
out = open(tempfile).readlines()[0].split()
os.system('rm %s'%tempfile)
precision = float(out[6][:-2])
recall = float(out[8][:-2])
f1score = float(out[10])
return {'p':precision, 'r':recall, 'f1':f1score}
评论列表
文章目录