diff --git a/src/SIL.Machine.Morphology.HermitCrab/AnalysisStratumRule.cs b/src/SIL.Machine.Morphology.HermitCrab/AnalysisStratumRule.cs index 48bc2474..ea46aa79 100644 --- a/src/SIL.Machine.Morphology.HermitCrab/AnalysisStratumRule.cs +++ b/src/SIL.Machine.Morphology.HermitCrab/AnalysisStratumRule.cs @@ -127,11 +127,11 @@ internal IEnumerable Apply(Word input, ref int alternativeCount) _prulesRule.Apply(input); input.Freeze(); - IDictionary shapeWord = null; + IDictionary wordCache = null; // Don't merge if tracing because it messes up the tracing. bool mergeEquivalentAnalyses = _morpher.MergeEquivalentAnalyses && !_morpher.TraceManager.IsTracing; if (mergeEquivalentAnalyses) - shapeWord = new Dictionary(FreezableEqualityComparer.Default); + wordCache = new Dictionary(); // AnalysisStratumRule.Apply should cover the inverse of SynthesisStratumRule.Apply. IEnumerable mruleOutWords = ApplyTemplates(input).Concat(ApplyMorphologicalRules(input)); @@ -152,14 +152,13 @@ internal IEnumerable Apply(Word input, ref int alternativeCount) mruleOutWord.Source = origInput; if (mergeEquivalentAnalyses) { - Shape shape = mruleOutWord.Shape; - Word canonicalWord; - if (shapeWord.TryGetValue(shape, out canonicalWord)) + var key = AnalysisStateKey.PinAndKey(mruleOutWord); + if (wordCache.TryGetValue(key, out Word canonicalWord)) { canonicalWord.Alternatives.Add(mruleOutWord); continue; } - shapeWord[shape] = mruleOutWord; + wordCache[key] = mruleOutWord; } output.Add(mruleOutWord); if (_morpher.TraceManager.IsTracing)