KnowledgeGraph converts the in-core knowledge graph to renderable data.
()
| 40 | |
| 41 | // KnowledgeGraph converts the in-core knowledge graph to renderable data. |
| 42 | func (a *graphViewPluginAdapter) KnowledgeGraph() (plugins.GraphData, error) { |
| 43 | g := a.cli.buildKnowledgeGraph() |
| 44 | data := plugins.GraphData{ |
| 45 | Nodes: make([]plugins.GraphNode, 0, g.Len()), |
| 46 | Edges: make([]plugins.GraphEdge, 0, g.Edges()), |
| 47 | } |
| 48 | for _, n := range g.Nodes() { |
| 49 | label := strings.TrimSpace(n.Title) |
| 50 | if label == "" { |
| 51 | label = n.ID |
| 52 | } |
| 53 | data.Nodes = append(data.Nodes, plugins.GraphNode{ |
| 54 | ID: n.ID, |
| 55 | Label: label, |
| 56 | Kind: string(n.Kind), |
| 57 | Summary: n.Summary, |
| 58 | Weight: n.Weight, |
| 59 | }) |
| 60 | } |
| 61 | seen := make(map[string]bool) |
| 62 | for _, n := range g.Nodes() { |
| 63 | for _, nb := range g.Neighbors(n.ID) { |
| 64 | x, y := n.ID, nb.ID |
| 65 | if x > y { |
| 66 | x, y = y, x |
| 67 | } |
| 68 | key := x + "\x00" + y |
| 69 | if seen[key] { |
| 70 | continue |
| 71 | } |
| 72 | seen[key] = true |
| 73 | data.Edges = append(data.Edges, plugins.GraphEdge{Source: x, Target: y, Weight: nb.Weight}) |
| 74 | } |
| 75 | } |
| 76 | return data, nil |
| 77 | } |
| 78 | |
| 79 | // ConversationGraph builds a graph of EVERYTHING in the current session, not |
| 80 | // just the message thread: a session root hub connects the conversation thread |