-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprocessing.py
More file actions
28 lines (24 loc) · 812 Bytes
/
processing.py
File metadata and controls
28 lines (24 loc) · 812 Bytes
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
import dict
import re
import random
def lookUp(word, age):
"""Returns a word, based on given word, corresponding to given age"""
# Handle small children
if age<3:
babyTalk = ["goo", "ga", "waa", "waaaa", "waah", "ooo"]
return babyTalk[random.randint(0, len(babyTalk)-1)]
# If 3 or older, use the actual translation dictionary
return dict.dictLookup(word,age)
def stringProcessor(text, age):
"""Returns processed text corresponding to given age"""
inarr = re.findall(r"[\w']+|[.,!?;]", text)
outarr = []
text = ""
for word in inarr:
outarr.append(lookUp(word, age))
for word in outarr:
if (word != ',' and word != '.') and text != "":
text = text + ' ' + word
else:
text = text + word
return text