dispatch
Output dispatch helpers for the CLTK CLI (pure; no I/O).
OUTPUT_TARGETS
module-attribute
OUTPUT_TARGETS: dict[
str, Callable[[Doc], OutputPayload]
] = {
"raw": lambda doc: _render_raw(doc),
"conllu": doc_to_conllu,
"feature-table": doc_to_feature_table,
"readers-guide": format_readers_guide,
"json": lambda doc: doc_to_json(doc),
}
OUTPUT_FORMATS
module-attribute
OUTPUT_FORMATS: dict[str, set[str]] = {
"feature-table": {"csv", "tsv", "parquet"},
"json": {"pretty", "min"},
}
DEFAULT_FORMATS
module-attribute
normalize_output_name
normalize_format
resolve_format
Validate and resolve the output format for an output target.
Source code in cltk/cli/dispatch.py
render_output
render_output(
doc: Doc,
out: str,
*,
max_sentences: Optional[int] = None,
max_tokens: Optional[int] = None
) -> OutputPayload
Render output for a document using the named output target.
Source code in cltk/cli/dispatch.py
doc_to_json
doc_to_json(
doc: Doc,
*,
max_sentences: Optional[int] = None,
max_tokens: Optional[int] = None
) -> dict[str, Any]
Return a JSON-serializable structure for a Doc.
Source code in cltk/cli/dispatch.py
ensure_text_payload
ensure_json_payload
Ensure a rendered payload is JSON-serializable dict.
raw_summary
raw_summary(
doc: Doc,
*,
max_sentences: Optional[int] = None,
max_tokens: Optional[int] = None
) -> str
Return a human-readable summary for Doc.