Filter unsafe automatic terminology constraints before book translation

This commit is contained in:
Kai Tan
2026-10-08 09:05:04 +08:00
parent 3ca7e09b71
commit 2c3feb37c9
4 changed files with 78 additions and 2 deletions
+19
View File
@@ -97,6 +97,25 @@ def test_name_aliases_do_not_match_common_lowercase_words():
assert set(glossary.relevant([entry('<p>Jobs invested in ARM.</p>')])) == {'Jobs', 'ARM'}
def test_automatic_glossary_does_not_force_generic_senses_or_implicit_surnames():
from src.translation.glossary import sanitize_automatic_terms
terms, excluded = sanitize_automatic_terms([
{'source': 'Otosan', 'target': '爸爸', 'aliases': ['Father']},
{'source': 'face', 'target': '面子'},
{'source': 'carried interest', 'target': '绩效分成', 'aliases': ['carry']},
{'source': 'World Health Organization', 'target': '世界卫生组织', 'aliases': ['WHO']},
{'source': 'Sun Microsystems', 'target': '太阳微系统公司', 'aliases': ['Sun']},
{'source': 'Sun Yafang', 'target': '孙亚芳'}], set())
assert excluded
glossary = BookGlossary(terms)
assert not glossary.validate('Father had a smile on his face and could carry a bag.', '父亲面带微笑,可以提包。')
assert not glossary.validate('WHO AM I?', '我是谁?')
assert not glossary.validate('Sun Yafang visited. Sun gave a talk.', '孙亚芳到访并发表演讲。')
assert glossary.validate('carried interest', '费用')
assert glossary.validate('Otosan', '广告')
assert not BookGlossary([{'source': 'Fortune', 'target': '《财富》'}]).validate('Fortune', '据《财富》报道。')
@pytest.mark.parametrize('html', [
'<p>Hello <em><b>world</b></em>.</p>',
'<p>The angle φ = 10, and φ1φ is literal mathematical text.</p>',