-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·76 lines (56 loc) · 1.49 KB
/
main.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
64
65
66
67
68
69
70
71
72
73
74
75
76
import string
import find_acr
import get_expansion
import only_lex
import search
import get_score
full_forms = {}
docmap = {}
def load_doc_map():
global docmap
index_path = 'index'
with open(index_path+'/'+'doc_id_map', 'r') as inputfile:
for line in inputfile:
if len(line) > 2:
docid = line.split(':')[0]
reststart = len(docid)
content = line[reststart+1:]
docmap[docid] = content
def disambiguate(acronym):
global full_forms
possible = get_expansion.get_all_expansions(acronym)
print(possible)
max_score = -1
most_likely = ':('
for case in possible:
lex_case = search.get_list(case.lower(), docmap)
#print(lex_case)
score = get_score.calc_score(lex_doc, lex_case)
if score > max_score:
max_score = score
most_likely = case
print(case)
print(score)
print('The chosen one')
print(most_likely)
print(max_score)
if max_score != -1:
full_forms[acronym.upper()] = most_likely
def make_result(file_name):
global full_forms
fp = open((file_name))
data = str(fp.read())
for map in full_forms:
data = data.replace(map, str(map + '(' + full_forms[map] + ')'))
#print(data)
with open("final.txt", "w") as done_file:
done_file.write(data)
print("Enter File Name")
file_name = str(input())
load_doc_map()
lex_doc = only_lex.make_lexical(file_name)
acro_list = find_acr.get_all_acronyms()
print(acro_list)
for acronym in acro_list:
disambiguate(acronym)
make_result(file_name)