Skip to content

Commit

Permalink
collapse error tables
Browse files Browse the repository at this point in the history
  • Loading branch information
russcam committed May 3, 2024
1 parent 267d1b8 commit 868ae85
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion build/Build/CombinedAccuracyReport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static void Create()
writer.WriteLine($"# {name} Accuracy report");
writer.WriteLine();
writer.Flush();
foreach (var report in Directory.GetFiles(implementationDir))
foreach (var report in Directory.GetFiles(implementationDir).OrderBy(p => p))
{
using var reportStream = File.OpenRead(report);
reportStream.CopyTo(combinedResportStream);
Expand Down
19 changes: 11 additions & 8 deletions tests/Lingua.AccuracyReport.Tests/LanguageDetectionStatistics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Lingua.AccuracyReport.Tests;
/// <summary>
/// Collects statistics for language detection for a given language.
/// </summary>
public class LanguageDetectionStatistics<TDetectorFactory>(IMessageSink messageSink) : IDisposable
public class LanguageDetectionStatistics<TDetectorFactory> : IDisposable
where TDetectorFactory : ILanguageDetectorFactory, new()
{
private readonly Dictionary<Language, int[]> _singleWordsStatistics = new();
Expand Down Expand Up @@ -49,11 +49,10 @@ public void Dispose()
);

var statisticsReport = StatisticsReport();
messageSink.OnMessage(new DiagnosticMessage(statisticsReport));

Directory.CreateDirectory(accuracyReportsDirectoryPath);
File.WriteAllText(accuracyReportFilePath, statisticsReport);
}

private string StatisticsReport()
{
var newlines = new string('\n', 2);
Expand Down Expand Up @@ -89,7 +88,7 @@ private string StatisticsReport()

if (Factory.SupportsLowAccuracyMode)
{
report.AppendLine($"{newlines}Overall average accuracy");
report.AppendLine($"{newlines}Average accuracy");
report.AppendLine();
report.AppendLine("| Low Accuracy Mode | High Accuracy Mode |");
report.AppendLine("| ----------------- | ------------------ |");
Expand All @@ -98,7 +97,7 @@ private string StatisticsReport()
}
else
{
report.AppendLine($"{newlines}Overall average accuracy");
report.AppendLine($"{newlines}Average accuracy");
report.AppendLine();
report.AppendLine("| High Accuracy Mode |");
report.AppendLine("| ------------------ |");
Expand Down Expand Up @@ -158,7 +157,7 @@ public void ComputeSentenceStatistics(string sentence)
_sentenceLengthCount += sentence.Length;
}

private void ComputeStatistics(Dictionary<Language, int[]> statistics, string element)
private static void ComputeStatistics(Dictionary<Language, int[]> statistics, string element)
{
var detectedLanguageInHighAccuracyMode = HighAccuracyDetector.DetectLanguageOf(element);
var detectedLanguageInLowAccuracyMode = Factory.SupportsLowAccuracyMode
Expand Down Expand Up @@ -200,7 +199,7 @@ private static double ComputeAccuracy(int languageCount, int totalLanguagesCount
string description)
{
var accuracies = statistics.GetValueOrDefault(Language, (0d, 0d));
var report = new StringBuilder($"### {Language} {description}");
var report = new StringBuilder($"###{Factory.Implementation}: {Language} {description}");
report.AppendLine();
report.AppendLine();
report.AppendLine($"Detection of {count} {description} (average length: {(int)((double)length / count)} chars)");
Expand All @@ -225,9 +224,13 @@ private static double ComputeAccuracy(int languageCount, int totalLanguagesCount
if (errors)
{
report.AppendLine();
report.AppendLine("Erroneously classified as");
report.AppendLine("<details>");
report.AppendLine("<summary>Error details</summary>");
report.AppendLine();
report.AppendLine("Erroneously classified as:");
report.AppendLine();
FormatStatistics(statistics, Language, report);
report.AppendLine("</details>");
}

return (accuracies, report.ToString());
Expand Down

0 comments on commit 868ae85

Please sign in to comment.