Skip to content

Commit bd0608d

Browse files
authored
LT-22780: Improve Hermit Crab performance (#1176)
* Improve Hermit Crab performance * Add transforms and fix bugs * Address Devin's review; fix bugs * Respond to Jason's comment
1 parent 28450df commit bd0608d

10 files changed

Lines changed: 104 additions & 49 deletions

File tree

‎Build/SilVersions.props‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<SilLibPalasoL10nsVersion>18.0.0-beta0012</SilLibPalasoL10nsVersion>
1818
<SilChorusVersion>6.0.0-beta0065</SilChorusVersion>
1919
<SilChorusL10nsVersion>3.0.1</SilChorusL10nsVersion>
20-
<SilMachineVersion>3.9.2</SilMachineVersion>
20+
<SilMachineVersion>3.9.5</SilMachineVersion>
2121
<SilIPCFrameworkVersion>1.1.1-beta0001</SilIPCFrameworkVersion>
2222
<L10NSharpVersion>10.0.0-beta0014</L10NSharpVersion>
2323
<EncodingConvertersCoreVersion>0.9.8</EncodingConvertersCoreVersion>

‎Src/LexText/ParserCore/FwXmlTraceManager.cs‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,20 @@ public void BeginUnapplyTemplate(AffixTemplate template, Word input)
6969
CreateWordElement("Input", input, true)));
7070
}
7171

72-
public void EndUnapplyTemplate(AffixTemplate template, Word output, bool unapplied)
72+
public void EndUnapplyTemplate(AffixTemplate template, Word output, bool unapplied, FailureReason reason)
7373
{
74-
((XElement) output.CurrentTrace).Add(new XElement("TemplateAnalysisTraceOut",
74+
var trace = new XElement(
75+
"TemplateAnalysisTraceOut",
7576
CreateHCRuleElement("AffixTemplate", template),
76-
CreateWordElement("Output", unapplied ? output : null, true)));
77+
CreateWordElement("Output", unapplied ? output : null, true)
78+
);
79+
if (reason == FailureReason.NonPartialRuleProhibitedAfterFinalTemplate)
80+
{
81+
trace.Add(
82+
new XElement("FailureReason", new XAttribute("type", "nonPartialRuleAfterFinalTemplate"))
83+
);
84+
}
85+
((XElement)output.CurrentTrace).Add(trace);
7786
}
7887

7988
public void MorphologicalRuleUnapplied(IMorphologicalRule rule, int subruleIndex, Word input, Word output)

‎Src/LexText/ParserCore/HCParser.cs‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public class HCParser : DisposableBase, IParser
3434
private bool m_guessRoots;
3535
private bool m_mergeAnalyses;
3636
private bool m_mergeMSAs = true;
37+
private bool m_makePartialsFinal = false;
3738

3839
// the public const strings are for GenerateHCConfigForFLExTrans and HCSynthByGlossLib
3940
internal const string CRuleID = "ID";
@@ -164,6 +165,7 @@ private void LoadParser()
164165
XElement guessRootsElem = parserParamsElem.Elements("HC").Elements("GuessRoots").FirstOrDefault();
165166
XElement mergeAnalysesElem = parserParamsElem.Elements("HC").Elements("MergeAnalyses").FirstOrDefault();
166167
XElement mergeMSAsElem = parserParamsElem.Elements("HC").Elements("MergeMSAs").FirstOrDefault();
168+
XElement makePartialsFinalElem = parserParamsElem.Elements("HC").Elements("MakePartialsFinal").FirstOrDefault();
167169
XElement maxRootsElem = parserParamsElem.Elements("HC").Elements("MaxRoots").FirstOrDefault();
168170
XElement maxAlternativesElem = parserParamsElem.Elements("HC").Elements("MaxAlternatives").FirstOrDefault();
169171
if (delReappsElem != null)
@@ -172,12 +174,12 @@ private void LoadParser()
172174
m_guessRoots = (bool) guessRootsElem;
173175
if (mergeAnalysesElem != null)
174176
m_mergeAnalyses = (bool)mergeAnalysesElem;
175-
if (mergeMSAsElem != null)
176-
m_mergeMSAs = (bool)mergeMSAsElem;
177177
if (maxRootsElem != null)
178178
maxStemCount = int.Parse(maxRootsElem.Value);
179179
if (maxAlternativesElem != null)
180180
maxAlternatives = int.Parse(maxAlternativesElem.Value);
181+
m_mergeMSAs = mergeMSAsElem != null ? (bool)mergeMSAsElem : true;
182+
m_makePartialsFinal = makePartialsFinalElem != null ? (bool)makePartialsFinalElem : false;
181183
writer.WriteStartElement("LoadErrors");
182184
if (m_mergeMSAs)
183185
{
@@ -190,10 +192,14 @@ private void LoadParser()
190192
}
191193
writer.WriteEndElement();
192194
}
193-
m_morpher = new Morpher(m_traceManager, m_language) { DeletionReapplications = delReapps };
194-
m_morpher.MaxStemCount = maxStemCount;
195-
m_morpher.MergeEquivalentAnalyses = m_mergeAnalyses;
196-
m_morpher.MaxAlternatives = maxAlternatives;
195+
m_morpher = new Morpher(m_traceManager, m_language)
196+
{
197+
DeletionReapplications = delReapps,
198+
MaxStemCount = maxStemCount,
199+
MergeEquivalentAnalyses = m_mergeAnalyses,
200+
MaxAlternatives = maxAlternatives,
201+
AlwaysEnforceFinalTemplates = m_makePartialsFinal,
202+
};
197203
}
198204

199205
private XDocument ParseToXml(string form, bool tracing, IEnumerable<int> selectTraceMorphs)

‎Src/LexText/ParserCore/ParserReport.cs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ public ParserReport DiffParserReports(ParserReport other)
248248

249249
// The following must go after AddParserReport is called.
250250
diff.IsDiff = true;
251+
diff.ChangesRecorded = ChangesRecorded || other.ChangesRecorded;
251252
diff.ProjectName = DiffNames(ProjectName, other.ProjectName);
252253
diff.SourceText = DiffNames(SourceText, other.SourceText);
253254
diff.MachineName = DiffNames(MachineName, other.MachineName);

‎Src/LexText/ParserCore/ParserWorker.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public bool ParseAndUpdateWordform(IWfiWordform wordform, ParserPriority priorit
173173
}
174174
stopWatch.Stop();
175175
lcResult.ParseTime = stopWatch.ElapsedMilliseconds;
176-
if (lcResult.Analyses.Count > 0 && lcResult.ErrorMessage == null)
176+
if (lcResult.Analyses.Count > 0 || (checkParser && !String.IsNullOrEmpty(lcResult.ErrorMessage)))
177177
{
178178
// Don't turn lcText into a wordform here.
179179
// This avoids a problem with broadcasting PropChanged (cf. LT-22079).

‎Src/LexText/ParserUI/ParserListener.cs‎

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -897,17 +897,15 @@ private static Form CreateInputBox(string title, ref string input)
897897
}
898898

899899
/// <summary>
900-
/// Suppress this parse result if it is an uppercase wordform whose analyses all came from its lowercase version.
901-
/// This only happens in projects that were parsed before we decided that the case of wordforms in analyses
902-
/// should be determined by the case of the word that was parsed rather than the case of the surface form.
903-
/// So, the wordform for "The" should be "the" rather than "The" because "The" is parsed as the determiner "the".
900+
/// Suppress this parse result if it is an uppercase wordform with no analyses
901+
/// that has a lowercase wordform in the same corpus.
904902
/// </summary>
905903
/// <param name="wordform"></param>
906904
/// <returns></returns>
907905
private bool SuppressableParseResult(IWfiWordform wordform)
908906
{
909907
var result = m_checkParserResults[wordform];
910-
if (result.Analyses.Count > 0)
908+
if (result.Analyses.Count > 0 || !String.IsNullOrEmpty(result.ErrorMessage))
911909
return false;
912910
// See if there is a lowercase version of wordform in the parse results.
913911
ITsString itsString = wordform.Form.VernacularDefaultWritingSystem;
@@ -923,25 +921,6 @@ private bool SuppressableParseResult(IWfiWordform wordform)
923921
{
924922
if (m_checkParserResults.ContainsKey(lcWordform))
925923
{
926-
var lcResult = m_checkParserResults[lcWordform];
927-
// See if lcResult covers wordform's approved analyses.
928-
var userAgent = wordform.Cache.LanguageProject.DefaultUserAgent;
929-
foreach (IWfiAnalysis wfAnalysis in wordform.AnalysesOC)
930-
{
931-
var wfOpinion = wfAnalysis.GetAgentOpinion(userAgent);
932-
if (wfOpinion == Opinions.approves)
933-
{
934-
foreach (ParseAnalysis lcWfAnalysis in lcResult.Analyses)
935-
{
936-
if (!lcWfAnalysis.MatchesIWfiAnalysis(wfAnalysis))
937-
{
938-
return false;
939-
}
940-
}
941-
}
942-
}
943-
// All approved analyses are covered.
944-
// Suppress the parse results for wordform.
945924
return true;
946925
}
947926
}

‎Src/LexText/ParserUI/ParserParametersDlg.cs‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public class ParserParametersDlg : ParserParametersBase
3535
private const string GuessRoots = "GuessRoots";
3636
private const string MergeAnalyses = "MergeAnalyses";
3737
private const string MergeMSAs = "MergeMSAs";
38+
private const string MakePartialsFinal = "MakePartialsFinal";
3839
private const string Strata = "Strata";
3940

4041
private const string XAmple = "XAmple";
@@ -281,11 +282,13 @@ public void SetDlgInfo(string title, string parserParameters, ILcmOwningSequence
281282
PopulateDataGrid(m_dataGrid1, XAmple);
282283
PopulateDataGrid(m_dataGrid2, HC);
283284
m_dataGrid2.TableStyles[0].GridColumnStyles[2].Width = 130;
285+
m_dataGrid2.TableStyles[0].GridColumnStyles[3].Width = 70;
284286
m_dataGrid2.TableStyles[0].GridColumnStyles[4].Width = 160;
285287
m_dataGrid2.TableStyles[0].GridColumnStyles[6].Width = 90;
286-
m_dataGrid2.TableStyles[0].GridColumnStyles[7].Width = 80;
288+
m_dataGrid2.TableStyles[0].GridColumnStyles[7].Width = 70;
287289
m_dataGrid2.TableStyles[0].GridColumnStyles[8].Width = 100;
288-
m_dataGrid2.TableStyles[0].GridColumnStyles[9].Width = 400;
290+
m_dataGrid2.TableStyles[0].GridColumnStyles[9].Width = 100;
291+
m_dataGrid2.TableStyles[0].GridColumnStyles[10].Width = 400;
289292

290293
m_compoundRules = compoundRules;
291294
if (m_compoundRules?.Count > 0)
@@ -322,6 +325,8 @@ private void LoadParserData(DataSet dsParserParameters)
322325
hcElem.Add(new XElement(MergeAnalyses, true));
323326
if (hcElem.Element(MergeMSAs) == null)
324327
hcElem.Add(new XElement(MergeMSAs, true));
328+
if (hcElem.Element(MakePartialsFinal) == null)
329+
hcElem.Add(new XElement(MakePartialsFinal, false));
325330
if (hcElem.Element(Strata) == null)
326331
hcElem.Add(new XElement(Strata, ""));
327332

@@ -377,6 +382,7 @@ private DataTable CreateHCDataTable()
377382
tblHC.Columns.Add(GuessRoots, typeof(bool));
378383
tblHC.Columns.Add(MergeAnalyses, typeof(bool));
379384
tblHC.Columns.Add(MergeMSAs, typeof(bool));
385+
tblHC.Columns.Add(MakePartialsFinal, typeof(bool));
380386
tblHC.Columns.Add(MaxAlternatives, typeof(int));
381387
tblHC.Columns.Add(Strata, typeof(string));
382388
return tblHC;

‎Src/Transforms/Presentation/FormatHCTrace.xsl‎

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ Main template
106106
<xsl:variable name="synthesisCompoundRules" select="$traceRoot/CompoundingRuleSynthesisTrace[MorphologicalRule/@type = 'compound'] | $traceRoot/MorphologicalRuleSynthesisTrace[MorphologicalRule/@type = 'compound']"/>
107107
<xsl:variable name="synthesizedWords" select="$traceRoot/LexLookupTrace/WordSynthesisTrace"/>
108108
<xsl:variable name="parseCompleteTraces" select="$traceRoot/ParseCompleteTrace"/>
109-
<xsl:variable name="parseNodes" select="$analysisAffixes | $synthesisAffixes | $analysisCompoundRules | $synthesisCompoundRules | $synthesizedWords | $parseCompleteTraces"/>
109+
<xsl:variable name="templateFailures" select="$traceRoot/TemplateAnalysisTraceOut[FailureReason]"/>
110+
<xsl:variable name="parseNodes" select="$analysisAffixes | $synthesisAffixes | $analysisCompoundRules | $synthesisCompoundRules | $synthesizedWords | $parseCompleteTraces | $templateFailures"/>
110111
<xsl:if test="$parseNodes">
111112
<xsl:text>Y</xsl:text>
112113
</xsl:if>
@@ -1244,8 +1245,9 @@ ShowMorph
12441245
<xsl:variable name="synthesisCompoundRules" select="$traceRoot/CompoundingRuleSynthesisTrace[MorphologicalRule/@type = 'compound'] | $traceRoot/MorphologicalRuleSynthesisTrace[MorphologicalRule/@type = 'compound']"/>
12451246
<xsl:variable name="synthesizedWords" select="$traceRoot/LexLookupTrace/WordSynthesisTrace"/>
12461247
<xsl:variable name="parseCompleteTraces" select="$traceRoot/ParseCompleteTrace"/>
1248+
<xsl:variable name="templateFailures" select="$traceRoot/TemplateAnalysisTraceOut[FailureReason]"/>
12471249

1248-
<xsl:variable name="parseNodes" select="$analysisAffixes | $synthesisAffixes | $analysisCompoundRules | $synthesisCompoundRules | $synthesizedWords | $parseCompleteTraces"/>
1250+
<xsl:variable name="parseNodes" select="$analysisAffixes | $synthesisAffixes | $analysisCompoundRules | $synthesisCompoundRules | $synthesizedWords | $parseCompleteTraces | $templateFailures"/>
12491251
<xsl:if test="$parseNodes">
12501252
<xsl:for-each select="$parseNodes">
12511253
<xsl:variable name="lastTemplateTrace" select="(preceding-sibling::*[name()='TemplateAnalysisTraceIn' or name()='TemplateSynthesisTraceIn' or name()='TemplateAnalysisTraceOut' or name()='TemplateSynthesisTraceOut'])[position() = last()]"/>
@@ -1351,6 +1353,29 @@ ShowMorph
13511353
</td>
13521354
</tr>
13531355
</xsl:when>
1356+
<xsl:when test="name() = 'TemplateAnalysisTraceOut'">
1357+
<tr>
1358+
<td valign="top">
1359+
<xsl:attribute name="style">
1360+
<xsl:text>color:</xsl:text>
1361+
<xsl:value-of select="$sFailureColor"/>
1362+
</xsl:attribute>
1363+
<xsl:text>Template </xsl:text>
1364+
<xsl:if test="string-length(normalize-space($template)) > 0">
1365+
<span>
1366+
<xsl:attribute name="style">
1367+
<xsl:call-template name="GetAnalysisFont"/>
1368+
</xsl:attribute>
1369+
<xsl:value-of select="normalize-space($template)"/>
1370+
</span>
1371+
</xsl:if>
1372+
<xsl:text> failed.</xsl:text>
1373+
</td>
1374+
<td valign="top">
1375+
<xsl:call-template name="ShowAnyFailure"/>
1376+
</td>
1377+
</tr>
1378+
</xsl:when>
13541379
<xsl:otherwise>
13551380
<tr>
13561381
<td valign="top">

‎Src/Transforms/Presentation/HCSynthByGlossFormatHCTrace.xsl‎

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ Main template
115115
<xsl:variable name="synthesisCompoundRules" select="$traceRoot/MorphologicalRuleSynthesisTrace[MorphologicalRule/@type = 'compound']"/>
116116
<xsl:variable name="synthesizedWords" select="$traceRoot/LexLookupTrace/WordSynthesisTrace"/>
117117
<xsl:variable name="parseCompleteTraces" select="$traceRoot/ParseCompleteTrace"/>
118-
<xsl:variable name="parseNodes" select="$synthesisAffixes | $synthesisCompoundRules | $synthesizedWords | $parseCompleteTraces"/>
118+
<xsl:variable name="templateFailures" select="$traceRoot/TemplateAnalysisTraceOut[FailureReason]"/>
119+
<xsl:variable name="parseNodes" select="$synthesisAffixes | $synthesisCompoundRules | $synthesizedWords | $parseCompleteTraces | $templateFailures"/>
119120
<xsl:if test="$parseNodes">
120121
<xsl:text>Y</xsl:text>
121122
</xsl:if>
@@ -1359,8 +1360,8 @@ ShowMorph
13591360
<xsl:variable name="synthesisCompoundRules" select="$traceRoot/MorphologicalRuleSynthesisTrace[MorphologicalRule/@type = 'compound']"/>
13601361
<xsl:variable name="synthesizedWords" select="$traceRoot/LexLookupTrace/WordSynthesisTrace"/>
13611362
<xsl:variable name="parseCompleteTraces" select="$traceRoot/ParseCompleteTrace"/>
1362-
1363-
<xsl:variable name="parseNodes" select="$synthesisAffixes | $synthesisCompoundRules | $synthesizedWords | $parseCompleteTraces"/>
1363+
<xsl:variable name="templateFailures" select="$traceRoot/TemplateAnalysisTraceOut[FailureReason]"/>
1364+
<xsl:variable name="parseNodes" select="$synthesisAffixes | $synthesisCompoundRules | $synthesizedWords | $parseCompleteTraces | $templateFailures"/>
13641365
<xsl:if test="$parseNodes">
13651366
<xsl:for-each select="$parseNodes">
13661367
<xsl:variable name="lastTemplateTrace" select="(preceding-sibling::*[name()='TemplateSynthesisTraceIn' or name()='TemplateSynthesisTraceOut'])[position() = last()]"/>
@@ -1466,6 +1467,29 @@ ShowMorph
14661467
</td>
14671468
</tr>
14681469
</xsl:when>
1470+
<xsl:when test="name() = 'TemplateAnalysisTraceOut'">
1471+
<tr>
1472+
<td valign="top">
1473+
<xsl:attribute name="style">
1474+
<xsl:text>color:</xsl:text>
1475+
<xsl:value-of select="$sFailureColor"/>
1476+
</xsl:attribute>
1477+
<xsl:text>Template </xsl:text>
1478+
<xsl:if test="string-length(normalize-space($template)) > 0">
1479+
<span>
1480+
<xsl:attribute name="style">
1481+
<xsl:call-template name="GetAnalysisFont"/>
1482+
</xsl:attribute>
1483+
<xsl:value-of select="normalize-space($template)"/>
1484+
</span>
1485+
</xsl:if>
1486+
<xsl:text> failed.</xsl:text>
1487+
</td>
1488+
<td valign="top">
1489+
<xsl:call-template name="ShowAnyFailure"/>
1490+
</td>
1491+
</tr>
1492+
</xsl:when>
14691493
<xsl:otherwise>
14701494
<tr>
14711495
<td valign="top">

‎Src/Utilities/HCSynthByGloss/HCSynthByGlossLib/HcXmlTraceManager.cs‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,20 @@ public void BeginUnapplyTemplate(AffixTemplate template, Word input)
9797
);
9898
}
9999

100-
public void EndUnapplyTemplate(AffixTemplate template, Word output, bool unapplied)
100+
public void EndUnapplyTemplate(AffixTemplate template, Word output, bool unapplied, FailureReason reason)
101101
{
102-
((XElement)output.CurrentTrace).Add(
103-
new XElement(
104-
"TemplateAnalysisTraceOut",
105-
CreateHCRuleElement("AffixTemplate", template),
106-
CreateWordElement("Output", unapplied ? output : null, true)
107-
)
102+
var trace = new XElement(
103+
"TemplateAnalysisTraceOut",
104+
CreateHCRuleElement("AffixTemplate", template),
105+
CreateWordElement("Output", unapplied ? output : null, true)
108106
);
107+
if (reason == FailureReason.NonPartialRuleProhibitedAfterFinalTemplate)
108+
{
109+
trace.Add(
110+
new XElement("FailureReason", new XAttribute("type", "nonPartialRuleAfterFinalTemplate"))
111+
);
112+
}
113+
((XElement)output.CurrentTrace).Add(trace);
109114
}
110115

111116
public void MorphologicalRuleUnapplied(

0 commit comments

Comments
 (0)