|
3 | 3 | using SIL.Machine.FeatureModel; |
4 | 4 | using SIL.Machine.Matching; |
5 | 5 | using SIL.Machine.Morphology.HermitCrab.MorphologicalRules; |
| 6 | +using SIL.Machine.Morphology.HermitCrab.PhonologicalRules; |
6 | 7 |
|
7 | 8 | namespace SIL.Machine.Morphology.HermitCrab; |
8 | 9 |
|
@@ -38,6 +39,65 @@ public void AnalyzeWord_CanAnalyze_ReturnsCorrectAnalysis() |
38 | 39 | ); |
39 | 40 | } |
40 | 41 |
|
| 42 | + [Test] |
| 43 | + public void AnalyzeWord_CanAnalyzeLinear_ReturnsCorrectAnalysis() |
| 44 | + { |
| 45 | + var any = FeatureStruct.New().Symbol(HCFeatureSystem.Segment).Value; |
| 46 | + |
| 47 | + var edSuffix = new AffixProcessRule |
| 48 | + { |
| 49 | + Id = "PAST", |
| 50 | + Name = "ed_suffix", |
| 51 | + Gloss = "PAST", |
| 52 | + RequiredSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem).Symbol("V").Value |
| 53 | + }; |
| 54 | + edSuffix.Allomorphs.Add( |
| 55 | + new AffixProcessAllomorph |
| 56 | + { |
| 57 | + Lhs = { Pattern<Word, ShapeNode>.New("1").Annotation(any).OneOrMore.Value }, |
| 58 | + Rhs = { new CopyFromInput("1"), new InsertSegments(Table3, "+d") } |
| 59 | + } |
| 60 | + ); |
| 61 | + Morphophonemic.MorphologicalRules.Add(edSuffix); |
| 62 | + |
| 63 | + // Adding rules shouldn't block sagd analysis when Linear. |
| 64 | + var tSuffix = new AffixProcessRule |
| 65 | + { |
| 66 | + Id = "PLURAL", |
| 67 | + Name = "t_suffix", |
| 68 | + Gloss = "PLURAL", |
| 69 | + RequiredSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem).Symbol("N").Value |
| 70 | + }; |
| 71 | + tSuffix.Allomorphs.Add( |
| 72 | + new AffixProcessAllomorph |
| 73 | + { |
| 74 | + Lhs = { Pattern<Word, ShapeNode>.New("1").Annotation(any).OneOrMore.Value }, |
| 75 | + Rhs = { new CopyFromInput("1"), new InsertSegments(Table3, "+t") } |
| 76 | + } |
| 77 | + ); |
| 78 | + Morphophonemic.MorphologicalRules.Add(tSuffix); |
| 79 | + |
| 80 | + // Add a phonological rule so that "sagd" becomes "sag[dt]" during unapplication. |
| 81 | + // This is to verify that unapplication works correctly. |
| 82 | + var rule1 = new RewriteRule |
| 83 | + { |
| 84 | + Name = "rule1", |
| 85 | + Lhs = Pattern<Word, ShapeNode>.New().Annotation(Character(Table1, "t")).Value |
| 86 | + }; |
| 87 | + rule1.Subrules.Add( |
| 88 | + new RewriteSubrule { Rhs = Pattern<Word, ShapeNode>.New().Annotation(Character(Table1, "d")).Value } |
| 89 | + ); |
| 90 | + Morphophonemic.PhonologicalRules.Add(rule1); |
| 91 | + |
| 92 | + SetRuleOrder(MorphologicalRuleOrder.Linear); |
| 93 | + var morpher = new Morpher(TraceManager, Language); |
| 94 | + |
| 95 | + Assert.That( |
| 96 | + morpher.AnalyzeWord("sagd"), |
| 97 | + Is.EquivalentTo(new[] { new WordAnalysis(new IMorpheme[] { Entries["32"], edSuffix }, 0, "V") }) |
| 98 | + ); |
| 99 | + } |
| 100 | + |
41 | 101 | [Test] |
42 | 102 | public void AnalyzeWord_CannotAnalyze_ReturnsEmptyEnumerable() |
43 | 103 | { |
|
0 commit comments