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-18682 #170

Merged
merged 6 commits into from
Oct 4, 2024
Merged
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
37 changes: 31 additions & 6 deletions Src/LexText/ParserCore/FwXmlTraceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
using SIL.Machine.Morphology.HermitCrab.MorphologicalRules;
using SIL.Machine.Morphology.HermitCrab.PhonologicalRules;
using SIL.Machine.FeatureModel;
using SIL.Machine.Annotations;
using System.Collections.Generic;
using System.Text;

namespace SIL.FieldWorks.WordWorks.Parser
{
Expand Down Expand Up @@ -129,16 +132,18 @@ public void PhonologicalRuleApplied(IPhonologicalRule rule, int subruleIndex, Wo
{
((XElement) output.CurrentTrace).Add(new XElement("PhonologicalRuleSynthesisTrace",
CreateHCRuleElement("PhonologicalRule", rule),
CreateWordElement("Input", input, false),
CreateWordElement("Output", output, false)));
// Show bracketed to make debugging phonological rules easier (fixes LT-18682).
CreateWordElement("Input", input, false, true),
CreateWordElement("Output", output, false, true)));
}

public void PhonologicalRuleNotApplied(IPhonologicalRule rule, int subruleIndex, Word input, FailureReason reason, object failureObj)
{
var pruleTrace = new XElement("PhonologicalRuleSynthesisTrace",
CreateHCRuleElement("PhonologicalRule", rule),
CreateWordElement("Input", input, false),
CreateWordElement("Output", input, false));
// Show bracketed to make debugging phonological rules easier (fixes LT-18682).
CreateWordElement("Input", input, false, true),
CreateWordElement("Output", input, false, true));

var rewriteRule = rule as RewriteRule;
if (rewriteRule != null)
Expand Down Expand Up @@ -386,16 +391,36 @@ private static XElement CreateInflFeaturesElement(string name, FeatureStruct fs)
return new XElement(name, fs.Head().ToString().Replace(",", ""));
}

private static XElement CreateWordElement(string name, Word word, bool analysis)
private static XElement CreateWordElement(string name, Word word, bool analysis, bool bracketed = false)
{
string wordStr;
if (word == null)
wordStr = "*None*";
else
wordStr = analysis ? word.Shape.ToRegexString(word.Stratum.CharacterDefinitionTable, true) : word.Shape.ToString(word.Stratum.CharacterDefinitionTable, true);
wordStr = analysis
? word.Shape.ToRegexString(word.Stratum.CharacterDefinitionTable, true)
: bracketed ? ToBracketedString(word.Shape, word.Stratum.CharacterDefinitionTable)
: word.Shape.ToString(word.Stratum.CharacterDefinitionTable, true);
return new XElement(name, wordStr);
}

private static string ToBracketedString(IEnumerable<ShapeNode> nodes, CharacterDefinitionTable table)
{
StringBuilder stringBuilder = new StringBuilder();
foreach (ShapeNode node in nodes)
{
string text = table.GetMatchingStrReps(node).FirstOrDefault();
if (text != null)
{
if (text.Length > 1)
text = "(" + text + ")";
stringBuilder.Append(text);
}
}

return stringBuilder.ToString();
}

private XElement CreateMorphemeElement(Morpheme morpheme)
{
var msaID = (int?) morpheme.Properties[HCParser.MsaID] ?? 0;
Expand Down
Loading