forked from Kareem-Emad/arabic-ocr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
edit.py
26 lines (20 loc) · 760 Bytes
/
edit.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
#!/usr/bin/python
from __future__ import print_function
import sys
import os
import editdistance
if len(sys.argv) != 3:
sys.exit('USAGE: edit.py PREDICTED_PATH TRUTH_PATH')
distances = []
accuracies = []
for file_name in os.listdir(sys.argv[2]):
with open(os.path.join(sys.argv[1], file_name)) as f:
predicted = ''.join(f.read().split())
with open(os.path.join(sys.argv[2], file_name)) as f:
truth = ''.join(f.read().split())
distance = editdistance.eval(predicted, truth)
distances.append(distance)
accuracies.append(max(0, 1 - distance / len(truth)))
print(f'{file_name}: {distance}')
print(f'Total distance = {sum(distances)}')
print('Average Accuracy = %.2f%%' % (sum(accuracies) / len(accuracies) * 100))