From 3479ddcf1ae97a6759799875c6ec02c85672466e Mon Sep 17 00:00:00 2001 From: mark-sil Date: Wed, 6 Dec 2023 13:03:42 -0500 Subject: [PATCH] GetBestGuess(): Allow lowercase matching for all words 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 --- CHANGELOG.md | 1 + .../DomainServices/AnalysisGuessServices.cs | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c85fc8f..391d360e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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`) diff --git a/src/SIL.LCModel/DomainServices/AnalysisGuessServices.cs b/src/SIL.LCModel/DomainServices/AnalysisGuessServices.cs index 34b0ea49..09e5ecd7 100644 --- a/src/SIL.LCModel/DomainServices/AnalysisGuessServices.cs +++ b/src/SIL.LCModel/DomainServices/AnalysisGuessServices.cs @@ -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. /// - public IAnalysis GetBestGuess(AnalysisOccurrence occurrence) + /// + /// True: Do lowercase matching only if the occurrence index is zero. + /// False: Do lowercase matching regardless of the occurrence index. + /// + 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))); @@ -693,9 +697,13 @@ public bool TryGetBestGuess(IAnalysis wag, int ws, out IAnalysis bestGuess) /// /// /// - public bool TryGetBestGuess(AnalysisOccurrence occurrence, out IAnalysis bestGuess) + /// + /// True: Do lowercase matching only if the occurrence index is zero. + /// False: Do lowercase matching regardless of the occurrence index. + /// + public bool TryGetBestGuess(AnalysisOccurrence occurrence, out IAnalysis bestGuess, bool onlyIndexZeroLowercaseMatching = true) { - bestGuess = GetBestGuess(occurrence); + bestGuess = GetBestGuess(occurrence, onlyIndexZeroLowercaseMatching); return !(bestGuess is NullWAG); } }