| """Five-language STRATA core contract. |
| |
| The project deliberately keeps the primary multilingual build to five languages |
| so graph supervision, tokenizer pressure, and tool-surface coverage stay |
| balanced enough to interpret. Additions beyond this set should be treated as |
| diagnostic or tier-2 experiments, not silent changes to the core training mix. |
| """ |
|
|
| from __future__ import annotations |
|
|
| from dataclasses import dataclass |
|
|
|
|
| @dataclass(frozen=True, slots=True) |
| class LanguageSpec: |
| code: str |
| name: str |
| primary_variety: str |
| graph_source: tuple[str, str] |
|
|
|
|
| CORE_LANGUAGES: tuple[LanguageSpec, ...] = ( |
| LanguageSpec("en", "English", "English", ("up", "UP_English-EWT")), |
| LanguageSpec("zh", "Mandarin Chinese", "Simplified Chinese primary", ("up", "UP_Chinese")), |
| LanguageSpec("de", "German", "German", ("up", "UP_German")), |
| LanguageSpec("es", "Spanish", "Spanish", ("up", "UP_Spanish")), |
| LanguageSpec("ar", "Arabic", "MSA primary; dialectal optional", ("ud", "UD_Arabic-PADT")), |
| ) |
|
|
| CORE_LANGUAGE_CODES: tuple[str, ...] = tuple(spec.code for spec in CORE_LANGUAGES) |
| CORE_LANGUAGE_NAMES: dict[str, str] = {spec.code: spec.name for spec in CORE_LANGUAGES} |
| CORE_GRAPH_SOURCES: dict[str, tuple[str, str]] = { |
| spec.code: spec.graph_source for spec in CORE_LANGUAGES |
| } |
|
|
|
|
| def normalize_language_codes(value: str | list[str] | tuple[str, ...]) -> tuple[str, ...]: |
| """Return normalized language codes from a comma-separated string or list.""" |
|
|
| if isinstance(value, str): |
| codes = tuple(part.strip() for part in value.split(",") if part.strip()) |
| else: |
| codes = tuple(str(part).strip() for part in value if str(part).strip()) |
| return codes |
|
|
|
|
| def require_core_languages(codes: str | list[str] | tuple[str, ...]) -> None: |
| """Raise if ``codes`` is not exactly the STRATA five-language core.""" |
|
|
| got = normalize_language_codes(codes) |
| if got != CORE_LANGUAGE_CODES: |
| raise ValueError( |
| f"expected STRATA core languages {','.join(CORE_LANGUAGE_CODES)}, " |
| f"got {','.join(got) or '<empty>'}" |
| ) |
|
|
|
|
| __all__ = [ |
| "CORE_GRAPH_SOURCES", |
| "CORE_LANGUAGES", |
| "CORE_LANGUAGE_CODES", |
| "CORE_LANGUAGE_NAMES", |
| "LanguageSpec", |
| "normalize_language_codes", |
| "require_core_languages", |
| ] |
|
|