Avoid matching named aliases against ordinary lowercase words

This commit is contained in:
Kai Tan
2026-10-08 08:55:13 +08:00
parent dd5a99dc23
commit 3ca7e09b71
4 changed files with 32 additions and 3 deletions
+19
View File
@@ -78,6 +78,25 @@ def test_shared_surname_is_removed_from_both_distinct_entities():
assert glossary.validate('Sun Microsystems supplied computers.', '孙先生提供了电脑。')
def test_acronyms_do_not_match_ordinary_pronouns():
glossary = BookGlossary([
{'source': 'World Health Organization', 'target': '世界卫生组织', 'aliases': ['WHO']},
{'source': 'United States', 'target': '美国', 'aliases': ['US']},
{'source': 'information technology', 'target': '信息技术', 'aliases': ['IT']}])
assert not glossary.validate('The people who helped us did it.', '帮助我们的人做了这件事。')
assert not glossary.relevant([entry('<p>Who helped us do it?</p>')])
assert glossary.validate('WHO met the US IT team.', '他们会见了团队。')
assert matches('WHO', 'The WHO report') and not matches('WHO', 'people who helped')
def test_name_aliases_do_not_match_common_lowercase_words():
glossary = BookGlossary([{'source': 'Steve Jobs', 'target': '乔布斯', 'aliases': ['Jobs']},
{'source': 'Arm Holdings', 'target': '安谋', 'aliases': ['Arm', 'ARM']}])
assert not glossary.validate('More jobs in its US arm.', '其美国分部增加就业。')
assert glossary.validate('Jobs bought Arm.', '他收购了这家公司。')
assert set(glossary.relevant([entry('<p>Jobs invested in ARM.</p>')])) == {'Jobs', 'ARM'}
@pytest.mark.parametrize('html', [
'<p>Hello <em><b>world</b></em>.</p>',
'<p>The angle φ = 10, and φ1φ is literal mathematical text.</p>',