diff options
Diffstat (limited to 'core/taxonomy.py')
| -rw-r--r-- | core/taxonomy.py | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/core/taxonomy.py b/core/taxonomy.py index 8aee0aa..e72d486 100644 --- a/core/taxonomy.py +++ b/core/taxonomy.py @@ -22,3 +22,11 @@ def save_taxonomy(model: TaxonomyModel, it_path: Path, en_path: Path) -> None: pairs = sorted(model.it_to_en.items(), key=lambda x: x[0]) it_path.write_text("\n".join(k for k, _ in pairs) + "\n") en_path.write_text("\n".join(v for _, v in pairs) + "\n") + +def load_categories(path: Path) -> list[str]: + if not path.exists(): + return [] + return sorted(l.strip() for l in path.read_text().splitlines() if l.strip()) + +def save_categories(path: Path, categories: list[str]) -> None: + path.write_text("\n".join(sorted(categories)) + "\n") |
