Skip to content

Commit 1839c2f

Browse files
author
Shujaat
committed
- New QA comparison engine added
- QAs that have more than 50% difference are discarded in comparison results
1 parent 125399f commit 1839c2f

27 files changed

+347
-291
lines changed

Common/LicenseGen.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public override bool Equals(object obj)
2424
var objLI = obj as LI;
2525

2626
return objLI.app.Trim() == this.app.Trim() &&
27-
objLI.email.Trim() == this.email.Trim() &&
27+
objLI.email.Trim().ToLower() == this.email.Trim().ToLower() &&
2828
objLI.code.Trim() == this.code.Trim();
2929
}
3030

HFQAppKeyGen/HFQAppKeyGen.csproj

+4-3
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@
5555
<SignAssembly>false</SignAssembly>
5656
</PropertyGroup>
5757
<PropertyGroup>
58-
<ManifestCertificateThumbprint>15177BB220298CCBAB0E47B339BA797E80817D7C</ManifestCertificateThumbprint>
58+
<ManifestCertificateThumbprint>63AE7E3A28B7D648F91A6236DF918692A2FEAE92</ManifestCertificateThumbprint>
5959
</PropertyGroup>
6060
<PropertyGroup>
61-
<ManifestKeyFile>HFQAppKeyGen_TemporaryKey.pfx</ManifestKeyFile>
61+
<ManifestKeyFile>HFQAppKeyGen_1_TemporaryKey.pfx</ManifestKeyFile>
6262
</PropertyGroup>
6363
<PropertyGroup>
6464
<GenerateManifests>true</GenerateManifests>
@@ -119,6 +119,7 @@
119119
<Resource Include="AUDIOWIDE-REGULAR.TTF">
120120
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
121121
</Resource>
122+
<None Include="HFQAppKeyGen_1_TemporaryKey.pfx" />
122123
<None Include="HFQAppKeyGen_TemporaryKey.pfx" />
123124
<None Include="Properties\Settings.settings">
124125
<Generator>SettingsSingleFileGenerator</Generator>
@@ -157,7 +158,7 @@
157158
</PropertyGroup>
158159
<ProjectExtensions>
159160
<VisualStudio>
160-
<UserProperties Reactor_Deploy="0" Reactor_Output="" Reactor_Configuration="Release" Reactor_Project="" Reactor_Commands="" Reactor_Enabled="1" />
161+
<UserProperties Reactor_Enabled="1" Reactor_Commands="" Reactor_Project="" Reactor_Configuration="Release" Reactor_Output="" Reactor_Deploy="0" />
161162
</VisualStudio>
162163
</ProjectExtensions>
163164
</Project>

HFQOApp/MainWindow.xaml.cs

+16-8
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,24 @@ private void HFQPane_QASelected(QA qa)
6464
{
6565
try
6666
{
67-
//scroll to the position of QA
68-
var PH = DV.PageViews[0].DocumentPage.Size.Height;
69-
var VH = DV.PageViews[0].ActualHeight;
67+
if (qa.StartPage <= 0)
68+
{
69+
ViewModelLocator.DialogService.ShowMessage($"Cannot locate this QA because StartPage value for this QA is invalid. QA.StartPage = {qa.StartPage}", false);
70+
}
71+
else
72+
{
73+
//scroll to the position of QA
74+
var PH = DV.PageViews[0].DocumentPage.Size.Height;
75+
var VH = DV.PageViews[0].ActualHeight;
7076

71-
var XPSPageHeight = DV.PageViews[0].ActualHeight + DV.VerticalPageSpacing + 2;
72-
var R = (qa.StartY / PH - 0.1) * VH;
77+
var XPSPageHeight = DV.PageViews[0].ActualHeight + DV.VerticalPageSpacing + 2;
78+
var R = (qa.StartY / PH - 0.1) * VH;
7379

74-
if (R < 0) R = 0;
80+
if (R < 0) R = 0;
7581

76-
DV.VerticalOffset = (qa.StartPage - 1) * XPSPageHeight + R;
82+
83+
DV.VerticalOffset = (qa.StartPage - 1) * XPSPageHeight + R;
84+
}
7785
}
7886
catch (Exception ee)
7987
{
@@ -139,7 +147,7 @@ private void AboutButton_Click(object sender, RoutedEventArgs e)
139147
{
140148
ViewModelLocatorBase.DialogService.OpenAboutWindow();
141149

142-
150+
143151
}
144152

145153
private void DeleteXPSFile(string xpsPath)

HFQOVM/ViewModelLocator.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ static ViewModelLocator()
3333
SimpleIoc.Default.Register<IHardwareHelper, HardwareHelper>();
3434

3535
#if(DEBUG)
36-
//SimpleIoc.Default.Register<ICameraService, DummyCameraService>();
37-
SimpleIoc.Default.Register<ICameraService, CameraService>();
36+
SimpleIoc.Default.Register<ICameraService, DummyCameraService>();
37+
//SimpleIoc.Default.Register<ICameraService, CameraService>();
3838
#else
3939
SimpleIoc.Default.Register<ICameraService, CameraService>();
4040
#endif

MultiDF.VM/DFResult.cs

+7-8
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,13 @@ public DFResultRow(int i1, int i2, double dist)
3939

4040
public override bool Equals(object obj)
4141
{
42-
if (obj == null || typeof(DFResultRow) != obj.GetType())
43-
return false;
44-
else
45-
{
46-
var Other = (DFResultRow)obj;
47-
return (Q1.Equals(Other.Q1) && Q2.Equals(Other.Q2)) ||
48-
(Q2.Equals(Other.Q1) && Q1.Equals(Other.Q2));
49-
}
42+
return
43+
obj != null &&
44+
obj is DFResultRow other &&
45+
(
46+
(Q1.Equals(other.Q1) && Q2.Equals(other.Q2)) ||
47+
(Q2.Equals(other.Q1) && Q1.Equals(other.Q2))
48+
);
5049
}
5150

5251
public override int GetHashCode()

MultiDF.VM/DefaultDocComparer.cs

+57-62
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ namespace MultiDF.VM
1010
{
1111
public class DefaultDocComparer : IDocComparer
1212
{
13+
private const float MAX_DIFF_THRESHOLD = 0.5f;
14+
1315
public event Action<XMLDoc, XMLDoc> DocCompareStarted;
1416
public event QAComparedDelegate QACompared;
1517
public event Action QASkipped;
@@ -18,9 +20,9 @@ public class DefaultDocComparer : IDocComparer
1820
//This list will keep record of pairs of question that have been dispatched for comparison, so that
1921
//we do not send them for comparison again. e.g. if X and Y have been dispatched for comparison, we will
2022
//not dispatch the inverse pair Y and X.
21-
List<DFResultRow> DispatchedItems = new List<DFResultRow>();
23+
//HashSet<(QA, QA)> DispatchedItems;
2224

23-
public Task<DFResult> Compare(XMLDoc d1, XMLDoc d2, IQAComparer qaComparer, bool ignoreCase, CancellationToken token)
25+
public DFResult Compare(XMLDoc d1, XMLDoc d2, IQAComparer qaComparer, bool ignoreCase, CancellationToken token)
2426
{
2527
DFResult Result = new DFResult(d1, d2, d1.QAs.Count, d2.QAs.Count);
2628

@@ -29,76 +31,69 @@ public Task<DFResult> Compare(XMLDoc d1, XMLDoc d2, IQAComparer qaComparer, bool
2931

3032
DocCompareStarted?.Invoke(d1, d2);
3133

32-
DispatchedItems.Clear();
34+
//DispatchedItems = new HashSet<(QA, QA)>();
3335

34-
return Task.Run(() =>
36+
try
3537
{
36-
Parallel.ForEach(d1.QAs, new ParallelOptions() { CancellationToken = token },
37-
q1 =>
38+
var AllComparisons = Parallel.ForEach(d1.QAs, new ParallelOptions() { CancellationToken = token, MaxDegreeOfParallelism = 3 },
39+
(q1) =>
40+
{
41+
42+
foreach (var q2 in d2.QAs)
43+
{
44+
Interlocked.Increment(ref LoopCount);
45+
var Prog = 100 * (LoopCount / TotalComparisons);
46+
47+
if (!q1.Equals(q2))
48+
{
49+
//var DFR = ProcessDFR(q1, q2, qaComparer, ignoreCase);
50+
51+
var DFR = new DFResultRow(q1, q2, 0);
52+
DFR.Distance = qaComparer.Distance(q1, q2, ignoreCase);
53+
54+
55+
if (DFR != null && DFR.Distance < MAX_DIFF_THRESHOLD)
3856
{
39-
foreach (var q2 in d2.QAs)
40-
{
41-
var DFR = ProcessDFR(q1, q2, qaComparer, ignoreCase, token);
42-
Interlocked.Increment(ref LoopCount);
43-
var Prog = 100 * (LoopCount / TotalComparisons);
44-
45-
if (DFR != null)
46-
{
47-
lock(this){
48-
Result.Items.Add(DFR.Value);
49-
QACompared?.Invoke(this, new QAComparedArgs() { QA1 = q1, QA2 = q2, Distance = DFR.Value.Distance, PercentProgress = Prog });
50-
}
51-
}
52-
else
53-
QASkipped?.Invoke();
54-
55-
token.ThrowIfCancellationRequested();
56-
}
57+
Result.Items.Add(DFR);
58+
QACompared?.Invoke(this, new QAComparedArgs() { QA1 = q1, QA2 = q2, Distance = DFR.Distance, PercentProgress = Prog });
5759
}
58-
);
59-
}).ContinueWith(t =>
60-
{
61-
if (t.Exception == null)
62-
{
63-
DocCompareCompleted?.Invoke(d1, d2);
64-
return Result;
65-
}
66-
else
67-
throw t.Exception;
68-
});
69-
}
60+
else
61+
QASkipped?.Invoke();
7062

63+
token.ThrowIfCancellationRequested();
64+
}
65+
}
7166

72-
private DFResultRow? ProcessDFR(QA q1, QA q2, IQAComparer qaComparer, bool ignoreCase, CancellationToken token)
73-
{
74-
if (q1 != q2)
67+
ViewModelLocator.Main.RaisePropertyChanged(nameof(MainVM.ElapsedTime));
68+
ViewModelLocator.Main.RaisePropertyChanged(nameof(MainVM.EstimatedRemainingTime));
69+
});
70+
}
71+
finally
7572
{
76-
var DFR = new DFResultRow(q1, q2, 0);
77-
78-
var Flag = false;
73+
DocCompareCompleted?.Invoke(d1, d2);
74+
}
7975

80-
lock (DispatchedItems)
81-
{
82-
if (!DispatchedItems.Any(i => i.Equals(DFR)))
83-
{
84-
DispatchedItems.Add(DFR);
85-
Flag = true;
86-
}
87-
}
88-
89-
if (Flag)
90-
{
91-
if (!token.IsCancellationRequested)
92-
{
93-
DFR.Distance = qaComparer.Distance(q1, q2, ignoreCase);
76+
return Result;
77+
}
9478

95-
if (!token.IsCancellationRequested)
96-
return DFR;
97-
}
98-
}
99-
}
79+
private DFResultRow? ProcessDFR(QA q1, QA q2, IQAComparer qaComparer, bool ignoreCase)
80+
{
81+
//if (!DispatchedItems.Contains((q1, q2)))
82+
//{
83+
// lock (DispatchedItems)
84+
// {
85+
// DispatchedItems.Add((q1, q2));
86+
// }
10087

101-
return null;
88+
var DFR = new DFResultRow(q1, q2, 0);
89+
DFR.Distance = qaComparer.Distance(q1, q2, ignoreCase);
90+
return DFR;
91+
//}
92+
//else
93+
//{
94+
// System.Diagnostics.Debug.Print("Already dispatched");
95+
// return null;
96+
//}
10297
}
10398
}
10499
}

MultiDF.VM/DefaultQAExtractionStrategy.cs

+2
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ private QA ExtractNextQA(List<WordParagraph> paragraphs, ref int i)
178178
{
179179
state = QAExtractionState.Choices;
180180
QA.Choices.Add(paragraphs[i].Text);
181+
QA.ChoicesUpper.Add(paragraphs[i].Text.ToUpperInvariant());
181182
}
182183
else if (NormalizedText.Contains("answer area:"))
183184
{
@@ -197,6 +198,7 @@ private QA ExtractNextQA(List<WordParagraph> paragraphs, ref int i)
197198
if (paragraphs[i].Type == ParagraphType.NumberedList || paragraphs[i].Type == ParagraphType.TableRow)
198199
{
199200
QA.Choices.Add(paragraphs[i].Text);
201+
QA.ChoicesUpper.Add(paragraphs[i].Text.ToUpperInvariant());
200202
}
201203
else
202204
{

MultiDF.VM/DiffVM.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public DiffVM()
4747
var Acopy = new List<string>(args.a1);
4848
var Bcopy = new List<string>(args.a2);
4949

50-
MinDistanceSort.Sort(Acopy, Bcopy, Levenshtein.CalcLevenshteinDistanceIgnoreCase);
50+
MinDistanceSort.Sort(Acopy, Bcopy, true, Fastenshtein.Levenshtein.Distance);
5151

5252
var Result2 = diff2.BuildDiffModel(string.Join(Environment.NewLine, Acopy), string.Join(Environment.NewLine, Bcopy), false);
5353

MultiDF.VM/Interfaces/IDocComparer.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class QAComparedArgs : EventArgs
1818

1919
public interface IDocComparer
2020
{
21-
Task<DFResult> Compare(XMLDoc d1, XMLDoc d2, IQAComparer qaComparer, bool ignoreCase, CancellationToken token);
21+
DFResult Compare(XMLDoc d1, XMLDoc d2, IQAComparer qaComparer, bool ignoreCase, CancellationToken token);
2222

2323
event Action<XMLDoc, XMLDoc> DocCompareStarted;
2424
event QAComparedDelegate QACompared;

0 commit comments

Comments
 (0)