Documentation
¶
Overview ¶
Package analyze provides graph analysis functions.
Package analyze provides graph analysis features including hub detection, community detection, and graph comparison.
Index ¶
- func AuthorityScore(nodeID string, edges []*graph.Edge) int
- func CohesionScore(members []string, adj map[string]map[string]bool) float64
- func EdgesByConfidence(edges []*graph.Edge) map[graph.Confidence][]*graph.Edge
- func EdgesByType(edges []*graph.Edge) map[string][]*graph.Edge
- func HubScore(nodeID string, edges []*graph.Edge) int
- func InferredEdges(edges []*graph.Edge) []*graph.Edge
- func IsolatedNodes(nodes []*graph.Node, edges []*graph.Edge, threshold int, excludeTypes []string) []*graph.Node
- func NodesByType(nodes []*graph.Node) map[string][]*graph.Node
- type ClusterAlgorithm
- type ClusterOptions
- type ClusterResult
- type Community
- type EdgeChange
- type GraphDiff
- type HubNode
- type LouvainOptions
- type LouvainResult
- type NodeChange
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AuthorityScore ¶
AuthorityScore calculates a simple authority score based on in-degree. High in-degree nodes are frequently referenced entities.
func CohesionScore ¶
CohesionScore calculates the ratio of actual intra-community edges to maximum possible.
func EdgesByConfidence ¶
EdgesByConfidence groups edges by their confidence level.
func EdgesByType ¶
EdgesByType groups edges by their type for analysis.
func HubScore ¶
HubScore calculates a simple hub score based on out-degree. High out-degree nodes are potential architectural hubs.
func InferredEdges ¶
InferredEdges returns edges with INFERRED or AMBIGUOUS confidence.
Types ¶
type ClusterAlgorithm ¶
type ClusterAlgorithm string
ClusterAlgorithm specifies the community detection algorithm to use.
const ( // AlgorithmLouvain uses the Louvain modularity optimization algorithm. AlgorithmLouvain ClusterAlgorithm = "louvain" // AlgorithmConnectedComponents uses connected components. AlgorithmConnectedComponents ClusterAlgorithm = "components" )
type ClusterOptions ¶
type ClusterOptions struct {
// Algorithm specifies which algorithm to use.
// Default: AlgorithmLouvain
Algorithm ClusterAlgorithm
// Resolution for Louvain algorithm (higher = smaller communities).
// Default: 1.0
Resolution float64
// ExcludeEdgeTypes lists edge types to exclude from community detection.
ExcludeEdgeTypes []string
// ExcludeNodeTypes lists node types to exclude from community detection.
ExcludeNodeTypes []string
}
ClusterOptions configures community detection.
func DefaultClusterOptions ¶
func DefaultClusterOptions() ClusterOptions
DefaultClusterOptions returns sensible defaults.
type ClusterResult ¶
type ClusterResult struct {
Communities []Community `json:"communities"`
NodeCommunity map[string]int `json:"node_community"`
Modularity float64 `json:"modularity,omitempty"`
}
ClusterResult contains the results of community detection.
func DetectCommunities ¶
func DetectCommunities(nodes []*graph.Node, edges []*graph.Edge) *ClusterResult
DetectCommunities performs community detection using the Louvain algorithm by default.
func DetectCommunitiesWithOptions ¶
func DetectCommunitiesWithOptions(nodes []*graph.Node, edges []*graph.Edge, opts ClusterOptions) *ClusterResult
DetectCommunitiesWithOptions performs community detection with configurable algorithm.
func LouvainToClusters ¶
func LouvainToClusters(result *LouvainResult, nodes []*graph.Node, edges []*graph.Edge) *ClusterResult
LouvainToClusters converts LouvainResult to ClusterResult for compatibility.
type Community ¶
type Community struct {
ID int `json:"id"`
Size int `json:"size"`
Cohesion float64 `json:"cohesion"`
Members []string `json:"members"`
Label string `json:"label,omitempty"`
}
Community represents a detected community in the graph.
type EdgeChange ¶
type EdgeChange struct {
From string `json:"from"`
To string `json:"to"`
Type string `json:"type"`
Confidence string `json:"confidence"`
}
EdgeChange represents an edge that was added or removed.
type GraphDiff ¶
type GraphDiff struct {
NewNodes []NodeChange `json:"new_nodes"`
RemovedNodes []NodeChange `json:"removed_nodes"`
NewEdges []EdgeChange `json:"new_edges"`
RemovedEdges []EdgeChange `json:"removed_edges"`
Summary string `json:"summary"`
}
GraphDiff represents the difference between two graph snapshots.
type HubNode ¶
type HubNode struct {
ID string `json:"id"`
Label string `json:"label"`
Type string `json:"type"`
InDegree int `json:"in_degree"`
OutDegree int `json:"out_degree"`
Total int `json:"total"`
}
HubNode represents a highly connected node in the graph.
type LouvainOptions ¶
type LouvainOptions struct {
// Resolution controls community granularity. Higher values = smaller communities.
// Default: 1.0 (standard modularity)
Resolution float64
// Seed for random number generator. Use 0 for non-deterministic.
Seed uint64
// ExcludeEdgeTypes lists edge types to exclude from community detection.
// Default: ["contains", "imports"] (structural edges)
ExcludeEdgeTypes []string
// ExcludeNodeTypes lists node types to exclude from community detection.
// Default: ["package", "file"] (hub nodes)
ExcludeNodeTypes []string
}
LouvainOptions configures the Louvain algorithm.
func DefaultLouvainOptions ¶
func DefaultLouvainOptions() LouvainOptions
DefaultLouvainOptions returns sensible defaults for Louvain.
type LouvainResult ¶
type LouvainResult struct {
// Communities maps community ID to member node IDs.
Communities map[int][]string
// NodeCommunity maps node ID to community ID.
NodeCommunity map[string]int
// Modularity is the Q score of the detected communities.
Modularity float64
// NumLevels is the number of hierarchical levels in the dendrogram.
NumLevels int
}
LouvainResult contains the results of Louvain community detection.
func DetectCommunitiesLouvain ¶
func DetectCommunitiesLouvain(nodes []*graph.Node, edges []*graph.Edge, opts LouvainOptions) *LouvainResult
DetectCommunitiesLouvain performs community detection using the Louvain algorithm.
type NodeChange ¶
type NodeChange struct {
ID string `json:"id"`
Label string `json:"label"`
Type string `json:"type"`
}
NodeChange represents a node that was added or removed.