Files
arzani 577b9f4557
LocationBasedServices/smartguide/pipeline/head This commit looks good
initial version of multipliers in three levels: bridgers, mentors & amplifiers
2026-07-16 01:52:54 +02:00

36 lines
1.5 KiB
Python

"""Tests for the pure parts of the signal joins: name/DOI normalization and
the ambiguity rule for news matching."""
from __future__ import annotations
from signals import normalize_doi, normalize_name
def test_normalize_name_diacritics_case_whitespace():
assert normalize_name("René Müller") == "rene muller"
assert normalize_name("CHRISTOPH GILLE") == "christoph gille" # news is often ALL-CAPS
assert normalize_name(" Anna-Lena Giesecke ") == "anna-lena giesecke"
assert normalize_name("Barbara Saccà") == normalize_name("Barbara Sacca")
assert normalize_name("Bülent Eken") == "bulent eken"
def test_normalize_doi_prefixes_and_case():
assert normalize_doi("https://doi.org/10.1371/journal.pone.0018216") == \
"10.1371/journal.pone.0018216"
assert normalize_doi("DOI:10.1016/J.CELL.2020.01.001") == "10.1016/j.cell.2020.01.001"
assert normalize_doi("doi.org/10.1/x") == "10.1/x"
assert normalize_doi("10.1/x") == "10.1/x"
assert normalize_doi("") is None
assert normalize_doi(None) is None
def test_ambiguous_name_rule():
"""Two cohort authors normalizing to the same name -> both excluded from news."""
from collections import defaultdict
names = {"A1": "Wei Zhang", "A2": "Wei ZHANG", "A3": "Unique Person"}
by_norm = defaultdict(list)
for aid, n in names.items():
by_norm[normalize_name(n)].append(aid)
ambiguous = {k for k, v in by_norm.items() if len(v) > 1}
assert normalize_name("Wei Zhang") in ambiguous
assert normalize_name("Unique Person") not in ambiguous