From ae2ee72299df4eb3eb2da7ca12d5baf8db526e04 Mon Sep 17 00:00:00 2001 From: niksedk Date: Wed, 13 Jun 2012 18:46:53 +0000 Subject: [PATCH] Fix common errors -> Start with uppercase letter after colon/semicolon moved to seperate fix item (no longer in start with uppercase after paragraph/period) git-svn-id: https://subtitleedit.googlecode.com/svn/trunk@1253 99eadd0c-20b8-1223-b5c4-2a2b2df33de2 --- src/Forms/FixCommonErrors.cs | 103 +++++++++++++++++++++++++++------ src/Logic/Language.cs | 1 + src/Logic/LanguageStructure.cs | 1 + src/Logic/Settings.cs | 6 ++ 4 files changed, 93 insertions(+), 18 deletions(-) diff --git a/src/Forms/FixCommonErrors.cs b/src/Forms/FixCommonErrors.cs index 9b9c52aaa..d14149c80 100644 --- a/src/Forms/FixCommonErrors.cs +++ b/src/Forms/FixCommonErrors.cs @@ -30,20 +30,21 @@ namespace Nikse.SubtitleEdit.Forms const int IndexAddPeriodAfterParagraph = 13; const int IndexStartWithUppercaseLetterAfterParagraph = 14; const int IndexStartWithUppercaseLetterAfterPeriodInsideParagraph = 15; - const int IndexAddMissingQuotes = 16; - const int IndexFixHyphens = 17; - const int IndexFix3PlusLines = 18; - const int IndexFixDoubleDash = 19; - const int IndexFixDoubleGreaterThan = 20; - const int IndexFixEllipsesStart = 21; - const int IndexFixMissingOpenBracket = 22; - const int IndexFixOcrErrorsViaReplaceList = 23; - const int IndexUppercaseIInsideLowercaseWord = 24; - const int IndexAloneLowercaseIToUppercaseIEnglish = 25; - const int IndexRemoveSpaceBetweenNumbers = 26; - const int IndexDialogsOnOneLine = 27; - const int IndexDanishLetterI = 28; - const int IndexFixSpanishInvertedQuestionAndExclamationMarks = 29; + const int IndexStartWithUppercaseLetterAfterColon = 16; + const int IndexAddMissingQuotes = 17; + const int IndexFixHyphens = 18; + const int IndexFix3PlusLines = 19; + const int IndexFixDoubleDash = 20; + const int IndexFixDoubleGreaterThan = 21; + const int IndexFixEllipsesStart = 22; + const int IndexFixMissingOpenBracket = 23; + const int IndexFixOcrErrorsViaReplaceList = 24; + const int IndexUppercaseIInsideLowercaseWord = 25; + const int IndexAloneLowercaseIToUppercaseIEnglish = 26; + const int IndexRemoveSpaceBetweenNumbers = 27; + const int IndexDialogsOnOneLine = 28; + const int IndexDanishLetterI = 29; + const int IndexFixSpanishInvertedQuestionAndExclamationMarks = 30; int _danishLetterIIndex = -1; int _spanishInvertedQuestionAndExclamationMarksIndex = -1; @@ -169,6 +170,7 @@ namespace Nikse.SubtitleEdit.Forms _fixActions.Add(new FixItem(_language.AddPeriods, string.Empty, delegate { FixMissingPeriodsAtEndOfLine(); }, ce.AddPeriodAfterParagraphTicked)); _fixActions.Add(new FixItem(_language.StartWithUppercaseLetterAfterParagraph, string.Empty, delegate { FixStartWithUppercaseLetterAfterParagraph(); }, ce.StartWithUppercaseLetterAfterParagraphTicked)); _fixActions.Add(new FixItem(_language.StartWithUppercaseLetterAfterPeriodInsideParagraph, string.Empty, delegate { FixStartWithUppercaseLetterAfterPeriodInsideParagraph(); }, ce.StartWithUppercaseLetterAfterPeriodInsideParagraphTicked)); + _fixActions.Add(new FixItem(_language.StartWithUppercaseLetterAfterColon, string.Empty, delegate { FixStartWithUppercaseLetterAfterColon(); }, ce.StartWithUppercaseLetterAfterColonTicked)); _fixActions.Add(new FixItem(_language.AddMissingQuotes, _language.AddMissingQuotesExample, delegate { AddMissingQuotes(); }, ce.AddMissingQuotesTicked)); _fixActions.Add(new FixItem(_language.FixHyphens, string.Empty, delegate { FixHyphens(); }, ce.FixHyphensTicked)); _fixActions.Add(new FixItem(_language.Fix3PlusLines, string.Empty, delegate { Fix3PlusLines(); }, ce.Fix3PlusLinesTicked)); @@ -2075,9 +2077,7 @@ namespace Nikse.SubtitleEdit.Forms !prevText.EndsWith("...") && (prevText.EndsWith(".") || prevText.EndsWith("!") || - prevText.EndsWith("?") || - prevText.EndsWith(":") || - prevText.EndsWith(";")); + prevText.EndsWith("?")); if (isPrevEndOfLine && prevText.Length > 5 && prevText.EndsWith(".") && prevText[prevText.Length - 3] == '.' && @@ -2138,9 +2138,75 @@ namespace Nikse.SubtitleEdit.Forms } if (noOfFixes > 0) LogStatus(_language.StartWithUppercaseLetterAfterPeriodInsideParagraph, noOfFixes.ToString()); - } + private void FixStartWithUppercaseLetterAfterColon() + { + string fixAction = _language.StartWithUppercaseLetterAfterColon; + int noOfFixes = 0; + for (int i = 0; i < _subtitle.Paragraphs.Count; i++) + { + Paragraph p = _subtitle.Paragraphs[i]; + Paragraph last = _subtitle.GetParagraphOrDefault(i - 1); + string oldText = p.Text; + int skipCount = 0; + + if (last != null) + { + string lastText = Utilities.RemoveHtmlTags(last.Text); + if (lastText.EndsWith(":") || lastText.EndsWith(";")) + { + var st = new StripableText(p.Text); + if (st.StrippedText.Length > 0 && st.StrippedText[0].ToString() != st.StrippedText[0].ToString().ToUpper()) + p.Text = st.Pre + st.StrippedText[0].ToString().ToUpper() + st.StrippedText.Remove(0, 1) + st.Post; + } + } + + if (oldText.Contains(":") || oldText.Contains(";")) + { + bool lastWasColon = false; + for (int j = 0; j < p.Text.Length; j++) + { + string s = p.Text[j].ToString(); + if (s == ":" || s == ";") + { + lastWasColon = true; + } + else if (lastWasColon) + { + if (skipCount > 0) + skipCount--; + else if (p.Text.Substring(j).StartsWith("")) + skipCount = 2; + else if (p.Text.Substring(j).StartsWith("")) + skipCount = 2; + else if (p.Text.Substring(j).StartsWith("")) + skipCount = 2; + else if (p.Text.Substring(j).StartsWith("")) + skipCount = p.Text.Substring(j).IndexOf(">") - p.Text.Substring(j).IndexOf(" 0) + LogStatus(_language.StartWithUppercaseLetterAfterColon, noOfFixes.ToString()); + } + + private bool IsAbbreviation(string text, int index) { if (text[index] != '.' && text[index] != '!' && text[index] != '?') @@ -3865,6 +3931,7 @@ namespace Nikse.SubtitleEdit.Forms ce.AddPeriodAfterParagraphTicked = listView1.Items[IndexAddPeriodAfterParagraph].Checked; ce.StartWithUppercaseLetterAfterParagraphTicked = listView1.Items[IndexStartWithUppercaseLetterAfterParagraph].Checked; ce.StartWithUppercaseLetterAfterPeriodInsideParagraphTicked = listView1.Items[IndexStartWithUppercaseLetterAfterPeriodInsideParagraph].Checked; + ce.StartWithUppercaseLetterAfterColonTicked = listView1.Items[IndexStartWithUppercaseLetterAfterColon].Checked; ce.AddMissingQuotesTicked = listView1.Items[IndexAddMissingQuotes].Checked; ce.FixHyphensTicked = listView1.Items[IndexFixHyphens].Checked; ce.Fix3PlusLinesTicked = listView1.Items[IndexFix3PlusLines].Checked; diff --git a/src/Logic/Language.cs b/src/Logic/Language.cs index 80c0f06d7..2fc12f33c 100644 --- a/src/Logic/Language.cs +++ b/src/Logic/Language.cs @@ -414,6 +414,7 @@ namespace Nikse.SubtitleEdit.Logic AddPeriods = "Add period after lines where next line start with uppercase letter", StartWithUppercaseLetterAfterParagraph = "Start with uppercase letter after paragraph", StartWithUppercaseLetterAfterPeriodInsideParagraph = "Start with uppercase letter after period inside paragraph", + StartWithUppercaseLetterAfterColon = "Start with uppercase letter after colon/semicolon", CommonOcrErrorsFixed = "Common OCR errors fixed (OcrReplaceList file used): {0}", RemoveSpaceBetweenNumber = "Remove space between numbers", FixDialogsOnOneLine = "Fix dialogs on one line", diff --git a/src/Logic/LanguageStructure.cs b/src/Logic/LanguageStructure.cs index bb430e93c..4e12ff41e 100644 --- a/src/Logic/LanguageStructure.cs +++ b/src/Logic/LanguageStructure.cs @@ -355,6 +355,7 @@ public string AddPeriods { get; set; } public string StartWithUppercaseLetterAfterParagraph { get; set; } public string StartWithUppercaseLetterAfterPeriodInsideParagraph { get; set; } + public string StartWithUppercaseLetterAfterColon { get; set; } public string FixLowercaseIToUppercaseI { get; set; } public string FixCommonOcrErrors { get; set; } public string CommonOcrErrorsFixed { get; set; } diff --git a/src/Logic/Settings.cs b/src/Logic/Settings.cs index 9fcd8b224..6bdb16cc1 100644 --- a/src/Logic/Settings.cs +++ b/src/Logic/Settings.cs @@ -203,6 +203,7 @@ namespace Nikse.SubtitleEdit.Logic public bool AddPeriodAfterParagraphTicked { get; set; } public bool StartWithUppercaseLetterAfterParagraphTicked { get; set; } public bool StartWithUppercaseLetterAfterPeriodInsideParagraphTicked { get; set; } + public bool StartWithUppercaseLetterAfterColonTicked { get; set; } public bool AloneLowercaseIToUppercaseIEnglishTicked { get; set; } public bool FixOcrErrorsViaReplaceListTicked { get; set; } public bool RemoveSpaceBetweenNumberTicked { get; set; } @@ -232,6 +233,7 @@ namespace Nikse.SubtitleEdit.Logic AddPeriodAfterParagraphTicked = false; StartWithUppercaseLetterAfterParagraphTicked = true; StartWithUppercaseLetterAfterPeriodInsideParagraphTicked = false; + StartWithUppercaseLetterAfterColonTicked = false; AloneLowercaseIToUppercaseIEnglishTicked = false; DanishLetterITicked = false; FixDoubleDashTicked = true; @@ -1233,6 +1235,9 @@ namespace Nikse.SubtitleEdit.Logic subNode = node.SelectSingleNode("StartWithUppercaseLetterAfterPeriodInsideParagraphTicked"); if (subNode != null) settings.CommonErrors.StartWithUppercaseLetterAfterPeriodInsideParagraphTicked = Convert.ToBoolean(subNode.InnerText); + subNode = node.SelectSingleNode("StartWithUppercaseLetterAfterColonTicked"); + if (subNode != null) + settings.CommonErrors.StartWithUppercaseLetterAfterColonTicked = Convert.ToBoolean(subNode.InnerText); subNode = node.SelectSingleNode("AloneLowercaseIToUppercaseIEnglishTicked"); if (subNode != null) settings.CommonErrors.AloneLowercaseIToUppercaseIEnglishTicked = Convert.ToBoolean(subNode.InnerText); @@ -1823,6 +1828,7 @@ namespace Nikse.SubtitleEdit.Logic textWriter.WriteElementString("AddPeriodAfterParagraphTicked", settings.CommonErrors.AddPeriodAfterParagraphTicked.ToString()); textWriter.WriteElementString("StartWithUppercaseLetterAfterParagraphTicked", settings.CommonErrors.StartWithUppercaseLetterAfterParagraphTicked.ToString()); textWriter.WriteElementString("StartWithUppercaseLetterAfterPeriodInsideParagraphTicked", settings.CommonErrors.StartWithUppercaseLetterAfterPeriodInsideParagraphTicked.ToString()); + textWriter.WriteElementString("StartWithUppercaseLetterAfterColonTicked", settings.CommonErrors.StartWithUppercaseLetterAfterColonTicked.ToString()); textWriter.WriteElementString("AloneLowercaseIToUppercaseIEnglishTicked", settings.CommonErrors.AloneLowercaseIToUppercaseIEnglishTicked.ToString()); textWriter.WriteElementString("FixOcrErrorsViaReplaceListTicked", settings.CommonErrors.FixOcrErrorsViaReplaceListTicked.ToString()); textWriter.WriteElementString("RemoveSpaceBetweenNumberTicked", settings.CommonErrors.RemoveSpaceBetweenNumberTicked.ToString());