for e in effs: raw_q = e.get("verbatim_evidence_quote") if raw_q is None and curated_rec["study_metadata"].get("source_text_type") == "Citation_Only_No_Abstract_Indexed": q = "" e["verbatim_evidence_quote"] = None else: q = (raw_q or "").strip() if len(q) > 345 and pmid not in CURATED_LANDMARK_PMIDS: q = q[:340].rsplit(" ", 1)[0].strip() e["verbatim_evidence_quote"] = q eid = e.get("effect_id") or "" if eid in CURATED_QUOTE_EXACT_OVERRIDES: for k_ov, v_ov in CURATED_QUOTE_EXACT_OVERRIDES[eid].items(): e[k_ov] = v_ov elif pmid in LEGACY_AUTO_CURATED_PMIDS or eid.startswith(f"pmid{pmid}_eff"): if eid.startswith(f"pmid{pmid}_eff") and not eid.endswith("_counterevidence"): d_dir, d_pen = classify_sentence_direction_and_penalty(q) e["effect_direction"] = d_dir e["secretome_or_differentiation_penalty_observed"] = d_pen t_m, t_s, c_m, c_s, u_m, lrr_m = parse_quantitative_numbers(q, d_dir) e["treatment_mean"] = t_m e["treatment_sd_or_sem"] = t_s e["control_mean"] = c_m e["control_sd_or_sem"] = c_s e["measurement_unit"] = u_m e["log_response_ratio_or_smd"] = lrr_m elif eid == "pmid37264229_eff1_counterevidence": e["treatment_n"] = None e["focal_arm_id"] = default_exp_arm e["comparator_arm_id"] = default_ctrl_arm if isinstance(e.get("log_response_ratio_or_smd"), (int, float)) else None else: if not isinstance(e.get("log_response_ratio_or_smd"), (int, float)): e["comparator_arm_id"] = None if not e.get("focal_arm_id") or e.get("focal_arm_id") == default_ctrl_arm: e["focal_arm_id"] = default_exp_arm if e.get("secretome_or_differentiation_penalty_observed") and e.get("effect_direction") != "Deleterious_or_Impaired": e["effect_direction"] = "Deleterious_or_Impaired" if eid == "lei2022_eff1_safasl_nhp_graft_survival_180days": e["treatment_mean"] = 188.0 for fn in ("treatment_mean", "control_mean", "treatment_sd_or_sem", "control_sd_or_sem", "treatment_n", "control_n", "p_value"): if e.get(fn) is not None and not _num_in_quote(e.get(fn), q, fn): e[fn] = None _populate_effect_provenance(e, dossier, dossier_sha, transplant_site) has_num = any(isinstance(e.get("log_response_ratio_or_smd"), (int, float)) for e in effs) if pmid in LEGACY_AUTO_CURATED_PMIDS and not has_num: curated_rec["arms"] = [a for a in arms if not a.get("is_reference_control", False)] elif pmid == "40782792": for a in arms: if a.get("arm_id") == "pmid40782792_arm2_comparator": a["arm_label"] = "Non-reconstructed PSC-islet control cohort in Meng et al. (2025)" a["sample_size_n"] = None a["sample_size_unit"] = None source_blob = json.dumps(dossier, ensure_ascii=False) is_subordinate_citation_only = ( curated_rec["study_metadata"].get("source_text_type") == "Citation_Only_No_Abstract_Indexed" and bool(curated_rec["study_metadata"].get("subordinate_followup_to_pmid")) ) for arm in curated_rec.get("arms", []): if ( not is_subordinate_citation_only and arm.get("sample_size_n") is not None and not _num_in_quote(arm["sample_size_n"], source_blob, "sample_size_n") ): arm["sample_size_n"] = None arm["sample_size_unit"] = None _apply_bibliographic_evidence_scope(curated_rec, dossier) validate_study_semantics(curated_rec, dossier) CURATED_DIR.mkdir(parents=True, exist_ok=True) if not curated_src_path.exists(): with open(curated_src_path, "w", encoding="utf-8") as f: json.dump(curated_rec, f, indent=2, ensure_ascii=False) f.write("\n") with open(out_path, "w", encoding="utf-8") as f: json.dump(curated_rec, f, indent=2, ensure_ascii=False) f.write("\n") preserved_count += 1 continue rec = extract_one_dossier(dossier) with open(out_path, "w", encoding="utf-8") as f: json.dump(rec, f, indent=2, ensure_ascii=False) f.write("\n") extracted_count += 1 if extracted_count == 0 and preserved_count == 0: print( f"[RING 1 EXTRACTION SKIPPED] Extracted: 0 | Preserved curated landmarks: 0 | Total Ring 1 queue: {len(ring1)} " "— raw full-text/abstract dossiers (data/dossiers/*.json) are excluded from the public bundle; " "using shipped pre-extracted study records in data/extracted/*.json without modification." ) return # JSONLs are a direct producer output, not a delayed manifest side effect. try: from scripts.study_artifact_exports import write_study_exports except ModuleNotFoundError: from study_artifact_exports import write_study_exports produced_studies = [json.loads(path.read_text(encoding="utf-8")) for path in sorted(EXTRACTED_DIR.glob("*.json")) if path.stem.isdigit()] write_study_exports(BASE_DIR, produced_studies) print( f"[RING 1 EXTRACTION COMPLETE] Extracted: {extracted_count} | " f"Preserved curated landmarks: {preserved_count} | Total Ring 1 queue: {len(ring1)}" ) if __name__ == "__main__": main()