<!-- Copyright (c) 2026 defconxt. All rights reserved. -->
<!-- Licensed under AGPL-3.0 — see LICENSE file for details. -->

# API Reference — Conducting Social Network Analysis

## NetworkX

### Graph Creation

```python
import networkx as nx

G = nx.DiGraph()  # Directed graph
G.add_node("user_a", platform="twitter", followers=5000)
G.add_edge("user_a", "user_b", relationship="follows", weight=1)
```

### Centrality Metrics

| Function | Description |
|---|---|
| `nx.degree_centrality(G)` | Connection count |
| `nx.betweenness_centrality(G)` | Bridge importance |
| `nx.closeness_centrality(G)` | Reachability |
| `nx.pagerank(G)` | Recursive influence |
| `nx.eigenvector_centrality(G)` | Connection quality |

### Community Detection

| Algorithm | Function |
|---|---|
| Louvain | `louvain_communities(G)` |
| Girvan-Newman | `girvan_newman(G)` |
| Label Propagation | `label_propagation_communities(G)` |

### I/O Formats

| Format | Read | Write |
|---|---|---|
| GEXF | `nx.read_gexf()` | `nx.write_gexf()` |
| GraphML | `nx.read_graphml()` | `nx.write_graphml()` |
| JSON | `nx.node_link_data()` | `nx.node_link_graph()` |

## Agent Script

```bash
node agent.js build-graph --input contacts.json --output network.gexf
node agent.js analyze --graph network.gexf --metrics degree,betweenness,pagerank
node agent.js communities --graph network.gexf --algorithm louvain
node agent.js path --graph network.gexf --source "user_a" --target "user_b"
node agent.js --self-test
```

## Input Data Format

```json
[
  {"source": "user_a", "target": "user_b", "weight": 1, "type": "follows"},
  {"source": "user_b", "target": "user_c", "weight": 3, "type": "mentions"}
]
```
