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-21088: Yellow Box while parsing words after promoting category #188

Merged
merged 7 commits into from
Oct 30, 2024
53 changes: 53 additions & 0 deletions Src/LexText/ParserCore/M3ToXAmpleTransformer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Linq;
using SIL.Utils;
using SIL.WordWorks.GAFAWS.PositionAnalysis;
using System.Collections.Generic;

namespace SIL.FieldWorks.WordWorks.Parser
{
Expand Down Expand Up @@ -94,6 +95,7 @@ public void PrepareTemplatesForXAmpleFiles(XDocument domModel, XDocument domTemp
foreach (XElement templateElem in domTemplate.Root.Elements("PartsOfSpeech").Elements("PartOfSpeech")
.Where(pe => pe.DescendantsAndSelf().Elements("AffixTemplates").Elements("MoInflAffixTemplate").Any(te => te.Element("PrefixSlots") != null || te.Element("SuffixSlots") != null)))
{
DefineUndefinedSlots(templateElem);
// transform the POS that has templates to GAFAWS format
string gafawsFile = m_database + "gafawsData.xml";
TransformPosInfoToGafawsInputFormat(templateElem, gafawsFile);
Expand All @@ -103,6 +105,57 @@ public void PrepareTemplatesForXAmpleFiles(XDocument domModel, XDocument domTemp
}
}

/// <summary>
/// Define undefined slots found in templateElem in AffixSlots.
/// </summary>
private void DefineUndefinedSlots(XElement templateElem)
{
ISet<string> undefinedSlots = new HashSet<string>();
GetUndefinedSlots(templateElem, undefinedSlots);
if (undefinedSlots.Count == 0)
return;
// Add undefined slots to AffixSlots.
foreach (XElement elem in templateElem.Elements())
{
if (elem.Name == "AffixSlots")
{
foreach (string slotId in undefinedSlots)
{
XElement slot = new XElement("MoInflAffixSlot");
slot.SetAttributeValue("Id", slotId);
elem.Add(slot);
}
break;
}
}
}

private void GetUndefinedSlots(XElement element, ISet<string> undefinedSlots)
{
// Recursively get undefined slots.
foreach (XElement elem in element.Elements())
{
GetUndefinedSlots(elem, undefinedSlots);
}
// Record slots encountered.
if (element.Name == "PrefixSlots" || element.Name == "SuffixSlots")
{
undefinedSlots.Add((string) element.Attribute("dst"));
}
// Remove slots that are defined at this level.
// NB: This must happen after we recursively get undefined slots.
foreach (XElement elem in element.Elements())
{
if (elem.Name == "AffixSlots")
{
foreach (XElement slot in elem.Elements())
{
undefinedSlots.Remove((string)slot.Attribute("Id"));
}
}
}
}

private void InsertOrderclassInfo(XDocument domModel, string resultFile)
{
// Check for a valid filename (see LT-6472).
Expand Down
Loading