Skip to content
Open
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
11 changes: 5 additions & 6 deletions src/SIL.Machine.Morphology.HermitCrab/AnalysisStratumRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,11 @@ internal IEnumerable<Word> Apply(Word input, ref int alternativeCount)

_prulesRule.Apply(input);
input.Freeze();
IDictionary<Shape, Word> shapeWord = null;
IDictionary<AnalysisStateKey, Word> 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<Shape, Word>(FreezableEqualityComparer<Shape>.Default);
wordCache = new Dictionary<AnalysisStateKey, Word>();

// AnalysisStratumRule.Apply should cover the inverse of SynthesisStratumRule.Apply.
IEnumerable<Word> mruleOutWords = ApplyTemplates(input).Concat(ApplyMorphologicalRules(input));
Expand All @@ -152,14 +152,13 @@ internal IEnumerable<Word> 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)
Expand Down
3 changes: 3 additions & 0 deletions src/SIL.Machine.Morphology.HermitCrab/Word.cs
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,9 @@ public override bool ValueEquals(Word other)
if (IsFrozen && other.IsFrozen && GetFrozenHashCode() != other.GetFrozenHashCode())
return false;

// We don't need to include SyntacticFeatureStruct because it is uniquely determined
// by the combination of _mruleApps and _realizationalFS. AffixTemplates check
// but don't change SyntacticFeatureStruct.
return _shape.ValueEquals(other._shape)
&& _realizationalFS.ValueEquals(other._realizationalFS)
&& _nonHeadApps.SequenceEqual(other._nonHeadApps, FreezableEqualityComparer<Word>.Default)
Expand Down
Loading