Skip to content

feat(metrics): Mutual Information / Kollokationen (Token-Paar-Assoziation) #49

@aspala

Description

@aspala

Was & Warum

Misst, welche Token-Paare überzufällig zusammen auftreten (Kollokationen). Hohe Mutual Information = feste Idiome/Boilerplate (defmodule+do, use+GenServer), niedrige = freie Kombination (arithmetische Operanden). Idiom-/Boilerplate-Erkennung über Assoziation statt reiner Häufigkeit.

Skala

Verhalten Beispiel erwartete MI
hoch (festes Idiom) defmodule X do / use GenServer hohe MI für das Paar
mittel Enum.map + Funktion mittlere MI
niedrig (frei) a + b; c * d; e - f MI ≈ 0

Umsetzung

  • Neues Modul lib/codeqa/metrics/file/collocations.ex, @behaviour CodeQA.Metrics.File.FileMetric.
  • Input: Bigram-Counts über ctx.tokens (gleiche Basis wie feat(metrics): Conditional Entropy & Markov-Perplexity (Token-Sequenz-Vorhersagbarkeit) #42). Pointwise MI: PMI(a,b) = log( P(a,b) / (P(a)·P(b)) ). Aggregieren zu mittlerer/maximaler PMI + Top-Kollokationen.
  • keys: ["mean_pmi", "max_pmi", "top_collocations"].
  • Registrieren in lib/codeqa/engine/analyzer.ex.
  • Edge-Cases: < 2 Tokens → Nullwerte.

Test

  • test/codeqa/metrics/file/collocations_test.exs, Muster wie brevity_test.exs.
  • Assertion: defmodule X do ... end wiederholt → defmoduleXdo als Top-Kollokation; rein variierende Arithmetik → niedrige mean_pmi.

Hinweis

Teilt sich die Bigram-Basis mit #42 (Conditional Entropy) und #45. Getrennte Module, kein Shared State.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions