-
Notifications
You must be signed in to change notification settings - Fork 141
/
wiki.py
52 lines (42 loc) · 1.67 KB
/
wiki.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
import wikipedia
s = wikipedia.summary("eicosanoid")
print(s)
print("eicosanoid".title())
entity_titles = []
entity_descriptions = []
with open("data/FB13/entities.txt") as f, open("data/FB13/entity2text_capital.txt", 'w') as f1:
lines = f.readlines()
for line in lines:
line = line.strip()
title = line.title().replace("_", " ")
print(title)
entity_titles.append(line + '\t' + title)
f1.write('\n'.join(entity_titles))
with open("data/FB13/entities.txt") as f, open("data/FB13/entity2text.txt", 'w') as f2:
lines = f.readlines()
for line in lines:
line = line.strip()
try:
description = wikipedia.summary(line)
except:
description = line.replace("_", " ").title()
description = description.replace("\n", " ").replace("\t", " ")
print(description)
if description.strip() == "":
description = line.title().replace("_", " ")
entity_descriptions.append(line + '\t' + description)
f2.write('\n'.join(entity_descriptions))
with open("data/umls/entities.txt") as f, open("data/umls/entity2textlong.txt", 'w') as f2:
lines = f.readlines()
for line in lines:
line = line.strip()
try:
description = wikipedia.summary(line)
except:
description = line.replace("_", " ").title()
description = description.replace("\n", " ").replace("\t", " ")
print(description)
if description.strip() == "":
description = line.title().replace("_", " ")
entity_descriptions.append(line + '\t' + description)
f2.write('\n'.join(entity_descriptions))