Skip to content

src/insight_analyzer

Phase 6 module for graph analysis and insight report generation.

Functions

load_graph(graph_path: str) → nx.DiGraph

Load a knowledge graph from JSON into NetworkX.

Parameters:

Name Type Description
graph_path str Path to knowledge_graph.json

Returns: NetworkX directed graph.


analyze_hub_concepts(G: nx.DiGraph) → list[dict]

Find bridge concepts that connect the most different scientific fields.

Parameters:

Name Type Description
G nx.DiGraph Knowledge graph

Returns: Sorted list of dicts:

[
    {
        "concept": "Protein Degradation Mechanisms",
        "field_count": 3,
        "fields": ["Biology", "Chemistry", "Physics"],
        "degree": 12
    },
    ...
]

analyze_field_influence(G: nx.DiGraph) → dict

Analyze which fields export concepts and which import them.

Parameters:

Name Type Description
G nx.DiGraph Knowledge graph

Returns: Dict with structure:

{
    "exports": {"Physics": 3, "Chemistry": 2, ...},
    "imports": {"Biology": 5, "Physics": 4, ...},
    "net": {"Physics": -1, "Biology": -5, ...}
}

analyze_temporal_patterns(G: nx.DiGraph) → list[dict]

Extract the timeline of cross-disciplinary migration events.

Parameters:

Name Type Description
G nx.DiGraph Knowledge graph

Returns: Sorted list of migration events:

[
    {
        "year": 1961,
        "source_concept": "...",
        "target_concept": "...",
        "source_field": "Physics",
        "target_field": "Biology",
        "description": "..."
    },
    ...
]

analyze_key_pathways(G: nx.DiGraph) → list[dict]

Find shortest cross-field concept paths (3–6 hops, spanning ≥2 fields).

Parameters:

Name Type Description
G nx.DiGraph Knowledge graph

Returns: List of pathway dicts with source, target, path, fields, length.


generate_report(G: nx.DiGraph, output_path: str) → None

Generate a complete Markdown analysis report and JSON data file.

Parameters:

Name Type Description
G nx.DiGraph Knowledge graph
output_path str Output directory path

Outputs:

  • {output_path}/insight_report.md — 6-section Markdown report
  • {output_path}/insight_report.json — Machine-readable analysis data

run() → None

Execute the full Phase 6 pipeline:

  1. Load configuration
  2. Load knowledge graph
  3. Run all analysis functions
  4. Generate report files
  5. Print key findings to console