forked from sintelligentdesign/emma
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pronouns.py
48 lines (41 loc) · 2.03 KB
/
pronouns.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
# Name: Antecedent Filler
# Description: Replaces words like "it" or "they" with the nouns that they refer to
# Section:
import utilities
from colorama import init, Fore
init(autoreset = True)
properPronouns = [
"he", "him", "his", "himself",
"she", "her", "hers", "herself",
"they", "them", "their", "theirs", "themself", "themselves"
]
otherPronouns = [
"it", "its", "itself"
]
# todo: make both of these work across sentences
def determine_references(sentence):
lastUsedProperNoun = ""
lastUsedNoun = ""
for count, word in enumerate(sentence):
if word[1] in ['NN', 'NNS']: lastUsedNoun = word
elif word[1] in ['NNP', 'NNPS']:
lastUsedProperNoun = word
if lastUsedNoun == "": lastUsedNoun = word
if word[0] in properPronouns and lastUsedProperNoun != "":
print Fore.GREEN + u"Replacing proper pronoun \'%s\' with \'%s\'..." % (word[0], lastUsedProperNoun[0])
sentence[count] = lastUsedProperNoun
elif word[0] in otherPronouns and lastUsedNoun != "":
print Fore.GREEN + u"Replacing pronoun \'%s\' with \'%s\'..." % (word[0], lastUsedNoun[0])
sentence[count] = lastUsedNoun
return sentence
posessiveReferences = {u"you": u"emma", u"your": u"emma", u"yours": u"emma", u"myself": u"emma"} # todo: add apostrophe + s when we're able to handle it
def flip_posessive_references(sentence, asker=""):
if asker != "": posessiveReferences.update({u"me": asker, u"i": asker, u"my": asker, u"mine": asker, u"myself": asker})
else: posessiveReferences.update({u"me": u"you", u"i": u"you", u"my": u"your", u"mine": u"yours", u"myself": u"yourself"})
for count, word in enumerate(sentence):
if word[0] in posessiveReferences.keys():
replacementWord = posessiveReferences[word[0]]
print Fore.GREEN + u"replacing posessive reference \'%s\' with \'%s\'..." % (word[0], replacementWord)
word[0] = replacementWord
word[1] = "NNP"
return sentence