What's New
Features
-
compareRoots— Root-AST structural similarity API — A new
deterministic, model-free API for comparing two RIDDLRootASTs and
getting back a similarity score with a full breakdown. Surfaced on the
cross-platformRiddlLibfacade (JVM, JS, and Native):def compareRoots(a: Root, b: Root)(using PlatformContext): RootSimilarity def similarityMarkdown(a: Root, b: Root)(using PlatformContext): String
RootSimilaritycarries per-kind counts (Map[String, (Int, Int)]),
fuzzy-matched and unmatched name pairs per definition kind, structural
metrics (max depth and top-level breadth), and an overall weighted score
in[0.0, 1.0]— exactly1.0for identical models, low for disjoint
ones.similarityMarkdownrenders the same data as a human/AI-readable
report.Matching is on definition kind + fuzzy name (lowercase-alphanumeric
normalization with greedy best Levenshtein-ratio pairing), making it
location- and case-independent — a renamed-but-structurally-equal
model still scores high on structure, and identically named definitions
at different source locations still match. It never uses
Definition.equals/hashCode(which include source location). Scoring
weights DDD-structural kinds (contexts, entities, message types) above
incidental ones, and blends a count-vector cosine term so that structure
is rewarded independently of naming.This was built for consumers that generate RIDDL models and need a
regression guard on how closely a generated model matches a
hand-authored reference — but it is a general-purpose AST diff/compare
utility usable by any tool.
Notes
- Additive only — new methods on the
RiddlLibtrait and object; no
existing signatures changed. Fully backward compatible with the 1.x line. - The comparison core (
RootComparison,RootSimilarity,
KindComparison) lives incom.ossuminc.riddl.passes.analysisand is
Native-safe (no regex or platform formatting). - Verified across JVM, JS, and Native builds.