Skip to content

Commit

Permalink
GetBestGuess(): Allow lowercase matching for all words
Browse files Browse the repository at this point in the history
By default, GetBestGuess() only tries to do lowercase matching for
occurrence index zero. This change adds a parameter to also allow
lowercase matching for all occurrence indexes.

https://jira.sil.org/browse/LT-21424
  • Loading branch information
mark-sil authored Dec 7, 2023
2 parents 5a74dbb + 3479ddc commit 52f0186
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Added

- [SIL.LCModel] Added a parameter to GetBestGuess() and TryGetBestGuess() to do lowercase matching regardless of the occurrence index
- [SIL.LCModel] Add GetCaptionOrHeadword() to CmPicture
- [SIL.LCModel] `LCModelStrings.NotSure` to allow clients to know if a grammatical category is the placeholder
- [SIL.LCModel.Utils] `DateTime` extension method `ToLCMTimeFormatWithMillisString()` (replaces `ReadWriteServices.FormatDateTime`)
Expand Down
16 changes: 12 additions & 4 deletions src/SIL.LCModel/DomainServices/AnalysisGuessServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -645,11 +645,15 @@ public IAnalysis GetBestGuess(IWfiAnalysis wa)
/// This guess factors in the placement of an occurrence in its segment for making other
/// decisions like matching lowercase alternatives for sentence initial occurrences.
/// </summary>
public IAnalysis GetBestGuess(AnalysisOccurrence occurrence)
/// <param name="onlyIndexZeroLowercaseMatching">
/// True: Do lowercase matching only if the occurrence index is zero.
/// False: Do lowercase matching regardless of the occurrence index.
/// </param>
public IAnalysis GetBestGuess(AnalysisOccurrence occurrence, bool onlyIndexZeroLowercaseMatching = true)
{
// first see if we can make a guess based on the lowercase form of a sentence initial (non-lowercase) wordform
// TODO: make it look for the first word in the sentence...may not be at Index 0!
if (occurrence.Analysis is IWfiWordform && occurrence.Index == 0)
if (occurrence.Analysis is IWfiWordform && (!onlyIndexZeroLowercaseMatching || occurrence.Index == 0))
{
ITsString tssWfBaseline = occurrence.BaselineText;
var cf = new CaseFunctions(Cache.ServiceLocator.WritingSystemManager.Get(tssWfBaseline.get_WritingSystemAt(0)));
Expand Down Expand Up @@ -693,9 +697,13 @@ public bool TryGetBestGuess(IAnalysis wag, int ws, out IAnalysis bestGuess)
/// <summary>
///
/// </summary>
public bool TryGetBestGuess(AnalysisOccurrence occurrence, out IAnalysis bestGuess)
/// <param name="onlyIndexZeroLowercaseMatching">
/// True: Do lowercase matching only if the occurrence index is zero.
/// False: Do lowercase matching regardless of the occurrence index.
/// </param>
public bool TryGetBestGuess(AnalysisOccurrence occurrence, out IAnalysis bestGuess, bool onlyIndexZeroLowercaseMatching = true)
{
bestGuess = GetBestGuess(occurrence);
bestGuess = GetBestGuess(occurrence, onlyIndexZeroLowercaseMatching);
return !(bestGuess is NullWAG);
}
}
Expand Down

0 comments on commit 52f0186

Please sign in to comment.