Help us shape the future of Go! Take the 2026 Go Developer Survey

graph

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 16, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GodNodes

func GodNodes(g *Graph, topN int) []types.Node

GodNodes returns the topN nodes sorted by total degree (in + out). These are the most-connected concepts in the graph — architectural hubs.

func RunLeiden

func RunLeiden(g *Graph) (map[string]int, error)

RunLeiden runs Leiden community detection on the graph by delegating to the bundled Python script (scripts/leiden.py). Returns a map of node ID → community ID (0-indexed integers).

If Python or the script is unavailable, a clear error is returned (no panic). The script itself falls back to connected-components if graspologic is missing.

func SuggestedQuestions

func SuggestedQuestions(nodes []types.Node, edges []types.Edge) []string

SuggestedQuestions returns 4–5 question templates populated with the names of the top god nodes. These are questions the graph is uniquely positioned to answer through path-finding and community analysis.

func SurpriseEdges

func SurpriseEdges(g *Graph, topN int) []types.Edge

SurpriseEdges returns the topN edges that cross community boundaries, ranked by the product of the degrees of their endpoints (a proxy for betweenness centrality: high-degree nodes in different communities that are directly connected are architecturally "surprising").

Types

type Graph

type Graph struct {
	Directed      *simple.DirectedGraph
	NodeIndex     map[string]int64     // node ID string → gonum int64 ID
	NodeByID      map[int64]types.Node // gonum int64 ID → types.Node
	ResolvedEdges []types.Edge         // only edges where both endpoints resolved
	Nodes         []types.Node
}

Graph wraps a gonum directed graph with auxiliary indexes for fast lookup.

func Build

func Build(nodes []types.Node, edges []types.Edge) (*Graph, error)

Build constructs a Graph from the provided nodes and edges.

Edge resolution:

  • e.Source must match a node ID exactly (it is always in "<file>:<name>" format).
  • e.Target is first tried as an exact ID, then as a bare label via labelIndex.

Only edges where BOTH endpoints resolve to known nodes are stored in ResolvedEdges and added to the gonum graph. Dangling edges (targeting stdlib/external symbols) are silently dropped — they add noise and break Obsidian graph view by creating isolated satellite dots.

func (*Graph) ApplyCommunities

func (g *Graph) ApplyCommunities(partition map[string]int) map[int][]string

ApplyCommunities writes community IDs back onto the graph's node metadata and populates the community → []nodeID index for report generation.

func (*Graph) Communities

func (g *Graph) Communities() map[int][]string

Communities returns a map of communityID → list of node IDs (empty until clustering is run).

func (*Graph) Degree

func (g *Graph) Degree(nodeID string) int

Degree returns the total degree (in + out) of the node with the given ID string.

func (*Graph) EdgeCount

func (g *Graph) EdgeCount() int

EdgeCount returns the number of resolved edges in the graph.

func (*Graph) NodeCount

func (g *Graph) NodeCount() int

NodeCount returns the number of nodes in the graph.

func (*Graph) ToTypes

func (g *Graph) ToTypes() *types.Graph

ToTypes converts this internal Graph to the types.Graph for serialisation. Only resolved edges are exported — dangling references are excluded.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL