Graphs & Algorithms

Turn search results and identifiers into rich knowledge graphs, then export or analyze with mbsoft graph packages.

What you get

Build graphs

use Scholarly\Contracts\Query;
use Scholarly\Factory\AdapterFactory;

$factory = AdapterFactory::make();
$src = $factory->adapter('openalex');
$exporter = $factory->graphExporter($src);

// Citation graph
$workGraph = $exporter->buildWorkCitationGraph(
    ['openalex:W1','openalex:W2'],
    Query::from(['limit' => 50])
);

// Collaboration graph
$authorGraph = $exporter->buildAuthorCollaborationGraph(
    ['openalex:A1','openalex:A2'],
    Query::from(['max_works' => 100, 'min_collaborations' => 2])
);

Caching

use Scholarly\Core\CacheLayer;
use Symfony\Component\Cache\Adapter\ArrayAdapter; // PSR-6 example

$cache = new CacheLayer(new ArrayAdapter());
$exporter = new Scholarly\Exporter\Graph\GraphExporter($src, $cache);

// Re-runs reuse references/citations from cache
$graph = $exporter->buildWorkCitationGraph(['openalex:W1'], Query::from(['limit' => 50]));

Exports

use Mbsoft\Graph\IO\CytoscapeJsonExporter;
use Mbsoft\Graph\IO\GraphMLExporter;

$json = (new CytoscapeJsonExporter())->export($workGraph);
$xml  = (new GraphMLExporter())->export($authorGraph);

Algorithms

use Mbsoft\Graph\Algorithms\Centrality\PageRank;

$scores = (new PageRank())->compute($workGraph);
arsort($scores); // top influential works

Progress & throttling

Advanced Graph Operations

Custom Progress Tracking

$progressCallback = function(int $current, ?int $total, string $itemId, array $meta) {
    $type = $meta['type'] ?? 'unknown';
    $progress = $total ? round(($current / $total) * 100, 1) : $current;
    echo "Processing {$type} {$current}" . ($total ? "/{$total} ({$progress}%)" : "") . ": {$itemId}\n";
};

$graph = $exporter->buildWorkCitationGraph(
    ['openalex:W123', 'openalex:W456'],
    Query::from(['limit' => 100]),
    $progressCallback
);

Graph Analysis Examples

Find Research Communities

use Mbsoft\Graph\Algorithms\Community\LouvainCommunities;

$communities = (new LouvainCommunities())->detect($authorGraph);
    foreach ($communities as $communityId => $members) {
    echo "Community {$communityId}: " . count($members) . " researchers\n";
}

Identify Key Papers

use Mbsoft\Graph\Algorithms\Centrality\BetweennessCentrality;

$betweenness = (new BetweennessCentrality())->compute($citationGraph);
$keyPapers = array_slice($betweenness, 0, 10, true);
foreach ($keyPapers as $workId => $score) {
    echo "Bridge paper {$workId}: {$score}\n";
}

Export Formats & Tools

Visualization Platforms

Integration with Analysis Tools

// Export for Python NetworkX
use Mbsoft\Graph\IO\GraphMLExporter;

$xml = (new GraphMLExporter())->export($graph);
file_put_contents('network.graphml', $xml);

// Export for web visualization (D3.js, vis.js)
use Mbsoft\Graph\IO\CytoscapeJsonExporter;
$json = (new CytoscapeJsonExporter())->export($graph);
file_put_contents('network.json', $json);

For more graph algorithms, see mbsoft31/graph-algorithms documentation.


Core Concepts: Contracts Architecture Getting Started
Features: Graph Analytics Laravel Integration Provider Adapters
Development: Extending GitHub Repository  
External Resources: OpenAlex API Semantic Scholar API Crossref API