paza-bench / src /language_metadata.py
muchai-mercy's picture
update pazabench space
53a73e0
from typing import List
from src.constants import COUNTRY_TO_REGION_MAP, LANGUAGE_TO_COUNTRIES_MAP
def get_language_countries(language: str) -> List[str]:
"""Get the list of countries where a language is spoken."""
return LANGUAGE_TO_COUNTRIES_MAP.get(language, ["Unknown"])
def get_language_regions(language: str) -> List[str]:
"""Get the list of African regions where a language is spoken."""
countries = get_language_countries(language)
regions = set()
for country in countries:
region = COUNTRY_TO_REGION_MAP.get(country)
if region:
regions.add(region)
return list(regions) if regions else ["Unknown"]
def get_all_regions() -> List[str]:
"""Get all unique African regions."""
regions = set(COUNTRY_TO_REGION_MAP.values())
return sorted(regions)
def get_languages_by_region(region: str) -> List[str]:
"""Get all languages spoken in a specific African region."""
countries_in_region = [c for c, r in COUNTRY_TO_REGION_MAP.items() if r == region]
languages = set()
for lang, countries in LANGUAGE_TO_COUNTRIES_MAP.items():
if any(c in countries_in_region for c in countries):
languages.add(lang)
return list(languages)