import re, inflect, os from utilities import constants def RemoveRole(text): return re.sub(r"^[a-zA-Z0-9_]+:\s*", "", text) def ReplaceNumbersWithWords(text): p = inflect.engine() words = text.split() print("words: "+str(words)) for i, word in enumerate(words): if word.isdigit(): print("word-isdigit: "+word) words[i] = p.number_to_words(word) elif word in constants.SYMBOL_TO_WORD: print("word - else: "+word+" symbol: "+constants.SYMBOL_TO_WORD[word]) words[i] = constants.SYMBOL_TO_WORD[word] reply=' '.join(words) print('returning: '+reply) return reply def CleanFileName(input_file): base_name_with_extension = os.path.basename(input_file) file_name, _ = os.path.splitext(base_name_with_extension) file_name = re.sub(r'[ .-]', '_', file_name) return file_name def CleanText(message): cleaned_message = re.sub(r':(\w+):', r'\1', message) cleaned_message = re.sub(r'http\S+|www.\S+', '', cleaned_message) return cleaned_message