Spaces:
Running on Zero
Running on Zero
Download examples/custom_taxonomy.py from Brianferrell787/range: direct link, hf CLI and curl.
- Browser
- Download file 1.4 kB
-
https://huggingface.co/spaces/Brianferrell787/range/resolve/main/examples/custom_taxonomy.py
- Command line
-
hf download hf://spaces/Brianferrell787/range/examples/custom_taxonomy.py
-
curl -L -o custom_taxonomy.py https://huggingface.co/spaces/Brianferrell787/range/resolve/main/examples/custom_taxonomy.py
1.4 kB
| """Extend the bundled general-economy taxonomy without modifying it in place.""" | |
| from __future__ import annotations | |
| import json | |
| from range_curate.examples.general_economy import DefaultTaxonomy, RelevanceEngine | |
| def add_regional_indicator(builder) -> None: | |
| builder.add_lexical_rule( | |
| rule_id="regional-manufacturing-survey", | |
| entity_concept="macroeconomic_indicator", | |
| tag_type="macroeconomic", | |
| phrases=("regional manufacturing survey",), | |
| target_id="MACRO:REGIONAL_MANUFACTURING", | |
| market_wide_authorized=True, | |
| source_id="custom-example", | |
| ) | |
| def main() -> None: | |
| base = DefaultTaxonomy() | |
| custom = base.extend(add_regional_indicator) | |
| assert base.fingerprint != custom.fingerprint | |
| assert "regional-manufacturing-survey" not in base.lexical_rule_ids | |
| assert "regional-manufacturing-survey" in custom.lexical_rule_ids | |
| decision = RelevanceEngine(taxonomy=custom, workers=1).predict( | |
| "The regional manufacturing survey weakened sharply.", | |
| timestamp="2025-01-15T08:30:00-05:00", | |
| article_id="custom-economy-1", | |
| source="custom-example", | |
| ) | |
| print(json.dumps(decision.summary(), indent=2)) | |
| print(f"\nBase taxonomy: {base.fingerprint}") | |
| print(f"Custom taxonomy: {custom.fingerprint}") | |
| if __name__ == "__main__": | |
| main() | |