Skip to content

Commit

Permalink
rename valid to invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
Harold-lkk committed Feb 28, 2023
1 parent 48fc4d7 commit 412c681
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions mmeval/metrics/one_minus_norm_edit_distance.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class OneMinusNormEditDistance(BaseMetric):
Usually, it only works for English characters. Defaults to
'unchanged'.
valid_symbol (str): A regular expression to filter out invalid or
invalid_symbol (str): A regular expression to filter out invalid or
not cared characters. Defaults to '[^A-Z^a-z^0-9^\u4e00-\u9fa5]'.
**kwargs: Keyword parameters passed to :class:`BaseMetric`.
Expand All @@ -43,13 +43,13 @@ class OneMinusNormEditDistance(BaseMetric):

def __init__(self,
letter_case: str = 'unchanged',
valid_symbol: str = '[^A-Z^a-z^0-9^\u4e00-\u9fa5]',
invalid_symbol: str = '[^A-Z^a-z^0-9^\u4e00-\u9fa5]',
**kwargs):
super().__init__(**kwargs)

assert letter_case in ['unchanged', 'upper', 'lower']
self.letter_case = letter_case
self.valid_symbol = re.compile(valid_symbol)
self.invalid_symbol = re.compile(invalid_symbol)

def add(self, predictions: Sequence[str], labels: Sequence[str]): # type: ignore # yapf: disable # noqa: E501
"""Process one batch of data and predictions.
Expand All @@ -62,8 +62,8 @@ def add(self, predictions: Sequence[str], labels: Sequence[str]): # type: ignor
if self.letter_case in ['upper', 'lower']:
pred = getattr(pred, self.letter_case)()
label = getattr(label, self.letter_case)()
label = self.valid_symbol.sub('', label)
pred = self.valid_symbol.sub('', pred)
label = self.invalid_symbol.sub('', label)
pred = self.invalid_symbol.sub('', pred)
norm_ed = Levenshtein.normalized_distance(pred, label)
self._results.append(norm_ed)

Expand Down

0 comments on commit 412c681

Please sign in to comment.