"""Compare free quotation with source-frame IDs under identical DEV evidence.""" import argparse from collections import Counter import json import re import sys from pathlib import Path import tiktoken from prepare_confirmation_source_cohort import OUT, read, digest from prepare_openqa_dev161_equal_budget import freeze, sha from study_population_witness_gate import counts, HEAD from quoted_population_count_resolution import resolve from population_count_selector_development import PROMPT OLD=OUT/'study_bound_numeric_binding_development_v2/population_count_selector_development_v1' DEST=OLD.parent/'population_frame_choice_development_v1' MARKER='\n\n-----Population frames-----\n' METHODS=['free_quote_with_catalog','frame_id_with_catalog'] def prepare(): DEST.mkdir(exist_ok=True) selectors=[r for r in read(OLD/'selectors32_before_readers.jsonl') if r['arm']=='masked'];unique=list(dict.fromkeys(r['request_id'] for r in selectors));assert len(unique)==8 inputs={r['id']:r for r in read(OLD/'requests24_local_only.jsonl')};encoder=tiktoken.encoding_for_model('gpt-4o');requests=[];catalogs=[];mapping=[] for oldid in unique: payload=json.loads(inputs[oldid]['messages'][1]['content']);original=payload['evidence'];assert MARKER not in original heads=list(HEAD.finditer(original));frames=[] for i,h in enumerate(heads): body=original[h.end():heads[i+1].start() if i+1