semantic

package
v0.2.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 15, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplySemanticEvidence

func ApplySemanticEvidence(baseSimilarity float64, signals1, signals2 SemanticSignals) float64

ApplySemanticEvidence adjusts a base (CFG/DFA-derived) similarity with AST-level counter-evidence: fully disjoint string-literal vocabularies, absence of any shared strong signal, or incompatible return categories each discount the score. Missing evidence on either side is given the benefit of the doubt.

func CompareCFGFeatures

func CompareCFGFeatures(f1, f2 *CFGFeatures) float64

CompareCFGFeatures computes similarity between two CFG feature sets. Returns a value between 0.0 (completely different) and 1.0 (identical).

func CompareDFAFeatures

func CompareDFAFeatures(f1, f2 *dfa.DFAFeatures) float64

CompareDFAFeatures computes similarity between two DFA feature sets. Returns a value between 0.0 (completely different) and 1.0 (identical).

func ComputeSimilarity

func ComputeSimilarity(cfg1, cfg2 *cfg.CFG, dfa1, dfa2 *dfa.DFAInfo, config Config) float64

ComputeSimilarity computes the combined CFG+DFA semantic similarity. Returns 0.0 when either CFG is nil (e.g. parse/build failures) to avoid false-positive matches on absent semantic data.

Types

type CFGFeatures

type CFGFeatures struct {
	BlockCount       int
	EdgeCount        int
	EdgeTypeCounts   map[cfg.EdgeType]int
	CyclomaticNumber int
	BranchingFactor  float64
	LoopEdgeCount    int
	ConditionalCount int
}

CFGFeatures holds structural features extracted from a CFG.

func ExtractCFGFeatures

func ExtractCFGFeatures(c *cfg.CFG) *CFGFeatures

ExtractCFGFeatures extracts structural features from a CFG.

type Config

type Config struct {
	EnableDFA        bool
	CFGFeatureWeight float64
	DFAFeatureWeight float64
}

Config holds configuration for semantic similarity computation.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns the default semantic similarity configuration.

type SemanticSignals

type SemanticSignals struct {
	StrongSignals    map[string]struct{}
	ReturnCategories map[string]struct{}
	StringLiterals   map[string]struct{}
}

SemanticSignals holds the language-independent semantic evidence extracted from a fragment's AST. Language adapters populate the sets: StrongSignals with kind-prefixed identifiers (e.g. "call:open", "attr:write"), ReturnCategories with return-shape categories (e.g. "none", "literal", "collection"), and StringLiterals with meaningful string constants.

func NewSemanticSignals

func NewSemanticSignals() SemanticSignals

NewSemanticSignals returns an empty signal set ready to be populated.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL