INNER CODE UNIT · Python

common_word

OpenChemistry/avogadrolibs · scripts/copy-default.py:201

def common_word(match):
    word = match.group(0)
    replacement = COMMON_SPELLING.get(word.lower())
    if replacement is None:
        return word
    return match_case(word, replacement)


def swap_z(match):
    """Replace only the z with s (keeping case); the rest is kept as written."""
    stem, z, suffix = match.group(1), match.group(2), match.group(3)
    keep = match.group(0)[:len(stem) + 1]
    return keep + ('S' if z == 'Z' else 's') + suffix


def respell_text(text, locale):
    """Respell a run of plain text (no markup) for the locale."""
    text = WORD_RE.sub(common_word, text)

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…