From 084c91d962594ae7d163a2f5f193a00d3c50a769 Mon Sep 17 00:00:00 2001 From: Nikolaj Olsson Date: Thu, 9 Mar 2017 16:03:22 +0100 Subject: [PATCH] Added "Total words" to statistics - thx Barbara :) --- Changelog.txt | 3 ++- LanguageMaster.xml | 1 + libse/Language.cs | 1 + libse/LanguageDeserializer.cs | 3 +++ libse/LanguageStructure.cs | 1 + src/Forms/Statistics.cs | 28 +++++++++++++--------------- 6 files changed, 21 insertions(+), 16 deletions(-) diff --git a/Changelog.txt b/Changelog.txt index 2f90a9e19..139df3ec4 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -6,7 +6,8 @@ * New ... * IMPROVED: * Updated Chinese translation - thx Leon - * Import plain text now also supports input as HTML + * Import plain text now also supports input as HTML + * Added "Total words" to statistics - thx Barbara * FIXED: * Fixed original file name bug in "Undo" - thx darnn * Fixed non default timecode scales in MKV - thx mkver diff --git a/LanguageMaster.xml b/LanguageMaster.xml index a0b191f8c..e864d2c1f 100644 --- a/LanguageMaster.xml +++ b/LanguageMaster.xml @@ -2048,6 +2048,7 @@ can edit in same subtitle file (collaboration) Number of characters as {0}: {1:#,###,##0} Number of characters in text only: {0:#,###,##0} Total characters/second: {0:0.0} seconds + Total words in subtitle: {0} Number of italic tags: {0} Number of bold tags: {0} Number of underline tags: {0} diff --git a/libse/Language.cs b/libse/Language.cs index 412dd0854..a1d1c065d 100644 --- a/libse/Language.cs +++ b/libse/Language.cs @@ -2351,6 +2351,7 @@ can edit in same subtitle file (collaboration)", NumberOfCharactersInTextOnly = "Number of characters in text only: {0:#,###,##0}", NumberOfItalicTags = "Number of italic tags: {0}", TotalCharsPerSecond = "Total characters/second: {0:0.0} seconds", + TotalWords = "Total words in subtitle: {0}", NumberOfBoldTags = "Number of bold tags: {0}", NumberOfUnderlineTags = "Number of underline tags: {0}", NumberOfFontTags = "Number of font tags: {0}", diff --git a/libse/LanguageDeserializer.cs b/libse/LanguageDeserializer.cs index 2c2bebd69..a62062639 100644 --- a/libse/LanguageDeserializer.cs +++ b/libse/LanguageDeserializer.cs @@ -5533,6 +5533,9 @@ namespace Nikse.SubtitleEdit.Core case "Statistics/TotalCharsPerSecond": language.Statistics.TotalCharsPerSecond = reader.Value; break; + case "Statistics/TotalWords": + language.Statistics.TotalWords = reader.Value; + break; case "Statistics/NumberOfItalicTags": language.Statistics.NumberOfItalicTags = reader.Value; break; diff --git a/libse/LanguageStructure.cs b/libse/LanguageStructure.cs index c3ef63091..b724606d9 100644 --- a/libse/LanguageStructure.cs +++ b/libse/LanguageStructure.cs @@ -2230,6 +2230,7 @@ public string LengthInFormatXinCharactersY { get; set; } public string NumberOfCharactersInTextOnly { get; set; } public string TotalCharsPerSecond { get; set; } + public string TotalWords { get; set; } public string NumberOfItalicTags { get; set; } public string NumberOfBoldTags { get; set; } public string NumberOfUnderlineTags { get; set; } diff --git a/src/Forms/Statistics.cs b/src/Forms/Statistics.cs index 6626395be..cd353c890 100644 --- a/src/Forms/Statistics.cs +++ b/src/Forms/Statistics.cs @@ -15,6 +15,7 @@ namespace Nikse.SubtitleEdit.Forms private readonly LanguageStructure.Statistics _l; private string _mostUsedLines; private string _general; + private int _totalWords; private string _mostUsedWords; private const string WriteFormat = @"File generated by: Subtitle Edit http://www.nikse.dk/subtitleedit/ @@ -45,21 +46,16 @@ https://github.com/SubtitleEdit/subtitleedit buttonOK.Text = Configuration.Settings.Language.General.Ok; UiUtil.FixLargeFonts(this, buttonOK); + CalculateWordStatistics(); CalculateGeneralStatistics(); - { - textBoxGeneral.Text = _general; - textBoxGeneral.SelectionStart = 0; - textBoxGeneral.SelectionLength = 0; - textBoxGeneral.ScrollToCaret(); - } - CalculateMostUsedWords(); - { - textBoxMostUsedWords.Text = _mostUsedWords; - } + textBoxGeneral.Text = _general; + textBoxGeneral.SelectionStart = 0; + textBoxGeneral.SelectionLength = 0; + textBoxGeneral.ScrollToCaret(); + textBoxMostUsedWords.Text = _mostUsedWords; + CalculateMostUsedLines(); - { - textBoxMostUsedLines.Text = _mostUsedLines; - } + textBoxMostUsedLines.Text = _mostUsedLines; } private void CalculateGeneralStatistics() @@ -121,6 +117,7 @@ https://github.com/SubtitleEdit/subtitleedit sb.AppendLine(string.Format(_l.LengthInFormatXinCharactersY, _format.FriendlyName, sourceLength)); sb.AppendLine(string.Format(_l.NumberOfCharactersInTextOnly, allText.Length)); sb.AppendLine(string.Format(_l.TotalCharsPerSecond, HtmlUtil.RemoveHtmlTags(allText.ToString()).Length / (totalDuration / TimeCode.BaseUnit))); + sb.AppendLine(string.Format(_l.TotalWords, _totalWords)); sb.AppendLine(string.Format(_l.NumberOfItalicTags, Utilities.CountTagInText(allTextToLower, ""))); sb.AppendLine(string.Format(_l.NumberOfBoldTags, Utilities.CountTagInText(allTextToLower, ""))); sb.AppendLine(string.Format(_l.NumberOfUnderlineTags, Utilities.CountTagInText(allTextToLower, ""))); @@ -155,7 +152,7 @@ https://github.com/SubtitleEdit/subtitleedit Clipboard.SetText(string.Format(WriteFormat, _general, _mostUsedWords, _mostUsedLines), TextDataFormat.UnicodeText); } - private static void MostUsedWordsAdd(Dictionary hashtable, string text) + private void MostUsedWordsAdd(Dictionary hashtable, string text) { if (text.Contains("< ")) text = HtmlUtil.FixInvalidItalicTags(text); @@ -182,6 +179,7 @@ https://github.com/SubtitleEdit/subtitleedit foreach (string word in text.Split(ExpectedChars, StringSplitOptions.RemoveEmptyEntries)) { var s = word.Trim(); + _totalWords++; if (s.Length > 1 && hashtable.ContainsKey(s)) { hashtable[s]++; @@ -240,7 +238,7 @@ https://github.com/SubtitleEdit/subtitleedit return text; } - private void CalculateMostUsedWords() + private void CalculateWordStatistics() { var hashtable = new Dictionary();