Skip to content

Filter final templates in analysis - #491

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

Filter final templates in analysis#491
jtmaxwell3 wants to merge 6 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, MorphemicMorphologicalRule.IsFinalTemplate and Word.IsLastUnappliedRuleNonTemplate. I also added AffixStateKey.IsLastUnappliedRuleNonTemplate.


This change is Reviewable

@jtmaxwell3
jtmaxwell3 marked this pull request as draft August 28, 2026 20:54
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.

1 participant