Download web/src/controllers/NetworkController.php from datamatters24/research-document-archive: direct link, hf CLI and curl.
- Browser
- Download file 2.1 kB
-
https://huggingface.co/datamatters24/research-document-archive/resolve/main/web/src/controllers/NetworkController.php
- Command line
-
hf download hf://datamatters24/research-document-archive/web/src/controllers/NetworkController.php
-
curl -L -o NetworkController.php https://huggingface.co/datamatters24/research-document-archive/resolve/main/web/src/controllers/NetworkController.php
2.1 kB
| declare(strict_types=1); | |
| class NetworkController | |
| { | |
| public function index(): void | |
| { | |
| $db = Database::getInstance(); | |
| // Get available sections | |
| $sections = $db->fetchAll( | |
| "SELECT DISTINCT source_section FROM entity_relationships ORDER BY source_section" | |
| ); | |
| $section = $_GET['section'] ?? ''; | |
| $section = Security::sanitize($section); | |
| $entityType = $_GET['type'] ?? 'PERSON'; | |
| $entityType = in_array($entityType, ['PERSON', 'ORG']) ? $entityType : 'PERSON'; | |
| $minCount = max(2, (int)($_GET['min'] ?? 10)); | |
| $relationships = []; | |
| $nodes = []; | |
| if ($section) { | |
| // Get top relationships for this section | |
| $relationships = $db->fetchAll( | |
| "SELECT entity_a, entity_b, co_occurrence_count, document_count, sample_doc_ids | |
| FROM entity_relationships | |
| WHERE source_section = :section AND entity_a_type = :type | |
| AND co_occurrence_count >= :minCount | |
| ORDER BY co_occurrence_count DESC | |
| LIMIT 200", | |
| ['section' => $section, 'type' => $entityType, 'minCount' => $minCount] | |
| ); | |
| // Build node set with degree counts | |
| $nodeDegree = []; | |
| foreach ($relationships as $rel) { | |
| $a = $rel['entity_a']; | |
| $b = $rel['entity_b']; | |
| $nodeDegree[$a] = ($nodeDegree[$a] ?? 0) + (int)$rel['co_occurrence_count']; | |
| $nodeDegree[$b] = ($nodeDegree[$b] ?? 0) + (int)$rel['co_occurrence_count']; | |
| } | |
| arsort($nodeDegree); | |
| $nodes = $nodeDegree; | |
| } | |
| // Stats | |
| $stats = $db->fetchAll( | |
| "SELECT entity_a_type as type, source_section as section, | |
| COUNT(*) as rels, SUM(co_occurrence_count) as cooccurrences | |
| FROM entity_relationships | |
| GROUP BY entity_a_type, source_section | |
| ORDER BY rels DESC" | |
| ); | |
| require __DIR__ . '/../views/network.php'; | |
| } | |
| } | |