Skip to content

Commit 343c561

Browse files
authored
LT-21945: Different modes for parsing vs. analyzing (#373)
* Fix LT-21945: Different modes for parsing vs. analyzing * Fix LT-21945: Rename menu items * Incorporate liblcm with related changes * Fix unit tests * Fixed problems reported by Jason
1 parent d1d8ce5 commit 343c561

10 files changed

Lines changed: 148 additions & 42 deletions

File tree

Build/mkall.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@
285285
<ChorusNugetVersion>5.2.0-beta0003</ChorusNugetVersion>
286286
<PalasoNugetVersion>15.0.0-beta0117</PalasoNugetVersion>
287287
<ParatextNugetVersion>9.4.0.1-beta</ParatextNugetVersion>
288-
<LcmNugetVersion>11.0.0-beta0121</LcmNugetVersion>
288+
<LcmNugetVersion>11.0.0-beta0124</LcmNugetVersion>
289289
<IcuNugetVersion>70.1.123</IcuNugetVersion>
290290
<HermitCrabNugetVersion>3.6.6</HermitCrabNugetVersion>
291291
<IPCFrameworkVersion>1.1.1-beta0001</IPCFrameworkVersion>

Build/nuget-common/packages.config

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@
5151
<package id="SIL.Core" version="8.1.0-beta0035" targetFramework="net461" />
5252
<package id="SIL.DesktopAnalytics" version="4.0.0" targetFramework="net461" />
5353
<package id="SIL.FLExBridge.IPCFramework" version="1.1.1-beta0001" targetFramework="net461" />
54-
<package id="SIL.LCModel.Build.Tasks" version="11.0.0-beta0121" targetFramework="net461" />
55-
<package id="SIL.LCModel.Core.Tests" version="11.0.0-beta0121" targetFramework="net461" />
56-
<package id="SIL.LCModel.Core" version="11.0.0-beta0121" targetFramework="net461" />
57-
<package id="SIL.LCModel.FixData" version="11.0.0-beta0121" targetFramework="net461" />
58-
<package id="SIL.LCModel.Tests" version="11.0.0-beta0121" targetFramework="net461" />
59-
<package id="SIL.LCModel.Tools" version="11.0.0-beta0121" targetFramework="net461" />
60-
<package id="SIL.LCModel.Utils.Tests" version="11.0.0-beta0121" targetFramework="net461" />
61-
<package id="SIL.LCModel.Utils" version="11.0.0-beta0121" targetFramework="net461" />
62-
<package id="SIL.LCModel" version="11.0.0-beta0121" targetFramework="net461" />
54+
<package id="SIL.LCModel.Build.Tasks" version="11.0.0-beta0124" targetFramework="net461" />
55+
<package id="SIL.LCModel.Core.Tests" version="11.0.0-beta0124" targetFramework="net461" />
56+
<package id="SIL.LCModel.Core" version="11.0.0-beta0124" targetFramework="net461" />
57+
<package id="SIL.LCModel.FixData" version="11.0.0-beta0124" targetFramework="net461" />
58+
<package id="SIL.LCModel.Tests" version="11.0.0-beta0124" targetFramework="net461" />
59+
<package id="SIL.LCModel.Tools" version="11.0.0-beta0124" targetFramework="net461" />
60+
<package id="SIL.LCModel.Utils.Tests" version="11.0.0-beta0124" targetFramework="net461" />
61+
<package id="SIL.LCModel.Utils" version="11.0.0-beta0124" targetFramework="net461" />
62+
<package id="SIL.LCModel" version="11.0.0-beta0124" targetFramework="net461" />
6363
<package id="SIL.Lexicon" version="15.0.0-beta0117" targetFramework="net462" />
6464
<package id="SIL.libpalaso.l10ns" version="6.0.0" targetFramework="net461" />
6565
<package id="SIL.Lift" version="15.0.0-beta0117" targetFramework="net462" />

DistFiles/Language Explorer/Configuration/Words/areaConfiguration.xml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,14 @@
2828
<command id="CmdChooseHCParser" label="Phonological Rule-based Parser (HermitCrab.NET)" message="ChooseParser">
2929
<parameters parser="HC"/>
3030
</command>
31+
<command id="CmdParsingDevelopmentMode" label="Parsing Development" message="SetParsingMode">
32+
<parameters value="true"/>
33+
</command>
34+
<command id="CmdTextAnalysisMode" label="Text Analysis" message="SetParsingMode">
35+
<parameters value="false"/>
36+
</command>
3137

32-
<!-- Texts Area commands-->
38+
<!-- Texts Area commands-->
3339
<command id="CmdInsertText" label="New _Text" message="InsertInterlinText" shortcut="Ctrl+T" icon="addNewText">
3440
<parameters className="StText"/>
3541
</command>
@@ -286,6 +292,10 @@
286292
<item command="CmdChooseXAmpleParser"/>
287293
<item command="CmdChooseHCParser"/>
288294
</menu>
295+
<menu id="ChooseModeMenu" label="Interlinear Mode">
296+
<item command="CmdParsingDevelopmentMode"/>
297+
<item command="CmdTextAnalysisMode"/>
298+
</menu>
289299
<item command="CmdEditParserParameters"/>
290300
</menu>
291301
<include path="Extensions/*/AreaConfigurationExtension.xml" query="root/menubar/*"/>

Src/LexText/Interlinear/ChooseAnalysisHandler.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ public void SetupCombo()
282282
var wordform = m_owner.GetWordformOfAnalysis();
283283

284284
// Add the analyses, and recursively the other items.
285-
var guess_services = new AnalysisGuessServices(m_cache);
285+
var guess_services = new AnalysisGuessServices(m_cache, IsParsingMode());
286286
var sorted_analyses = guess_services.GetSortedAnalysisGuesses(wordform, m_occurrence, false);
287287
foreach (var wa in sorted_analyses)
288288
{
@@ -311,7 +311,7 @@ void AddAnalysisItems(IWfiAnalysis wa)
311311
{
312312
AddItem(wa,
313313
MakeAnalysisStringRep(wa, m_cache, StyleSheet != null, (m_owner as SandboxBase).RawWordformWs), true);
314-
var guess_services = new AnalysisGuessServices(m_cache);
314+
var guess_services = new AnalysisGuessServices(m_cache, IsParsingMode());
315315
var sorted_glosses = guess_services.GetSortedGlossGuesses(wa, m_occurrence);
316316
foreach (var gloss in sorted_glosses)
317317
{
@@ -323,6 +323,13 @@ void AddAnalysisItems(IWfiAnalysis wa)
323323
AddItem(wa, MakeSimpleString(ITextStrings.ksNewWordGloss), false, WfiGlossTags.kClassId);
324324
}
325325

326+
private bool IsParsingMode()
327+
{
328+
if (Owner?.InterlinDoc?.GetMaster() == null)
329+
return false;
330+
return Owner.InterlinDoc.GetMaster().IsParsingMode();
331+
}
332+
326333
protected ITsString MakeSimpleString(String str)
327334
{
328335
ITsStrBldr builder = TsStringUtils.MakeStrBldr();

Src/LexText/Interlinear/ITextStrings.Designer.cs

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Src/LexText/Interlinear/ITextStrings.resx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -986,4 +986,11 @@ Click "Cancel" to abort this import.</value>
986986
<data name="ksConcordanceExportTitle" xml:space="preserve">
987987
<value>Export Concordance Results</value>
988988
</data>
989+
<data name="ComplexConcControl_ResultsMayBeIncomplete" xml:space="preserve">
990+
<value>Results may be incomplete.</value>
991+
</data>
992+
<data name="ksParsingMode" xml:space="preserve">
993+
<value>Parsing</value>
994+
<comment>alternate name for Analyze tab</comment>
995+
</data>
989996
</root>

Src/LexText/Interlinear/InterlinDocRootSiteBase.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,7 @@ protected virtual void SetRootInternal(int hvo)
10131013
NonUndoableUnitOfWorkHelper.Do(Cache.ActionHandlerAccessor, () =>
10141014
InterlinMaster.LoadParagraphAnnotationsAndGenerateEntryGuessesIfNeeded(RootStText, true));
10151015
// Sync Guesses data before we redraw anything.
1016+
Vc.RootSite = this;
10161017
UpdateGuessData();
10171018
}
10181019
// FWR-191: we don't need to reconstruct the display if we didn't need to reload annotations

Src/LexText/Interlinear/InterlinMaster.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ public partial class InterlinMaster : InterlinMasterBase, IFocusablePanePortion
5555

5656
private string m_currentTool = "";
5757

58+
private string m_analyzeTabName = "";
59+
5860
public string CurrentTool
5961
{
6062
get { return m_currentTool; }
@@ -87,6 +89,8 @@ public InterlinMaster()
8789
{
8890
// This call is required by the Windows.Forms Form Designer.
8991
InitializeComponent();
92+
// Save the Analyze tab name.
93+
m_analyzeTabName = m_tpInterlinear.Text;
9094
}
9195

9296
internal string BookmarkId
@@ -721,6 +725,7 @@ public override void Init(Mediator mediator, PropertyTable propertyTable, XmlNod
721725
m_mediator = mediator;
722726
// InitBase will do this, but we need it in place before calling SetInitialTabPage().
723727
m_propertyTable = propertyTable;
728+
SetParsingMode(IsParsingMode());
724729

725730
// Making the tab control currently requires this first...
726731
if (!fHideTitlePane)
@@ -1246,6 +1251,46 @@ public bool OnConfigureInterlinear(object argument)
12461251
return true; // We handled this
12471252
}
12481253

1254+
public bool OnDisplaySetParsingMode(object commandObject,
1255+
ref UIItemDisplayProperties display)
1256+
{
1257+
var cmd = (Command)commandObject;
1258+
bool value = cmd.GetParameter("value") == "true";
1259+
display.Checked = IsParsingMode() == value;
1260+
return true;
1261+
}
1262+
1263+
public bool OnSetParsingMode(object argument)
1264+
{
1265+
var cmd = (Command)argument;
1266+
string value = cmd.GetParameter("value");
1267+
SetParsingMode(value == "true");
1268+
// Refresh the display.
1269+
RootStText = null;
1270+
m_idcAnalyze.ResetAnalysisCache();
1271+
Clerk.JumpToIndex(Clerk.CurrentIndex);
1272+
return true; // we handled this
1273+
}
1274+
1275+
public void SetParsingMode(bool value)
1276+
{
1277+
m_propertyTable.SetProperty("ParsingMode", value, PropertyTable.SettingsGroup.LocalSettings, false);
1278+
if (value)
1279+
{
1280+
m_tpInterlinear.Text = ITextStrings.ksParsingMode;
1281+
}
1282+
else
1283+
{
1284+
// Restore Analyze tab name.
1285+
m_tpInterlinear.Text = m_analyzeTabName;
1286+
}
1287+
}
1288+
1289+
public bool IsParsingMode()
1290+
{
1291+
return m_propertyTable.GetBoolProperty("ParsingMode", false, PropertyTable.SettingsGroup.LocalSettings);
1292+
}
1293+
12491294
/// <summary>
12501295
/// Use this to determine whether the last selected tab page which was
12511296
/// persisted in the PropertyTable, pertains to an interlinear document.

Src/LexText/Interlinear/InterlinVc.cs

Lines changed: 44 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -373,17 +373,24 @@ public void ResetAnalysisCache()
373373
if (m_loader != null)
374374
{
375375
CheckDisposed();
376-
m_loader.ResetGuessCache();
376+
m_loader.ResetGuessCache(IsParsingMode());
377377
}
378378
}
379379

380+
internal bool IsParsingMode()
381+
{
382+
if (RootSite?.GetMaster() == null)
383+
return false;
384+
return RootSite.GetMaster().IsParsingMode();
385+
}
386+
380387
internal AnalysisGuessServices GuessServices
381388
{
382389
get
383390
{
384391
if (m_loader != null && m_loader.GuessServices != null)
385392
return m_loader.GuessServices;
386-
return new AnalysisGuessServices(m_cache);
393+
return new AnalysisGuessServices(m_cache, IsParsingMode());
387394
}
388395
}
389396

@@ -541,10 +548,32 @@ private void SetGuessing(IVwEnv vwenv, int bgColor)
541548
UsingGuess = true;
542549
}
543550

544-
private void SetGuessing(IVwEnv vwenv)
551+
private int GetGuessColor(ICmObject obj)
545552
{
546-
SetGuessing(vwenv, ApprovedGuessColor);
547-
UsingGuess = true;
553+
IWfiAnalysis wa;
554+
if (IsParsingMode())
555+
{
556+
// Parser approval takes precedence over User approval.
557+
wa = (obj is IWfiGloss) ? ((IWfiGloss)obj).Analysis : obj as IWfiAnalysis;
558+
if (wa != null)
559+
{
560+
Opinions opinion = wa.GetAgentOpinion(wa.Cache.LangProject.DefaultParserAgent);
561+
if (opinion == Opinions.approves)
562+
return MachineGuessColor;
563+
}
564+
return ApprovedGuessColor;
565+
}
566+
// User approval takes precedence over Parser approval.
567+
if (obj is IWfiGloss)
568+
return ApprovedGuessColor;
569+
wa = obj as IWfiAnalysis;
570+
if (wa != null)
571+
{
572+
Opinions opinion = wa.GetAgentOpinion(wa.Cache.LangProject.DefaultUserAgent);
573+
if (opinion == Opinions.approves)
574+
return ApprovedGuessColor;
575+
}
576+
return MachineGuessColor;
548577
}
549578

550579
public bool UsingGuess { get; set; }
@@ -1822,11 +1851,7 @@ private void DisplayMorphemes()
18221851
// Display the morpheme bundles.
18231852
if (m_hvoDefault != m_hvoWordBundleAnalysis)
18241853
{
1825-
// Real analysis isn't what we're displaying, so morph breakdown
1826-
// is a guess. Is it a human-approved guess?
1827-
bool isHumanGuess = m_this.GuessCache.get_IntProp(m_hvoDefault, InterlinViewDataCache.OpinionAgentFlid) !=
1828-
(int) AnalysisGuessServices.OpinionAgent.Parser;
1829-
m_this.SetGuessing(m_vwenv, isHumanGuess ? ApprovedGuessColor : MachineGuessColor);
1854+
m_this.SetGuessing(m_vwenv, m_this.GetGuessColor(m_defaultObj));
18301855
// Let the exporter know that this is a guessed analysis.
18311856
m_vwenv.set_StringProperty(ktagAnalysisStatus, "guess");
18321857
}
@@ -1842,7 +1867,7 @@ private void DisplayMorphemes()
18421867
if (m_hvoWordBundleAnalysis == m_hvoWordform)
18431868
{
18441869
// Real analysis is just word, one we're displaying is a default
1845-
m_this.SetGuessing(m_vwenv);
1870+
m_this.SetGuessing(m_vwenv, m_this.GetGuessColor(m_defaultObj));
18461871
// Let the exporter know that this is a guessed analysis.
18471872
m_vwenv.set_StringProperty(ktagAnalysisStatus, "guess");
18481873
}
@@ -1866,11 +1891,7 @@ private void DisplayWordGloss(InterlinLineSpec spec, int choiceIndex)
18661891
case WfiAnalysisTags.kClassId:
18671892
if (m_hvoDefault != m_hvoWordBundleAnalysis)
18681893
{
1869-
// Real analysis isn't what we're displaying, so morph breakdown
1870-
// is a guess. Is it a human-approved guess?
1871-
bool isHumanGuess = m_this.GuessCache.get_IntProp(m_hvoDefault, InterlinViewDataCache.OpinionAgentFlid) !=
1872-
(int)AnalysisGuessServices.OpinionAgent.Parser;
1873-
m_this.SetGuessing(m_vwenv, isHumanGuess ? ApprovedGuessColor : MachineGuessColor);
1894+
m_this.SetGuessing(m_vwenv, m_this.GetGuessColor(m_defaultObj));
18741895
}
18751896
var wa = (IWfiAnalysis) m_defaultObj;
18761897
if (wa.MeaningsOC.Count == 0)
@@ -1899,7 +1920,7 @@ private void DisplayWordGloss(InterlinLineSpec spec, int choiceIndex)
18991920
}
19001921
else
19011922
{
1902-
m_this.SetGuessing(m_vwenv);
1923+
m_this.SetGuessing(m_vwenv, m_this.GetGuessColor(m_defaultObj));
19031924
m_vwenv.AddObj(m_hvoDefault, m_this, kfragLineChoices + choiceIndex);
19041925
}
19051926
break;
@@ -1919,18 +1940,14 @@ private void DisplayWordPOS(int choiceIndex)
19191940
case WfiAnalysisTags.kClassId:
19201941
if (m_hvoDefault != m_hvoWordBundleAnalysis)
19211942
{
1922-
// Real analysis isn't what we're displaying, so POS is a guess.
1923-
bool isHumanApproved = m_this.GuessCache.get_IntProp(m_hvoDefault, InterlinViewDataCache.OpinionAgentFlid)
1924-
!= (int)AnalysisGuessServices.OpinionAgent.Parser;
1925-
1926-
m_this.SetGuessing(m_vwenv, isHumanApproved ? ApprovedGuessColor : MachineGuessColor);
1943+
m_this.SetGuessing(m_vwenv, m_this.GetGuessColor(m_defaultObj));
19271944
}
19281945
m_this.AddAnalysisPos(m_vwenv, m_hvoDefault, m_hvoWordBundleAnalysis, choiceIndex);
19291946
break;
19301947
case WfiGlossTags.kClassId:
19311948
m_hvoWfiAnalysis = m_defaultObj.Owner.Hvo;
19321949
if (m_hvoWordBundleAnalysis == m_hvoWordform) // then our analysis is a guess
1933-
m_this.SetGuessing(m_vwenv);
1950+
m_this.SetGuessing(m_vwenv, m_this.GetGuessColor(m_defaultObj));
19341951
m_vwenv.AddObj(m_hvoWfiAnalysis, m_this, kfragAnalysisCategoryChoices + choiceIndex);
19351952
break;
19361953
default:
@@ -2288,7 +2305,7 @@ private void EnsureLoader()
22882305

22892306
internal virtual IParaDataLoader CreateParaLoader()
22902307
{
2291-
return new InterlinViewCacheLoader(new AnalysisGuessServices(m_cache), GuessCache);
2308+
return new InterlinViewCacheLoader(new AnalysisGuessServices(m_cache, IsParsingMode()), GuessCache);
22922309
}
22932310

22942311
internal void RecordGuessIfNotKnown(AnalysisOccurrence selected)
@@ -2409,7 +2426,7 @@ public interface IParaDataLoader
24092426
{
24102427
void LoadParaData(IStTxtPara para);
24112428
void LoadSegmentData(ISegment seg);
2412-
void ResetGuessCache();
2429+
void ResetGuessCache(bool parsingMode);
24132430
bool UpdatingOccurrence(IAnalysis oldAnalysis, IAnalysis newAnalysis);
24142431
void RecordGuessIfNotKnown(AnalysisOccurrence occurrence);
24152432
IAnalysis GetGuessForWordform(IWfiWordform wf, int ws);
@@ -2533,10 +2550,11 @@ protected virtual void SetInt(int hvo, int flid, int n)
25332550
#region IParaDataLoader Members
25342551

25352552

2536-
public void ResetGuessCache()
2553+
public void ResetGuessCache(bool parsingMode)
25372554
{
25382555
// recreate the guess services, so they will use the latest FDO data.
25392556
GuessServices.ClearGuessData();
2557+
GuessServices.PrioritizeParser = parsingMode;
25402558
// clear the cache for the guesses, so it won't have any stale data.
25412559
m_guessCache.ClearPropFromCache(InterlinViewDataCache.AnalysisMostApprovedFlid);
25422560
}

0 commit comments

Comments
 (0)