Add unknowns_classifier/src/unknowns_classifier/cli.py
This commit is contained in:
parent
0bf82cff06
commit
cddc8fbaa2
1 changed files with 61 additions and 0 deletions
61
unknowns_classifier/src/unknowns_classifier/cli.py
Normal file
61
unknowns_classifier/src/unknowns_classifier/cli.py
Normal file
|
|
@ -0,0 +1,61 @@
|
||||||
|
import argparse
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import List, Dict
|
||||||
|
|
||||||
|
from unknowns_classifier.core import classify_unknowns
|
||||||
|
|
||||||
|
def main() -> None:
|
||||||
|
"""CLI entrypoint for classifying unknown cases from drift reports."""
|
||||||
|
parser = argparse.ArgumentParser(
|
||||||
|
description="Klassifiziert Unknown-Cases aus Drift-Reports in vordefinierte Kategorien."
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--input",
|
||||||
|
required=True,
|
||||||
|
help="Pfad zum Ordner mit drift_report.json-Dateien."
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--output",
|
||||||
|
required=False,
|
||||||
|
default="output/classified_unknowns.json",
|
||||||
|
help="Pfad zur Ausgabedatei für Klassifikationsergebnisse."
|
||||||
|
)
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
input_path = Path(args.input)
|
||||||
|
output_path = Path(args.output)
|
||||||
|
|
||||||
|
if not input_path.exists() or not input_path.is_dir():
|
||||||
|
raise FileNotFoundError(f"Eingabeordner nicht gefunden: {input_path}")
|
||||||
|
|
||||||
|
unknown_cases: List[Dict] = []
|
||||||
|
|
||||||
|
for report_file in input_path.glob("*.json"):
|
||||||
|
with report_file.open('r', encoding='utf-8') as f:
|
||||||
|
try:
|
||||||
|
data = json.load(f)
|
||||||
|
except json.JSONDecodeError as e:
|
||||||
|
raise ValueError(f"Fehler beim Lesen von {report_file}: {e}") from e
|
||||||
|
if isinstance(data, dict) and 'unknowns' in data:
|
||||||
|
cases = data['unknowns']
|
||||||
|
if isinstance(cases, list):
|
||||||
|
unknown_cases.extend(cases)
|
||||||
|
|
||||||
|
if not unknown_cases:
|
||||||
|
print("Keine Unknown-Cases gefunden.")
|
||||||
|
return
|
||||||
|
|
||||||
|
classified = classify_unknowns(unknown_cases)
|
||||||
|
|
||||||
|
output_path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
|
with output_path.open('w', encoding='utf-8') as f:
|
||||||
|
json.dump([c.__dict__ for c in classified], f, indent=2, ensure_ascii=False)
|
||||||
|
|
||||||
|
print(f"Klassifikation abgeschlossen. Ergebnisse gespeichert in: {output_path}")
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
Loading…
Reference in a new issue