Skip to content

feat: PageRank, betweenness centrality, entity resolution, weighted path, D3 viz, concurrency#1

Open
furkan-cyber wants to merge 2 commits into
Cognipeer:mainfrom
furkan-cyber:main
Open

feat: PageRank, betweenness centrality, entity resolution, weighted path, D3 viz, concurrency#1
furkan-cyber wants to merge 2 commits into
Cognipeer:mainfrom
furkan-cyber:main

Conversation

@furkan-cyber

Copy link
Copy Markdown

Summary

This PR adds 5 major capability improvements to graph-builder.

1. Graph Analytics (analyze.ts)

  • PageRank — 30-iteration iterative PageRank (damping 0.85) for every node. Exposed as result.analysis.pageRank
  • Betweenness Centrality — Brandes BFS algorithm (O(VE)); auto-skipped for graphs > 500 nodes. Exposed as result.analysis.betweenness
  • Bridge Node Detection — Tarjan's articulation point algorithm (O(V+E)) to find nodes whose removal disconnects the graph. Exposed as result.analysis.bridgeNodes

2. Cross-Document Entity Resolution (build.ts)

  • New resolveEntities(graph) function merges nodes with the same normalizedLabel + type (function/class/interface/enum/method) that originate from different source items into a single canonical node
  • Merged nodes carry a mergedFrom: string[] field listing the original IDs
  • Activated via options.entityResolution: true

3. Weighted Shortest Path + Improved Query Scoring (query.ts)

  • shortestPath upgraded from BFS to Dijkstra — edge weight = 1 / confidenceScore so high-confidence edges are preferred
  • GraphBuilderPathResult gains totalWeight field
  • scoreNodes improved: prefix-match bonus (+50), TYPE_PRIORITY map that boosts document/class/function nodes and demotes resource/tag/package nodes

4. D3.js Interactive HTML Visualization (artifacts.ts)

  • Replaced vis-network with D3.js v7 force-directed layout
  • Node size scales with PageRank; color by community (10-color palette) or type fallback
  • Edge style by confidence: solid (EXTRACTED), dashed (INFERRED), dotted (AMBIGUOUS)
  • Hover tooltip shows label, type, degree, pageRank, betweenness, sourceItemId
  • Click highlights node + immediate neighbors; sidebar shows live node detail panel
  • Search sidebar with top-N list sorted by degree; label toggle; zoom/pan; responsive resize

5. Concurrency-Limited Extraction (graph-builder.ts)

  • New options.concurrency setting limits parallel extraction workers (worker-queue pattern)
  • Useful for rate-limited providers (APIs, LLMs); defaults to unlimited (existing behaviour)

Type Changes (types.ts)

  • GraphBuilderNode.mergedFrom?: string[]
  • GraphBuilderAnalysis.pageRank / betweenness / bridgeNodes
  • GraphBuilderPathResult.totalWeight?: number
  • GraphBuilderOptions.concurrency / entityResolution

Tests

5 new tests added; full suite 18/18 passing.

…on, weighted path, D3 viz, concurrency

- analyze.ts: add computePageRank (30-iter damping 0.85), computeBetweenness
  (Brandes BFS, capped at 500 nodes), detectBridgeNodes (Tarjan articulation
  points); expose pageRank / betweenness / bridgeNodes on GraphBuilderAnalysis
- build.ts: add resolveEntities() -- merges cross-document nodes of the same
  normalizedLabel+type (function/class/interface/enum/method) into a single
  node with mergedFrom[] metadata; activated via options.entityResolution
- query.ts: replace BFS shortestPath with Dijkstra weighted by 1/confidenceScore;
  improve scoreNodes with prefix-match bonus (+50) and TYPE_PRIORITY weighting;
  GraphBuilderPathResult gains totalWeight field
- artifacts.ts: replace vis-network HTML output with D3.js v7 force-directed
  interactive graph (zoom/pan, node colour by community, size by PageRank,
  edge style by confidence, hover tooltip, click-to-highlight, sidebar search
  with live node list and detail panel, label toggle, responsive resize)
- graph-builder.ts: add concurrency-limited extraction via options.concurrency
  (worker-queue pattern); wire resolveEntities step after graph build
- types.ts: add GraphBuilderNode.mergedFrom, GraphBuilderAnalysis.pageRank /
  betweenness / bridgeNodes, GraphBuilderPathResult.totalWeight,
  GraphBuilderOptions.concurrency / entityResolution
- tests: 5 new tests covering all new features; total suite 18/18 passing
@sercanuste sercanuste requested a review from anilguleroglu June 1, 2026 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant