Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/SIL.Machine.Morphology.HermitCrab.Tool/HCContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ internal class HCContext(Language language, TextWriter outWriter)

public void Compile()
{
_morpher = new Morpher(new TraceManager(), _language);
_morpher = new Morpher(new TraceManager { RetainWords = false }, _language);
}

public Language Language
Expand Down
47 changes: 4 additions & 43 deletions src/SIL.Machine.Morphology.HermitCrab.Tool/ParseCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,28 +74,19 @@ private void PrintTrace(Trace trace, int indent, HashSet<int> lineIndices)
_context.Out.Write("{0}: {1}", ruleLabel, trace.Source.Name);
first = false;
}
bool analysis = IsAnalysis(trace.Type);
if (trace.Input != null)
if (trace.InputText != null)
{
if (!first)
_context.Out.Write(", ");
first = false;
CharacterDefinitionTable table = trace.Input.Stratum.CharacterDefinitionTable;
_context.Out.Write(
"Input: {0}",
analysis ? trace.Input.Shape.ToRegexString(table, true) : trace.Input.Shape.ToString(table, true)
);
_context.Out.Write("Input: {0}", trace.InputText);
}
if (trace.Output != null)
if (trace.OutputText != null)
{
if (!first)
_context.Out.Write(", ");
first = false;
CharacterDefinitionTable table = trace.Output.Stratum.CharacterDefinitionTable;
_context.Out.Write(
"Output: {0}",
analysis ? trace.Output.Shape.ToRegexString(table, true) : trace.Output.Shape.ToString(table, true)
);
_context.Out.Write("Output: {0}", trace.OutputText);
}
if (trace.FailureReason != FailureReason.None)
{
Expand Down Expand Up @@ -130,36 +121,6 @@ private void PrintIndent(int indent, HashSet<int> lineIndices)
_context.Out.Write(lineIndices.Contains(i) ? "|" : " ");
}

private static bool IsAnalysis(TraceType type)
{
switch (type)
{
case TraceType.WordAnalysis:
case TraceType.LexicalLookup:
case TraceType.StratumAnalysisInput:
case TraceType.StratumAnalysisOutput:
case TraceType.TemplateAnalysisInput:
case TraceType.TemplateAnalysisOutput:
case TraceType.MorphologicalRuleAnalysis:
case TraceType.PhonologicalRuleAnalysis:
return true;

case TraceType.WordSynthesis:
case TraceType.Successful:
case TraceType.Failed:
case TraceType.Blocked:
case TraceType.StratumSynthesisInput:
case TraceType.StratumSynthesisOutput:
case TraceType.TemplateSynthesisInput:
case TraceType.TemplateSynthesisOutput:
case TraceType.MorphologicalRuleSynthesis:
case TraceType.PhonologicalRuleSynthesis:
return false;
}

return false;
}

private static string GetRuleLabelString(IHCRule rule)
{
if (rule is Stratum)
Expand Down
56 changes: 56 additions & 0 deletions src/SIL.Machine.Morphology.HermitCrab/Trace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,38 @@ internal Trace(TraceType type, IHCRule source)
SubruleIndex = -1;
}

private string _inputText;
private string _outputText;

internal void SetTexts(string inputText, string outputText)
{
_inputText = inputText;
_outputText = outputText;
}

private string FormatText(Word word)
{
return word?.GetTraceText(IsAnalysis(_type));
}

internal static bool IsAnalysis(TraceType type)
Comment thread
claude[bot] marked this conversation as resolved.
Resolved
{
switch (type)
{
case TraceType.WordAnalysis:
case TraceType.LexicalLookup:
case TraceType.StratumAnalysisInput:
case TraceType.StratumAnalysisOutput:
case TraceType.TemplateAnalysisInput:
case TraceType.TemplateAnalysisOutput:
case TraceType.MorphologicalRuleAnalysis:
case TraceType.PhonologicalRuleAnalysis:
return true;
default:
return false;
}
}

public TraceType Type
{
get { return _type; }
Expand All @@ -147,10 +179,34 @@ public IHCRule Source

public int SubruleIndex { get; internal set; }

/// <summary>
/// Gets the word this step started from. It is <c>null</c> when the node has no input, and always
/// <c>null</c> when <see cref="TraceManager.RetainWords"/> is <c>false</c>, because a retained word keeps
/// its whole shape alive for as long as the trace lives. Use <see cref="InputText"/> in both modes.
/// </summary>
public Word Input { get; internal set; }

/// <summary>
/// Gets the word this step produced. It is <c>null</c> when the node has no output, and always
/// <c>null</c> when <see cref="TraceManager.RetainWords"/> is <c>false</c>. Use <see cref="OutputText"/>
/// in both modes.
/// </summary>
public Word Output { get; internal set; }

/// <summary>
/// Gets the shape text of the input in its display form: the regular-expression form for analysis node
/// types except <see cref="TraceType.CompoundingRuleAnalysis"/>, and the plain form otherwise. It is
/// <c>null</c> when the node has no input. With retained words, the text is formatted from
/// <see cref="Input"/>; frozen words cache the formatted text for their lifetime.
/// </summary>
public string InputText => _inputText ?? FormatText(Input);
Comment thread
claude[bot] marked this conversation as resolved.
Resolved

/// <summary>
/// Gets the shape text of the output, in the same form as <see cref="InputText"/>. It is <c>null</c> when
/// the node has no output.
/// </summary>
public string OutputText => _outputText ?? FormatText(Output);

public FailureReason FailureReason { get; internal set; }
}
}
Loading
Loading