def distances(self, hyp, ref, bestonly): # print(hyp) # print(ref) bo = 1 if bestonly else 0 dist = Levenshtein.compare_lists(hyp, ref, self.threshold, bo) # replace special value -1 meaning "above threshold"0 # print(dist) # print(dist==-1) dist[dist == -1] = np.NaN for i, hyp_ngram in enumerate(hyp): for j, ref_ngram in enumerate(ref): if dist[i][j] != 0: ref_ngram_split = ref_ngram.split(' ') all_matched = True hyp_ngram_split = hyp_ngram.split(' ') if len(ref_ngram_split) == len(hyp_ngram_split): for k, hyp_w in enumerate(hyp_ngram_split): ref_w = ref_ngram_split[k] if self.wordnet_similarity_distance( hyp_word=hyp_w, ref_word=ref_w) > 0.5: all_matched = False break if all_matched: dist[i][j] = 0 print(dist) return dist
def distances(self, hyp, ref, bestonly): bo = 1 if bestonly else 0 dist = Levenshtein.compare_lists(hyp, ref, self.threshold, bo) # replace special value -1 meaning "above threshold" dist[dist == -1] = np.NaN return dist