| import json |
| from pathlib import Path |
|
|
| |
| |
| map_json_path = None |
| |
| right_txt_path = "/nfs/ywang29/Reward_finetuning/VideoX-Fun/VBench/VBench-2.0/prompts/prompt_aug/Wanx_full_text_aug.txt" |
| left_txt_path = "/nfs/ywang29/Reward_finetuning/VideoX-Fun/VBench/VBench-2.0/prompts/VBench2_full_text.txt" |
|
|
| |
| query_txt_path = "/nfs/ywang29/Reward_finetuning/VideoX-Fun/VBench/VBench-2.0/missing_prompts.txt" |
|
|
| |
| mapped_txt_out ="/nfs/ywang29/Reward_finetuning/VideoX-Fun/VBench/VBench-2.0/missing_prompts_wan_aug.txt" |
| miss_report_out = "query.missing.txt" |
|
|
| |
| strip_line = True |
|
|
| |
| def build_mapping_from_pair(left_path, right_path, strip_line=True): |
| left_lines = Path(left_path).read_text(encoding="utf-8").splitlines() |
| right_lines = Path(right_path).read_text(encoding="utf-8").splitlines() |
| if len(left_lines) != len(right_lines): |
| raise ValueError(f"行数不一致:{len(left_lines)} vs {len(right_lines)}") |
| if strip_line: |
| left_lines = [s.strip() for s in left_lines] |
| right_lines = [s.strip() for s in right_lines] |
| mapping = {} |
| for l, r in zip(left_lines, right_lines): |
| if l in mapping: |
| if isinstance(mapping[l], list): |
| mapping[l].append(r) |
| else: |
| mapping[l] = [mapping[l], r] |
| else: |
| mapping[l] = r |
| return mapping |
|
|
| if map_json_path and Path(map_json_path).exists(): |
| mapping = json.loads(Path(map_json_path).read_text(encoding="utf-8")) |
| else: |
| mapping = build_mapping_from_pair(left_txt_path, right_txt_path, strip_line=strip_line) |
|
|
| |
| query_lines = Path(query_txt_path).read_text(encoding="utf-8").splitlines() |
| if strip_line: |
| query_lines = [s.strip() for s in query_lines] |
|
|
| mapped_lines = [] |
| missing = [] |
|
|
| for i, q in enumerate(query_lines): |
| if q in mapping: |
| v = mapping[q] |
| |
| if isinstance(v, list): |
| mapped_lines.append(" ||| ".join(v)) |
| else: |
| mapped_lines.append(str(v)) |
| else: |
| mapped_lines.append(f"__MISSING__:{q}") |
| missing.append({"line_idx": i, "query": q}) |
|
|
| |
| Path(mapped_txt_out).write_text("\n".join(mapped_lines), encoding="utf-8") |
|
|
| |
| if missing: |
| Path(miss_report_out).write_text( |
| json.dumps(missing, ensure_ascii=False, indent=2), |
| encoding="utf-8" |
| ) |
| print(f"完成:{mapped_txt_out}\n有 {len(missing)} 条未匹配,详情见 {miss_report_out}") |
| else: |
| print(f"完成:{mapped_txt_out}\n全部行成功匹配。") |
|
|