Skip to content

Commit

Permalink
Add includeContext parameter to GetBestGuess
Browse files Browse the repository at this point in the history
  • Loading branch information
jtmaxwell3 authored and jasonleenaylor committed Jun 12, 2024
1 parent dd403d4 commit f8406cd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/SIL.LCModel/DomainServices/AnalysisGuessServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,11 @@ public IAnalysis GetBestGuess(IWfiAnalysis wa)
/// 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)
/// <param name="includeContext">
/// True: Consider previous word when getting best guess.
/// False: Ignore previous word when getting best guess.
/// </param>
public IAnalysis GetBestGuess(AnalysisOccurrence occurrence, bool onlyIndexZeroLowercaseMatching = true, bool includeContext = true)
{
// first see if there is a relevant 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!
Expand All @@ -654,7 +658,7 @@ public IAnalysis GetBestGuess(AnalysisOccurrence occurrence, bool onlyIndexZeroL
if (ws == -1)
return new NullWAG(); // happens with empty translation lines
IAnalysis bestGuess;
IAnalysis previous = GetPreviousWordform(occurrence.Segment, occurrence.Index);
IAnalysis previous = includeContext ? GetPreviousWordform(occurrence.Segment, occurrence.Index) : m_nullWAG;
if (TryGetContextAwareGuess(occurrence.Analysis, lowercaseWf, previous, out bestGuess))
return bestGuess;
return new NullWAG();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1388,6 +1388,8 @@ public void ExpectedContextAwareGloss_PreferContextedOverUncontexted()
// Make sure we get a contexted guess for occurrence instead of an uncontexted guess.
guessActual = setup.GuessServices.GetBestGuess(occurrence);
Assert.AreEqual(contextedApprovedGloss, guessActual);
guessActual = setup.GuessServices.GetBestGuess(occurrence, includeContext: false);
Assert.AreEqual(uncontextedApprovedGloss, guessActual);
// Verify uncontexted guess for sort.
var sorted_glosses = setup.GuessServices.GetSortedGlossGuesses(analysis);
Assert.AreEqual(2, sorted_glosses.Count);
Expand Down

0 comments on commit f8406cd

Please sign in to comment.