Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion text/cleaners.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
from .numbers import normalize_numbers


# Regular expression matching whitespace:
# Regular expression matching whitespace punctuation, dash:
_whitespace_re = re.compile(r'\s+')
_punctuation_re = re.compile(r'[()!@#$%^&*+?/,.;\"\'\[\]]')
_dash_re = re.compile(r'[-]')

# List of (regular expression, replacement) pairs for abbreviations:
_abbreviations = [(re.compile('\\b%s\\.' % x[0], re.IGNORECASE), x[1]) for x in [
Expand Down Expand Up @@ -65,6 +67,14 @@ def convert_to_ascii(text):
return unidecode(text)


def replace_dash(text):
return re.sub(_dash_re, '', text)


def collapse_punctuation(text):
return re.sub(_punctuation_re, '', text)


def basic_cleaners(text):
'''Basic pipeline that lowercases and collapses whitespace without transliteration.'''
text = lowercase(text)
Expand All @@ -87,4 +97,6 @@ def english_cleaners(text):
text = expand_numbers(text)
text = expand_abbreviations(text)
text = collapse_whitespace(text)
text = collapse_punctuation(text)
text = replace_dash(text)
return text