nemo_curator.stages.text.experimental.translation.utils.field_paths

View as Markdown

Helpers for wildcard dot-path reads and writes.

Module Contents

Functions

NameDescription
_append_if_stringAppend value when it is a string.
_find_nestedRecursive worker for wildcard dot-path extraction.
_next_valueReturn the next replacement value, or None when exhausted.
_set_dict_valueSet a terminal dict value when the current value is a string.
_set_list_valuesSet matching list items for wildcard traversal.
_set_nestedRecursive worker for wildcard dot-path writes.
extract_nested_fieldsExtract string values matching a wildcard dot-path.
is_wildcard_pathReturn whether the path contains *.
normalize_text_fieldNormalize text_field to a list of field paths.
parse_structured_valueReturn parsed dict/list data when the value looks like JSON.
set_nested_fieldsWrite values back to a wildcard dot-path in traversal order.

API

nemo_curator.stages.text.experimental.translation.utils.field_paths._append_if_string(
value: object,
collected: list[str]
) -> None

Append value when it is a string.

nemo_curator.stages.text.experimental.translation.utils.field_paths._find_nested(
obj: object,
remaining: list[str],
collected: list[str]
) -> None

Recursive worker for wildcard dot-path extraction.

nemo_curator.stages.text.experimental.translation.utils.field_paths._next_value(
values: list[str],
value_index: list[int]
) -> str | None

Return the next replacement value, or None when exhausted.

nemo_curator.stages.text.experimental.translation.utils.field_paths._set_dict_value(
container: dict[str, object],
key: str,
values: list[str],
value_index: list[int]
) -> None

Set a terminal dict value when the current value is a string.

nemo_curator.stages.text.experimental.translation.utils.field_paths._set_list_values(
items: list[object],
remaining: list[str],
values: list[str],
value_index: list[int]
) -> None

Set matching list items for wildcard traversal.

nemo_curator.stages.text.experimental.translation.utils.field_paths._set_nested(
obj: object,
remaining: list[str],
values: list[str],
value_index: list[int]
) -> None

Recursive worker for wildcard dot-path writes.

nemo_curator.stages.text.experimental.translation.utils.field_paths.extract_nested_fields(
record: dict[str, object],
path: str
) -> list[str]

Extract string values matching a wildcard dot-path.

nemo_curator.stages.text.experimental.translation.utils.field_paths.is_wildcard_path(
path: str
) -> bool

Return whether the path contains *.

nemo_curator.stages.text.experimental.translation.utils.field_paths.normalize_text_field(
text_field: str | list[str]
) -> list[str]

Normalize text_field to a list of field paths.

nemo_curator.stages.text.experimental.translation.utils.field_paths.parse_structured_value(
value: object
) -> object | None

Return parsed dict/list data when the value looks like JSON.

nemo_curator.stages.text.experimental.translation.utils.field_paths.set_nested_fields(
record: dict[str, object],
path: str,
values: list[str]
) -> dict[str, object]

Write values back to a wildcard dot-path in traversal order.