-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathname_entity_processing.py
47 lines (40 loc) · 1.6 KB
/
name_entity_processing.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
class NEP:
def transform_pronoun(self, raw_data):
# tokenizer = nltk.data.load('tokenizers/punkt/english.pickle')
# target_dir = sys.argv[1]
# target_file_object = open(target_dir)
# raw_data = target_file_object.read()
word_list = raw_data.lower().split(" ")
ne_gender = None
he_count = word_list.count("he")
she_count = word_list.count("she")
if he_count >= she_count:
ne_gender = "he"
else:
ne_gender = "she"
sentences = raw_data.split("\n")
NE = sentences[0]
first_name = NE.split(" ")[0]
last_name = NE.split(" ")[1]
sentences_nep = []
if ne_gender == "he":
for s in sentences:
tmp = s.replace(" he ", " " + NE + " ")
tmp = tmp.replace(" He ", " " + NE + " ")
tmp = tmp.replace("He ", NE + " ")
tmp = tmp.replace(" his ", " " + NE + "'s ")
tmp = tmp.replace(" His ", " " + NE + "'s ")
tmp = tmp.replace(" him ", " " + NE + " ")
sentences_nep.append(tmp)
else:
for s in sentences:
tmp = s.replace(" she ", " " + NE + " ")
tmp = tmp.replace(" She ", " " + NE + " ")
tmp = tmp.replace(" Her ", " " + NE + "'s ")
sentences_nep.append(tmp)
return ["\n".join(sentences_nep), [NE, first_name, last_name]]
# NEP = NEP()
# output = NEP.transform_pronoun()
# # print(test)
# print("************************ \n\n\n\n *******************")
# print(output)