File size: 1,079 Bytes
e91ae53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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