"""专名对照:定位原文、建议称谓,作者例外只对该版本该位置有效。""" import pytest from muse.交付连载.文字校对 import 文字疑点 from muse.交付连载.模型 import 交付错误 def 章(chapter_id, text, revision=1, document_hash="a" * 64): return { "chapter_id": chapter_id, "revision": revision, "document_hash": document_hash, "text": text, } @pytest.mark.case_id( "NC-r2-c0ed01", environment="离线单元", given="同一专名在正文出现两处且登记对照称谓", when="生成文字疑点", then=["两处分别定位并给出建议称谓"], contract="docs/系统架构/新版设计/模块设计/B08-交付连载.md", ) def test_专名对照逐处定位并给出建议称谓__c0ed01(): text = "青禾推门。门外青禾还站着。" findings = 文字疑点([章("c1", text)], names={"青禾": "青禾儿"}) names = [f for f in findings if f["kind"] == "专名对照"] assert [f["quote"] for f in names] == ["青禾", "青禾"] assert [f["suggestion"] for f in names] == ["青禾儿", "青禾儿"] assert [f["start"] for f in names] == [0, text.index("青禾", 1)] assert {f["disposition"] for f in names} == {"review"} assert names[0]["id"] != names[1]["id"] @pytest.mark.case_id( "NC-r2-c0ed02", environment="离线单元", given="空专名或对照称谓与原文相同", when="生成文字疑点", then=["拒绝非法专名对照"], contract="docs/系统架构/新版设计/模块设计/B08-交付连载.md", ) def test_空或相同专名对照拒绝__c0ed02(): chapter = 章("c1", "青禾在场。") for names in ({"": "青禾儿"}, {"青禾": ""}, {"青禾": "青禾"}): with pytest.raises(交付错误, match="专名对照") as err: 文字疑点([chapter], names=names) assert err.value.错误码 == "COPYEDIT_INVALID" @pytest.mark.case_id( "NC-r2-c0ed03", environment="离线单元", given="作者对某一处专名命中声明例外", when="再次生成文字疑点", then=["例外只对该版本该位置生效"], contract="docs/系统架构/新版设计/模块设计/B08-交付连载.md", ) def test_作者例外只对该版本该位置有效__c0ed03(): first = 章("c1", "青禾推门。", revision=1, document_hash="a" * 64) second = 章("c2", "青禾推门。", revision=1, document_hash="b" * 64) all_findings = 文字疑点([first, second], names={"青禾": "青禾儿"}) names = [f for f in all_findings if f["kind"] == "专名对照"] assert len(names) == 2 kept = names[0]["id"] again = 文字疑点([first, second], names={"青禾": "青禾儿"}, exceptions=(kept,)) by_id = {f["id"]: f for f in again if f["kind"] == "专名对照"} assert by_id[kept]["disposition"] == "preserved" other = names[1]["id"] assert by_id[other]["disposition"] == "review" newer = 章("c1", "青禾推门。", revision=2, document_hash="a" * 64) moved = 文字疑点([newer], names={"青禾": "青禾儿"}, exceptions=(kept,)) assert moved[0]["kind"] == "专名对照" assert moved[0]["id"] != kept assert moved[0]["disposition"] == "review"