Skip to content

Commit 17d0b91

Browse files
authored
Fix LT-21908: Create a utility to remove user-approved analyses (#354)
* Fix LT-21908: Create a utility to remove user-approved analyses * Fix bugs in LT-21908
1 parent bef6b77 commit 17d0b91

5 files changed

Lines changed: 150 additions & 0 deletions

File tree

DistFiles/Language Explorer/Configuration/UtilityCatalogInclude.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<utility assemblyPath="LexEdDll.dll" class="SIL.FieldWorks.XWorks.LexEd.HomographResetter"/>
44
<utility assemblyPath="MorphologyEditorDll.dll" class="SIL.FieldWorks.XWorks.MorphologyEditor.ParserAnalysisRemover"/>
55
<utility assemblyPath="MorphologyEditorDll.dll" class="SIL.FieldWorks.XWorks.MorphologyEditor.ParserAnnotationRemover"/>
6+
<utility assemblyPath="MorphologyEditorDll.dll" class="SIL.FieldWorks.XWorks.MorphologyEditor.UserAnalysisRemover"/>
67
<utility assemblyPath="FixFwDataDll.dll" class="SIL.FieldWorks.FixData.ErrorFixer"/>
78
<utility assemblyPath="FixFwDataDll.dll" class="SIL.FieldWorks.FixData.WriteAllObjectsUtility"/>
89
<utility assemblyPath="ITextDll.dll" class="SIL.FieldWorks.IText.DuplicateWordformFixer"/>

DistFiles/Language Explorer/Configuration/strings-en.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,12 @@
303303
<string id="WhatDescription" txt="This utility removes all parser annotations from the system. Parser annotations used to be added by the parser when there was a problem parsing a word. "/>
304304
<string id="RedoDescription" txt="You cannot use 'Undo' to cancel the effect of this utility."/>
305305
</group>
306+
<group id="RemoveUserAnalyses">
307+
<string id="Label" txt="Remove User-approved analyses"/>
308+
<string id="WhenDescription" txt="Run this utility when you want to remove all user-approved analyses. This is useful if the parser changes how it analyses wordforms."/>
309+
<string id="WhatDescription" txt="This utility removes all user approved analyses from the system. It does not remove analyses that are approved/disapproved of by the parser, however. "/>
310+
<string id="RedoDescription" txt="You cannot use 'Undo' to cancel the effect of this utility. Therefore, you should back up your project before running this."/>
311+
</group>
306312
<group id="NaturalClassChooser">
307313
<string id="kstidChooseNaturalClass" txt="Choose Natural Class"/>
308314
<string id="kstidNaturalClassListing" txt="The following natural classes have been specified in the grammar area."/>

Src/LexText/Interlinear/InterlinMaster.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,15 @@ protected override void OnValidating(System.ComponentModel.CancelEventArgs e)
883883
SaveWorkInProgress();
884884
}
885885

886+
public void OnRefreshInterlin(object argument)
887+
{
888+
// Reset data.
889+
RootStText = null;
890+
m_idcAnalyze.ResetAnalysisCache();
891+
// Refresh the display.
892+
Clerk.JumpToIndex(Clerk.CurrentIndex);
893+
}
894+
886895
protected override void ShowRecord()
887896
{
888897
SaveWorkInProgress();

Src/LexText/Morphology/MorphologyEditorDll.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,7 @@
384384
<SubType>UserControl</SubType>
385385
</Compile>
386386
<Compile Include="RuleFormulaVcBase.cs" />
387+
<Compile Include="UserAnalysisRemover.cs" />
387388
<Compile Include="WordformGoDlg.cs">
388389
<SubType>Form</SubType>
389390
</Compile>
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using SIL.FieldWorks.Common.FwUtils;
8+
using SIL.FieldWorks.FwCoreDlgs;
9+
using SIL.LCModel.Infrastructure;
10+
using SIL.LCModel;
11+
12+
namespace SIL.FieldWorks.XWorks.MorphologyEditor
13+
{
14+
/// <summary>
15+
/// This class serves to remove all analyses that are only approved by the user.
16+
/// Analyses that have a parser evaluation (approved or disapproved) remain afterwards.
17+
/// </summary>
18+
public class UserAnalysisRemover : IUtility
19+
{
20+
#region Data members
21+
22+
private UtilityDlg m_dlg;
23+
const string kPath = "/group[@id='Linguistics']/group[@id='Morphology']/group[@id='RemoveUserAnalyses']/";
24+
25+
#endregion Data members
26+
27+
/// <summary>
28+
/// Override method to return the Label property.
29+
/// </summary>
30+
/// <returns></returns>
31+
public override string ToString()
32+
{
33+
return Label;
34+
}
35+
36+
#region IUtility implementation
37+
38+
/// <summary>
39+
/// Get the main label describing the utility.
40+
/// </summary>
41+
public string Label
42+
{
43+
get
44+
{
45+
Debug.Assert(m_dlg != null);
46+
return StringTable.Table.GetStringWithXPath("Label", kPath);
47+
}
48+
}
49+
50+
/// <summary>
51+
/// Set the UtilityDlg.
52+
/// </summary>
53+
/// <remarks>
54+
/// This must be set, before calling any other property or method.
55+
/// </remarks>
56+
public UtilityDlg Dialog
57+
{
58+
set
59+
{
60+
Debug.Assert(value != null);
61+
Debug.Assert(m_dlg == null);
62+
63+
m_dlg = value;
64+
}
65+
}
66+
67+
/// <summary>
68+
/// Load 0 or more items in the list box.
69+
/// </summary>
70+
public void LoadUtilities()
71+
{
72+
Debug.Assert(m_dlg != null);
73+
m_dlg.Utilities.Items.Add(this);
74+
75+
}
76+
77+
/// <summary>
78+
/// Notify the utility that has been selected in the dlg.
79+
/// </summary>
80+
public void OnSelection()
81+
{
82+
Debug.Assert(m_dlg != null);
83+
m_dlg.WhenDescription = StringTable.Table.GetStringWithXPath("WhenDescription", kPath);
84+
m_dlg.WhatDescription = StringTable.Table.GetStringWithXPath("WhatDescription", kPath);
85+
m_dlg.RedoDescription = StringTable.Table.GetStringWithXPath("RedoDescription", kPath);
86+
}
87+
88+
/// <summary>
89+
/// Have the utility do what it does.
90+
/// </summary>
91+
public void Process()
92+
{
93+
Debug.Assert(m_dlg != null);
94+
var cache = m_dlg.PropTable.GetValue<LcmCache>("cache");
95+
IWfiAnalysis[] analyses = cache.ServiceLocator.GetInstance<IWfiAnalysisRepository>().AllInstances().ToArray();
96+
if (analyses.Length == 0)
97+
return;
98+
99+
// Set up progress bar.
100+
m_dlg.ProgressBar.Minimum = 0;
101+
m_dlg.ProgressBar.Maximum = analyses.Length;
102+
m_dlg.ProgressBar.Step = 1;
103+
104+
NonUndoableUnitOfWorkHelper.Do(cache.ActionHandlerAccessor, () =>
105+
{
106+
foreach (IWfiAnalysis analysis in analyses)
107+
{
108+
ICmAgentEvaluation[] humanEvals = analysis.EvaluationsRC.Where(evaluation => evaluation.Human).ToArray();
109+
foreach (ICmAgentEvaluation humanEval in humanEvals)
110+
analysis.EvaluationsRC.Remove(humanEval);
111+
112+
IWfiWordform wordform = analysis.Wordform;
113+
if (analysis.EvaluationsRC.Count == 0)
114+
wordform.AnalysesOC.Remove(analysis);
115+
116+
if (humanEvals.Length > 0)
117+
{
118+
wordform.Checksum = 0;
119+
if (analysis.Cache != null)
120+
analysis.MoveConcAnnotationsToWordform();
121+
}
122+
123+
m_dlg.ProgressBar.PerformStep();
124+
}
125+
});
126+
127+
m_dlg.Mediator.SendMessage("RefreshInterlin", null);
128+
129+
}
130+
131+
#endregion IUtility implementation
132+
}
133+
}

0 commit comments

Comments
 (0)