kapps_ogm.node.node_data_formatter#
Data formatting and sanitization utilities for Node instances.
- kapps_ogm.node.node_data_formatter.sanitize_data(data: Dict, node: Node, known_nodes: Dict[int, 'Node'] | None = None) tuple[dict[IRI, List[Any]], IRI | BNode | None][source]#
Recursively converts provided data dict into a unified format.
The output is a dict with items in any of the forms:
IRI: List[Any] # literal property -> list of literal values
IRI: List[Node] # class property -> list of Node instances with IRI ids
IRI: List[Node] # complex property -> list of Node instances with blank ids
In the input, property keys can be either str or IRI. Class and complex property values may be represented as dicts.
- Parameters:
data – Raw data dictionary to sanitize.
ogm – OGM instance for creating nested Node instances.
- Returns:
- Sanitized data with IRI keys and
list values, and the node ID if the data carried one.
- Return type:
- Raises:
ValueError – If data cannot be converted into the expected format.
- kapps_ogm.node.node_data_formatter.format_for_instance(node: Node) Dict[str, List[Any]][source]#
Recursively resolve property data to a model.
Converts Nodes to their data, property IRIs to their lined representation.
- Parameters:
node – The Node instance to format data for.
- Returns:
Formatted data ready for Pydantic validation.
- Return type:
Dict[str, List[Any]]
Notes
Assigns a new ID to the node if it doesn’t have one.
Recursively formats nested Node instances.