Skip to content

Commit ae83b1c

Browse files
committed
Add output exception "feature" to compound rules & do XML config
1 parent 4a6d420 commit ae83b1c

File tree

7 files changed

+53
-2
lines changed

7 files changed

+53
-2
lines changed

src/SIL.Machine.Morphology.HermitCrab/HermitCrabInput.dtd

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,8 +371,11 @@
371371
nonheadPartsOfSpeech refers to one or more PartOfSpeech IDs
372372
headSubcategorizedRules refers to one or more SyntacticRule IDs
373373
nonheadSubcategorizedRules refers to one or more SyntacticRule IDs
374+
headProdRestrictionsMprFeatures refers to zero or more exception "features" IDs
375+
nonHeadProdRestrictionsMprFeatures refers to zero or more exception "features" IDs
374376
outputPartOfSpeech refers to a PartOfSpeech ID
375377
outputSubcategorization refers to one or more SyntacticRule IDs
378+
outputProdRestrictionsMprFeatures refers to zero or more exception "features" IDs
376379
outputObligatoryFeatures refers to one or more (HeadFeature) FeatureDefinition IDs
377380
(Note: what was Output Subcategorization (sub) in the text form of Hermit Crab has been split into
378381
the outputSubcategorization attribute plus the OutputSubcategorizationOverrides element (and its content).)
@@ -388,8 +391,11 @@
388391
nonHeadPartsOfSpeech IDREFS #IMPLIED
389392
headSubcategorizedRules IDREFS #IMPLIED
390393
nonHeadSubcategorizedRules IDREFS #IMPLIED
394+
headProdRestrictionsMprFeatures IDREFS #IMPLIED
395+
nonHeadProdRestrictionsMprFeatures IDREFS #IMPLIED
391396
outputPartOfSpeech IDREF #IMPLIED
392397
outputSubcategorization IDREFS #IMPLIED
398+
outputProdRestrictionsMprFeatures IDREFS #IMPLIED
393399
outputObligatoryFeatures IDREFS #IMPLIED
394400
>
395401

src/SIL.Machine.Morphology.HermitCrab/MorphologicalRules/CompoundingRule.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public CompoundingRule()
2222
NonHeadRequiredSyntacticFeatureStruct = FeatureStruct.New().Value;
2323
HeadProdRestrictionsMprFeatures = new MprFeatureSet();
2424
NonHeadProdRestrictionsMprFeatures = new MprFeatureSet();
25+
OutputProdRestrictionsMprFeatures = new MprFeatureSet();
2526
OutSyntacticFeatureStruct = FeatureStruct.New().Value;
2627

2728
_subrules = new List<CompoundingSubrule>();
@@ -46,6 +47,8 @@ public IList<CompoundingSubrule> Subrules
4647

4748
public MprFeatureSet NonHeadProdRestrictionsMprFeatures { get; set; }
4849

50+
public MprFeatureSet OutputProdRestrictionsMprFeatures { get; set; }
51+
4952
public FeatureStruct OutSyntacticFeatureStruct { get; set; }
5053

5154
public ICollection<Feature> ObligatorySyntacticFeatures

src/SIL.Machine.Morphology.HermitCrab/MorphologicalRules/SynthesisCompoundingRule.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ public IEnumerable<Word> Apply(Word input)
176176
Word outWord = ApplySubrule(_rule.Subrules[i], headMatch, nonHeadMatch);
177177

178178
outWord.MprFeatures.AddOutput(_rule.Subrules[i].OutMprFeatures);
179+
outWord.MprFeatures.AddOutput(_rule.OutputProdRestrictionsMprFeatures);
179180

180181
outWord.SyntacticFeatureStruct = syntacticFS;
181182
outWord.SyntacticFeatureStruct.PriorityUnion(_rule.OutSyntacticFeatureStruct);

src/SIL.Machine.Morphology.HermitCrab/XmlLanguageLoader.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,6 +1214,16 @@ out IMorphologicalRule mrule
12141214
fs.Freeze();
12151215
compRule.OutSyntacticFeatureStruct = fs;
12161216

1217+
compRule.HeadProdRestrictionsMprFeatures.UnionWith(
1218+
LoadMprFeatures((string)compRuleElem.Attribute("headProdRestrictionsMprFeatures"))
1219+
);
1220+
compRule.NonHeadProdRestrictionsMprFeatures.UnionWith(
1221+
LoadMprFeatures((string)compRuleElem.Attribute("nonHeadProdRestrictionsMprFeatures"))
1222+
);
1223+
compRule.OutputProdRestrictionsMprFeatures.UnionWith(
1224+
LoadMprFeatures((string)compRuleElem.Attribute("outputProdRestrictionsMprFeatures"))
1225+
);
1226+
12171227
var obligHeadIDsStr = (string)compRuleElem.Attribute("outputObligatoryFeatures");
12181228
if (!string.IsNullOrEmpty(obligHeadIDsStr))
12191229
{

src/SIL.Machine.Morphology.HermitCrab/XmlLanguageWriter.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,26 @@ private XElement WriteCompoundingRule(CompoundingRule crule, Dictionary<IMorphol
836836
if (nonHeadRequiredFootFS != null)
837837
ruleElem.Add(new XElement("NonHeadRequiredFootFeatures", WriteFeatureStruct(nonHeadRequiredFootFS)));
838838

839+
MprFeatureSet headProdRestrictionsMprFeatures = crule.HeadProdRestrictionsMprFeatures;
840+
if (headProdRestrictionsMprFeatures.Count > 0)
841+
ruleElem.Add(
842+
WriteIDs("headProdRestrictionsMprFeatures", crule.HeadProdRestrictionsMprFeatures, _mprFeatures)
843+
);
844+
MprFeatureSet nonHeadProdRestrictionsMprFeatures = crule.NonHeadProdRestrictionsMprFeatures;
845+
if (nonHeadProdRestrictionsMprFeatures.Count > 0)
846+
ruleElem.Add(
847+
WriteIDs(
848+
"nonHeadProdRestrictionsMprFeatures",
849+
crule.NonHeadProdRestrictionsMprFeatures,
850+
_mprFeatures
851+
)
852+
);
853+
MprFeatureSet outputProdRestrictionsMprFeatures = crule.OutputProdRestrictionsMprFeatures;
854+
if (outputProdRestrictionsMprFeatures.Count > 0)
855+
ruleElem.Add(
856+
WriteIDs("outputProdRestrictionsMprFeatures", crule.OutputProdRestrictionsMprFeatures, _mprFeatures)
857+
);
858+
839859
return ruleElem;
840860
}
841861

tests/SIL.Machine.Morphology.HermitCrab.Tests/MorphologicalRules/CompoundingRuleTests.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ public void ProdRestrictRule()
213213
// The word should no longer parse
214214
Assert.That(morpher.ParseWord("pʰutdat"), Is.Empty);
215215

216-
// Removee the exception "feature" from the head root
216+
// Remove the exception "feature" from the head root
217217
head.MprFeatures.Remove(excFeat);
218218
// Add the exception "feature" to the nonhead root
219219
var nonhead = Allophonic.Entries.ElementAt(5);
@@ -222,6 +222,17 @@ public void ProdRestrictRule()
222222
output = morpher.ParseWord("pʰutdat").ToList();
223223
AssertMorphsEqual(output, "5 8");
224224
AssertRootAllomorphsEquals(output, "5");
225+
226+
// Test output exception "feature"
227+
// The output should not have it yet
228+
Assert.That(rule1.OutputProdRestrictionsMprFeatures.Count == 0);
229+
// Add the exception "feature" to the output set
230+
rule1.OutputProdRestrictionsMprFeatures.Add(excFeat);
231+
// It should still parse and the output MprFeatures should have the exception "feature"
232+
output = morpher.ParseWord("pʰutdat").ToList();
233+
AssertMorphsEqual(output, "5 8");
234+
AssertRootAllomorphsEquals(output, "5");
235+
Assert.That(rule1.OutputProdRestrictionsMprFeatures.Contains(excFeat));
225236
}
226237

227238
private static void AssertRootAllomorphsEquals(IEnumerable<Word> words, params string[] expected)

tests/SIL.Machine.Morphology.HermitCrab.Tests/TestData/XmlLanguageSerializationTests.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@
216216
<Stratum characterDefinitionTable="table1" morphologicalRuleOrder="unordered" phonologicalRules="prule1 prule2" morphologicalRules="mrule1">
217217
<Name>stratum 1</Name>
218218
<MorphologicalRuleDefinitions>
219-
<CompoundingRule id="mrule1" blockable="false" multipleApplication="3" headPartsOfSpeech="pos1" nonHeadPartsOfSpeech="pos2" outputPartOfSpeech="pos2" outputObligatoryFeatures="hfeat2">
219+
<CompoundingRule id="mrule1" blockable="false" multipleApplication="3" headPartsOfSpeech="pos1" nonHeadPartsOfSpeech="pos2" outputPartOfSpeech="pos2" outputObligatoryFeatures="hfeat2" headProdRestrictionsMprFeatures="mpr1" nonHeadProdRestrictionsMprFeatures="mpr2" outputProdRestrictionsMprFeatures="mpr3">
220220
<Name>compounding rule 1</Name>
221221
<CompoundingSubrules>
222222
<CompoundingSubrule>

0 commit comments

Comments
 (0)