Skip to content

Commit

Permalink
LT-21756: Fix some of the issues from Jason's review
Browse files Browse the repository at this point in the history
* Also some minor merge related clean-up
  • Loading branch information
jtmaxwell3 authored and jasonleenaylor committed Jul 11, 2024
1 parent cdb09d5 commit f7ac285
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 73 deletions.
60 changes: 21 additions & 39 deletions Src/LexText/ParserCore/ParserReport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,6 @@ public ParserReport(LcmCache cache)
/// <summary>
/// Adds parse report to ParseReports and update statistics.
/// </summary>
/// <param name="word"></param>
/// <param name="report"></param>
public void AddParseReport(string word, ParseReport report)
{
ParseReports[word] = report;
Expand All @@ -149,8 +147,6 @@ public void AddParseReport(string word, ParseReport report)
/// <summary>
/// Read the given json file as a ParserReport.
/// </summary>
/// <param name="filename"></param>
/// <returns></returns>
public static ParserReport ReadJsonFile(string filename)
{
string json = File.ReadAllText(filename);
Expand All @@ -168,8 +164,7 @@ public static ParserReport ReadJsonFile(string filename)
/// <summary>
/// Write this parser report as json on the given filename.
/// </summary>
/// <param name="filename"></param>
public void WriteJsonFile(string filename)
private void WriteJsonFile(string filename)
{
string json = JsonConvert.SerializeObject(this);
using (StreamWriter outputFile = new StreamWriter(filename))
Expand All @@ -182,7 +177,6 @@ public void WriteJsonFile(string filename)
/// <summary>
/// Write this parser report as json in the standard place and return the filename.
/// </summary>
/// <param name="cache"></param>
public string WriteJsonFile(LcmCache cache)
{
var reportDir = GetProjectReportsDirectory(cache);
Expand All @@ -204,8 +198,6 @@ public void DeleteJsonFile()
/// Get the project reports directory for the project.
/// This is where project reports are stored.
/// </summary>
/// <param name="cache"></param>
/// <returns></returns>
public static string GetProjectReportsDirectory(LcmCache cache)
{
// TODO: Handle the case when the project isn't local.
Expand All @@ -218,40 +210,38 @@ public static string GetProjectReportsDirectory(LcmCache cache)
/// <summary>
/// Return the differences between the current report and another report.
/// </summary>
/// <param name="report2"></param>
/// <returns></returns>
public ParserReport DiffParserReports (ParserReport report2)
public ParserReport DiffParserReports(ParserReport other)
{
ParserReport diff = new ParserReport();
diff.IsDiff = true;
diff.ProjectName = DiffNames(ProjectName, report2.ProjectName);
diff.SourceText = DiffNames(SourceText, report2.SourceText);
diff.MachineName = DiffNames(MachineName, report2.MachineName);
diff.Timestamp = Timestamp - report2.Timestamp;
diff.NumWords = NumWords - report2.NumWords;
diff.NumParseErrors = NumParseErrors - report2.NumParseErrors;
diff.NumZeroParses = NumZeroParses - report2.NumZeroParses;
diff.TotalParseTime = TotalParseTime - report2.TotalParseTime;
diff.TotalAnalyses = TotalAnalyses - report2.TotalAnalyses;
diff.TotalUserApprovedAnalysesMissing = TotalUserApprovedAnalysesMissing - report2.TotalUserApprovedAnalysesMissing;
diff.TotalUserDisapprovedAnalyses = TotalUserDisapprovedAnalyses - report2.TotalUserDisapprovedAnalyses;
diff.TotalUserNoOpinionAnalyses = TotalUserNoOpinionAnalyses - report2.TotalUserNoOpinionAnalyses;
diff.ProjectName = DiffNames(ProjectName, other.ProjectName);
diff.SourceText = DiffNames(SourceText, other.SourceText);
diff.MachineName = DiffNames(MachineName, other.MachineName);
diff.Timestamp = Timestamp - other.Timestamp;
diff.NumWords = NumWords - other.NumWords;
diff.NumParseErrors = NumParseErrors - other.NumParseErrors;
diff.NumZeroParses = NumZeroParses - other.NumZeroParses;
diff.TotalParseTime = TotalParseTime - other.TotalParseTime;
diff.TotalAnalyses = TotalAnalyses - other.TotalAnalyses;
diff.TotalUserApprovedAnalysesMissing = TotalUserApprovedAnalysesMissing - other.TotalUserApprovedAnalysesMissing;
diff.TotalUserDisapprovedAnalyses = TotalUserDisapprovedAnalyses - other.TotalUserDisapprovedAnalyses;
diff.TotalUserNoOpinionAnalyses = TotalUserNoOpinionAnalyses - other.TotalUserNoOpinionAnalyses;

ParseReport missingReport = new ParseReport
{
ErrorMessage = "missing"
};

foreach (string key in report2.ParseReports.Keys)
foreach (string key in other.ParseReports.Keys)
{
ParseReport oldReport = report2.ParseReports[key];
ParseReport oldReport = other.ParseReports[key];
ParseReport newReport = ParseReports.ContainsKey(key) ? ParseReports[key] : missingReport;
ParseReport diffReport = newReport.DiffParseReport(oldReport);
diff.AddParseReport(key, diffReport);
}
foreach (string key in ParseReports.Keys)
{
if (!report2.ParseReports.ContainsKey(key))
if (!other.ParseReports.ContainsKey(key))
{
ParseReport newReport = ParseReports[key];
ParseReport diffReport = newReport.DiffParseReport(missingReport);
Expand All @@ -263,18 +253,16 @@ public ParserReport DiffParserReports (ParserReport report2)
return diff;
}

string DiffNames(string name1, string name2)
string DiffNames(string name, string otherName)
{
if (name1 == name2)
return name1;
return name1 + " - " + name2;
if (name == otherName)
return name;
return name + " - " + otherName;
}

/// <summary>
/// Is this parse report equal to other?
/// </summary>
/// <param name="other"></param>
/// <returns></returns>
public bool Equals(ParserReport other)
{
if (other is null)
Expand Down Expand Up @@ -370,8 +358,6 @@ public class ParseReport : IEquatable<ParseReport>
/// Create a parse report from a wordform and a parse result.
/// The wordform is needed to check user approval of parse analyses.
/// </summary>
/// <param name="wordform"></param>
/// <param name="result"></param>
public ParseReport(IWfiWordform wordform, ParseResult result)
{
ParseTime = result.ParseTime;
Expand Down Expand Up @@ -422,8 +408,6 @@ public ParseReport(IWfiWordform wordform, ParseResult result)
/// <summary>
/// Return the diff between the current report and the old report.
/// </summary>
/// <param name="oldReport"></param>
/// <returns></returns>
public ParseReport DiffParseReport(ParseReport oldReport)
{
ParseReport diffReport = new ParseReport
Expand All @@ -446,8 +430,6 @@ public ParseReport DiffParseReport(ParseReport oldReport)
/// <summary>
/// Is this parse report equal to other?
/// </summary>
/// <param name="other"></param>
/// <returns></returns>
public bool Equals(ParseReport other)
{
if (ParseTime != other.ParseTime) return false;
Expand Down
1 change: 1 addition & 0 deletions Src/LexText/ParserCore/ParserWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ public bool UpdateWordform(IWfiWordform wordform, ParserPriority priority, bool

if (sLower != form.Text)
{
var text = TsStringUtils.MakeString(sLower, form.get_WritingSystem(0));
IWfiWordform lcWordform;
// We cannot use WfiWordformServices.FindOrCreateWordform because of props change (LT-21810).
// Only parse the lowercase version if it exists.
Expand Down
28 changes: 14 additions & 14 deletions Src/LexText/ParserUI/ParserReportDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,69 +25,69 @@
<DataGridTextColumn Binding="{Binding Word}">
<DataGridTextColumn.Header>
<StackPanel>
<Label ToolTip="the word that was parsed">Word</Label>
<Label ToolTip="The word that was parsed">Word</Label>
<Separator/>
<Label ToolTip ="number of words"
<Label ToolTip ="Number of words"
Content="{Binding DataContext.ParserReport.NumWords, RelativeSource={RelativeSource AncestorType=DataGrid}}"></Label>
</StackPanel>
</DataGridTextColumn.Header>
</DataGridTextColumn>
<DataGridTextColumn Binding="{Binding ErrorMessage}">
<DataGridTextColumn.Header>
<StackPanel>
<Label ToolTip="the error message reported by the parser">Error Message</Label>
<Label ToolTip="The error message reported by the parser">Error Message</Label>
<Separator/>
<Label ToolTip ="number of parse errors"
<Label ToolTip ="Number of parse errors"
Content="{Binding DataContext.ParserReport.NumParseErrors, RelativeSource={RelativeSource AncestorType=DataGrid}}"></Label>
</StackPanel>
</DataGridTextColumn.Header>
</DataGridTextColumn>
<DataGridTextColumn Binding="{Binding NumAnalyses}">
<DataGridTextColumn.Header>
<StackPanel>
<Label ToolTip="the number of analyses produced by the parser">Num Analyses</Label>
<Label ToolTip="The number of analyses produced by the parser">Num Analyses</Label>
<Separator/>
<Label ToolTip ="total number of analyses"
<Label ToolTip ="Total number of analyses"
Content="{Binding DataContext.ParserReport.TotalAnalyses, RelativeSource={RelativeSource AncestorType=DataGrid}}"></Label>
</StackPanel>
</DataGridTextColumn.Header>
</DataGridTextColumn>
<DataGridTextColumn Binding="{Binding NumUserApprovedAnalysesMissing}">
<DataGridTextColumn.Header>
<StackPanel>
<Label ToolTip="the number of analyses approved by the user that the parser didn't produce">Missing Analyses</Label>
<Label ToolTip="The number of analyses approved by the user that the parser didn't produce">Missing Analyses</Label>
<Separator/>
<Label ToolTip ="total number of missing analyses"
<Label ToolTip ="Total number of missing analyses"
Content="{Binding DataContext.ParserReport.TotalUserApprovedAnalysesMissing, RelativeSource={RelativeSource AncestorType=DataGrid}}"></Label>
</StackPanel>
</DataGridTextColumn.Header>
</DataGridTextColumn>
<DataGridTextColumn Binding="{Binding NumUserDisapprovedAnalyses}">
<DataGridTextColumn.Header>
<StackPanel>
<Label ToolTip="the number of analyses produced by the parser that were disapproved by the user">Disapproved Analyses</Label>
<Label ToolTip="The number of analyses produced by the parser that were disapproved by the user">Disapproved Analyses</Label>
<Separator/>
<Label ToolTip ="total number of disapproved analyses"
<Label ToolTip ="Total number of disapproved analyses"
Content="{Binding DataContext.ParserReport.TotalUserDisapprovedAnalyses, RelativeSource={RelativeSource AncestorType=DataGrid}}"></Label>
</StackPanel>
</DataGridTextColumn.Header>
</DataGridTextColumn>
<DataGridTextColumn Binding="{Binding NumUserNoOpinionAnalyses}">
<DataGridTextColumn.Header>
<StackPanel>
<Label ToolTip="the number of analyses produced by the parser that were neither approved nor disapproved by the user">No Opinion Analyses</Label>
<Label ToolTip="The number of analyses produced by the parser that were neither approved nor disapproved by the user">No Opinion Analyses</Label>
<Separator/>
<Label ToolTip ="total number of analyses with no opinion"
<Label ToolTip ="Total number of analyses with no opinion"
Content="{Binding DataContext.ParserReport.TotalUserNoOpinionAnalyses, RelativeSource={RelativeSource AncestorType=DataGrid}}"></Label>
</StackPanel>
</DataGridTextColumn.Header>
</DataGridTextColumn>
<DataGridTextColumn Binding="{Binding ParseTime}">
<DataGridTextColumn.Header>
<StackPanel>
<Label ToolTip="the time it took to parse the word">Parse Time</Label>
<Label ToolTip="The time it took to parse the word">Parse Time</Label>
<Separator/>
<Label ToolTip ="total parse time"
<Label ToolTip ="Total parse time"
Content="{Binding DataContext.ParserReport.TotalParseTime, RelativeSource={RelativeSource AncestorType=DataGrid}}"></Label>
</StackPanel>
</DataGridTextColumn.Header>
Expand Down
4 changes: 0 additions & 4 deletions Src/LexText/ParserUI/ParserReportViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ public ParserReportViewModel()
ParserReport.AddParseReport("test", new ParseReport(null, new ParseResult(new List<ParseAnalysis>())));
ParserReport.AddParseReport("error", new ParseReport(null, new ParseResult("error")));
}
else
{
// Runtime data loading logic here
}
}
}
}
24 changes: 12 additions & 12 deletions Src/LexText/ParserUI/ParserReportsDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
</DataGridTemplateColumn>
<DataGridTemplateColumn>
<DataGridTemplateColumn.Header>
<Label ToolTip="the second argument to the diff">2nd</Label>
<Label ToolTip="The second argument to the diff">2nd</Label>
</DataGridTemplateColumn.Header>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
Expand All @@ -58,57 +58,57 @@
</DataGridTemplateColumn>
<DataGridTextColumn Binding="{Binding SourceText}">
<DataGridTextColumn.Header>
<Label ToolTip="the text that was parsed">Text</Label>
<Label ToolTip="The text that was parsed">Text</Label>
</DataGridTextColumn.Header>
</DataGridTextColumn>
<DataGridTextColumn Binding="{Binding Timestamp, Converter={StaticResource FileTimeToDateTimeConverter}, StringFormat=\{0:G\}}">
<DataGridTextColumn.Header>
<Label ToolTip="when the text was parsed">Timestamp</Label>
<Label ToolTip="When the text was parsed">Timestamp</Label>
</DataGridTextColumn.Header>
</DataGridTextColumn>
<DataGridTextColumn Binding="{Binding MachineName}">
<DataGridTextColumn.Header>
<Label ToolTip="the machine that the text was parsed on">Machine Name</Label>
<Label ToolTip="The machine that the text was parsed on">Machine Name</Label>
</DataGridTextColumn.Header>
</DataGridTextColumn>
<DataGridTextColumn Binding="{Binding NumWords}">
<DataGridTextColumn.Header>
<Label ToolTip="the number of distinct words parsed in the text">Num Words Parsed</Label>
<Label ToolTip="The number of distinct words parsed in the text">Num Words Parsed</Label>
</DataGridTextColumn.Header>
</DataGridTextColumn>
<DataGridTextColumn Binding="{Binding NumParseErrors}">
<DataGridTextColumn.Header>
<Label ToolTip="the number of errors in the words parsed">Num Parse Errors</Label>
<Label ToolTip="The number of errors in the words parsed">Num Parse Errors</Label>
</DataGridTextColumn.Header>
</DataGridTextColumn>
<DataGridTextColumn Binding="{Binding NumZeroParses}">
<DataGridTextColumn.Header>
<Label ToolTip="the number of zero parses in the words parsed">Num Zero Parses</Label>
<Label ToolTip="The number of zero parses in the words parsed">Num Zero Parses</Label>
</DataGridTextColumn.Header>
</DataGridTextColumn>
<DataGridTextColumn Binding="{Binding TotalParseTime}">
<DataGridTextColumn.Header>
<Label ToolTip="the time it took to parse all the distinct words in the text">Total Parse Time</Label>
<Label ToolTip="The time it took to parse all the distinct words in the text">Total Parse Time</Label>
</DataGridTextColumn.Header>
</DataGridTextColumn>
<DataGridTextColumn Binding="{Binding TotalAnalyses}">
<DataGridTextColumn.Header>
<Label ToolTip="the number of analyses in the words parsed">Total Analyses</Label>
<Label ToolTip="The number of analyses in the words parsed">Total Analyses</Label>
</DataGridTextColumn.Header>
</DataGridTextColumn>
<DataGridTextColumn Binding="{Binding TotalUserApprovedAnalysesMissing}">
<DataGridTextColumn.Header>
<Label ToolTip="the number of approved analyses missing in the words parsed">Total Missing Analyses</Label>
<Label ToolTip="The number of approved analyses missing in the words parsed">Total Missing Analyses</Label>
</DataGridTextColumn.Header>
</DataGridTextColumn>
<DataGridTextColumn Binding="{Binding TotalUserDisapprovedAnalyses}">
<DataGridTextColumn.Header>
<Label ToolTip="the number of disapproved analyses in the words parsed">Total Disapproved Analyses</Label>
<Label ToolTip="The number of disapproved analyses in the words parsed">Total Disapproved Analyses</Label>
</DataGridTextColumn.Header>
</DataGridTextColumn>
<DataGridTextColumn Binding="{Binding TotalUserNoOpinionAnalyses}">
<DataGridTextColumn.Header>
<Label ToolTip="the number of analyses that were neither approved not disapproved in the words parsed">Total No Opinion Analyses</Label>
<Label ToolTip="The number of analyses that were neither approved not disapproved in the words parsed">Total No Opinion Analyses</Label>
</DataGridTextColumn.Header>
</DataGridTextColumn>
</DataGrid.Columns>
Expand Down
4 changes: 0 additions & 4 deletions Src/LexText/ParserUI/ParserReportsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ public ParserReportsViewModel()
NumZeroParses = 1
});
}
else
{
// Runtime data loading logic here
}
}
}
}

0 comments on commit f7ac285

Please sign in to comment.