@@ -67,7 +67,7 @@ def atisfold(fold):
6767
6868
6969# metrics function using conlleval.pl
70- def conlleval (p , g , w , filename ):
70+ def conlleval (p , g , w , filename , script_path ):
7171 '''
7272 INPUT:
7373 p :: predictions
@@ -79,6 +79,10 @@ def conlleval(p, g, w, filename):
7979 are written. it will be the input of conlleval.pl script
8080 for computing the performance in terms of precision
8181 recall and f1 score
82+
83+ OTHER:
84+ script_path :: path to the directory containing the
85+ conlleval.pl script
8286 '''
8387 out = ''
8488 for sl , sp , sw in zip (g , p , w ):
@@ -91,27 +95,26 @@ def conlleval(p, g, w, filename):
9195 f .writelines (out )
9296 f .close ()
9397
94- return get_perf (filename )
98+ return get_perf (filename , script_path )
9599
96100
97- def download (origin ):
101+ def download (origin , destination ):
98102 '''
99103 download the corresponding atis file
100104 from http://www-etud.iro.umontreal.ca/~mesnilgr/atis/
101105 '''
102106 print 'Downloading data from %s' % origin
103- name = origin .split ('/' )[- 1 ]
104- urllib .urlretrieve (origin , name )
107+ urllib .urlretrieve (origin , destination )
105108
106109
107- def get_perf (filename ):
110+ def get_perf (filename , folder ):
108111 ''' run conlleval.pl perl script to obtain
109112 precision/recall and F1 score '''
110- _conlleval = 'conlleval.pl'
113+ _conlleval = os . path . join ( folder , 'conlleval.pl' )
111114 if not os .path .isfile (_conlleval ):
112115 url = 'http://www-etud.iro.umontreal.ca/~mesnilgr/atis/conlleval.pl'
113- download (url )
114- os .chmod ('conlleval.pl' , stat .S_IRWXU ) # give the execute permissions
116+ download (url , _conlleval )
117+ os .chmod (_conlleval , stat .S_IRWXU ) # give the execute permissions
115118
116119 proc = subprocess .Popen (["perl" ,
117120 _conlleval ],
@@ -333,11 +336,13 @@ def main(param=None):
333336 res_test = conlleval (predictions_test ,
334337 groundtruth_test ,
335338 words_test ,
336- folder + '/current.test.txt' )
339+ folder + '/current.test.txt' ,
340+ folder )
337341 res_valid = conlleval (predictions_valid ,
338342 groundtruth_valid ,
339343 words_valid ,
340- folder + '/current.valid.txt' )
344+ folder + '/current.valid.txt' ,
345+ folder )
341346
342347 if res_valid ['f1' ] > best_f1 :
343348
0 commit comments