git-subtree-dir: fiscal git-subtree-mainline:d95165fc8fgit-subtree-split:102ba84500
32 lines
1.3 KiB
Python
32 lines
1.3 KiB
Python
"""Prepare versioned candidate evidence from already computed deterministic candidates."""
|
|
import argparse
|
|
import json
|
|
from pathlib import Path
|
|
|
|
from central.app.ai.retrieval_v3 import prepare_candidate_set
|
|
|
|
|
|
def main(input_path, output_path):
|
|
source = json.loads(Path(input_path).read_text(encoding="utf-8"))
|
|
prepared = []
|
|
for item in source.get("items", []):
|
|
prepared.append(prepare_candidate_set(
|
|
type("WorkItem", (), {"task_type": item.get("task_type", "INVALID_NCM"), "dedup_key": item["dedup_key"], "payload": item.get("payload", {})})(),
|
|
[tuple(row) for row in item.get("candidates", [])],
|
|
dataset_versions=source.get("dataset_versions"),
|
|
gtin_evidence=item.get("gtin_evidence"),
|
|
kb_neighbors=item.get("kb_neighbors"),
|
|
hierarchical_context=item.get("hierarchical_context"),
|
|
))
|
|
report = {"artifact": "AI_CANDIDATE_PREPARATION_V3", "items": prepared, "semantic_decisions": 0}
|
|
Path(output_path).write_text(json.dumps(report, indent=2, ensure_ascii=False) + "\n", encoding="utf-8")
|
|
return report
|
|
|
|
|
|
if __name__ == "__main__":
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("input_path")
|
|
parser.add_argument("output_path")
|
|
args = parser.parse_args()
|
|
print(json.dumps(main(args.input_path, args.output_path), indent=2, ensure_ascii=False))
|