-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpaddleocr
173 lines (131 loc) · 4.93 KB
/
paddleocr
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
from paddleocr import PaddleOCR,draw_ocr
ocr = PaddleOCR(use_angle_cls=True, lang='en')
result = ocr.ocr(r"C:\Users\Subhadeep\Downloads\Book-2.png")
extracted_text = []
for i in range(0,len(result[0])):
text = result[0][i][1][0] # Extracting the text from the tuple
extracted_text.append(text)
print(extracted_text)
*******************************
ocr_list=extracted_text
key_value_pairs={}
for i in range(len(ocr_list)):
# Look for specific keys and extract their corresponding values
if ocr_list[i] == 'Group Name:':
key_value_pairs['Group Name'] = ocr_list[i + 1]
elif ocr_list[i] == 'Eff. Date:':
key_value_pairs['Effective Date'] = ocr_list[i + 1]
elif ocr_list[i] == 'Network:':
key_value_pairs['Network'] = ocr_list[i + 1]
elif ocr_list[i] == 'Single Deductible:':
key_value_pairs['Single Deductible'] = ocr_list[i + 1]
elif ocr_list[i] == 'Family Deductible:':
key_value_pairs['Family Deductible'] = ocr_list[i + 1]
elif ocr_list[i] == 'PCP:':
key_value_pairs['PCP'] = ocr_list[i + 1]
elif ocr_list[i] == 'Specialist:':
key_value_pairs['Specialist'] = ocr_list[i + 1]
elif ocr_list[i] == 'ER Copay:':
key_value_pairs['ER Copay:'] = ocr_list[i + 1]
sd_index = data.index('Single Deductible:')
single_deductible_inn = {
'Single Deductible INN': [data[sd_index + 1], data[sd_index + 2]]
}
second_sd_index = data.index('Single Deductible:', sd_index + 1)
single_deductible_oon = {
'Single Deductible OON': [data[second_sd_index + 1], data[second_sd_index + 2]]
}
fd_index = data.index('Family Deductible:')
family_deductible_inn = {
'Family Deductible INN': [data[fd_index + 1], data[fd_index + 2]]
}
second_fd_index = data.index('Family Deductible:', fd_index + 1)
family_deductible_oon = {
'Family Deductible OON': [data[second_fd_index + 1], data[second_fd_index + 2]]
}
coins_index = data.index('Coinsurance:')
coins_inn = {
'Coinsurance INN': [data[coins_index + 1], data[coins_index + 2]]
}
second_coins_index = data.index('Coinsurance:', coins_index + 1)
coins_oon = {
'Coinsurance OON': [data[second_coins_index + 1], data[second_coins_index + 2]]
}
# Single M.O.O.P.
moop_index = data.index('Single M.O.O.P.')
single_moop_inn = {
'Single M.O.O.P. INN': [data[moop_index + 1], data[moop_index + 2]]
}
second_moop_index = data.index('Single M.O.O.P.', moop_index + 1)
single_moop_oon = {
'Single M.O.O.P. OON': [data[second_moop_index + 1], data[second_moop_index + 2]]
}
# Modify values based on conditions for single deductibles
for key, value in single_deductible_inn.items():
if ':' in value[1]:
single_deductible_inn[key] = value[0]
elif '$' in value[0]:
single_deductible_inn[key] = value[1]
for key, value in single_deductible_oon.items():
if ':' in value[1]:
single_deductible_oon[key] = value[0]
elif '$' in value[0]:
single_deductible_oon[key] = value[1]
# Modify values based on conditions for family deductibles
for key, value in family_deductible_inn.items():
if ':' in value[1]:
family_deductible_inn[key] = value[0]
elif '$' in value[0]:
family_deductible_inn[key] = value[1]
for key, value in family_deductible_oon.items():
if ':' in value[1]:
family_deductible_oon[key] = value[0]
elif '$' in value[0]:
family_deductible_oon[key] = value[1]
# Modify values based on conditions for single MOOP
for key, value in single_moop_inn.items():
if ':' in value[1]:
single_moop_inn[key] = value[0]
elif '$' in value[0]:
single_moop_inn[key] = value[1]
for key, value in single_moop_oon.items():
if ':' in value[1]:
single_moop_oon[key] = value[0]
elif '$' in value[0]:
single_moop_oon[key] = value[1]
for key, value in coins_inn.items():
if ':' in value[1]:
coins_inn[key] = value[0]
elif '$' in value[0]:
coins_inn[key] = value[1]
for key, value in coins_oon.items():
if 'Single' in value[1] or 'Coinsurance' in value[1]:
coins_oon[key] = value[0]
elif '%' in value[0]:
coins_oon[key] = value[1]
deductible_dict = {**key_value_pairs,
**single_deductible_inn,
**single_deductible_oon,
**family_deductible_inn,
**family_deductible_oon,
**single_moop_inn,
**single_moop_oon,
**coins_inn,
**coins_oon
}
print(deductible_dict)
*****
ref_list=[''.join(char.lower() for char in string if char.isalnum() or char.isspace()) for string in cleaned_text]
word_replacements = {
'Single Ded': 'Single Deductible:',
'Family Ded': 'Family Deductible:',
'Coinsurance': 'Coinsurance:',
'Single M.': 'Single M.O.O.P.',
'Family M.': 'Family M.O.O.P.'
}
# Iterate through the list and replace elements if necessary
for i, element in enumerate(my_list):
for word, replacement in word_replacements.items():
if word in element:
my_list[i] = replacement
break