vgrabovets
4/28/2017 - 9:09 AM

replacement dictionary

replacement dictionary

REPLACEMENTS = {
    'ass': 'association',
    'assoc': 'association',
    'asso': 'association',
    'soc': 'societe',        
}

PATTERN_REPLACEMENTS = regex.compile(r'\b(' + '|'.join(REPLACEMENTS.keys()) + r')\b')

PATTERN_REPLACEMENTS.sub(lambda x: REPLACEMENTS[x.group()], text)