Skip to content

Commit 5b9e474

Browse files
LT-22137 (#425)
* Fix for LT-10373 Change-Id: Id5176780bd7b0b77a91badf4af5c3dcd7bec1467 * LT-22138: Add UI for exception "features" in compound rules Change-Id: I3fde502e57a604f65cbe440f6529e67275cb16c6 * LT-22139 Add exception "features" for compound rules for XAmple Change-Id: Ib246809bbaaa4940b56d15a63d5221a878ccdce8 * LT-22144 Prod restricts in compounds in XAmple word grammar debugger Change-Id: I7887192686a64ecfd5f6b3550417114e473f214a * LT-22138: make inactive prod restricts show in grey Change-Id: I170dcb5b338b0d09d0984525a91a80c8ffbea3b5 * LT-22141: add prod restricts in compounds to morph sketch Change-Id: I10ba91423d1540a8cd1ff2204a86bd3939568323 * LT-22140 add prod restricts to Hermit Crab Change-Id: I145dc82cbe9646f3579fa2477f25488aac561c53 --------- Co-authored-by: Jason Naylor <jasonleenaylor@users.noreply.github.com>
1 parent 338e882 commit 5b9e474

29 files changed

Lines changed: 2626 additions & 844 deletions

Build/mkall.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@
236236
<ParatextNugetVersion>9.4.0.1-beta</ParatextNugetVersion>
237237
<LcmNugetVersion>11.0.0-beta0131</LcmNugetVersion>
238238
<IcuNugetVersion>70.1.123</IcuNugetVersion>
239-
<HermitCrabNugetVersion>3.6.6</HermitCrabNugetVersion>
239+
<HermitCrabNugetVersion>3.6.7</HermitCrabNugetVersion>
240240
<IPCFrameworkVersion>1.1.1-beta0001</IPCFrameworkVersion>
241241
<!-- bt393 is the master branch build of ExCss for Windows development. Update when appropriate. -->
242242
<ExCssBuildType Condition="'$(OS)'=='Windows_NT'">bt393</ExCssBuildType>

Build/nuget-common/packages.config

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@
6363
<package id="SIL.libpalaso.l10ns" version="6.0.0" targetFramework="net461" />
6464
<package id="SIL.Lift" version="15.0.0-beta0117" targetFramework="net462" />
6565
<package id="SIL.Media" version="15.0.0-beta0117" targetFramework="net462" />
66-
<package id="SIL.Machine" version="3.6.6" targetFramework="netstandard2.0" />
67-
<package id="SIL.Machine.Morphology.HermitCrab" version="3.6.6" targetFramework="netstandard2.0" />
66+
<package id="SIL.Machine" version="3.6.7" targetFramework="netstandard2.0" />
67+
<package id="SIL.Machine.Morphology.HermitCrab" version="3.6.7" targetFramework="netstandard2.0" />
6868
<package id="SIL.ParatextShared" version="7.4.0.1" targetFramework="net40" /> <!-- REVIEW (Hasso) 2023.05: do we still integrate with PT 7? -->
6969
<package id="SIL.Scripture" version="15.0.0-beta0117" targetFramework="net461" />
7070
<package id="SIL.TestUtilities" version="15.0.0-beta0117" targetFramework="net461" />

DistFiles/Language Explorer/Configuration/Parts/Morphology.fwlayout

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,22 @@
4343
<layout class="MoStemMsa" type="detail" name="Category">
4444
<part ref="Category"/>
4545
<part ref="InflectionClass"/>
46+
<part ref="ProdRestrict" visibility="ifdata"/>
4647
</layout>
4748
<layout class="MoStemMsa" type="detail" name="CategoryDisabled">
4849
<part ref="CategoryDisabled"/>
4950
<part ref="InflectionClassDisabled"/>
51+
<part ref="ProdRestrictDisabled" visibility="ifdata"/>
5052
</layout>
5153
<layout class="MoStemMsa" type="detail" name="Result">
5254
<part ref="Category"/>
5355
<part ref="InflectionClass"/>
56+
<part ref="ProdRestrict" visibility="ifdata"/>
5457
</layout>
5558
<layout class="MoStemMsa" type="detail" name="ResultDisabled">
5659
<part ref="CategoryDisabled"/>
5760
<part ref="InflectionClassDisabled"/>
61+
<part ref="ProdRestrictDisabled" visibility="ifdata"/>
5862
</layout>
5963

6064

DistFiles/Language Explorer/Configuration/Parts/MorphologyParts.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,11 @@
667667
</chooserInfo>
668668
</slice>
669669
</part>
670+
<part id="MoStemMsa-Detail-ProdRestrictDisabled" type="Detail">
671+
<slice field="ProdRestrict" label='Exception "Features"' textStyle="Disabled Text" editor="Custom" assemblyPath="MorphologyEditorDll.dll" class="SIL.FieldWorks.XWorks.MorphologyEditor.AdhocCoProhibVectorReferenceDisabledSlice" menu="mnuDataTree-Help">
672+
<deParams displayProperty="LongName" ws="vernacular"/>
673+
</slice>
674+
</part>
670675
<part id="MoStemMsa-Detail-PartOfSpeech" type="Detail">
671676
<slice field="PartOfSpeech" label="Category" editor="atomicreferencepos" menu="mnuDataTree-Help">
672677
<deParams ws="best analorvern"/>
@@ -2106,6 +2111,14 @@
21062111
<part id="MoBinaryCompoundRule-Detail-LeftMsa" type="Detail">
21072112
<obj field="LeftMsa" label="Left MSA" layout="LeftMsa"/>
21082113
</part>
2114+
<part id="MoBinaryCompoundRule-Detail-ProdRestrict" type="Detail">
2115+
<slice field="ProdRestrict" label='Exception "Features"' editor="possVectorReference" menu="mnuDataTree-Help">
2116+
<deParams ws="best analorvern"/>
2117+
<chooserInfo text='The following exception "features" are available.'>
2118+
<chooserLink type="goto" label='Edit the Exception "Features"' tool="ProdRestrictEdit"/>
2119+
</chooserInfo>
2120+
</slice>
2121+
</part>
21092122
<part id="MoBinaryCompoundRule-Detail-RightMsa" type="Detail">
21102123
<obj field="RightMsa" label="Right MSA" layout="RightMsa"/>
21112124
</part>

Src/LexText/ParserCore/FwXmlTraceManager.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
using SIL.Machine.Annotations;
1414
using System.Collections.Generic;
1515
using System.Text;
16+
using SIL.Machine.Rules;
17+
using SIL.Core.ClearShare;
1618

1719
namespace SIL.FieldWorks.WordWorks.Parser
1820
{
@@ -91,6 +93,40 @@ public void MorphologicalRuleNotUnapplied(IMorphologicalRule rule, int subruleIn
9193
{
9294
}
9395

96+
public void CompoundingRuleNotUnapplied(IMorphologicalRule rule, int subruleIndex, Word input, FailureReason reason, object obj)
97+
{
98+
var trace = new XElement("CompoundingRuleAnalysisTrace",
99+
CreateMorphologicalRuleElement(rule));
100+
var crule = rule as CompoundingRule;
101+
if (crule != null)
102+
{
103+
var stremProdRestricts = obj as MprFeatureSet;
104+
if (stremProdRestricts != null)
105+
{
106+
trace.Add(new XElement("FailureReason", new XAttribute("type", "missingProdRestrict"),
107+
new XElement("StemProdRestricts", stremProdRestricts.Select(f => new XElement("MprFeature", f))),
108+
new XElement("RuleProdRestricts", crule.NonHeadProdRestrictionsMprFeatures.Select(f => new XElement("MprFeature", f)))));
109+
}
110+
}
111+
trace.Add(new XElement("Output", "*None*"));
112+
((XElement)input.CurrentTrace).Add(trace);
113+
}
114+
115+
public void CompoundingRuleNotApplied(IMorphologicalRule rule, int subruleIndex, Word input, FailureReason reason, object failureObj)
116+
{
117+
var trace = new XElement("CompoundingRuleSynthesisTrace",
118+
CreateMorphologicalRuleElement(rule));
119+
var crule = rule as CompoundingRule;
120+
if (crule != null)
121+
{
122+
trace.Add(new XElement("FailureReason", new XAttribute("type", "missingProdRestrict"),
123+
new XElement("StemProdRestricts", input.MprFeatures.Select(f => new XElement("MprFeature", f))),
124+
new XElement("RuleProdRestricts", crule.HeadProdRestrictionsMprFeatures.Select(f => new XElement("MprFeature", f)))));
125+
}
126+
trace.Add(new XElement("Output", "*None*"));
127+
((XElement)input.CurrentTrace).Add(trace);
128+
}
129+
94130
public void LexicalLookup(Stratum stratum, Word input)
95131
{
96132
var trace = new XElement("LexLookupTrace",

Src/LexText/ParserCore/HCLoader.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,10 @@ private void LoadLanguage()
177177

178178
var prodRestrictsGroup = new MprFeatureGroup { Name = "exceptionFeatures", MatchType = MprFeatureGroupMatchType.All };
179179
foreach (ICmPossibility prodRestrict in m_cache.LanguageProject.MorphologicalDataOA.ProdRestrictOA.ReallyReallyAllPossibilities)
180+
{
180181
LoadMprFeature(prodRestrict, prodRestrictsGroup);
182+
183+
}
181184
if (prodRestrictsGroup.MprFeatures.Count > 0)
182185
m_language.MprFeatureGroups.Add(prodRestrictsGroup);
183186

@@ -1838,19 +1841,29 @@ private CompoundingRule LoadEndoCompoundingRule(IMoEndoCompound compoundRule)
18381841
{
18391842
var headRequiredFS = new FeatureStruct();
18401843
var nonheadRequiredFS = new FeatureStruct();
1844+
var headProdResticts = new MprFeatureSet();
1845+
var nonheadProdResticts = new MprFeatureSet();
18411846
if (compoundRule.HeadLast)
18421847
{
18431848
if (compoundRule.RightMsaOA.PartOfSpeechRA != null)
18441849
headRequiredFS.AddValue(m_posFeature, LoadAllPartsOfSpeech(compoundRule.RightMsaOA.PartOfSpeechRA));
18451850
if (compoundRule.LeftMsaOA.PartOfSpeechRA != null)
18461851
nonheadRequiredFS.AddValue(m_posFeature, LoadAllPartsOfSpeech(compoundRule.LeftMsaOA.PartOfSpeechRA));
1852+
if (compoundRule.RightMsaOA.ProdRestrictRC.Count > 0)
1853+
CreateProdRestricts(compoundRule.RightMsaOA.ProdRestrictRC, headProdResticts);
1854+
if (compoundRule.LeftMsaOA.ProdRestrictRC.Count > 0)
1855+
CreateProdRestricts(compoundRule.LeftMsaOA.ProdRestrictRC, nonheadProdResticts);
18471856
}
18481857
else
18491858
{
18501859
if (compoundRule.RightMsaOA.PartOfSpeechRA != null)
18511860
nonheadRequiredFS.AddValue(m_posFeature, LoadAllPartsOfSpeech(compoundRule.RightMsaOA.PartOfSpeechRA));
18521861
if (compoundRule.LeftMsaOA.PartOfSpeechRA != null)
18531862
headRequiredFS.AddValue(m_posFeature, LoadAllPartsOfSpeech(compoundRule.LeftMsaOA.PartOfSpeechRA));
1863+
if (compoundRule.RightMsaOA.ProdRestrictRC.Count > 0)
1864+
CreateProdRestricts(compoundRule.RightMsaOA.ProdRestrictRC, nonheadProdResticts);
1865+
if (compoundRule.LeftMsaOA.ProdRestrictRC.Count > 0)
1866+
CreateProdRestricts(compoundRule.LeftMsaOA.ProdRestrictRC, headProdResticts);
18541867
}
18551868
headRequiredFS.Freeze();
18561869
nonheadRequiredFS.Freeze();
@@ -1870,6 +1883,8 @@ private CompoundingRule LoadEndoCompoundingRule(IMoEndoCompound compoundRule)
18701883
Name = compoundRule.Name.BestAnalysisAlternative.Text,
18711884
HeadRequiredSyntacticFeatureStruct = headRequiredFS,
18721885
NonHeadRequiredSyntacticFeatureStruct = nonheadRequiredFS,
1886+
HeadProdRestrictionsMprFeatures = headProdResticts,
1887+
NonHeadProdRestrictionsMprFeatures = nonheadProdResticts,
18731888
OutSyntacticFeatureStruct = outFS,
18741889
Properties = { { HCParser.CRuleID, compoundRule.Hvo } }
18751890
};
@@ -1894,6 +1909,14 @@ private CompoundingRule LoadEndoCompoundingRule(IMoEndoCompound compoundRule)
18941909
return hcCompoundRule;
18951910
}
18961911

1912+
private void CreateProdRestricts(ILcmReferenceCollection<ICmPossibility> ruleProdRestricts, MprFeatureSet prodResticts)
1913+
{
1914+
foreach (var prodRstrict in ruleProdRestricts)
1915+
{
1916+
prodResticts.Add(m_mprFeatures[prodRstrict]);
1917+
}
1918+
}
1919+
18971920
private IEnumerable<CompoundingRule> LoadExoCompoundingRule(IMoExoCompound compoundRule)
18981921
{
18991922
var rightRequiredFS = new FeatureStruct();
@@ -1908,6 +1931,12 @@ private IEnumerable<CompoundingRule> LoadExoCompoundingRule(IMoExoCompound compo
19081931
if (compoundRule.ToMsaOA.PartOfSpeechRA != null)
19091932
outFS.AddValue(m_posFeature, m_posFeature.PossibleSymbols["pos" + compoundRule.ToMsaOA.PartOfSpeechRA.Hvo]);
19101933
outFS.Freeze();
1934+
var headProdResticts = new MprFeatureSet();
1935+
var nonheadProdResticts = new MprFeatureSet();
1936+
if (compoundRule.RightMsaOA.ProdRestrictRC.Count > 0)
1937+
CreateProdRestricts(compoundRule.RightMsaOA.ProdRestrictRC, headProdResticts);
1938+
if (compoundRule.LeftMsaOA.ProdRestrictRC.Count > 0)
1939+
CreateProdRestricts(compoundRule.LeftMsaOA.ProdRestrictRC, nonheadProdResticts);
19111940

19121941
var headPattern = new Pattern<Word, ShapeNode>("head", AnyPlus());
19131942
headPattern.Freeze();
@@ -1919,6 +1948,8 @@ private IEnumerable<CompoundingRule> LoadExoCompoundingRule(IMoExoCompound compo
19191948
Name = compoundRule.Name.BestAnalysisAlternative.Text,
19201949
HeadRequiredSyntacticFeatureStruct = rightRequiredFS,
19211950
NonHeadRequiredSyntacticFeatureStruct = leftRequiredFS,
1951+
HeadProdRestrictionsMprFeatures = headProdResticts,
1952+
NonHeadProdRestrictionsMprFeatures = nonheadProdResticts,
19221953
OutSyntacticFeatureStruct = outFS,
19231954
Properties = { { HCParser.CRuleID, compoundRule.Hvo } }
19241955
};
@@ -1944,6 +1975,8 @@ private IEnumerable<CompoundingRule> LoadExoCompoundingRule(IMoExoCompound compo
19441975
Name = compoundRule.Name.BestAnalysisAlternative.Text,
19451976
HeadRequiredSyntacticFeatureStruct = leftRequiredFS,
19461977
NonHeadRequiredSyntacticFeatureStruct = rightRequiredFS,
1978+
HeadProdRestrictionsMprFeatures = nonheadProdResticts,
1979+
NonHeadProdRestrictionsMprFeatures = headProdResticts,
19471980
OutSyntacticFeatureStruct = outFS,
19481981
Properties = { { HCParser.CRuleID, compoundRule.Hvo } }
19491982
};

Src/LexText/ParserCore/ParserCoreTests/HCLoaderTests.cs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,27 @@ public void EndoCompoundRule()
944944
Assert.That(subrule.HeadLhs.Select(p => p.ToString()), Is.EqualTo(new[] {AnyPlus}));
945945
Assert.That(subrule.NonHeadLhs.Select(p => p.ToString()), Is.EqualTo(new[] {AnyPlus}));
946946
Assert.That(subrule.Rhs.Select(a => a.ToString()), Is.EqualTo(new[] {"<nonhead>", "+", "<head>"}));
947+
948+
// test for exception "features"
949+
compoundRule.LeftMsaOA.ProdRestrictRC.Add(AddExceptionFeature("Left prod restrict"));
950+
LoadLanguage();
951+
952+
Assert.That(m_lang.Strata[0].MorphologicalRules.Count, Is.EqualTo(1));
953+
hcCompoundRule = (CompoundingRule)m_lang.Strata[0].MorphologicalRules[0];
954+
955+
Assert.That(hcCompoundRule.HeadProdRestrictionsMprFeatures.Count, Is.EqualTo(0));
956+
Assert.That(hcCompoundRule.NonHeadProdRestrictionsMprFeatures.Count, Is.EqualTo(1));
957+
Assert.That(hcCompoundRule.NonHeadProdRestrictionsMprFeatures.ElementAt(0).Name, Is.EqualTo("Left prod restrict"));
958+
959+
compoundRule.RightMsaOA.ProdRestrictRC.Add(AddExceptionFeature("Right prod restrict"));
960+
LoadLanguage();
961+
962+
Assert.That(m_lang.Strata[0].MorphologicalRules.Count, Is.EqualTo(1));
963+
hcCompoundRule = (CompoundingRule)m_lang.Strata[0].MorphologicalRules[0];
964+
965+
Assert.That(hcCompoundRule.NonHeadProdRestrictionsMprFeatures.Count, Is.EqualTo(1));
966+
Assert.That(hcCompoundRule.HeadProdRestrictionsMprFeatures.Count, Is.EqualTo(1));
967+
Assert.That(hcCompoundRule.HeadProdRestrictionsMprFeatures.ElementAt(0).Name, Is.EqualTo("Right prod restrict"));
947968
}
948969

949970
[Test]
@@ -984,6 +1005,28 @@ public void ExoCompoundRule()
9841005
Assert.That(subrule.NonHeadLhs.Select(p => p.ToString()), Is.EqualTo(new[] {AnyPlus}));
9851006
Assert.That(subrule.Rhs.Select(a => a.ToString()), Is.EqualTo(new[] {"<head>", "+", "<nonhead>"}));
9861007
Assert.That(subrule.OutMprFeatures.Select(mf => mf.ToString()), Is.EquivalentTo(new[] {"inflClass"}));
1008+
1009+
// test for exception "features"
1010+
compoundRule.LeftMsaOA.ProdRestrictRC.Add(AddExceptionFeature("Left prod restrict"));
1011+
LoadLanguage();
1012+
1013+
Assert.That(m_lang.Strata[0].MorphologicalRules.Count, Is.EqualTo(2));
1014+
hcCompoundRule = (CompoundingRule)m_lang.Strata[0].MorphologicalRules[0];
1015+
1016+
Assert.That(hcCompoundRule.HeadProdRestrictionsMprFeatures.Count, Is.EqualTo(0));
1017+
Assert.That(hcCompoundRule.NonHeadProdRestrictionsMprFeatures.Count, Is.EqualTo(1));
1018+
Assert.That(hcCompoundRule.NonHeadProdRestrictionsMprFeatures.ElementAt(0).Name, Is.EqualTo("Left prod restrict"));
1019+
1020+
compoundRule.RightMsaOA.ProdRestrictRC.Add(AddExceptionFeature("Right prod restrict"));
1021+
LoadLanguage();
1022+
1023+
Assert.That(m_lang.Strata[0].MorphologicalRules.Count, Is.EqualTo(2));
1024+
hcCompoundRule = (CompoundingRule)m_lang.Strata[0].MorphologicalRules[0];
1025+
1026+
Assert.That(hcCompoundRule.NonHeadProdRestrictionsMprFeatures.Count, Is.EqualTo(1));
1027+
Assert.That(hcCompoundRule.HeadProdRestrictionsMprFeatures.Count, Is.EqualTo(1));
1028+
Assert.That(hcCompoundRule.HeadProdRestrictionsMprFeatures.ElementAt(0).Name, Is.EqualTo("Right prod restrict"));
1029+
9871030
}
9881031

9891032
[Test]

Src/LexText/ParserCore/ParserCoreTests/M3ToXAmpleTransformerTests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public class M3ToXAmpleTransformerTests
4040
string m_sM3FXTIrregularlyInflectedFormsDump;
4141
string m_sM3FXTQuechuaMYLDump;
4242
string m_sM3FXTEmiFLExDump;
43+
string m_sM3FXTCompundRulesWithExceptionFeaturesFLExDump;
4344
private string m_sAbazaOrderClassPlayDump;
4445
readonly Dictionary<string, XPathDocument> m_mapXmlDocs = new Dictionary<string, XPathDocument>();
4546

@@ -87,6 +88,7 @@ private void SetUpM3FXTDump()
8788
m_sAbazaOrderClassPlayDump = Path.Combine(m_sTestPath, "Abaza-OrderclassPlay.xml");
8889
m_sM3FXTQuechuaMYLDump = Path.Combine(m_sTestPath, "QuechuaMYLFxtResult.xml");
8990
m_sM3FXTEmiFLExDump = Path.Combine(m_sTestPath, "emi-flexFxtResult.xml");
91+
m_sM3FXTCompundRulesWithExceptionFeaturesFLExDump = Path.Combine(m_sTestPath, "CompundRulesWithExceptionFeatures.xml");
9092

9193
SetupXmlDocument(m_sM3FXTDump);
9294
SetupXmlDocument(m_sM3FXTCircumfixDump);
@@ -105,6 +107,7 @@ private void SetUpM3FXTDump()
105107
SetupXmlDocument(m_sAbazaOrderClassPlayDump);
106108
SetupXmlDocument(m_sM3FXTQuechuaMYLDump);
107109
SetupXmlDocument(m_sM3FXTEmiFLExDump);
110+
SetupXmlDocument(m_sM3FXTCompundRulesWithExceptionFeaturesFLExDump);
108111
}
109112

110113
private void SetupXmlDocument(string filepath)
@@ -182,6 +185,7 @@ public void CreateXAmpleWordGrammarFile()
182185
ApplyTransform(m_sM3FXTAffixAlloFeatsDump, m_gramTransform, "AffixAlloFeatsWordGrammar.txt");
183186
ApplyTransform(m_sM3FXTLatinDump, m_gramTransform, "LatinWordGrammar.txt");
184187
ApplyTransform(m_sM3FXTQuechuaMYLDump, m_gramTransform, "QuechuaMYLgram.txt");
188+
ApplyTransform(m_sM3FXTCompundRulesWithExceptionFeaturesFLExDump, m_gramTransform, "CompundRulesWithExceptionFeaturesWordGrammar.txt");
185189
}
186190
private void ApplyTransform(string sInput, XslCompiledTransform transform, string sExpectedOutput)
187191
{

0 commit comments

Comments
 (0)