datamatters24 commited on
Commit
457056e
·
verified ·
1 Parent(s): 1e94321

Upload web/src/controllers/NetworkController.php with huggingface_hub

Browse files
web/src/controllers/NetworkController.php ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ declare(strict_types=1);
4
+
5
+ class NetworkController
6
+ {
7
+ public function index(): void
8
+ {
9
+ $db = Database::getInstance();
10
+
11
+ // Get available sections
12
+ $sections = $db->fetchAll(
13
+ "SELECT DISTINCT source_section FROM entity_relationships ORDER BY source_section"
14
+ );
15
+
16
+ $section = $_GET['section'] ?? '';
17
+ $section = Security::sanitize($section);
18
+ $entityType = $_GET['type'] ?? 'PERSON';
19
+ $entityType = in_array($entityType, ['PERSON', 'ORG']) ? $entityType : 'PERSON';
20
+ $minCount = max(2, (int)($_GET['min'] ?? 10));
21
+
22
+ $relationships = [];
23
+ $nodes = [];
24
+
25
+ if ($section) {
26
+ // Get top relationships for this section
27
+ $relationships = $db->fetchAll(
28
+ "SELECT entity_a, entity_b, co_occurrence_count, document_count, sample_doc_ids
29
+ FROM entity_relationships
30
+ WHERE source_section = :section AND entity_a_type = :type
31
+ AND co_occurrence_count >= :minCount
32
+ ORDER BY co_occurrence_count DESC
33
+ LIMIT 200",
34
+ ['section' => $section, 'type' => $entityType, 'minCount' => $minCount]
35
+ );
36
+
37
+ // Build node set with degree counts
38
+ $nodeDegree = [];
39
+ foreach ($relationships as $rel) {
40
+ $a = $rel['entity_a'];
41
+ $b = $rel['entity_b'];
42
+ $nodeDegree[$a] = ($nodeDegree[$a] ?? 0) + (int)$rel['co_occurrence_count'];
43
+ $nodeDegree[$b] = ($nodeDegree[$b] ?? 0) + (int)$rel['co_occurrence_count'];
44
+ }
45
+ arsort($nodeDegree);
46
+ $nodes = $nodeDegree;
47
+ }
48
+
49
+ // Stats
50
+ $stats = $db->fetchAll(
51
+ "SELECT entity_a_type as type, source_section as section,
52
+ COUNT(*) as rels, SUM(co_occurrence_count) as cooccurrences
53
+ FROM entity_relationships
54
+ GROUP BY entity_a_type, source_section
55
+ ORDER BY rels DESC"
56
+ );
57
+
58
+ require __DIR__ . '/../views/network.php';
59
+ }
60
+ }