@unrdf/graph-analytics
v26.4.8
Published
Advanced graph analytics for RDF knowledge graphs using graphlib
Maintainers
Readme
@unrdf/graph-analytics
Advanced graph analytics for RDF knowledge graphs using graphlib.
Features
1. RDF to Graph Conversion
Convert RDF triple stores to graphlib Graph instances for analysis.
import { createStore } from '@unrdf/oxigraph';
import { rdfToGraph, getGraphStats } from '@unrdf/graph-analytics';
const store = createStore();
// ... add RDF triples ...
const graph = rdfToGraph(store);
const stats = getGraphStats(graph);
console.log(`Nodes: ${stats.nodeCount}, Edges: ${stats.edgeCount}`);2. Centrality Algorithms
Compute entity importance using PageRank and degree centrality.
import { computePageRank, getTopNodes } from '@unrdf/graph-analytics';
const pagerank = computePageRank(graph, { dampingFactor: 0.85 });
const top10 = getTopNodes(pagerank, 10);
console.log('Most important entities:', top10);3. Path Finding
Discover relationships through shortest paths and path enumeration.
import { findShortestPath, findAllPaths } from '@unrdf/graph-analytics';
const shortestPath = findShortestPath(graph, sourceUri, targetUri);
console.log('Path:', shortestPath.path);
const allPaths = findAllPaths(graph, sourceUri, targetUri, { maxDepth: 4 });
console.log(`Found ${allPaths.length} paths`);4. Community Detection
Identify clusters and communities in knowledge graphs.
import { detectCommunitiesLPA, getCommunityStats } from '@unrdf/graph-analytics';
const communities = detectCommunitiesLPA(graph);
const stats = getCommunityStats(communities);
console.log(`Detected ${stats.totalCommunities} communities`);Installation
pnpm add @unrdf/graph-analyticsQuick Start
# Run demo
pnpm demo
# Run tests
pnpm test
# Run with coverage
pnpm test -- --coverageAPI Reference
Converter
rdfToGraph(store, options)- Convert RDF store to graphsparqlResultsToGraph(results, options)- Convert SPARQL results to graphgetGraphStats(graph)- Compute graph statistics
Centrality
computePageRank(graph, options)- PageRank algorithmcomputeDegreeCentrality(graph)- Degree centralitycomputeBetweennessCentrality(graph)- Betweenness centralitygetTopNodes(scores, k)- Get top K nodes by score
Paths
findShortestPath(graph, source, target)- Dijkstra shortest pathfindAllPaths(graph, source, target, options)- All paths enumerationfindCommonNeighbors(graph, node1, node2)- Common neighborsfindKHopNeighbors(graph, source, k)- K-hop neighborhooddiscoverRelationshipChains(graph, source, target)- Relationship patterns
Clustering
detectCommunitiesLPA(graph, options)- Label propagationdetectCommunitiesModularity(graph, options)- Modularity-basedfindKCore(graph, k)- K-core decompositiongetCommunityStats(communities)- Community statistics
Performance
Optimized for RDF knowledge graphs:
- Efficient graph conversion (streaming support)
- Fast PageRank convergence
- Scalable path algorithms
- Memory-efficient community detection
License
MIT
