Skip to content

Filter final templates in analysis - #491

Draft
jtmaxwell3 wants to merge 11 commits into
masterfrom
filter-final-templates-in-analysis
Draft

Filter final templates in analysis#491
jtmaxwell3 wants to merge 11 commits into
masterfrom
filter-final-templates-in-analysis

Conversation

@jtmaxwell3

@jtmaxwell3 jtmaxwell3 commented Aug 28, 2026

Copy link
Copy Markdown
Collaborator

Hermit Crab tries all possible interleavings of templates and affix process rules during analysis even if the templates are final. This is expensive if there are a lot of final templates and affix process rules that could apply to a word. Sometimes it takes minutes or hours to parse a word because of this.

There is code in SynthesisAffixProcessRule.Apply that prevents derivational affixes from applying to final templates during synthesis, but it is skipped if the input’s root is partial:

       // if a final template was last applied,
       // do not allow a non-partial rule to apply unless the input is partial
       if (
           !_rule.IsTemplateRule
           && (input.IsLastAppliedRuleFinal ?? false)
           && !input.IsPartial
           && !_rule.IsPartial
       )
       {
           if (_morpher.TraceManager.IsTracing)
           {
               _morpher.TraceManager.MorphologicalRuleNotApplied(
                   _rule,
                   -1,
                   input,
                   FailureReason.NonPartialRuleProhibitedAfterFinalTemplate,
                   null
               );
           }
           return Enumerable.Empty<Word>();
       }

The corresponding analysis code can’t filter final templates being unapplied after derivational affixes because it doesn’t know whether the root is partial yet. However, if nothing in the grammar is final then we can filter final templates if they are unapplied after a non-template affix. To support this, I added the properties Morpher.IsFinal, Morpher.AlwaysEnforceFinalTemplates, and Word.FinalTemplateState. I also added AffixStateKey.FinalTemplateState.


This change is Reviewable

@jtmaxwell3
jtmaxwell3 marked this pull request as draft August 28, 2026 20:54
@codecov-commenter

codecov-commenter commented Sep 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 82.60870% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.76%. Comparing base (5d26fac) to head (96c97f7).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
...icalRules/AnalysisRealizationalAffixProcessRule.cs 18.75% 12 Missing and 1 partial ⚠️
....Machine.Morphology.HermitCrab/AnalysisStateKey.cs 50.00% 1 Missing and 1 partial ⚠️
...rab/MorphologicalRules/SynthesisCompoundingRule.cs 0.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #491      +/-   ##
==========================================
+ Coverage   73.53%   73.76%   +0.23%     
==========================================
  Files         449      449              
  Lines       37633    37719      +86     
  Branches     5174     5184      +10     
==========================================
+ Hits        27673    27825     +152     
+ Misses       8824     8767      -57     
+ Partials     1136     1127       -9     

☔ 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.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants