graph

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache added in v0.4.0

type Cache struct {
	// contains filtered or unexported fields
}

Cache holds a recently built graph to avoid rebuilding on every analyze call.

func NewCache added in v0.4.0

func NewCache(b backend.Backend, ttl time.Duration) *Cache

NewCache creates a graph cache with the given TTL.

func (*Cache) Get added in v0.4.0

func (c *Cache) Get(ctx context.Context) (*Graph, error)

Get returns a cached graph or builds a fresh one if expired.

func (*Cache) Invalidate added in v0.4.0

func (c *Cache) Invalidate()

Invalidate forces the next Get to rebuild.

type Cluster

type Cluster struct {
	ID    int      `json:"id"`
	Size  int      `json:"size"`
	Pages []string `json:"pages"`
	Hub   string   `json:"hub"`
}

Cluster is a group of densely connected pages.

type ConnectionResult

type ConnectionResult struct {
	From              string     `json:"from"`
	To                string     `json:"to"`
	DirectlyLinked    bool       `json:"directlyLinked"`
	Paths             [][]string `json:"paths"`
	SharedConnections []string   `json:"sharedConnections"`
}

ConnectionResult describes how two pages are connected.

type GapInfo

type GapInfo struct {
	OrphanPages   []string   `json:"orphanPages"`
	DeadEndPages  []string   `json:"deadEndPages"`
	WeaklyLinked  []PageStat `json:"weaklyLinked"`
	SingletonTags []string   `json:"singletonTags,omitempty"`
}

GapInfo describes a knowledge gap or sparse area.

type Graph

type Graph struct {
	// Forward links: page name (lowercase) → set of linked page names (original case)
	Forward map[string]map[string]bool
	// Backward links: page name (lowercase) → set of pages that link to it
	Backward map[string]map[string]bool
	// Pages: lowercase name → PageEntity
	Pages map[string]types.PageEntity
	// BlockCounts: lowercase name → total block count
	BlockCounts map[string]int
}

Graph is an in-memory representation of the knowledge graph's link structure.

func Build

func Build(ctx context.Context, c backend.Backend) (*Graph, error)

Build fetches all pages and their block trees, constructing the link graph.

func (*Graph) FindConnections

func (g *Graph) FindConnections(from, to string, maxDepth int) ConnectionResult

FindConnections finds how two pages are connected.

func (*Graph) InDegree

func (g *Graph) InDegree(name string) int

InDegree returns the number of incoming links to a page.

func (*Graph) KnowledgeGaps

func (g *Graph) KnowledgeGaps() GapInfo

KnowledgeGaps finds sparse areas in the graph.

func (*Graph) OriginalName

func (g *Graph) OriginalName(key string) string

OriginalName returns the display name for a page.

func (*Graph) OutDegree

func (g *Graph) OutDegree(name string) int

OutDegree returns the number of outgoing links from a page.

func (*Graph) Overview

func (g *Graph) Overview() OverviewStats

Overview computes global graph statistics.

func (*Graph) TopicClusters

func (g *Graph) TopicClusters() []Cluster

TopicClusters finds connected components in the undirected link graph.

func (*Graph) TotalDegree

func (g *Graph) TotalDegree(name string) int

TotalDegree returns outgoing + incoming link count for a page.

type OverviewStats

type OverviewStats struct {
	TotalPages    int            `json:"totalPages"`
	TotalBlocks   int            `json:"totalBlocks"`
	TotalLinks    int            `json:"totalLinks"`
	JournalPages  int            `json:"journalPages"`
	OrphanPages   int            `json:"orphanPages"`
	MostConnected []PageStat     `json:"mostConnected"`
	MostLinkedTo  []PageStat     `json:"mostLinkedTo"`
	Namespaces    map[string]int `json:"namespaces"`
}

OverviewStats contains global graph statistics.

type PageStat

type PageStat struct {
	Name        string `json:"name"`
	OutLinks    int    `json:"outLinks"`
	InLinks     int    `json:"inLinks"`
	TotalDegree int    `json:"totalDegree"`
	BlockCount  int    `json:"blockCount"`
}

PageStat is a page with its connectivity score.

Jump to

Keyboard shortcuts

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