community

package
v0.0.0-beta.30 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HierarchicalLouvain

func HierarchicalLouvain(g *Graph, maxLevels, maxIter int) [][]int

HierarchicalLouvain runs Louvain at multiple levels. Returns a slice of levels, each level is a map nodeID → communityLabel.

func Louvain

func Louvain(g *Graph, maxIter int) []int

Louvain runs the Louvain community detection algorithm. Returns a map from node index → community ID (integer).

Uses the standard modularity gain formula:

ΔQ = [k_i_in / (2m)] - [sigma_tot * k_i / (2m²)]

where:

  • k_i_in = sum of edge weights from node i to nodes in community C
  • sigma_tot = sum of all edge weights incident to nodes in community C
  • k_i = weighted degree of node i
  • m = total edge weight of the graph

Types

type CommunityReport

type CommunityReport struct {
	Title   string
	Summary string
}

CommunityReport holds LLM-generated community metadata.

func Summarize

func Summarize(ctx context.Context, provider llm.Provider, entityDescriptions []string, relDescriptions []string) (*CommunityReport, error)

Summarize generates a community report using the LLM.

type Edge

type Edge struct {
	Source, Target int
	Weight         float64
}

Edge in the graph.

type Graph

type Graph struct {
	Nodes []string

	Edges []Edge
	// contains filtered or unexported fields
}

Graph represents an undirected weighted graph for community detection.

func NewGraph

func NewGraph(nodes []string, edges [][3]any) *Graph

NewGraph builds a graph from node IDs and weighted edges.

func (*Graph) NodeIndex

func (g *Graph) NodeIndex(id string) (int, bool)

NodeIndex returns the index for a node ID.

Jump to

Keyboard shortcuts

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