Skip to content

Commit 4fcaa4b

Browse files
committed
Fix LT-22605: Add ability to limit Hermit Crab parses
1 parent 99858db commit 4fcaa4b

4 files changed

Lines changed: 20 additions & 5 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.8.2</SilMachineVersion>
20+
<SilMachineVersion>3.9.2</SilMachineVersion>
2121
<SilIPCFrameworkVersion>1.1.1-beta0001</SilIPCFrameworkVersion>
2222
<L10NSharpVersion>10.0.0-beta0004</L10NSharpVersion>
2323
<EncodingConvertersCoreVersion>0.9.8</EncodingConvertersCoreVersion>

Src/LexText/ParserCore/HCParser.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using SIL.Machine.Annotations;
1616
using SIL.Machine.Morphology.HermitCrab;
1717
using SIL.Machine.Morphology.HermitCrab.MorphologicalRules;
18+
using SIL.Machine.Rules;
1819
using SIL.ObjectModel;
1920

2021
namespace SIL.FieldWorks.WordWorks.Parser
@@ -149,6 +150,7 @@ private void LoadParser()
149150
// For Hermit Crab, the maximum number of roots/stems allowed is between one and ten.
150151
// The default is two in order to allow for compounding (which requires there be at least two roots/stems).
151152
int maxStemCount = 2;
153+
int maxAlternatives = 0;
152154
string loadErrorsFile = Path.Combine(m_outputDirectory, m_cache.ProjectId.Name + "HCLoadErrors.xml");
153155
using (XmlWriter writer = XmlWriter.Create(loadErrorsFile))
154156
using (new WorkerThreadReadHelper(m_cache.ServiceLocator.GetInstance<IWorkerThreadReadHandler>()))
@@ -161,6 +163,7 @@ private void LoadParser()
161163
XElement guessRootsElem = parserParamsElem.Elements("HC").Elements("GuessRoots").FirstOrDefault();
162164
XElement mergeAnalysesElem = parserParamsElem.Elements("HC").Elements("MergeAnalyses").FirstOrDefault();
163165
XElement maxRootsElem = parserParamsElem.Elements("HC").Elements("MaxRoots").FirstOrDefault();
166+
XElement maxAlternativesElem = parserParamsElem.Elements("HC").Elements("MaxAlternatives").FirstOrDefault();
164167
if (delReappsElem != null)
165168
delReapps = (int) delReappsElem;
166169
if (guessRootsElem != null)
@@ -169,10 +172,13 @@ private void LoadParser()
169172
m_mergeAnalyses = (bool) mergeAnalysesElem;
170173
if (maxRootsElem != null)
171174
maxStemCount = int.Parse(maxRootsElem.Value);
175+
if (maxRootsElem != null)
176+
maxAlternatives = int.Parse(maxAlternativesElem.Value);
172177
}
173178
m_morpher = new Morpher(m_traceManager, m_language) { DeletionReapplications = delReapps };
174179
m_morpher.MaxStemCount = maxStemCount;
175180
m_morpher.MergeEquivalentAnalyses = m_mergeAnalyses;
181+
m_morpher.MaxAlternatives = maxAlternatives;
176182
}
177183

178184
private XDocument ParseToXml(string form, bool tracing, IEnumerable<int> selectTraceMorphs)
@@ -577,6 +583,10 @@ private string ProcessParseException(Exception e)
577583
}
578584
return string.Format(ParserCoreStrings.ksHCInvalidWordform, ise.String, ise.Position + 1, rest, phonemesFoundSoFar);
579585
}
586+
if (e is MaxAlternativesExceededException)
587+
{
588+
return e.Message;
589+
}
580590

581591
return String.Format(ParserCoreStrings.ksHCDefaultErrorMsg, e.Message);
582592
}

Src/LexText/ParserUI/ParserParametersDlg.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public class ParserParametersDlg : ParserParametersBase
4343
private const string MaxInfixes = "MaxInfixes";
4444
private const string MaxInterfixes = "MaxInterfixes";
4545
private const string MaxRoots = "MaxRoots";
46+
private const string MaxAlternatives = "MaxAlternatives";
4647
private const string MaxAnalysesToReturn = "MaxAnalysesToReturn";
4748

4849
#region Data members
@@ -280,7 +281,8 @@ public void SetDlgInfo(string title, string parserParameters, ILcmOwningSequence
280281
m_dataGrid2.TableStyles[0].GridColumnStyles[2].Width = 130;
281282
m_dataGrid2.TableStyles[0].GridColumnStyles[4].Width = 160;
282283
m_dataGrid2.TableStyles[0].GridColumnStyles[6].Width = 90;
283-
m_dataGrid2.TableStyles[0].GridColumnStyles[7].Width = 400;
284+
m_dataGrid2.TableStyles[0].GridColumnStyles[7].Width = 100;
285+
m_dataGrid2.TableStyles[0].GridColumnStyles[8].Width = 400;
284286

285287
m_compoundRules = compoundRules;
286288
if (m_compoundRules?.Count > 0)
@@ -305,6 +307,8 @@ private void LoadParserData(DataSet dsParserParameters)
305307
hcElem.Add(new XElement(NoDefaultCompounding, false));
306308
if (hcElem.Element(MaxRoots) == null)
307309
hcElem.Add(new XElement(MaxRoots, 2));
310+
if (hcElem.Element(MaxAlternatives) == null)
311+
hcElem.Add(new XElement(MaxAlternatives, 0));
308312
if (hcElem.Element(NotOnClitics) == null)
309313
hcElem.Add(new XElement(NotOnClitics, true));
310314
if (hcElem.Element(AcceptUnspecifiedGraphemes) == null)
@@ -367,6 +371,7 @@ private DataTable CreateHCDataTable()
367371
tblHC.Columns.Add(AcceptUnspecifiedGraphemes, typeof(bool));
368372
tblHC.Columns.Add(GuessRoots, typeof(bool));
369373
tblHC.Columns.Add(MergeAnalyses, typeof(bool));
374+
tblHC.Columns.Add(MaxAlternatives, typeof(int));
370375
tblHC.Columns.Add(Strata, typeof(string));
371376
return tblHC;
372377
}

Src/LexText/ParserUI/ParserParametersDlg.resx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@
252252
<value>8, 64</value>
253253
</data>
254254
<data name="m_dataGrid1.Size" type="System.Drawing.Size, System.Drawing">
255-
<value>576, 72</value>
255+
<value>546, 72</value>
256256
</data>
257257
<data name="m_dataGrid1.TabIndex" type="System.Int32, mscorlib">
258258
<value>6</value>
@@ -300,7 +300,7 @@
300300
<value>8, 165</value>
301301
</data>
302302
<data name="m_dataGrid2.Size" type="System.Drawing.Size, System.Drawing">
303-
<value>976, 100</value>
303+
<value>1076, 100</value>
304304
</data>
305305
<data name="m_dataGrid2.TabIndex" type="System.Int32, mscorlib">
306306
<value>8</value>
@@ -351,7 +351,7 @@
351351
<value>5, 13</value>
352352
</data>
353353
<data name="$this.ClientSize" type="System.Drawing.Size, System.Drawing">
354-
<value>1000, 388</value>
354+
<value>1100, 388</value>
355355
</data>
356356
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
357357
<value>

0 commit comments

Comments
 (0)