venkatasg commited on
Commit
fc51350
·
1 Parent(s): 5c84599

input is list of strings, not file paths

Browse files
Files changed (1) hide show
  1. gleu.py +9 -10
gleu.py CHANGED
@@ -78,21 +78,20 @@ class GLEU():
78
 
79
  def load_hypothesis_sentence(self,hypothesis) :
80
  self.hlen = len(hypothesis)
81
- self.this_h_ngrams = [ self.get_ngram_counts(hypothesis,n)
82
- for n in range(1,self.order+1) ]
83
 
84
- def load_sources(self,spath) :
85
- self.all_s_ngrams = [ [ self.get_ngram_counts(line.split(),n)
86
  for n in range(1,self.order+1) ]
87
- for line in open(spath) ]
88
 
89
- def load_references(self,rpaths) :
90
  self.refs = [ [] for i in range(len(self.all_s_ngrams)) ]
91
  self.rlens = [ [] for i in range(len(self.all_s_ngrams)) ]
92
- for rpath in rpaths :
93
- for i,line in enumerate(open(rpath)) :
94
- self.refs[i].append(line.split())
95
- self.rlens[i].append(len(line.split()))
96
 
97
  # count number of references each n-gram appear sin
98
  self.all_rngrams_freq = [ Counter() for i in range(self.order) ]
 
78
 
79
  def load_hypothesis_sentence(self,hypothesis) :
80
  self.hlen = len(hypothesis)
81
+ self.this_h_ngrams = [self.get_ngram_counts(hypothesis,n)
82
+ for n in range(1,self.order+1) ]
83
 
84
+ def load_sources(self,source_sents) :
85
+ self.all_s_ngrams = [[self.get_ngram_counts(source_sent.split(),n)
86
  for n in range(1,self.order+1) ]
87
+ for source_sent in source_sents ]
88
 
89
+ def load_references(self,ref_sents) :
90
  self.refs = [ [] for i in range(len(self.all_s_ngrams)) ]
91
  self.rlens = [ [] for i in range(len(self.all_s_ngrams)) ]
92
+ for i, ref_sent in enumerate(ref_sents) :
93
+ self.refs[i].append(ref_sent.split())
94
+ self.rlens[i].append(len(ref_sent.split()))
 
95
 
96
  # count number of references each n-gram appear sin
97
  self.all_rngrams_freq = [ Counter() for i in range(self.order) ]