-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnormalize.py
executable file
·52 lines (42 loc) · 1.37 KB
/
normalize.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
#!/usr/bin/python3
"""
WordNet persistence
Author: John McCrae <[email protected]> for original code
Author: Bernard Bou <[email protected]> for rewrite and revamp
"""
# Copyright (c) 2024.
# Creative Commons 4 for original code
# GPL3 for rewrite
import argparse
import glob
import sys
import time
import yaml
def normalize(home: str, verbose: bool = False) -> None:
""" Normalize (home dir)"""
if verbose:
print(f'normalizing YAML in {home}')
for f in glob.glob(f"{home}/*.yaml"):
data = yaml.load(open(f), Loader=yaml.CLoader)
with open(f, "w", encoding='utf-8') as out:
yaml.dump(data, out, allow_unicode=True)
if verbose:
print(f'normalized YAML in {home}')
def main() -> None:
"""
WordNet normalize
Will test YAML well-formedness
Will have a limited normalizing effect, after which it's not modified
YAML keys are not alphabetically reordered,
turn to load()-save() if this is desired
"""
arg_parser = argparse.ArgumentParser(description="load from yaml and save")
arg_parser.add_argument('in_dir', type=str, help='from-dir')
args = arg_parser.parse_args()
normalize(args.in_dir)
if __name__ == '__main__':
start_time = time.time()
main()
end_time = time.time()
duration = end_time - start_time
print(f"Normalizing took {duration:.6f} seconds", file=sys.stderr)