Adjusted the protected-glossary capitalization logic so capitalization checks only apply when the same protected glossary identity was already present in the original text.
This commit is contained in:
@@ -106,8 +106,6 @@ class ProtectedVocabulary:
|
||||
if after_item.text == after_item.canonical:
|
||||
continue
|
||||
return "correction changes protected glossary term capitalization"
|
||||
if after_item.text != after_item.canonical:
|
||||
return "correction changes protected glossary term capitalization"
|
||||
return None
|
||||
|
||||
|
||||
|
||||
@@ -74,11 +74,11 @@ def test_protected_vocabulary_blocks_noncanonical_capitalization():
|
||||
== "correction changes protected glossary term capitalization"
|
||||
)
|
||||
assert (
|
||||
vocabulary.violation_reason("gestures", "jesters")
|
||||
vocabulary.violation_reason("Jesters", "jesters")
|
||||
== "correction changes protected glossary term capitalization"
|
||||
)
|
||||
assert (
|
||||
vocabulary.glossary_stage_violation_reason("Hrank moves.", "POPOV moves.")
|
||||
vocabulary.glossary_stage_violation_reason("Popov moves.", "POPOV moves.")
|
||||
== "correction changes protected glossary term capitalization"
|
||||
)
|
||||
|
||||
@@ -88,7 +88,9 @@ def test_protected_vocabulary_allows_corrections_toward_protected_terms():
|
||||
|
||||
assert vocabulary.violation_reason("Pawpaw moves.", "Popov moves.") is None
|
||||
assert vocabulary.violation_reason("gestures", "Jesters") is None
|
||||
assert vocabulary.violation_reason("gestures", "jesters") is None
|
||||
assert vocabulary.violation_reason("rank", "Hrank") is None
|
||||
assert vocabulary.violation_reason("rank", "hrank") is None
|
||||
assert vocabulary.violation_reason("spend", "Svend") is None
|
||||
|
||||
|
||||
@@ -179,6 +181,51 @@ def test_protected_glossary_terms_validator_returns_proposal_indexed_decisions()
|
||||
assert result.decisions[1].approved is True
|
||||
|
||||
|
||||
def test_protected_glossary_terms_validator_allows_nonglossary_to_lowercase_glossary_replacement():
|
||||
validator = ProtectedGlossaryTermsValidator("protected_glossary_guard")
|
||||
transcript = parse_transcript_json(
|
||||
"""
|
||||
[
|
||||
{"id": 1, "speaker": "Eric", "start": 0.0, "end": 1.0, "text": "gestures advance."},
|
||||
{"id": 2, "speaker": "Eric", "start": 1.0, "end": 2.0, "text": "rank moves."}
|
||||
]
|
||||
"""
|
||||
)
|
||||
proposals = [
|
||||
CorrectionProposal(
|
||||
proposal_index=0,
|
||||
module_instance="homophones",
|
||||
module_key="homophones",
|
||||
id=1,
|
||||
original_text="gestures",
|
||||
corrected_text="jesters",
|
||||
confidence=0.9,
|
||||
),
|
||||
CorrectionProposal(
|
||||
proposal_index=1,
|
||||
module_instance="homophones",
|
||||
module_key="homophones",
|
||||
id=2,
|
||||
original_text="rank",
|
||||
corrected_text="hrank",
|
||||
confidence=0.9,
|
||||
),
|
||||
]
|
||||
|
||||
result = validator.validate(
|
||||
ValidationContext(
|
||||
proposals=proposals,
|
||||
transcript=transcript,
|
||||
glossary=_glossary(),
|
||||
config=None, # type: ignore[arg-type]
|
||||
run_spec=ModuleRunSpec(instance_name="homophones", module_key="homophones", module=None), # type: ignore[arg-type]
|
||||
run_dir=__import__("pathlib").Path("."),
|
||||
)
|
||||
)
|
||||
|
||||
assert [decision.approved for decision in result.decisions] == [True, True]
|
||||
|
||||
|
||||
def test_glossary_stage_protected_glossary_terms_validator_allows_glossary_to_glossary_replacement():
|
||||
validator = GlossaryStageProtectedGlossaryTermsValidator("glossary_stage_protected_glossary_guard")
|
||||
transcript = parse_transcript_json(
|
||||
@@ -223,8 +270,8 @@ def test_glossary_stage_protected_glossary_terms_validator_allows_glossary_to_gl
|
||||
|
||||
assert [decision.proposal_index for decision in result.decisions] == [0, 1]
|
||||
assert result.decisions[0].approved is True
|
||||
assert result.decisions[1].approved is False
|
||||
assert result.decisions[1].reason == "correction changes protected glossary term capitalization"
|
||||
assert result.decisions[1].approved is True
|
||||
assert result.decisions[1].reason is None
|
||||
|
||||
|
||||
def test_protected_glossary_terms_validator_uses_proposal_span_only():
|
||||
|
||||
Reference in New Issue
Block a user