ConceptGraph¶
ConceptGraph
¶
Tree of business concepts with feature leaves.
Internally backed by a networkx.DiGraph where edges point from parent to
child. Every node carries the attributes kind and metadata.
Invariants enforced at construction:
- Exactly one root (a concept node with no parent).
- Every leaf is a
featurenode; every internal node is aconcept. - Every feature node is a leaf.
- Node names are unique across the graph.
Source code in src/concept_graph_xai/graph.py
nodes_in_order
¶
from_dict
classmethod
¶
from_dict(data: Mapping[str, Any] | Mapping[str, list[str] | Mapping[str, Any]], *, root: str | None = None) -> ConceptGraph
Build a ConceptGraph from a nested-dict representation.
data is a mapping with exactly one top-level key (the root concept)
whose value describes the tree:
- a list of strings: a concept whose children are all features;
- a mapping
name -> subtree: a concept whose children are concepts (recursive) or, when the leaf value is a list, features.
Source code in src/concept_graph_xai/graph.py
from_networkx
classmethod
¶
from_networkx(graph: DiGraph, root: str) -> ConceptGraph
Wrap an existing NetworkX DiGraph (must already have kind attrs).
NodeView¶
NodeView
dataclass
¶
NodeView(name: str, kind: NodeKind, parent: str | None, path: tuple[str, ...], metadata: Mapping[str, Any])
Read-only view of a single node in the graph.