def get_perf(filename, folder):
 _conlleval = os.path.join(folder, 'conlleval.pl')
 if (not os.path.isfile(_conlleval)):
  url = 'http://www-etud.iro.umontreal.ca/~mesnilgr/atis/conlleval.pl'
  download(url, _conlleval)
  os.chmod(_conlleval, stat.S_IRWXU)
 proc = subprocess.Popen(['perl', _conlleval], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
 (stdout, _) = proc.communicate(''.join(open(filename).readlines()).encode('utf-8'))
 stdout = stdout.decode('utf-8')
 out = None
 for line in stdout.split('\n'):
  if ('accuracy' in line):
   out = line.split()
   break
 if (out is None):
  print(stdout.split('\n'))
 precision = float(out[6][:(-2)])
 recall = float(out[8][:(-2)])
 f1score = float(out[10])
 return {'p': precision, 'r': recall, 'f1': f1score}

def get_perf ( filename , folder ) : _conlleval = os . path . join ( folder , 'conlleval.pl' ) if ( not os . path . isfile ( _conlleval ) ) : url = 'http://www-etud.iro.umontreal.ca/~mesnilgr/atis/conlleval.pl' download ( url , _conlleval ) os . chmod ( _conlleval , stat . S_IRWXU ) proc = subprocess . Popen ( [ 'perl' , _conlleval ] , stdin = subprocess . PIPE , stdout = subprocess . PIPE ) ( stdout , _ ) = proc . communicate ( '' . join ( open ( filename ) . readlines ( ) ) . encode ( 'utf-8' ) ) stdout = stdout . decode ( 'utf-8' ) out = None for line in stdout . split ( '\n' ) : if ( 'accuracy' in line ) : out = line . split ( ) break if ( out is None ) : print ( stdout . split ( '\n' ) ) precision = float ( out [ 6 ] [ : ( - 2 ) ] ) recall = float ( out [ 8 ] [ : ( - 2 ) ] ) f1score = float ( out [ 10 ] ) return { 'p' : precision , 'r' : recall , 'f1' : f1score }
run conlleval .