Skip to content

Commit 7fd440c

Browse files
authored
Fix LT-22121: Analysis guesser should not guess ras for rAs (#326)
* Fix LT-22121: Analysis guesser should not guess ras for rAs * Add test case for mixed case words
1 parent 69b6c0a commit 7fd440c

File tree

2 files changed

+52
-16
lines changed

2 files changed

+52
-16
lines changed

src/SIL.LCModel/DomainServices/AnalysisGuessServices.cs

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -729,18 +729,9 @@ public IAnalysis GetBestGuess(AnalysisOccurrence occurrence, bool onlyIndexZeroL
729729
private IWfiWordform GetLowercaseWordform(AnalysisOccurrence occurrence, int ws,
730730
bool onlyIndexZeroLowercaseMatching, IWfiWordform wordform)
731731
{
732-
// TODO: make it look for the first word in the sentence...may not be at Index 0!
733-
if (occurrence == null)
734-
return null;
735-
if (onlyIndexZeroLowercaseMatching && occurrence.Index != 0)
736-
return null;
737-
if (occurrence.Segment == null || !occurrence.Segment.IsValidObject)
738-
return null;
739-
ITsString tssWfBaseline = occurrence.BaselineText;
740-
var cf = new CaseFunctions(Cache.ServiceLocator.WritingSystemManager.Get(ws));
741-
string sLower = cf.ToLower(tssWfBaseline.Text);
732+
string sLower = GetLowercaseOfTitleCase(occurrence, ws, onlyIndexZeroLowercaseMatching);
742733
// don't bother looking up the lowercased wordform if the instanceOf is already in lowercase form.
743-
if (sLower != wordform.ShortName)
734+
if (sLower != null && sLower != wordform.ShortName)
744735
{
745736
return GetWordformIfNeeded(sLower, ws);
746737
}
@@ -752,18 +743,37 @@ private IWfiWordform GetLowercaseWordform(AnalysisOccurrence occurrence, int ws,
752743
// if it lowercases to the given wordform.
753744
// Otherwise, return null.
754745
// </summary>
755-
private IWfiWordform GetOriginalCaseWordform(AnalysisOccurrence occurrence, IWfiWordform wordform, int ws)
746+
private IWfiWordform GetOriginalCaseWordform(AnalysisOccurrence occurrence, IWfiWordform wordform,
747+
int ws, bool onlyIndexZeroLowercaseMatching)
756748
{
757-
ITsString tssWfBaseline = occurrence.BaselineText;
758-
var cf = new CaseFunctions(Cache.ServiceLocator.WritingSystemManager.Get(ws));
759-
string sLower = cf.ToLower(tssWfBaseline.Text);
749+
string sLower = GetLowercaseOfTitleCase(occurrence, ws, onlyIndexZeroLowercaseMatching);
760750
if (sLower == wordform.GetForm(ws).Text)
761751
{
752+
ITsString tssWfBaseline = occurrence.BaselineText;
762753
return GetWordformIfNeeded(tssWfBaseline.Text, ws);
763754
}
764755
return null;
765756
}
766757

758+
// <summary>
759+
// Get the lowercase form of occurrence if it is Title case.
760+
// </summary>
761+
private string GetLowercaseOfTitleCase(AnalysisOccurrence occurrence, int ws, bool onlyIndexZeroLowercaseMatching)
762+
{
763+
// TODO: make it look for the first word in the sentence...may not be at Index 0!
764+
if (occurrence == null)
765+
return null;
766+
if (onlyIndexZeroLowercaseMatching && occurrence.Index != 0)
767+
return null;
768+
if (occurrence.Segment == null || !occurrence.Segment.IsValidObject)
769+
return null;
770+
ITsString tssWfBaseline = occurrence.BaselineText;
771+
var cf = new CaseFunctions(Cache.ServiceLocator.WritingSystemManager.Get(ws));
772+
if (cf.StringCase(tssWfBaseline.Text) == StringCaseStatus.title)
773+
return cf.ToLower(tssWfBaseline.Text);
774+
return null;
775+
}
776+
767777
/// <summary>
768778
/// Get a wordform for word if it already exists or
769779
/// if it has an entry in the lexicon.
@@ -862,7 +872,7 @@ private List<IWfiAnalysis> GetSortedAnalysisGuesses(IWfiWordform wordform, int w
862872
{
863873
// Sometimes the user selects a lowercase wordform for an uppercase word.
864874
// Get the original case so that we can include uppercase analyses.
865-
var originalCaseWf = GetOriginalCaseWordform(occurrence, wordform, ws);
875+
var originalCaseWf = GetOriginalCaseWordform(occurrence, wordform, ws, onlyIndexZeroLowercaseMatching);
866876
if (originalCaseWf != null)
867877
wordform = originalCaseWf;
868878
}

tests/SIL.LCModel.Tests/DomainServices/AnalysisGuessServicesTests.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,17 @@ internal void DoDataSetup()
170170
" " + Words_para0[4].Form.BestVernacularAlternative.Text +
171171
".", wsVern));
172172
Para0.Contents = bldr4.GetString();
173+
/* rAs ras */
174+
IWfiWordform rAs = wfFactory.Create(TsStringUtils.MakeString("rAs", wsVern));
175+
Words_para0.Add(rAs);
176+
IWfiWordform ras = wfFactory.Create(TsStringUtils.MakeString("ras", wsVern));
177+
Words_para0.Add(ras);
178+
var bldr5 = Para0.Contents.GetIncBldr();
179+
bldr5.AppendTsString(TsStringUtils.MakeString(
180+
" " + Words_para0[20].Form.BestVernacularAlternative.Text +
181+
" " + Words_para0[21].Form.BestVernacularAlternative.Text +
182+
".", wsVern));
183+
Para0.Contents = bldr5.GetString();
173184
using (ParagraphParser pp = new ParagraphParser(Cache))
174185
{
175186
foreach (IStTxtPara para in StText.ParagraphsOS)
@@ -921,6 +932,21 @@ public void ExpectedAnalysisGuess_ForSentenceInitialOnlyLowercase()
921932
}
922933
}
923934

935+
/// <summary>
936+
/// if a wordform is mixed case, don't look for lower case.
937+
/// </summary>
938+
[Test]
939+
public void ExpectedAnalysisGuess_ForSentenceInitialMixedCase()
940+
{
941+
using (var setup = new AnalysisGuessBaseSetup(Cache))
942+
{
943+
WordAnalysisOrGlossServices.CreateNewAnalysisWAG(setup.Words_para0[21]); // ras
944+
var wagLowercaseB = new AnalysisOccurrence(setup.Para0.SegmentsOS[5], 0); // rAs
945+
var guessActual = setup.GuessServices.GetBestGuess(wagLowercaseB);
946+
Assert.AreEqual(new NullWAG(), guessActual);
947+
}
948+
}
949+
924950
/// <summary>
925951
/// This class allows us to fake out the guesser by passing an analysis occurrence with the analyis we want,
926952
/// even though it isn't the analysis recorded in the paragraph.

0 commit comments

Comments
 (0)