graphcast.architecture.onto
¶
Core ontology and data structures for graph database operations.
This module defines the fundamental data structures and types used throughout the graphcast package for working with graph databases. It provides:
- Core data types for vertices and edges
- Database index configurations
- Graph container implementations
- Edge mapping and casting utilities
- Action context for graph transformations
The module is designed to be database-agnostic, supporting both ArangoDB and Neo4j through the DBFlavor enum. It provides a unified interface for working with graph data structures while allowing for database-specific optimizations and features.
Key Components
- EdgeMapping: Defines how edges are mapped between vertices
- IndexType: Supported database index types
- EdgeType: Types of edge handling in the graph database
- GraphContainer: Main container for graph data
- ActionContext: Context for graph transformation operations
Example
container = GraphContainer(vertices={}, edges={}, linear=[]) index = Index(fields=["name", "age"], type=IndexType.PERSISTENT) context = ActionContext()
ABCFields
dataclass
¶
Bases: BaseDataclass
Abstract base class for entities that have fields.
Attributes:
Name | Type | Description |
---|---|---|
name |
Optional[str]
|
Optional name of the entity |
fields |
list[str]
|
List of field names |
Source code in graphcast/architecture/onto.py
cfield(x)
¶
Creates a composite field name by combining the entity name with a field name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
str
|
Field name to combine with entity name |
required |
Returns:
Type | Description |
---|---|
str
|
Composite field name in format "entity@field" |
Source code in graphcast/architecture/onto.py
ActionContext
dataclass
¶
Bases: BaseDataclass
Context for graph transformation actions.
Attributes:
Name | Type | Description |
---|---|---|
acc_v_local |
defaultdict[str, defaultdict[Optional[str], list]]
|
Local accumulation of vertices |
acc_vertex |
defaultdict[str, defaultdict[Optional[str], list]]
|
Global accumulation of vertices |
acc_global |
defaultdict[GraphEntity, list]
|
Global accumulation of graph entities |
buffer_vertex |
defaultdict[GraphEntity, dict]
|
Buffer for vertex data |
cdoc |
dict
|
Current document being processed |
Source code in graphcast/architecture/onto.py
EdgeCastingType
¶
Bases: BaseEnum
Types of edge casting supported.
PAIR_LIKE: Edges are cast as pairs of vertices PRODUCT_LIKE: Edges are cast as products of vertex sets
Source code in graphcast/architecture/onto.py
EdgeMapping
¶
Bases: BaseEnum
Defines how edges are mapped between vertices.
ALL: Maps all vertices to all vertices ONE_N: Maps one vertex to many vertices
Source code in graphcast/architecture/onto.py
EdgeType
¶
Bases: BaseEnum
Defines how edges are handled in the graph database.
INDIRECT: Defined as a collection with indexes, may be used after data ingestion DIRECT: In addition to indexes, these edges are generated during ingestion
Source code in graphcast/architecture/onto.py
EncodingType
¶
GraphContainer
dataclass
¶
Bases: BaseDataclass
Container for graph data including vertices and edges.
Attributes:
Name | Type | Description |
---|---|---|
vertices |
dict[str, list]
|
Dictionary mapping vertex names to lists of vertex data |
edges |
dict[tuple[str, str, str | None], list]
|
Dictionary mapping edge IDs to lists of edge data |
linear |
list[defaultdict[str | tuple[str, str, str | None], list[Any]]]
|
List of default dictionaries containing linear data |
Source code in graphcast/architecture/onto.py
from_docs_list(list_default_dicts)
classmethod
¶
Create a GraphContainer from a list of default dictionaries.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
list_default_dicts
|
list[defaultdict[GraphEntity, list]]
|
List of default dictionaries containing vertex and edge data |
required |
Returns:
Type | Description |
---|---|
GraphContainer
|
New GraphContainer instance |
Raises:
Type | Description |
---|---|
AssertionError
|
If edge IDs are not properly formatted |
Source code in graphcast/architecture/onto.py
items()
¶
loop_over_relations(edge_def)
¶
Iterate over edges matching the given edge definition.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
edge_def
|
tuple[str, str, str | None]
|
Tuple of (source, target, optional_purpose) |
required |
Returns:
Type | Description |
---|---|
Generator yielding matching edge IDs |
Source code in graphcast/architecture/onto.py
pick_unique()
¶
Remove duplicate entries from vertices and edges.
Index
dataclass
¶
Bases: BaseDataclass
Configuration for database indexes.
Attributes:
Name | Type | Description |
---|---|---|
name |
str | None
|
Optional name of the index |
fields |
list[str]
|
List of fields to index |
unique |
bool
|
Whether the index enforces uniqueness |
type |
IndexType
|
Type of index to create |
deduplicate |
bool
|
Whether to deduplicate index entries |
sparse |
bool
|
Whether to create a sparse index |
exclude_edge_endpoints |
bool
|
Whether to exclude edge endpoints from index |
Source code in graphcast/architecture/onto.py
__iter__()
¶
db_form(db_type)
¶
Convert index configuration to database-specific format.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
db_type
|
DBFlavor
|
Type of database (ARANGO or NEO4J) |
required |
Returns:
Type | Description |
---|---|
dict
|
Dictionary of index configuration in database-specific format |
Raises:
Type | Description |
---|---|
ValueError
|
If db_type is not supported |
Source code in graphcast/architecture/onto.py
IndexType
¶
Bases: BaseEnum
Types of database indexes supported.
PERSISTENT: Standard persistent index HASH: Hash-based index for fast lookups SKIPLIST: Sorted index using skip list data structure FULLTEXT: Index optimized for text search
Source code in graphcast/architecture/onto.py
ItemsView
¶
View class for iterating over vertices and edges in a GraphContainer.
Source code in graphcast/architecture/onto.py
__iter__()
¶
Iterate over vertices and edges in the container.
Weight
dataclass
¶
Bases: ABCFields
Defines weight configuration for edges.
Attributes:
Name | Type | Description |
---|---|---|
discriminant |
Optional[str]
|
Optional field used to discriminate between weights |
map |
dict
|
Dictionary mapping field values to weights |
filter |
dict
|
Dictionary of filter conditions for weights |