@@ -250,3 +250,167 @@ Structured validation error with field name and message.
250250
251251- `from` node must exist in graph
252252- `to` node must exist in graph
253+
254+ ---
255+
256+ ## Package `query`
257+
258+ Graph traversal algorithms.
259+
260+ ### Traverser
261+
262+ ```go
263+ type Traverser struct {
264+ // private fields
265+ }
266+
267+ func NewTraverser (g *graph .Graph ) *Traverser
268+ func NewTraverserFromEdges(edges []*graph.Edge, nodes map[string]*graph.Node) *Traverser
269+ ```
270+
271+ Creates a traverser for graph exploration.
272+
273+ ### Direction
274+
275+ ```go
276+ type Direction int
277+
278+ const (
279+ Outgoing Direction = iota // Follow edges from source to target
280+ Incoming // Follow edges from target to source
281+ Both // Follow edges in both directions
282+ )
283+ ```
284+
285+ ### TraversalResult
286+
287+ ```go
288+ type TraversalResult struct {
289+ StartNode string // Node where traversal began
290+ Visited []string // Visited node IDs in order
291+ Edges []*graph.Edge // Traversed edges
292+ Depth map [string ]int // Node ID to depth from start
293+ Parents map [string ]*graph.Edge // Node ID to edge that led to it
294+ }
295+ ```
296+
297+ ### Traversal Methods
298+
299+ | Method | Signature | Description |
300+ | --------| -----------| -------------|
301+ | ` BFS ` | ` func (t *Traverser) BFS(start string, dir Direction, maxDepth int, edgeTypes []string) *TraversalResult ` | Breadth-first search |
302+ | ` DFS ` | ` func (t *Traverser) DFS(start string, dir Direction, maxDepth int, edgeTypes []string) *TraversalResult ` | Depth-first search |
303+ | ` FindPath ` | ` func (t *Traverser) FindPath(from, to string, edgeTypes []string) *TraversalResult ` | Find shortest path |
304+
305+ ** Parameters:**
306+
307+ | Parameter | Description |
308+ | -----------| -------------|
309+ | ` start ` | Starting node ID |
310+ | ` dir ` | Traversal direction (Outgoing, Incoming, Both) |
311+ | ` maxDepth ` | Maximum traversal depth (0 = default 100) |
312+ | ` edgeTypes ` | Filter by edge types (nil = all types) |
313+
314+ ---
315+
316+ ## Package ` analyze `
317+
318+ Graph analysis algorithms.
319+
320+ ### Hub Detection
321+
322+ ``` go
323+ type HubNode struct {
324+ ID string
325+ Label string
326+ Type string
327+ InDegree int
328+ OutDegree int
329+ Total int
330+ }
331+
332+ func FindHubs (nodes []*graph .Node , edges []*graph .Edge , topN int , excludeTypes []string ) []HubNode
333+ func IsolatedNodes(nodes []*graph.Node, edges []*graph.Edge, threshold int, excludeTypes []string) []*graph.Node
334+ ```
335+
336+ | Function | Description |
337+ |----------|-------------|
338+ | `FindHubs` | Returns top N most connected nodes |
339+ | `IsolatedNodes` | Returns nodes with degree <= threshold |
340+
341+ ### Community Detection
342+
343+ ```go
344+ type Community struct {
345+ ID int
346+ Size int
347+ Cohesion float64
348+ Members []string
349+ Label string
350+ }
351+
352+ type ClusterResult struct {
353+ Communities []Community
354+ NodeCommunity map [string ]int
355+ Modularity float64
356+ }
357+
358+ func DetectCommunities (nodes []*graph .Node , edges []*graph .Edge ) *ClusterResult
359+ func DetectCommunitiesWithOptions(nodes []*graph.Node, edges []*graph.Edge, opts ClusterOptions) *ClusterResult
360+ ```
361+
362+ Uses the Louvain algorithm for modularity optimization.
363+
364+ ### ClusterOptions
365+
366+ ```go
367+ type ClusterOptions struct {
368+ Algorithm ClusterAlgorithm // "louvain" or "components"
369+ Resolution float64 // Higher = smaller communities (default 1.0)
370+ ExcludeEdgeTypes []string // Edge types to ignore
371+ ExcludeNodeTypes []string // Node types to ignore
372+ }
373+
374+ func DefaultClusterOptions () ClusterOptions
375+ ```
376+
377+ ### Graph Diff
378+
379+ ```go
380+ type GraphDiff struct {
381+ NewNodes []NodeChange
382+ RemovedNodes []NodeChange
383+ NewEdges []EdgeChange
384+ RemovedEdges []EdgeChange
385+ Summary string
386+ }
387+
388+ type NodeChange struct {
389+ ID string
390+ Label string
391+ Type string
392+ }
393+
394+ type EdgeChange struct {
395+ From string
396+ To string
397+ Type string
398+ Confidence string
399+ }
400+
401+ func DiffGraphs (oldNodes , newNodes []*graph .Node , oldEdges , newEdges []*graph .Edge ) *GraphDiff
402+ ```
403+
404+ Compares two graph snapshots and returns changes.
405+
406+ ### Utility Functions
407+
408+ | Function | Signature | Description |
409+ |----------|-----------|-------------|
410+ | `NodesByType` | `func NodesByType(nodes []*graph.Node) map[string][]*graph.Node` | Group nodes by type |
411+ | `EdgesByType` | `func EdgesByType(edges []*graph.Edge) map[string][]*graph.Edge` | Group edges by type |
412+ | `EdgesByConfidence` | `func EdgesByConfidence(edges []*graph.Edge) map[graph.Confidence][]*graph.Edge` | Group edges by confidence |
413+ | `CohesionScore` | `func CohesionScore(members []string, adj map[string]map[string]bool) float64` | Calculate community density |
414+ | `HubScore` | `func HubScore(nodeID string, edges []*graph.Edge) int` | Calculate out-degree |
415+ | `AuthorityScore` | `func AuthorityScore(nodeID string, edges []*graph.Edge) int` | Calculate in-degree |
416+ | `InferredEdges` | `func InferredEdges(edges []*graph.Edge) []*graph.Edge` | Get INFERRED/AMBIGUOUS edges |
0 commit comments