graflo.architecture.schema.context.graph¶
Adjacency index over a schema's vertex types.
EdgeConfig is keyed only by :data:~graflo.architecture.graph_types.EdgeId,
so "which edges touch this vertex type" has no answer without a scan. This module
builds that index once and exposes the schema graph as a navigable object.
Naming discipline. "Neighbours" here means adjacent vertex types in the
schema, never adjacent instances in a data graph. The instance-plane counterpart
is Connection.graph_neighbors; the two must never share a name or an endpoint.
SchemaGraph
¶
Read-only adjacency index over a :class:Schema's vertex types.
Built once per schema and never mutates it. Plain dicts throughout — no networkx, because this is layer 2 and the whole point is to stay free of heavyweight dependencies.
Source code in graflo/architecture/schema/context/graph.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 | |
edge_ids
property
¶
Every declared edge id, in deterministic order.
schema
property
¶
The indexed schema. Treat as read-only.
vertex_types
property
¶
Every declared vertex type name.
degree(vertex_type)
¶
Total incident edge count (out + in), counting self-loops twice.
edge(edge_id)
¶
from_schema(schema)
classmethod
¶
in_edges(vertex_type)
¶
isolated_types()
¶
out_edges(vertex_type)
¶
relation_vocabulary()
¶
Distinct non-null relation names across all edges.
relations_between(a, b, *, max_len=3, max_paths=20, direction=EdgeDirection.ANY)
¶
Simple paths from vertex type a to b, shortest first.
Bounded breadth-first enumeration: no vertex repeats within a path, so
cycles terminate. Results are ordered by (length, edge ids) and are
therefore reproducible run to run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
str
|
Source vertex type. |
required |
b
|
str
|
Target vertex type. |
required |
max_len
|
int
|
Maximum hops per path. |
3
|
max_paths
|
int
|
Maximum number of paths returned. |
20
|
direction
|
EdgeDirection
|
Orientation followed from each frontier vertex. |
ANY
|
Returns:
| Type | Description |
|---|---|
list[SchemaPath]
|
list[SchemaPath]: paths found, possibly empty. |
Raises:
| Type | Description |
|---|---|
KeyError
|
if either endpoint is not declared in the schema. |
Source code in graflo/architecture/schema/context/graph.py
schema_neighbors(vertex_type, *, hops=1, direction=EdgeDirection.ANY, edge_relations=None)
¶
Vertex types adjacent to vertex_type within hops.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vertex_type
|
str
|
Seed vertex type. Must be declared. |
required |
hops
|
int
|
Maximum hop distance. |
1
|
direction
|
EdgeDirection
|
Orientation followed from each frontier vertex. Defaults to
:attr: |
ANY
|
edge_relations
|
set[str | None] | None
|
Restrict traversal to these relation names ( |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
SchemaNeighborhood |
SchemaNeighborhood
|
distances per reachable type and the edges used. |
Raises:
| Type | Description |
|---|---|
KeyError
|
if vertex_type is not declared in the schema. |
Source code in graflo/architecture/schema/context/graph.py
SchemaNeighborhood
¶
Bases: ConfigBaseModel
Vertex types reachable from a seed within a hop bound.
Source code in graflo/architecture/schema/context/graph.py
vertex_types
property
¶
Reachable vertex types, nearest first then alphabetical.
SchemaPath
¶
Bases: ConfigBaseModel
One path between two vertex types, as an alternating vertex/edge walk.
Source code in graflo/architecture/schema/context/graph.py
length
property
¶
Number of hops (edges) in this path.
edge_sort_key(edge_id)
¶
Total order over edge ids.
relation is str | None, so plain tuple comparison raises TypeError
as soon as a relation-less edge meets a named one. Every ordering in this
package goes through here so results stay deterministic and comparable.