From a2a3c947af1704d6164258b05f4c07874fc31dff Mon Sep 17 00:00:00 2001 From: John Maxwell Date: Tue, 17 Sep 2024 11:52:57 -0700 Subject: [PATCH] Fix bugs in root guesser --- .../CharacterDefinitionTable.cs | 1 + src/SIL.Machine.Morphology.HermitCrab/Morpher.cs | 12 ++++++------ .../MorpherTests.cs | 1 + 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/SIL.Machine.Morphology.HermitCrab/CharacterDefinitionTable.cs b/src/SIL.Machine.Morphology.HermitCrab/CharacterDefinitionTable.cs index d08d231d..9e2fc8de 100644 --- a/src/SIL.Machine.Morphology.HermitCrab/CharacterDefinitionTable.cs +++ b/src/SIL.Machine.Morphology.HermitCrab/CharacterDefinitionTable.cs @@ -147,6 +147,7 @@ private bool GetShapeNodes(string str, out IEnumerable nodes, out int { NaturalClass naturalClass = _naturalClassLookup[className]; var node = new ShapeNode(naturalClass.FeatureStruct); + node.Annotation.IsNaturalClass = true; nodesList.Add(node); i = closePos + 1; continue; diff --git a/src/SIL.Machine.Morphology.HermitCrab/Morpher.cs b/src/SIL.Machine.Morphology.HermitCrab/Morpher.cs index 13424862..71d63220 100644 --- a/src/SIL.Machine.Morphology.HermitCrab/Morpher.cs +++ b/src/SIL.Machine.Morphology.HermitCrab/Morpher.cs @@ -375,13 +375,8 @@ private IEnumerable LexicalGuess(Word input) // Create a root allomorph for the guess. string shapeString = match.ToString(table, false); var root = new RootAllomorph(new Segments(table, shapeString)) { Guessed = true }; - // Point the root allomorph to the lexical pattern in FieldWorks. - if (lexicalPattern.Properties.ContainsKey("ID")) - root.Properties["ID"] = lexicalPattern.Properties["ID"]; - if (lexicalPattern.Morpheme != null && lexicalPattern.Morpheme.Properties.ContainsKey("ID")) - root.Morpheme.Properties["ID"] = lexicalPattern.Morpheme.Properties["ID"]; // Create a lexical entry to hold the root allomorph. - // (The root allmorph will point to the lexical entry.) + // (The root's Morpheme will point to the lexical entry.) var lexEntry = new LexEntry { Id = shapeString, @@ -391,6 +386,11 @@ private IEnumerable LexicalGuess(Word input) IsPartial = input.SyntacticFeatureStruct.IsEmpty }; lexEntry.Allomorphs.Add(root); + // Point the root allomorph to the lexical pattern in FieldWorks. + if (lexicalPattern.Properties.ContainsKey("ID")) + root.Properties["ID"] = lexicalPattern.Properties["ID"]; + if (lexicalPattern.Morpheme != null && lexicalPattern.Morpheme.Properties.ContainsKey("ID")) + root.Morpheme.Properties["ID"] = lexicalPattern.Morpheme.Properties["ID"]; // Create a new word that uses the root allomorph. Word newWord = input.Clone(); newWord.RootAllomorph = root; diff --git a/tests/SIL.Machine.Morphology.HermitCrab.Tests/MorpherTests.cs b/tests/SIL.Machine.Morphology.HermitCrab.Tests/MorpherTests.cs index 267d0160..4e7634c4 100644 --- a/tests/SIL.Machine.Morphology.HermitCrab.Tests/MorpherTests.cs +++ b/tests/SIL.Machine.Morphology.HermitCrab.Tests/MorpherTests.cs @@ -96,6 +96,7 @@ public void AnalyzeWord_CanGuess_ReturnsCorrectAnalysis() var naturalClass = new NaturalClass(new FeatureStruct()) { Name = "Any" }; Table1.AddNaturalClass(naturalClass); var lexicalPattern = new RootAllomorph(new Segments(Table1, "[Any]*")); + Assert.That(lexicalPattern.IsPattern); var morpher = new Morpher(TraceManager, Language); morpher.LexicalPatterns.Add(lexicalPattern);