Skip to content
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
5 changes: 5 additions & 0 deletions Src/GenerateHCConfig/ConsoleLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,5 +118,10 @@ public void OutOfScopeSlot(IMoInflAffixSlot slot, IMoInflAffixTemplate template,
{
Console.WriteLine(reason);
}

void IHCLoadErrorLogger.UnmatchedReduplicationIndexedClass(IMoForm form, string reason, string environment)
{
throw new NotImplementedException();
}
}
}
43 changes: 35 additions & 8 deletions Src/LexText/ParserCore/HCLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1471,16 +1471,17 @@ private AffixProcessAllomorph LoadFormAffixProcessAllomorph(IMoForm allo, IPhEnv
case MoMorphTypeTags.kMorphSuffixingInterfix:
case MoMorphTypeTags.kMorphEnclitic:
hcAllo.Lhs.Add(stemPattern);
hcAllo.Lhs.AddRange(LoadReduplicationPatterns(contexts.Item1));
var lhsPatterns = LoadReduplicationPatterns(contexts.Item1);
hcAllo.Lhs.AddRange(lhsPatterns);
var suffixNull = new Pattern<Word, ShapeNode>("suffixNull", SuffixNull());
suffixNull.Freeze();
hcAllo.Lhs.Add(suffixNull);

hcAllo.Rhs.Add(new CopyFromInput("stem"));
hcAllo.Rhs.AddRange(LoadReduplicationOutputActions(contexts.Item1));
hcAllo.Rhs.AddRange(LoadReduplicationOutputActions(contexts.Item1, lhsPatterns, allo));
hcAllo.Rhs.Add(new CopyFromInput("suffixNull"));
hcAllo.Rhs.Add(new InsertSegments(Segments("+")));
hcAllo.Rhs.AddRange(LoadReduplicationOutputActions(form));
hcAllo.Rhs.AddRange(LoadReduplicationOutputActions(form, lhsPatterns, allo));
break;

case MoMorphTypeTags.kMorphPrefix:
Expand All @@ -1489,13 +1490,14 @@ private AffixProcessAllomorph LoadFormAffixProcessAllomorph(IMoForm allo, IPhEnv
var prefixNull = new Pattern<Word, ShapeNode>("prefixNull", PrefixNull());
prefixNull.Freeze();
hcAllo.Lhs.Add(prefixNull);
hcAllo.Lhs.AddRange(LoadReduplicationPatterns(contexts.Item2));
lhsPatterns = LoadReduplicationPatterns(contexts.Item2);
hcAllo.Lhs.AddRange(lhsPatterns);
hcAllo.Lhs.Add(stemPattern);

hcAllo.Rhs.AddRange(LoadReduplicationOutputActions(form));
hcAllo.Rhs.AddRange(LoadReduplicationOutputActions(form, lhsPatterns, allo));
hcAllo.Rhs.Add(new InsertSegments(Segments("+")));
hcAllo.Rhs.Add(new CopyFromInput("prefixNull"));
hcAllo.Rhs.AddRange(LoadReduplicationOutputActions(contexts.Item2));
hcAllo.Rhs.AddRange(LoadReduplicationOutputActions(contexts.Item2, lhsPatterns, allo));
hcAllo.Rhs.Add(new CopyFromInput("stem"));
break;
}
Expand Down Expand Up @@ -1611,13 +1613,38 @@ private IEnumerable<Pattern<Word, ShapeNode>> LoadReduplicationPatterns(string p
}
}

private IEnumerable<MorphologicalOutputAction> LoadReduplicationOutputActions(string patternStr)
private IEnumerable<MorphologicalOutputAction> LoadReduplicationOutputActions(string patternStr, IEnumerable<Pattern<Word, ShapeNode>> patterns, IMoForm form)
{
foreach (string token in TokenizeContext(patternStr))
{
if (token.StartsWith("["))
{
yield return new CopyFromInput(XmlConvert.EncodeName(token.Substring(1, token.Length - 2).Trim()));
bool isValid = true;
if (token.Contains("^"))
{
// The ^ gets replaced by _x005E_ so we need to do it here to match in patterns
string indexedToken = token.Substring(1, token.Length - 2).Trim().Replace("^", "_x005E_");
isValid = patterns.Any(p => p.Name == indexedToken);
if (!isValid)
{
// add error message to logger
string envs = "";
var environments = form.AllomorphEnvironments;
if (environments != null)
{
StringBuilder sb = new StringBuilder();
foreach (IPhEnvironment env in environments)
{
sb.Append(env.ShortName);
sb.Append(" ");
}
envs = sb.ToString();
}
m_logger.UnmatchedReduplicationIndexedClass(form, "Ill-formed index:" + token, envs);
}
}
if (isValid)
yield return new CopyFromInput(XmlConvert.EncodeName(token.Substring(1, token.Length - 2).Trim()));
}
else
{
Expand Down
10 changes: 10 additions & 0 deletions Src/LexText/ParserCore/HCParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,16 @@ public void OutOfScopeSlot(IMoInflAffixSlot slot, IMoInflAffixTemplate template,
m_xmlWriter.WriteElementString("Reason", reason);
m_xmlWriter.WriteEndElement();
}
public void UnmatchedReduplicationIndexedClass(IMoForm form, string reason, string pattern)
{
m_xmlWriter.WriteStartElement("LoadError");
m_xmlWriter.WriteAttributeString("type", "unmatched-redup-indexed-class");
m_xmlWriter.WriteElementString("Form", form.Form.VernacularDefaultWritingSystem.Text);
m_xmlWriter.WriteElementString("Pattern", pattern);
m_xmlWriter.WriteElementString("Reason", reason);
m_xmlWriter.WriteElementString("Hvo", form.Hvo.ToString(CultureInfo.InvariantCulture));
m_xmlWriter.WriteEndElement();
}
}
}
}
1 change: 1 addition & 0 deletions Src/LexText/ParserCore/IHCLoadErrorLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ public interface IHCLoadErrorLogger
void InvalidRewriteRule(IPhRegularRule prule, string reason);
void InvalidStrata(string strata, string reason);
void OutOfScopeSlot(IMoInflAffixSlot slot, IMoInflAffixTemplate template, string reason);
void UnmatchedReduplicationIndexedClass(IMoForm form, string reason, string environment);
}
}
32 changes: 31 additions & 1 deletion Src/LexText/ParserCore/ParserCoreTests/HCLoaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ private enum LoadErrorType
InvalidEnvironment,
InvalidRedupForm,
InvalidRewriteRule,
InvalidStrata
InvalidStrata,
UnmatchedReduplicationIndexedClass
}

private class TestHCLoadErrorLogger : IHCLoadErrorLogger
Expand Down Expand Up @@ -99,6 +100,11 @@ public void OutOfScopeSlot(IMoInflAffixSlot slot, IMoInflAffixTemplate template,
{
throw new NotImplementedException();
}
public void UnmatchedReduplicationIndexedClass(IMoForm form, string reason, string patterns)
{
m_loadErrors.Add(Tuple.Create(LoadErrorType.UnmatchedReduplicationIndexedClass, (ICmObject)form));
}

}

private readonly List<Tuple<LoadErrorType, ICmObject>> m_loadErrors = new List<Tuple<LoadErrorType, ICmObject>>();
Expand Down Expand Up @@ -596,6 +602,30 @@ public void InvalidPartialReduplicationEnvironment()
LoadLanguage();

Assert.That(m_lang.Strata[0].MorphologicalRules.Count, Is.EqualTo(0));

// now check for missing indexed class which is removed but with an logged error message
// LT-18767
// case 1: the form has the indexed class, but the environment does not
var env = allo.PhoneEnvRC.ElementAt(0);
allo.PhoneEnvRC.Remove(env);
allo.PhoneEnvRC.Add(AddEnvironment("/_[C^1]"));
LoadLanguage();

Assert.That(m_lang.Strata[0].MorphologicalRules.Count, Is.EqualTo(1));
Assert.That(m_loadErrors.Count == 1);
var err = m_loadErrors.ElementAt(0);
Assert.That(err.Item1 == LoadErrorType.UnmatchedReduplicationIndexedClass);

// case 2: the environment has the indexed class, but the form does not
env = allo.PhoneEnvRC.ElementAt(0);
allo.PhoneEnvRC.Remove(env);
allo.PhoneEnvRC.Add(AddEnvironment("/_[C^2][V^1]"));
LoadLanguage();

Assert.That(m_lang.Strata[0].MorphologicalRules.Count, Is.EqualTo(1));
Assert.That(m_loadErrors.Count == 1);
err = m_loadErrors.ElementAt(0);
Assert.That(err.Item1 == LoadErrorType.UnmatchedReduplicationIndexedClass);
}

[Test]
Expand Down
15 changes: 15 additions & 0 deletions Src/Transforms/Presentation/FormatCommon.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,21 @@
<xsl:text> </xsl:text>
</li>
</xsl:when>
<xsl:when test="@type = 'unmatched-redup-indexed-class'">
<li>
<xsl:text>The reduplication form "</xsl:text>
<xsl:value-of select="Form" />
<xsl:text>" is invalid. Reason: </xsl:text>
<xsl:value-of select="Reason" />
<xsl:text> </xsl:text>
<span style="cursor:pointer; text-decoration:underline">
<xsl:attribute name="id">
<xsl:value-of select="Hvo"/>
</xsl:attribute>
<xsl:text>(Click here to see the entry.)</xsl:text>
</span>
</li>
</xsl:when>
<xsl:otherwise>
<!-- Do not expect any others to happen, but just in case, we show them in all their HC glory -->
<li><xsl:value-of select="."/></li>
Expand Down
Loading