Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix LT-21939 #264

Merged
merged 3 commits into from
Oct 23, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,13 @@ public Word ApplyRhs(PatternRule<Word, ShapeNode> rule, Match<Word, ShapeNode> m
_allomorph,
output.MorphologicalRuleApplicationCount.ToString()
);

if (outputNewMorph == null)
{
// There are no new output morphs in a truncation rule,
// so we add its allomorph to the last output shape.
string morphID = output.MorphologicalRuleApplicationCount.ToString();
output.MarkMorph(new List<ShapeNode>() { output.Shape.Last }, _allomorph, morphID);
}
var markedAllomorphs = new HashSet<Allomorph>();
foreach (Annotation<ShapeNode> inputMorph in match.Input.Morphs)
{
Expand All @@ -178,11 +184,24 @@ public Word ApplyRhs(PatternRule<Word, ShapeNode> rule, Match<Word, ShapeNode> m
}
else if (inputMorph.Parent == null && !markedAllomorphs.Contains(allomorph))
{
// an existing morph has been completely subsumed by the new morph
// mark the subsumed morph so we don't lose track of it
// this is only necessary if the allomorph hasn't already been marked elsewhere
Annotation<ShapeNode> outputMorph = output.MarkSubsumedMorph(outputNewMorph, allomorph, morphID);
MarkSubsumedMorphs(match.Input, output, inputMorph, outputMorph);
// This is only necessary if the allomorph hasn't already been marked elsewhere.
if (outputNewMorph == null)
{
// There are no new output morphs in a truncation rule,
// So we add allomorph to the first output shape.
output.MarkMorph(new List<ShapeNode>() { output.Shape.First }, allomorph, morphID);
}
else
{
// an existing morph has been completely subsumed by the new morph
// mark the subsumed morph so we don't lose track of it
Annotation<ShapeNode> outputMorph = output.MarkSubsumedMorph(
outputNewMorph,
allomorph,
morphID
);
MarkSubsumedMorphs(match.Input, output, inputMorph, outputMorph);
}
}
markedAllomorphs.Add(allomorph);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1192,7 +1192,7 @@ public void TruncateRules()
Morphophonemic.MorphologicalRules.Add(truncate);

var morpher = new Morpher(TraceManager, Language);
AssertMorphsEqual(morpher.ParseWord("sa"), "32");
AssertMorphsEqual(morpher.ParseWord("sa"), "32 3SG");

truncate.Allomorphs.Clear();
truncate.Allomorphs.Add(
Expand All @@ -1208,7 +1208,7 @@ public void TruncateRules()
);

morpher = new Morpher(TraceManager, Language);
AssertMorphsEqual(morpher.ParseWord("ag"), "32");
AssertMorphsEqual(morpher.ParseWord("ag"), "32 3SG");

truncate.Allomorphs.Clear();
truncate.Allomorphs.Add(
Expand All @@ -1224,7 +1224,7 @@ public void TruncateRules()
);

morpher = new Morpher(TraceManager, Language);
AssertMorphsEqual(morpher.ParseWord("ag"), "32");
AssertMorphsEqual(morpher.ParseWord("ag"), "32 3SG");

truncate.Allomorphs.Clear();
truncate.Allomorphs.Add(
Expand All @@ -1240,7 +1240,7 @@ public void TruncateRules()
);

morpher = new Morpher(TraceManager, Language);
AssertMorphsEqual(morpher.ParseWord("sa"), "32");
AssertMorphsEqual(morpher.ParseWord("sa"), "32 3SG");

truncate.Allomorphs.Clear();
truncate.Allomorphs.Add(
Expand Down Expand Up @@ -1866,10 +1866,32 @@ public void SubsumedAffix()
);
Morphophonemic.MorphologicalRules.Add(nominalizer);

var deleteVowelSuffix = new AffixProcessRule
{
Name = "delete_vowel_suffix",
Gloss = "PRES",
RequiredSyntacticFeatureStruct = FeatureStruct.New(Language.SyntacticFeatureSystem).Symbol("V").Value,
};
deleteVowelSuffix.Allomorphs.Add(
new AffixProcessAllomorph
{
Lhs =
{
Pattern<Word, ShapeNode>.New("1").Annotation(any).OneOrMore.Value,
Pattern<Word, ShapeNode>.New("2").Annotation(vowel).Value
},
Rhs = { new CopyFromInput("1") }
}
);
Morphophonemic.MorphologicalRules.Add(deleteVowelSuffix);

var morpher = new Morpher(TraceManager, Language);
AssertMorphsEqual(morpher.ParseWord("tagu"), "47 3SG");
AssertMorphsEqual(morpher.ParseWord("tags"), "47 3SG PAST");
AssertMorphsEqual(morpher.ParseWord("tagsv"), "47 3SG PAST NOM");
// Test deleteVowelSuffix.
AssertMorphsEqual(morpher.ParseWord("tag"), "47 3SG PRES", "47");
AssertMorphsEqual(morpher.ParseWord("bubib"), "42 PRES", "43 PRES");
}

[Test]
Expand Down
Loading