From f28237ba50faddaeee54dc454005b192db60e8ab Mon Sep 17 00:00:00 2001 From: John Maxwell Date: Wed, 4 Dec 2024 08:44:17 -0800 Subject: [PATCH 1/2] Fix bug with MorphologicalRuleOrder.Linear for LT-21988 --- .../AnalysisStratumRule.cs | 13 ++----------- .../HermitCrabTestBase.cs | 9 +++++++++ .../MorpherTests.cs | 6 ++++++ 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/SIL.Machine.Morphology.HermitCrab/AnalysisStratumRule.cs b/src/SIL.Machine.Morphology.HermitCrab/AnalysisStratumRule.cs index 97c31c2e..0edc7f9b 100644 --- a/src/SIL.Machine.Morphology.HermitCrab/AnalysisStratumRule.cs +++ b/src/SIL.Machine.Morphology.HermitCrab/AnalysisStratumRule.cs @@ -69,17 +69,8 @@ public IEnumerable Apply(Word input) _prulesRule.Apply(input); input.Freeze(); - IEnumerable 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 mruleOutWords = ApplyTemplates(input).Concat(ApplyMorphologicalRules(input)); Debug.Assert(mruleOutWords != null); var output = new HashSet(FreezableEqualityComparer.Default) { input }; diff --git a/tests/SIL.Machine.Morphology.HermitCrab.Tests/HermitCrabTestBase.cs b/tests/SIL.Machine.Morphology.HermitCrab.Tests/HermitCrabTestBase.cs index d6b56ed6..74d80ffa 100644 --- a/tests/SIL.Machine.Morphology.HermitCrab.Tests/HermitCrabTestBase.cs +++ b/tests/SIL.Machine.Morphology.HermitCrab.Tests/HermitCrabTestBase.cs @@ -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) diff --git a/tests/SIL.Machine.Morphology.HermitCrab.Tests/MorpherTests.cs b/tests/SIL.Machine.Morphology.HermitCrab.Tests/MorpherTests.cs index a01ec12c..e17f09f9 100644 --- a/tests/SIL.Machine.Morphology.HermitCrab.Tests/MorpherTests.cs +++ b/tests/SIL.Machine.Morphology.HermitCrab.Tests/MorpherTests.cs @@ -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] From 1e77851007716e361b0312187d88f67ed3be7219 Mon Sep 17 00:00:00 2001 From: John Maxwell Date: Wed, 4 Dec 2024 08:51:43 -0800 Subject: [PATCH 2/2] Fix formatting --- .../HermitCrabTestBase.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/SIL.Machine.Morphology.HermitCrab.Tests/HermitCrabTestBase.cs b/tests/SIL.Machine.Morphology.HermitCrab.Tests/HermitCrabTestBase.cs index 74d80ffa..a7736f41 100644 --- a/tests/SIL.Machine.Morphology.HermitCrab.Tests/HermitCrabTestBase.cs +++ b/tests/SIL.Machine.Morphology.HermitCrab.Tests/HermitCrabTestBase.cs @@ -821,7 +821,7 @@ 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)