Canonicalise an operator brand from a system id / name ("smovengo" → "Vélib'
Métropole").
Pattern-matches against OPERATOR_PATTERNS (case-insensitive). On no match returns
default if given, else the original value unchanged (non-lossy); safe to apply across a
whole catalogue so only recognised brands get collapsed.
See Also
systems_catalog : The catalogue whose operator names this cleans.
Source code in src/gbfs_toolkit/io/catalog.py
| def normalize_operator(value: str | None, *, default: str | None = None) -> str | None:
"""Canonicalise an operator brand from a system id / name (``"smovengo"`` → ``"Vélib'
Métropole"``).
Pattern-matches against `OPERATOR_PATTERNS` (case-insensitive). On no match returns
``default`` if given, else the original value unchanged (non-lossy); safe to apply across a
whole catalogue so only recognised brands get collapsed.
See Also
--------
[`systems_catalog`][gbfs_toolkit.systems_catalog] : The catalogue whose operator names this cleans.
"""
if value is None:
return default
s = str(value).lower()
for pattern, brand in OPERATOR_PATTERNS:
if re.search(pattern, s):
return brand
return default if default is not None else str(value)
|