@@ -37,11 +37,11 @@ def score_instance(self,
37
37
reference : List [str ]) -> float :
38
38
hyp_joined = " " .join (hypothesis )
39
39
hyp_chars = [x for x in list (hyp_joined ) if x not in self .ignored ]
40
- hyp_ngrams = self . _get_ngrams (hyp_chars , self .n )
40
+ hyp_ngrams = _get_ngrams (hyp_chars , self .n )
41
41
42
42
ref_joined = " " .join (reference )
43
43
ref_chars = [x for x in list (ref_joined ) if x not in self .ignored ]
44
- ref_ngrams = self . _get_ngrams (ref_chars , self .n )
44
+ ref_ngrams = _get_ngrams (ref_chars , self .n )
45
45
46
46
if not hyp_chars or not ref_chars :
47
47
if "" .join (hyp_chars ) == "" .join (ref_chars ):
@@ -69,7 +69,7 @@ def chr_r(self, hyp_ngrams: NGramDicts, ref_ngrams: NGramDicts) -> float:
69
69
ref_count , hyp_ngrams [m - 1 ][ngr ])
70
70
return np .mean (np .divide (
71
71
count_matched , count_all , out = np .ones_like (count_all ),
72
- where = (count_all != 0 )))
72
+ where = (count_all != 0 )))
73
73
74
74
def chr_p (self , hyp_ngrams : NGramDicts , ref_ngrams : NGramDicts ) -> float :
75
75
count_all = np .zeros (self .n )
@@ -83,18 +83,18 @@ def chr_p(self, hyp_ngrams: NGramDicts, ref_ngrams: NGramDicts) -> float:
83
83
hyp_count , ref_ngrams [m - 1 ][ngr ])
84
84
return np .mean (np .divide (
85
85
count_matched , count_all , out = np .ones_like (count_all ),
86
- where = (count_all != 0 )))
87
-
88
- def _get_ngrams ( self , tokens : List [ str ], n : int ) -> NGramDicts :
89
- ngr_dicts = []
90
- for m in range ( 1 , n + 1 ):
91
- ngr_dict = {} # type: Dict[str, int]
92
- # if m > len(tokens), return an empty dict
93
- for i in range (m , len (tokens ) + 1 ):
94
- ngr = "" .join (tokens [i - m :i ])
95
- ngr_dict [ngr ] = ngr_dict .setdefault (ngr , 0 ) + 1
96
- ngr_dicts .append (ngr_dict )
97
- return ngr_dicts
86
+ where = (count_all != 0 )))
87
+
88
+
89
+ def _get_ngrams ( tokens : List [ str ], n : int ) -> NGramDicts :
90
+ ngr_dicts = []
91
+ for m in range ( 1 , n + 1 ):
92
+ ngr_dict = {} # type: Dict[str, int]
93
+ for i in range (m , len (tokens ) + 1 ):
94
+ ngr = "" .join (tokens [i - m :i ])
95
+ ngr_dict [ngr ] = ngr_dict .setdefault (ngr , 0 ) + 1
96
+ ngr_dicts .append (ngr_dict )
97
+ return ngr_dicts
98
98
99
99
100
100
# pylint: disable=invalid-name
0 commit comments