SPB Git

spb/wp45_uqo

Public
2.9 KB · 34 lines python
1import json, jsonschema, pytest2from jof250 import rhetoric, segmentation34def minimal_annotation():5    mv = lambda: {"present": True, "sentence_index": 0}6    return {"genre": "empirical", "subfield": "asset_pricing", "subfield_secondary": "", "primary_method": "reduced_form_regression",7            "identification": {"estimand": "e", "strategy": "s", "key_assumptions": [], "threats_addressed": [], "causal_language_strength": 3, "uses_causal_claim": False},8            "abstract_moves": {k: mv() for k in ["question", "gap", "method", "results", "magnitude", "contribution"]},9            "introduction": {"moves": [{"paragraph_index": 0, "move": "motivation"}], "contribution_paragraph_index": 0, "contribution_types": ["new_evidence"], "roadmap_present": True, "literature_positioning_location": "inside_introduction"},10            "section_roles": [{"idx": 0, "role": "introduction"}], "results_presentation": {"economic_significance_discussed": True, "statistical_significance_language": "stars_and_tstats", "magnitude_statements_in_intro": True},11            "robustness": {"location": "appendix", "types": ["placebo"]}, "tables": {"convention_notes": "", "units_stated_in_notes": True, "standard_errors_description": "clustered"}, "figures": {"uncertainty_shown": "yes"},12            "conclusion": {"bounded_claims": True, "policy_implications": False, "open_questions": True, "restates_contribution": True}, "hedging": {"level": "moderate", "typical_devices": []},13            "claim_evidence": [{"claim": "c", "evidence_type": "table", "evidence_ref": "Table I"}], "structural_summary": "s", "writing_profile_keywords": ["k"], "confidence": 0.9, "notes": ""}1415def test_schema_accepts_valid_and_rejects_bad_enum():16    a = minimal_annotation(); assert rhetoric.validate_full(a) == []17    a["genre"] = "poetry"; assert rhetoric.validate_full(a)18    b = minimal_annotation(); del b["identification"]["causal_language_strength"]; assert rhetoric.validate_full(b)1920def test_section_roles():21    assert segmentation.section_role("Data and Sample Construction") == "data"22    assert segmentation.section_role("Robustness Checks") == "robustness"23    assert segmentation.section_role("Concluding Remarks") == "conclusion"24    assert segmentation.section_role("Anything", is_appendix=True) == "appendix"25    assert segmentation.section_role("Model") == "theory"2627def test_payload_respects_rights_cap(synthetic_pdf, tmp_path, monkeypatch):28    from jof250 import parsing, config29    d = parsing.parse_pdf(synthetic_pdf, "syn_1", {"relpath": "synthetic.pdf"})30    # inflate the intro to exceed the cap and check trimming31    intro = next(s for s in d["sections"] if s.get("is_intro")); intro["paragraphs"] = [{"text": "word " * 4000, "page": 1}] * 3032    p = segmentation.annotation_payload(d); cap = config.load("rights")["external_api_excerpt_policy"]["max_excerpt_chars_per_call"]33    assert p["payload_chars"] <= cap * 1.0534
Files · main
Menu

Theme