Constrain automatic aliases and cache terminology matchers

This commit is contained in:
Kai Tan
2026-10-08 09:21:47 +08:00
parent 2c3feb37c9
commit 4f124a0335
4 changed files with 34 additions and 8 deletions
+12
View File
@@ -116,6 +116,18 @@ def test_automatic_glossary_does_not_force_generic_senses_or_implicit_surnames()
assert not BookGlossary([{'source': 'Fortune', 'target': '《财富》'}]).validate('Fortune', '据《财富》报道。')
def test_auto_aliases_require_evidence_but_explicit_nicknames_remain():
from src.translation.glossary import sanitize_automatic_terms
terms, _ = sanitize_automatic_terms([
{'source': 'Theresa May', 'target': '特蕾莎·梅', 'aliases': ['May']},
{'source': 'University of California, Berkeley', 'target': '加州大学伯克利分校', 'aliases': ['Berkeley', 'UC Berkeley']},
{'source': 'Masayoshi Son', 'target': '孙正义', 'aliases': ['Masa'], 'notes': 'Masa is his nickname.'}], set())
glossary = BookGlossary(terms)
assert not glossary.validate('In May he stayed at the Berkeley hotel.', '五月他住在伯克利酒店。')
assert glossary.validate('Masa studied at UC Berkeley.', '他去上学。')
assert glossary.validate('Theresa May visited.', '五月来访。')
@pytest.mark.parametrize('html', [
'<p>Hello <em><b>world</b></em>.</p>',
'<p>The angle φ = 10, and φ1φ is literal mathematical text.</p>',