Datasets:
Tasks:
Text Classification
Formats:
parquet
Languages:
Ancient Greek (to 1453)
Size:
10K - 100K
License:
| """Canonical JSON representation for model-facing text units.""" | |
| from __future__ import annotations | |
| import json | |
| def load_text_units(encoded: str) -> list[str]: | |
| """Load a published text field and enforce a non-empty string list.""" | |
| units = json.loads(encoded) | |
| if not isinstance(units, list) or not units: | |
| raise ValueError("text must encode a non-empty JSON list") | |
| if not all(isinstance(unit, str) and unit.strip() for unit in units): | |
| raise ValueError("every text unit must be a non-empty string") | |
| return units | |
| def source_text_units(value: str) -> list[str]: | |
| """Accept either an internal atomic string or published JSON text units.""" | |
| try: | |
| return load_text_units(value) | |
| except (json.JSONDecodeError, TypeError, ValueError): | |
| if not isinstance(value, str) or not value.strip(): | |
| raise ValueError("source text must be a non-empty string") | |
| return [value] | |
| def encode_text_units(units: list[str]) -> str: | |
| """Serialize text units without losing their original strings.""" | |
| if not units or not all(isinstance(unit, str) and unit.strip() for unit in units): | |
| raise ValueError("text units must be non-empty strings") | |
| return json.dumps(units, ensure_ascii=False) | |