Disambiguate shared glossary aliases without discarding full entity names

This commit is contained in:
Kai Tan
2026-10-08 08:42:17 +08:00
parent 0e4aec82d8
commit dd5a99dc23
4 changed files with 60 additions and 22 deletions
+14
View File
@@ -64,6 +64,20 @@ def test_zenmux_credentials_override_unrelated_openai_key(tmp_path, monkeypatch)
assert load_global_config(config)['llm']['api_key'] == 'test-zenmux-key'
def test_shared_surname_is_removed_from_both_distinct_entities():
from src.translation.glossary import merge_proposal
terms = [{'source': 'Sun Microsystems', 'target': '太阳微系统公司', 'aliases': ['Sun']}]
conflicts, ambiguous = [], set()
terms = merge_proposal(terms, {'source': 'David Sun', 'target': '孙大卫', 'aliases': ['Sun']}, conflicts, ambiguous)
assert len(terms) == 2 and ambiguous == {'sun'}
assert all(not t['aliases'] for t in terms)
terms = merge_proposal(terms, {'source': 'Sun Microsystems', 'target': '太阳微系统公司', 'aliases': ['Sun']}, conflicts, ambiguous)
glossary = BookGlossary(terms)
assert not glossary.validate('David Sun founded Kingston.', '孙大卫创办了金士顿。')
assert not glossary.validate('Sun made an investment.', '孙先生作了投资。')
assert glossary.validate('Sun Microsystems supplied computers.', '孙先生提供了电脑。')
@pytest.mark.parametrize('html', [
'<p>Hello <em><b>world</b></em>.</p>',
'<p>The angle φ = 10, and φ1φ is literal mathematical text.</p>',