mict-zhaw commited on
Commit
124b74c
·
1 Parent(s): 0c707aa

Make preprocess_text static

Browse files
Files changed (1) hide show
  1. chall.py +5 -3
chall.py CHANGED
@@ -544,7 +544,7 @@ class Chall(GeneratorBasedBuilder):
544
  """
545
 
546
  clear_text = self.remove_annotations(raw_text)
547
- clear_text = self.preprocess_text(clear_text)
548
 
549
  if self.config.num_to_words:
550
  clear_text = self.num_to_words(clear_text)
@@ -560,13 +560,15 @@ class Chall(GeneratorBasedBuilder):
560
 
561
  return clear_text
562
 
563
- def preprocess_text(self, transcript: str) -> str:
 
564
  """
565
  Preprocesses the text by removing words between brackets and parentheses,
566
  standardizing spaces before apostrophes, removing commas between digits,
567
  and replacing special characters.
568
 
569
  :param transcript: The input transcript to preprocess.
 
570
  :return: The preprocessed transcript with various text normalization applied.
571
  """
572
 
@@ -574,7 +576,7 @@ class Chall(GeneratorBasedBuilder):
574
  transcript = re.sub(r"\(([^)]+?)\)", "", transcript) # remove words between parenthesis
575
  transcript = re.sub(r"\s+'", "'", transcript) # standardize when there's a space before an apostrophe
576
  transcript = re.sub(r"(\d),(\d)", r"\1\2", transcript) # remove commas between digits
577
- if "." not in self.config.allowed_chars:
578
  transcript = re.sub(r"\.([^0-9]|$)", r" \1", transcript) # remove periods not followed by numbers
579
 
580
  # Replace special characters
 
544
  """
545
 
546
  clear_text = self.remove_annotations(raw_text)
547
+ clear_text = self.preprocess_text(clear_text, allowed_chars=self.config.allowed_chars)
548
 
549
  if self.config.num_to_words:
550
  clear_text = self.num_to_words(clear_text)
 
560
 
561
  return clear_text
562
 
563
+ @staticmethod
564
+ def preprocess_text(transcript: str, allowed_chars: set) -> str:
565
  """
566
  Preprocesses the text by removing words between brackets and parentheses,
567
  standardizing spaces before apostrophes, removing commas between digits,
568
  and replacing special characters.
569
 
570
  :param transcript: The input transcript to preprocess.
571
+ :param allowed_chars: Set of allowed chars
572
  :return: The preprocessed transcript with various text normalization applied.
573
  """
574
 
 
576
  transcript = re.sub(r"\(([^)]+?)\)", "", transcript) # remove words between parenthesis
577
  transcript = re.sub(r"\s+'", "'", transcript) # standardize when there's a space before an apostrophe
578
  transcript = re.sub(r"(\d),(\d)", r"\1\2", transcript) # remove commas between digits
579
+ if "." not in allowed_chars:
580
  transcript = re.sub(r"\.([^0-9]|$)", r" \1", transcript) # remove periods not followed by numbers
581
 
582
  # Replace special characters