Skip to content

COGANT Graph Construction, Normalization, Translation

COGANT Graph Construction, Normalization, and Translation Engine

Which doc should I read? Short inventory: Graph engine summary. Ingest/static pipeline: Reference index. Architecture: Architecture index. Hub: README.md.

This document describes the complete engine for COGANT - the Codebase-to-GNN Translation system. The engine consists of three major components: normalization, graph construction, and semantic translation.

Architecture Overview

┌─────────────────────────────────────────────────────────────┐
│                    STATIC/DYNAMIC ANALYSIS                  │
│              (Language-specific facts extracted)             │
└──────────────────────────┬──────────────────────────────────┘
                           │
                           ▼
┌─────────────────────────────────────────────────────────────┐
│                  NORMALIZATION LAYER                         │
│  • IdentityResolver: Stable ID generation                    │
│  • CanonicalNormalizer: Language-agnostic transformation    │
└──────────────────────────┬──────────────────────────────────┘
                           │
                           ▼
┌─────────────────────────────────────────────────────────────┐
│                  GRAPH CONSTRUCTION LAYER                    │
│  • ProgramGraphBuilder: Typed nodes and edges                │
│  • GraphQuery: Analysis and traversal                        │
│  • GraphMerger: Combine static + dynamic evidence            │
└──────────────────────────┬──────────────────────────────────┘
                           │
                           ▼
┌─────────────────────────────────────────────────────────────┐
│                  TRANSLATION LAYER                           │
│  • TranslationEngine: Rule orchestration                     │
│  • 22 Concrete Rules: Pattern detection                       │
│  • ConfidenceModel: Evidence scoring                         │
│  • ReviewManager: Human curation                            │
└──────────────────────────┬──────────────────────────────────┘
                           │
                           ▼
┌─────────────────────────────────────────────────────────────┐
│              SEMANTIC MAPPINGS (for GNN training)            │
│  • Observations, Actions, Hidden State                       │
│  • Policies, Constraints, Preferences                        │
│  • Provenance and Confidence Tiers                           │
└─────────────────────────────────────────────────────────────┘

1. Normalization Layer

1.1 IdentityResolver (cogant/normalize/identities.py)

Purpose: Generate stable, deterministic IDs for all repository elements.

Key Methods: - generate_id() - Create stable ID using SHA256(repo_uri | path | qualified_name) - get_id() - Get or create ID (idempotent) - lookup_id() - Look up without creating - generate_edge_id() - Create stable edge IDs - deduplicate_ids() - Remove duplicates while preserving order

Example:

from cogant.normalize.identities import IdentityResolver

resolver = IdentityResolver()
# Generate a stable ID for a module entity. Same inputs always yield the
# same ID (SHA256 of repo_uri | path | qualified_name).
module_id = resolver.get_id(
    entity_type="module",
    repo_uri="https://github.com/example/repo",
    path="src/mymodule.py",
    qualified_name="myapp.core",
)

1.2 CanonicalNormalizer (cogant/normalize/canonical.py)

Purpose: Convert language-specific facts into canonical NodeKind objects.

Mapping Examples: - python:class → NodeKind.CLASS - javascript:async_function → NodeKind.FUNCTION - java:interface → NodeKind.CLASS

Key Methods: - normalize() - Convert single LanguageFact to NormalizedFact - normalize_batch() - Convert multiple facts - to_node() - Create Node object from normalized fact - get_normalization_stats() - Track unmapped facts