Documentation
¶
Index ¶
- type Cache
- type Cluster
- type ConnectionResult
- type GapInfo
- type Graph
- func (g *Graph) FindConnections(from, to string, maxDepth int) ConnectionResult
- func (g *Graph) InDegree(name string) int
- func (g *Graph) KnowledgeGaps() GapInfo
- func (g *Graph) OriginalName(key string) string
- func (g *Graph) OutDegree(name string) int
- func (g *Graph) Overview() OverviewStats
- func (g *Graph) TopicClusters() []Cluster
- func (g *Graph) TotalDegree(name string) int
- type OverviewStats
- type PageStat
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache holds a recently built graph to avoid rebuilding on every analyze call.
func NewCache ¶
NewCache creates a graph cache with the given TTL backed by the provided backend.Backend. Returns a Cache that lazily builds the graph on the first Cache.Get call and re-uses it until the TTL expires.
func (*Cache) Get ¶
Get returns the cached graph if it was built within the TTL, or builds a fresh one by calling Build. Returns an error if the graph build fails. Safe for concurrent use (serialized via mutex).
func (*Cache) Invalidate ¶
func (c *Cache) Invalidate()
Invalidate clears the cached graph, forcing the next Cache.Get call to rebuild it from the backend. Safe for concurrent use.
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"`
}
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 ¶
Build fetches all pages and their block trees from the backend and constructs an in-memory link graph. Returns the graph with forward links, backward links, page metadata, and block counts populated. Pages with empty names are skipped; block tree fetch errors are logged and skipped (partial graph). Returns an error if GetAllPages fails.
func (*Graph) FindConnections ¶
func (g *Graph) FindConnections(from, to string, maxDepth int) ConnectionResult
FindConnections finds how two pages are connected by checking for direct links, finding paths via BFS (up to maxDepth, default 5, max 10 paths), and identifying shared connections. Returns a ConnectionResult with direct link status, paths, and shared connections sorted alphabetically.
func (*Graph) InDegree ¶
InDegree returns the number of incoming links to the named page. Returns 0 if the page does not exist in the graph or has no incoming links.
func (*Graph) KnowledgeGaps ¶
KnowledgeGaps finds sparse areas in the graph by identifying orphan pages (no links in or out), dead-end pages (incoming links but no outgoing), and weakly linked pages (total degree ≤ 2). Journal pages are excluded from the analysis. Returns a GapInfo with sorted lists and up to 20 weakly linked pages.
func (*Graph) OriginalName ¶
OriginalName returns the original display name for a page identified by its lowercase key. Returns the key itself if the page is not found or has no OriginalName set.
func (*Graph) OutDegree ¶
OutDegree returns the number of outgoing links from the named page. Returns 0 if the page does not exist in the graph.
func (*Graph) Overview ¶
func (g *Graph) Overview() OverviewStats
Overview computes global graph statistics including total pages, blocks, links, journal page count, orphan count, top-10 most connected pages, top-10 most linked-to pages, and namespace distribution. Returns the statistics as an OverviewStats value.
func (*Graph) TopicClusters ¶
TopicClusters finds connected components in the undirected link graph using BFS. Returns a slice of Cluster sorted by size descending. Each cluster includes the list of page names, the hub page (highest degree), and the cluster size. Singleton pages and journal pages are excluded.
func (*Graph) TotalDegree ¶
TotalDegree returns the sum of outgoing and incoming link counts for the named page. Returns 0 if the page does not exist in the graph.
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.