graphcast.architecture.util
¶
Utility functions for graph architecture operations.
This module provides utility functions for working with graph data structures and transformations. It includes functions for dictionary projection and graph entity name formatting.
Key Functions
- project_dict: Project dictionary fields based on inclusion/exclusion
- cast_graph_name_to_triple: Convert graph names to standardized triple format
Example
data = {"a": 1, "b": 2, "c": 3} project_dict(data, ["a", "b"], how="include") {'a': 1, 'b': 2} cast_graph_name_to_triple("user_post_graph") ('user', 'post', None)
cast_graph_name_to_triple(s)
¶
Convert a graph name string to a triple format.
This function parses graph entity names into a standardized triple format (source, target, type). It handles various naming patterns and special suffixes like "graph" or "edges".
Parameters:
Name | Type | Description | Default |
---|---|---|---|
s
|
GraphEntity
|
Graph entity name or ID |
required |
Returns:
Type | Description |
---|---|
Union[str, tuple]
|
Union[str, tuple]: Either a string for simple names or a tuple representing (source, target, type) for complex names |
Raises:
Type | Description |
---|---|
ValueError
|
If the graph name cannot be cast to a valid format |
Example
cast_graph_name_to_triple("user_post_graph") ('user', 'post', None) cast_graph_name_to_triple("simple_vertex") ('simple', None)
Source code in graphcast/architecture/util.py
project_dict(item, keys, how='include')
¶
Project dictionary fields based on inclusion or exclusion.
This function filters a dictionary based on a list of keys, either including or excluding the specified keys.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
item
|
Dictionary to project |
required | |
keys
|
List of keys to include or exclude |
required | |
how
|
Projection mode - "include" or "exclude" (default: "include") |
'include'
|
Returns:
Name | Type | Description |
---|---|---|
dict |
Projected dictionary containing only the specified fields |
Example
data = {"a": 1, "b": 2, "c": 3} project_dict(data, ["a", "b"], how="include") {'a': 1, 'b': 2} project_dict(data, ["a"], how="exclude")