Datasets:
Tasks:
Text Classification
Formats:
parquet
Languages:
Ancient Greek (to 1453)
Size:
100K - 1M
ArXiv:
License:
Download scripts/text_units.py from Urdatorn/sphragis: direct link, hf CLI and curl.
- Browser
- Download file 1.16 kB
-
https://huggingface.co/datasets/Urdatorn/sphragis/resolve/main/scripts/text_units.py
- Command line
-
hf download hf://datasets/Urdatorn/sphragis/scripts/text_units.py
-
curl -L -o text_units.py https://huggingface.co/datasets/Urdatorn/sphragis/resolve/main/scripts/text_units.py
1.16 kB
| """Model-facing text units. | |
| ``text`` is a list of strings with one entry per sentence or metrical line, in | |
| the same order as ``conllu``. It used to be a JSON-encoded string; it is now a | |
| plain list, so nothing needs decoding before use. | |
| """ | |
| from __future__ import annotations | |
| from typing import Any | |
| def load_text_units(units: Any) -> list[str]: | |
| """Validate a published text column and return it unchanged.""" | |
| if not isinstance(units, list) or not units: | |
| raise ValueError("text must be a non-empty 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: Any) -> list[str]: | |
| """Accept either one internal string or an already-published list.""" | |
| if isinstance(value, str): | |
| if not value.strip(): | |
| raise ValueError("source text must be a non-empty string") | |
| return [value] | |
| return load_text_units(value) | |
| def encode_text_units(units: list[str]) -> list[str]: | |
| """Validate text units for publication without changing them.""" | |
| return load_text_units(units) | |