Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug with MorphologicalRuleOrder.Linear for LT-21988 #279

Merged
merged 2 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading