-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathhocr-spec
executable file
·75 lines (68 loc) · 2.13 KB
/
hocr-spec
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
#!/usr/bin/env python
from __future__ import print_function
from future import standard_library
standard_library.install_aliases()
import sys
from hocr_spec import HocrValidator, HocrSpec
from argparse import ArgumentParser
def main(args):
validator = HocrValidator(
args.profile,
skip_check=args.skip_check,
implicit_capabilities=args.implicit_capabilities)
failed = 0
for source in args.sources:
report = validator.validate(
source, parse_strict=args.parse_strict, filename=args.filename)
failed += not report.is_valid()
if not args.silent:
print(report.format(args.format))
sys.exit(0 if not failed else 1)
if __name__ == "__main__":
parser = ArgumentParser()
parser.add_argument(
'sources',
nargs='+',
help="hOCR file to check or '-' to read from STDIN")
parser.add_argument(
'--format',
'-f',
choices=HocrValidator.formats,
default=HocrValidator.formats[0],
help="Report format")
parser.add_argument(
'--filename',
help="Filename to use in report")
parser.add_argument(
'--profile',
'-p',
default='standard',
choices=HocrSpec.list('profiles'),
help="Validation profile")
parser.add_argument(
'--implicit_capabilities',
'-C',
action='append',
metavar='CAPABILITY',
choices=HocrSpec.list('capabilities'),
help="Enable this capability. Use '*' to enable all capabilities. "
"In addition to the 'ocr*' classes, you can use %s" %
HocrSpec.list('capabilities')
)
parser.add_argument(
'--skip-check',
'-X',
action='append',
choices=HocrSpec.checks,
help="Skip one check")
parser.add_argument(
'--parse-strict',
action='store_true',
help="Parse HTML with less tolerance for errors")
parser.add_argument(
'--silent',
'-s',
action='store_true',
help="Don't produce any output but signal success with exit code.")
args = parser.parse_args()
main(args)