Add standalone subtree classifier module (Refs #497)#254
Merged
Conversation
Introduce a pure, self-contained classifier that decides the coarse "bucket" a source subtree represents — the layer above the recognizers described in issue #497: - theme_presentation (CSS animation / JS that only toggles classes) - custom_block (cohesive, repeatable, user-editable content unit) - custom_application (stateful / data-driven; input drives logic) - custom_plugin (site-wide functional JS, not component-bound) - unknown (weak/conflicting -> conservative fallback) GENERIC structural signals only (DOM shape, declared CSS, associated JS); no fixture/site-specific strings. Conservative + confidence-scored: ties and weak evidence return unknown so the caller can fall back to core/html. Standalone module only — NOT wired into the conversion flow. Wiring is a deliberate follow-up after the HtmlTransformer decomposition (#242). HtmlTransformer and existing recognizers are untouched. Adds a plain-PHP unit suite (tests/unit) wired into composer test:canonical; existing canonical + 128 parity fixtures stay green. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
chubes4
added a commit
that referenced
this pull request
Jun 28, 2026
…258) Run the standalone SubtreeClassifier (#254) on subtrees that fall back to raw core/html and attach its verdict (bucket + confidence + top signals) to the existing fallback diagnostic. This surfaces, across the corpus, which core/html dumps the classifier believes should have been native blocks — the data the pattern-recognition swarm optimizes against. Measurement only: routing and block output are unchanged. The classifier runs solely on the core/html fallback emission path (script, canvas, template, inline SVG, form, iframe, unsupported-element), never per converted element, and only adds a `classification` key to the diagnostic. Parity 128 -> 128 with byte-identical block output; full composer test green. Adds a contract assertion that the canvas core/html fallback now carries a classifier verdict. Refs #497 Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #497
Summary
Standalone classifier v1 for the subtree classification taxonomy (#497). It is a pure, tested unit that decides the coarse bucket a source subtree fundamentally represents — the layer above the recognizers. Wiring it into the conversion flow is a deliberate follow-up after the HtmlTransformer decomposition (#242), which is actively in flight; this PR adds the module + tests only.
New namespace:
Automattic\BlocksEngine\PhpTransformer\HtmlToBlocks\ClassificationSubtreeClassifier—classify(DOMElement, ClassificationContext): ClassificationResultClassificationContext— declared CSS + associated JS + optional ancestryClassificationResult—bucket,confidence(0..1),signals(diagnostics)Buckets & generic signals (per #497)
data-wp-*); canvas. Input drives logic.core/html+ a diagnostic.Only generic structural signals are used (DOM shape, declared CSS text, associated JS text) — no fixture/site-specific strings. Conservative + confidence-scored: a minimum winning score and a minimum margin over the runner-up are required, otherwise
unknown.Tests
Plain-PHP unit suite
tests/unit/subtree-classifier.php(style oftests/contract/run.php), wired intocomposer test:canonicalvia a newtest:unitscript. 23 assertions across 10 cases: one confident case per bucket, ambiguous/weak →unknown, and negatives (decorative animation is not a block; static content is not an application; input-driven app is not a plugin; component-local tabs are not a plugin; single non-repeated unit → unknown).Gates
composer test:canonical— green (includes the new unit suite)composer parity— green, 128 fixtures unaffectedphp -lclean on all new filesScope guarantee
HtmlTransformer.phpand all existing converters/recognizers are untouched — additive only (3 source files + 1 test +composer.jsonscript wiring).DO NOT MERGE — standalone classifier v1; wiring into the conversion flow is a follow-up post-#242 decomposition.