-
Notifications
You must be signed in to change notification settings - Fork 14
/
_doublecheck_viewer.py
128 lines (99 loc) · 3.76 KB
/
_doublecheck_viewer.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
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
import os, shutil
htmlTop = """
<!DOCTYPE html>
<html>
<head>
<title>fileName</title>
<meta charset="UTF-8">
<meta name="description" content="Reviewing OCR Training/Testing Data">
<meta name="keywords" content="HTML">
<meta name="author" content="Open ITI Corpus Team">
<link href='http://fonts.googleapis.com/earlyaccess/amiri.css' rel='stylesheet' type='text/css'>
<style>
body {background-color: white;}
p {color: red; direction: rtl; font-size: 22pt; font-weight: bold; text-align: center; font-family: "Courier New", "Geeza Pro", "Amiri"}
h1 {color: darkgreen; font-size: 20pt; text-align: left; font-family: "Baskerville", "Garamond"}
img {height: 50pt; text-align: center}
#download_button {
position: fixed;
padding: 0;
text-align: left;
width: 15%;
bottom: 10px;
right: 20px;
font-size: 16pt;
color: #8B0000;
font-weight: bold;
}
</style>
</head>
<body>
<table style="width:100%" align="center">
"""
htmlBot = """
</table>
<a id="download_button">To Save: `Ctrl+s`, make sure to choose `Webpage, complete`!</a>
</body>
</html>
"""
def getText(fileName):
with open(fileName[:-4]+'.gt.txt', "r", encoding="utf8") as f1:
text = f1.read()
text = text.replace('"', "«»")
#print(text)
#text = list(text)
#print(text)
#text.reverse()
#print(text)
#text = "".join(text)
#print(text)
#input()
return(text)
import math
def roundup(x, par):
newX = int(math.ceil(int(x) / float(par)) * par)
return(newX)
def createHTMLs(folder, pref, lines):
files = os.listdir(folder)
relFolder = folder.split("/")
relFolder = "./"+"/".join(relFolder[-2:])+"/"
#input(relFolder)
counter = 0
table = []
for f in files:
if f.endswith(".png"):
# <a href="file://C:/path/to/file/file.html">Link Anchor</a>
href = '<h1>File: %s (if the image is defective, simply delete all Arabic text and the line will be excluded)</h1>'
head = href % (f[:-4]+'.gt.txt')
tags = head + '<p><img src="%s"></p>' % (relFolder+"/"+f)
text = tags+"<p contenteditable=\"true\" fileNameId=\"%s\">%s</p>" % ((f[:-4]+'.gt.txt'), getText(folder+"/"+f))
table.append('<tr align="center">%s</tr><hr>' % text)
counter += 1
if counter % lines == 0:
fileName = "%s%06d.html" % (pref, counter)
corr = fileName[:-5]+"_corrected.html"
newHTML = htmlTop.replace(">fileName<", ">"+fileName[:-5]+"_corrected.html<")
with open("./ara/"+fileName, "w", encoding="utf8") as f9:
f9.write(newHTML + "\n\n".join(table) + htmlBot)
table = []
print("%s%06d.html" % (pref, counter))
#input("Check!")
newCount = roundup(counter, lines)
fileName = "%s%06d.html" % (pref, newCount)
corr = fileName[:-5]+"_corrected.html"
newHTML = htmlTop.replace(">fileName<", ">"+fileName[:-5]+"_corrected.html<")
with open("./ara/"+fileName, "w", encoding="utf8") as f9:
f9.write(newHTML + "\n\n".join(table) + htmlBot)
def processAll():
sub = "./ara/"
lofol = os.listdir(sub)
suf = "/7_final/"
for fol in lofol:
if fol.startswith(("book_", "lq_")):
print(fol+suf)
folder = sub+fol+suf
pref = (os.path.abspath(folder)).split("/")[-2].replace(".","_")
pref = "z_ALL_"+pref+"_"
print(pref)
createHTMLs(os.path.abspath(folder), pref, 500)
processAll()