-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheaders.py
More file actions
55 lines (48 loc) · 1.61 KB
/
Copy pathheaders.py
File metadata and controls
55 lines (48 loc) · 1.61 KB
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
import sys
import json
from os import listdir
from fuzzywuzzy import fuzz
from fuzzywuzzy import process
import receipt2json as receipt
import operator
def readHeaders(path='dat/stores.json'):
"""
"""
if 'stores.json' in listdir(path='dat/'):
#print('store header info loaded')
with open(path) as f:
header_dict = json.load(f)
return header_dict
else:
#print('store header info not found')
return None
def matchHeader(lines):
real_lines = [line for line in lines[:20] if len(line) > 4]
header_dict = readHeaders()
store_matches = {}
for store, head_lines in header_dict.items():
store_match_v = 0
for head_line in head_lines:
fuzz_val = 0
for line in real_lines:
fp_ratio = fuzz.partial_ratio(head_line, line)
#print(fp_ratio,line)
fuzz_val = max(fp_ratio, fuzz_val)
store_match_v += fuzz_val
#print(fuzz_val)
store_matches.update({store: store_match_v})
#print(store_match, store)
return max(store_matches.items(), key=operator.itemgetter(1))[0]
if __name__ == '__main__':
mode = sys.argv[1] if len(sys.argv) > 1 else None
print(mode)
header_dict = readHeaders()
for key,lines in header_dict.items():
print(key)
for line in lines:
print("-", line)
img_list, history_list = receipt.findImages()
img_list.extend(history_list)
for file in img_list:
lines = receipt.tesseractImage('img/'+file).splitlines()
print(matchHeader(lines), file, sep='\t')