Repository navigation
Add TraceManager.RetainWords to keep trace text, not Words #571
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) | ||
| { | ||
| 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; } | ||
|
|
@@ -147,10 +179,33 @@ 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 and the plain form otherwise. It is <c>null</c> when the node has no input. With retained words | ||
| /// it is computed from <see cref="Input"/> on each read. | ||
| /// </summary> | ||
| public string InputText => _inputText ?? FormatText(Input); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI: F2. With |
||
|
|
||
| /// <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; } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI: F1.
IsAnalysisomitsCompoundingRuleAnalysis, so that node's publicInputTextis the plain form, while theInputTextdoc promises the regular-expression form for analysis node types. Keeping CLI output byte-identical is a fair reason; name the exception in the doc so a library caller is not surprised.