Skip to content
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

GetBestGuess(): Allow lowercase matching for all words #290

Merged
merged 1 commit into from
Dec 7, 2023
Merged
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
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
Loading