-
Notifications
You must be signed in to change notification settings - Fork 2
/
word_mapping.py
65 lines (45 loc) · 1.69 KB
/
word_mapping.py
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import string
word_mappings = {
"doesn't" : [ "doesn't" ],
"can't" : [ "can't" ],
"won't" : ["would","not"] ,
"don't" : ["don't" ],
"i've" : ["i've" ],
"i'd" : ["i'd" ],
"i'm" : ["i'm" ] ,
"i'll" : ["i'll"],
"she's" : ["she's"],
"he's" : ["he's"],
"it's" : ["it's"],
"there's" : ["there's"],
"they're" : ["they" , "are" ] ,
"we're" : ["we","are"],
"you've" : ["you've"],
"you're" : ["you're"],
"couldn't": ["could","not"],
"shouldn't": ["should","not"],
"wouldn't" : ["would", "not"],
}
def process_sentence(sentence):
sentence = sentence.lower()
new_sentence = []
for word in sentence.split(' '):
if word == '':
continue
if word in string.punctuation:
continue
if '?' in word:
word=word.replace('?','')
if '\'' in word:
if word in word_mappings.keys():
for each in word_mappings[word]:
new_sentence.append(each)
else:
index = word.index('\'')
word = word[:index]
new_sentence.append(word)
elif '%' in word:
new_sentence.append( word.replace("%","") )
else:
new_sentence.append(word)
return ' '.join(new_sentence)