1- """Generic enrich helpers for AVID report JSON and JSONL files."""
1+ """Generic normalize helpers for AVID report JSON and JSONL files."""
22
33import json
44from pathlib import Path
55
6- from .utils import apply_enrich_normalizations
6+ from .utils import apply_normalizations
77
88
9- def _enrich_report (report : dict ) -> None :
10- """Apply generic enrich normalizations to a single report dict."""
9+ def _normalize_report (report : dict ) -> None :
10+ """Apply generic normalizations to a single report dict."""
1111
12- apply_enrich_normalizations (report )
12+ apply_normalizations (report )
1313
1414
1515def process_json_file (
1616 input_path : Path ,
1717 dry_run : bool ,
1818) -> int :
19- """Enrich a JSON file containing one report object or a list of reports."""
19+ """Normalize a JSON file containing one report object or a list of reports."""
2020
2121 with input_path .open ("r" , encoding = "utf-8" ) as file_obj :
2222 payload = json .load (file_obj )
2323
24- reports_enriched = 0
24+ reports_normalized = 0
2525
2626 if isinstance (payload , dict ):
27- _enrich_report (payload )
28- reports_enriched += 1
27+ _normalize_report (payload )
28+ reports_normalized += 1
2929 elif isinstance (payload , list ):
3030 for index , report in enumerate (payload , 1 ):
3131 if not isinstance (report , dict ):
3232 raise ValueError (
3333 "Invalid item at index "
3434 f"{ index } in JSON list: expected object"
3535 )
36- _enrich_report (report )
37- reports_enriched += 1
36+ _normalize_report (report )
37+ reports_normalized += 1
3838 else :
3939 raise ValueError ("Unsupported JSON structure: expected object or list" )
4040
@@ -43,17 +43,17 @@ def process_json_file(
4343 json .dump (payload , file_obj , indent = 2 )
4444 file_obj .write ("\n " )
4545
46- return reports_enriched
46+ return reports_normalized
4747
4848
4949def process_jsonl_file (
5050 input_path : Path ,
5151 dry_run : bool ,
5252) -> int :
53- """Enrich each report object in a JSONL file."""
53+ """Normalize each report object in a JSONL file."""
5454
55- reports_enriched = 0
56- enriched_lines = []
55+ reports_normalized = 0
56+ normalized_lines = []
5757
5858 with input_path .open ("r" , encoding = "utf-8" ) as file_obj :
5959 for line_num , line in enumerate (file_obj , 1 ):
@@ -73,20 +73,20 @@ def process_jsonl_file(
7373 f"Invalid JSON object on line { line_num } : expected object"
7474 )
7575
76- _enrich_report (report )
77- reports_enriched += 1
78- enriched_lines .append (json .dumps (report , ensure_ascii = False ))
76+ _normalize_report (report )
77+ reports_normalized += 1
78+ normalized_lines .append (json .dumps (report , ensure_ascii = False ))
7979
8080 if not dry_run :
8181 with input_path .open ("w" , encoding = "utf-8" ) as file_obj :
82- if enriched_lines :
83- file_obj .write ("\n " .join (enriched_lines ) + "\n " )
82+ if normalized_lines :
83+ file_obj .write ("\n " .join (normalized_lines ) + "\n " )
8484
85- return reports_enriched
85+ return reports_normalized
8686
8787
88- def enrich_file (input_path : Path , dry_run : bool = False ) -> int :
89- """Dispatch enrich processing based on input file extension."""
88+ def normalize_file (input_path : Path , dry_run : bool = False ) -> int :
89+ """Dispatch normalize processing based on input file extension."""
9090
9191 if input_path .suffix == ".json" :
9292 return process_json_file (input_path , dry_run )
0 commit comments