Skip to content

Commit

Permalink
Fix bug with MorphologicalRuleOrder.Linear for LT-21988
Browse files Browse the repository at this point in the history
  • Loading branch information
jtmaxwell3 committed Dec 4, 2024
1 parent 3b98936 commit f28237b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
13 changes: 2 additions & 11 deletions src/SIL.Machine.Morphology.HermitCrab/AnalysisStratumRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,8 @@ public IEnumerable<Word> Apply(Word input)
_prulesRule.Apply(input);
input.Freeze();

IEnumerable<Word> mruleOutWords = null;
switch (_stratum.MorphologicalRuleOrder)
{
case MorphologicalRuleOrder.Linear:
mruleOutWords = ApplyTemplates(input);
break;

case MorphologicalRuleOrder.Unordered:
mruleOutWords = ApplyTemplates(input).Concat(ApplyMorphologicalRules(input));
break;
}
// AnalysisStratumRule.Apply should cover the inverse of SynthesisStratumRule.Apply.
IEnumerable<Word> mruleOutWords = ApplyTemplates(input).Concat(ApplyMorphologicalRules(input));
Debug.Assert(mruleOutWords != null);

var output = new HashSet<Word>(FreezableEqualityComparer<Word>.Default) { input };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,15 @@ public void TestCleanup()
stratum.MorphologicalRules.Clear();
stratum.AffixTemplates.Clear();
}
SetRuleOrder(MorphologicalRuleOrder.Unordered);
}

protected void SetRuleOrder(MorphologicalRuleOrder ruleOrder)
{
foreach (Stratum stratum in Language.Strata)
{
stratum.MorphologicalRuleOrder = ruleOrder;
}
}

public LexEntry AddEntry(string gloss, FeatureStruct syntacticFS, Stratum stratum, params string[] forms)
Expand Down
6 changes: 6 additions & 0 deletions tests/SIL.Machine.Morphology.HermitCrab.Tests/MorpherTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ public void AnalyzeWord_CanAnalyze_ReturnsCorrectAnalysis()
morpher.AnalyzeWord("sagd"),
Is.EquivalentTo(new[] { new WordAnalysis(new IMorpheme[] { Entries["32"], edSuffix }, 0, "V") })
);

SetRuleOrder(MorphologicalRuleOrder.Linear);
Assert.That(
morpher.AnalyzeWord("sagd"),
Is.EquivalentTo(new[] { new WordAnalysis(new IMorpheme[] { Entries["32"], edSuffix }, 0, "V") })
);
}

[Test]
Expand Down

0 comments on commit f28237b

Please sign in to comment.