Skip to content

HermitCrab: analysis metathesis keeps the middle context so it undoes synthesis - #620

Open
johnml1135 wants to merge 6 commits into
masterfrom
fix/619-metathesis-middle-context
Open

johnml1135 wants to merge 6 commits into
masterfrom
fix/619-metathesis-middle-context

Conversation

@johnml1135

@johnml1135 johnml1135 commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator

HermitCrab metathesis analysis now exactly undoes synthesis when something sits between the two switch groups. The analysis spec used to drop the nodes between the groups while synthesis leaves them in place. So a rule t i k -> k i t produced kita from tika, but parsing kita never recovered tika.

  • Middle context: analysis now keeps the middle context (segments, natural classes and non-switch groups) and swaps only the switch groups.
  • Boundaries: boundaries in the middle are skipped, because analysis never sees them.
  • Unchanged: adjacent-switch behaviour.

Tests cover a middle segment (inside and outside a group) and a middle natural class. They failed before the fix. HermitCrab.Tests: 179 passed. ./local_check.sh --agent-strict is clean.

Fixes #619

🤖 Generated with Claude Code


This change is Reviewable

Also affects rewrite rules: DeepCloneExceptBoundaries is shared with rewrite-subrule environments, CopyFromInput and ModifyFromInput; a boundary-only alternative now stays as an empty group there too. Pinned by RewriteRuleTests.BoundaryOnlyAlternativeInEnvironment_AnalysisUndoesSynthesis.

@codecov-commenter

codecov-commenter commented Nov 6, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.59%. Comparing base (e7422c1) to head (47a83b6).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #620      +/-   ##
==========================================
+ Coverage   75.53%   75.59%   +0.06%     
==========================================
  Files         455      455              
  Lines       38933    38955      +22     
  Branches     5428     5436       +8     
==========================================
+ Hits        29407    29449      +42     
+ Misses       8376     8360      -16     
+ Partials     1150     1146       -4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@claude

This comment has been minimized.

@claude

This comment has been minimized.

johnml1135 and others added 6 commits November 20, 2026 09:28
…ch groups so it undoes synthesis

Fixes #619.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Remove boundaries recursively from middle context because analysis filters them out, and accept untyped constraints.
…nvironment still matches the surface

DeepCloneExceptBoundaries is shared by metathesis and rewrite-rule analysis, so the boundary-only alternative
change reaches rewrite environments too.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…tive as an empty group

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…udget

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@johnml1135
johnml1135 force-pushed the fix/619-metathesis-middle-context branch from 77efe56 to 47a83b6 Compare November 20, 2026 15:36
morpher.GenerateWords(entry, System.Array.Empty<Morpheme>(), new FeatureStruct()),
Is.EquivalentTo(new[] { "kita" })
);
AssertMorphsEqual(morpher.ParseWord("kita"), "root", "tika");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: F6. This test fails when run alone: it expects gloss tika, but its only entry is root. tika comes from entries the MiddleSegment/MiddleNaturalClass tests leave in the shared Morphophonemic stratum, which TestCleanup does not clear. dotnet test --filter UntypedMiddleConstraint_AnalysisUndoesSynthesis: 4 failed, "Expected: equivalent to < root, tika > But was: < root >". Expect only root.

PatternNode<Word, ShapeNode>[] nodes = pattern.Children.ToArray();
int firstGroupIndex = Array.FindIndex(nodes, n => n is Group<Word, ShapeNode>);
int lastGroupIndex = Array.FindLastIndex(nodes, n => n is Group<Word, ShapeNode>);
for (int i = firstGroupIndex; i <= lastGroupIndex; i++)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: F7. A misspelled LeftSwitchName or RightSwitchName no longer fails when the Morpher is built. The old groups[name] threw KeyNotFoundException. This loop just treats an unmatched group as an ordinary one, so the error only shows up at parse time. A pattern with no groups now throws IndexOutOfRangeException on nodes[-1]. Checking both names against groups first would keep the early error. Unverified: read, not run.

@claude

claude Bot commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

Approve with fixes. 47a83b6 fixes F5: the PR text now names the rewrite-rule effect, and a rewrite-rule test pins it at both parallelism settings.

  1. Most important: Important F6, at MetathesisRuleTests.cs:426. UntypedMiddleConstraint_AnalysisUndoesSynthesis passes only because other tests leave a tika entry in the shared stratum; run alone, all four cases fail.
  2. Counts: Critical 0, Important 1 (F6), Low 1 (F7).
  3. Ran: gh pr checks 620: comment hygiene passes; the ubuntu and windows builds and claude-review are pending. The compare with 77efe56 reported diverged, so this round reviewed the whole PR again. /code-review high returned 5 candidates; 2 were on lines this PR does not touch. dotnet test --filter UntypedMiddleConstraint_AnalysisUndoesSynthesis failed 4 of 4 (expected root, tika, got root).
  4. Not verified: F7 was read, not run. The full suite was not run here at the new head; that is left to CI.

Public API, target framework, package, machine.py parity: None verified.

F1 addressed. F2 addressed. F3 addressed. F4 addressed. F5 addressed. F6 new. F7 new, unverified.

Reviewed at 47a83b6

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HermitCrab: analysis metathesis drops the middle context that synthesis keeps

3 participants