Skip to content
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
29 changes: 28 additions & 1 deletion src/SIL.LCModel/DomainServices/AnalysisGuessServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,21 @@ public class AnalysisGuessServices
///
/// </summary>
/// <param name="cache"></param>
public AnalysisGuessServices(LcmCache cache)
public AnalysisGuessServices(LcmCache cache) : this(cache, false)
{
}

/// <summary>
///
/// </summary>
/// <param name="cache"></param>
/// <param name="prioritizeParser">whether parser approval should be prioritized over human approval</param>
public AnalysisGuessServices(LcmCache cache, bool prioritizeParser)
{
Cache = cache;
m_emptyWAG = new EmptyWAG();
m_nullWAG = new NullWAG();
PrioritizeParser = prioritizeParser;
}

/// <summary>
Expand All @@ -57,6 +67,8 @@ public enum OpinionAgent

public AnalysisOccurrence IgnoreOccurrence { get; set; }

public bool PrioritizeParser { get; set; }

LcmCache Cache { get; set; }

// PriorityCount provides a count of the number of times an analysis
Expand Down Expand Up @@ -644,6 +656,21 @@ private void AddAnalysisCount(IAnalysis context, IAnalysis analysis, int priorit
/// </summary>
private int ComparePriorityCounts(IAnalysis a1, IAnalysis a2, AnalysisOccurrence occurrence, ContextCount contextCount)
{
if (PrioritizeParser)
{
// Sort by parser approval.
IWfiAnalysis wfi1 = a1 as IWfiAnalysis;
IWfiAnalysis wfi2 = a2 as IWfiAnalysis;
if (wfi1 != null && wfi2 != null)
{
int p1 = IsParserApproved(wfi1) ? 3 : IsParserDisapproved(wfi1) ? 1 : 2;
int p2 = IsParserApproved(wfi2) ? 3 : IsParserDisapproved(wfi2) ? 1 : 2;
if (p1 < p2)
return 1;
if (p1 > p2)
return -1;
}
}
// Compare contexted counts.
if (occurrence != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ internal enum Flags

LcmCache Cache { get; set; }

internal AnalysisGuessBaseSetup(LcmCache cache) : this()
internal AnalysisGuessBaseSetup(LcmCache cache, bool prioritizeParser = false) : this()
{
Cache = cache;
UserAgent = Cache.LanguageProject.DefaultUserAgent;
ParserAgent = Cache.LangProject.DefaultParserAgent;
GuessServices = new AnalysisGuessServices(Cache);
GuessServices = new AnalysisGuessServices(Cache, prioritizeParser);
EntryFactory = Cache.ServiceLocator.GetInstance<ILexEntryFactory>();
DoDataSetup();
}
Expand Down Expand Up @@ -1251,6 +1251,22 @@ public void ExpectedGuess_PreferUserApprovedAnalysisOverParserApprovedAnalysis()
}
}

/// <summary>
/// </summary>
[Test]
public void ExpectedGuess_PreferParserApprovedAnalysisOverUserApprovedAnalysis()
{
using (var setup = new AnalysisGuessBaseSetup(Cache, true))
{
var newWagParserApproves = WordAnalysisOrGlossServices.CreateNewAnalysisWAG(setup.Words_para0[1]);
var newWagHumanApproves = WordAnalysisOrGlossServices.CreateNewAnalysisWAG(setup.Words_para0[1]);
setup.ParserAgent.SetEvaluation(newWagParserApproves.Analysis, Opinions.approves);
setup.UserAgent.SetEvaluation(newWagHumanApproves.Analysis, Opinions.approves);
var guessActual = setup.GuessServices.GetBestGuess(setup.Words_para0[1]);
Assert.AreEqual(newWagParserApproves.Analysis, guessActual);
}
}

/// <summary>
/// Prefer analyses that are in the right context over analyses that are not.
/// </summary>
Expand Down
Loading