Spaces:
Running on Zero
Running on Zero
Download vendor/range_curate/customization.py from Brianferrell787/range: direct link, hf CLI and curl.
- Browser
- Download file 2.06 kB
-
https://huggingface.co/spaces/Brianferrell787/range/resolve/main/vendor/range_curate/customization.py
- Command line
-
hf download hf://spaces/Brianferrell787/range/vendor/range_curate/customization.py
-
curl -L -o customization.py https://huggingface.co/spaces/Brianferrell787/range/resolve/main/vendor/range_curate/customization.py
2.06 kB
| """Public taxonomy composition and deterministic ranking contracts.""" | |
| from __future__ import annotations | |
| from importlib.resources import files as resource_files | |
| from pathlib import Path | |
| from ._taxonomy_impl import ( | |
| DefaultRanker, | |
| DefaultTaxonomy, | |
| Ranker, | |
| Taxonomy, | |
| TaxonomyBuilder, | |
| ) | |
| # Keep repr(), documentation, and pickling pointed at the public module after | |
| # the pre-release namespace migration. | |
| for _public_type in ( | |
| DefaultRanker, | |
| DefaultTaxonomy, | |
| Ranker, | |
| Taxonomy, | |
| TaxonomyBuilder, | |
| ): | |
| _public_type.__module__ = __name__ | |
| class GeneralEconomyTaxonomy(DefaultTaxonomy): | |
| """The bundled, conservative taxonomy for economy and broad-market news.""" | |
| def copy_default_taxonomy( | |
| destination: str | Path, | |
| *, | |
| overwrite: bool = False, | |
| ) -> Path: | |
| """Copy the bundled general-economy taxonomy to an editable directory.""" | |
| root = Path(destination).expanduser().resolve() | |
| package = resource_files("range_curate._core") | |
| copies = ( | |
| (package.joinpath("configs", "default.yml"), root / "taxonomy.yml"), | |
| ( | |
| package.joinpath("catalogs", "entities.yml"), | |
| root / "catalogs" / "entities.yml", | |
| ), | |
| ( | |
| package.joinpath("catalogs", "lexical.yml"), | |
| root / "catalogs" / "lexical.yml", | |
| ), | |
| ) | |
| existing = [target for _source, target in copies if target.exists()] | |
| if existing and not overwrite: | |
| names = ", ".join(str(path) for path in existing) | |
| raise FileExistsError( | |
| f"taxonomy files already exist: {names}; pass overwrite=True to replace them" | |
| ) | |
| for source, target in copies: | |
| target.parent.mkdir(parents=True, exist_ok=True) | |
| target.write_bytes(source.read_bytes()) | |
| return root / "taxonomy.yml" | |
| __all__ = [ | |
| "DefaultRanker", | |
| "DefaultTaxonomy", | |
| "GeneralEconomyTaxonomy", | |
| "Ranker", | |
| "Taxonomy", | |
| "TaxonomyBuilder", | |
| "copy_default_taxonomy", | |
| ] | |