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
This commit is contained in:
niksedk 2012-06-13 18:46:53 +00:00
parent 87fd61a7e8
commit ae2ee72299
4 changed files with 93 additions and 18 deletions

View File

@ -30,20 +30,21 @@ namespace Nikse.SubtitleEdit.Forms
const int IndexAddPeriodAfterParagraph = 13; const int IndexAddPeriodAfterParagraph = 13;
const int IndexStartWithUppercaseLetterAfterParagraph = 14; const int IndexStartWithUppercaseLetterAfterParagraph = 14;
const int IndexStartWithUppercaseLetterAfterPeriodInsideParagraph = 15; const int IndexStartWithUppercaseLetterAfterPeriodInsideParagraph = 15;
const int IndexAddMissingQuotes = 16; const int IndexStartWithUppercaseLetterAfterColon = 16;
const int IndexFixHyphens = 17; const int IndexAddMissingQuotes = 17;
const int IndexFix3PlusLines = 18; const int IndexFixHyphens = 18;
const int IndexFixDoubleDash = 19; const int IndexFix3PlusLines = 19;
const int IndexFixDoubleGreaterThan = 20; const int IndexFixDoubleDash = 20;
const int IndexFixEllipsesStart = 21; const int IndexFixDoubleGreaterThan = 21;
const int IndexFixMissingOpenBracket = 22; const int IndexFixEllipsesStart = 22;
const int IndexFixOcrErrorsViaReplaceList = 23; const int IndexFixMissingOpenBracket = 23;
const int IndexUppercaseIInsideLowercaseWord = 24; const int IndexFixOcrErrorsViaReplaceList = 24;
const int IndexAloneLowercaseIToUppercaseIEnglish = 25; const int IndexUppercaseIInsideLowercaseWord = 25;
const int IndexRemoveSpaceBetweenNumbers = 26; const int IndexAloneLowercaseIToUppercaseIEnglish = 26;
const int IndexDialogsOnOneLine = 27; const int IndexRemoveSpaceBetweenNumbers = 27;
const int IndexDanishLetterI = 28; const int IndexDialogsOnOneLine = 28;
const int IndexFixSpanishInvertedQuestionAndExclamationMarks = 29; const int IndexDanishLetterI = 29;
const int IndexFixSpanishInvertedQuestionAndExclamationMarks = 30;
int _danishLetterIIndex = -1; int _danishLetterIIndex = -1;
int _spanishInvertedQuestionAndExclamationMarksIndex = -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.AddPeriods, string.Empty, delegate { FixMissingPeriodsAtEndOfLine(); }, ce.AddPeriodAfterParagraphTicked));
_fixActions.Add(new FixItem(_language.StartWithUppercaseLetterAfterParagraph, string.Empty, delegate { FixStartWithUppercaseLetterAfterParagraph(); }, ce.StartWithUppercaseLetterAfterParagraphTicked)); _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.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.AddMissingQuotes, _language.AddMissingQuotesExample, delegate { AddMissingQuotes(); }, ce.AddMissingQuotesTicked));
_fixActions.Add(new FixItem(_language.FixHyphens, string.Empty, delegate { FixHyphens(); }, ce.FixHyphensTicked)); _fixActions.Add(new FixItem(_language.FixHyphens, string.Empty, delegate { FixHyphens(); }, ce.FixHyphensTicked));
_fixActions.Add(new FixItem(_language.Fix3PlusLines, string.Empty, delegate { Fix3PlusLines(); }, ce.Fix3PlusLinesTicked)); _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("?") || prevText.EndsWith("?"));
prevText.EndsWith(":") ||
prevText.EndsWith(";"));
if (isPrevEndOfLine && prevText.Length > 5 && prevText.EndsWith(".") && if (isPrevEndOfLine && prevText.Length > 5 && prevText.EndsWith(".") &&
prevText[prevText.Length - 3] == '.' && prevText[prevText.Length - 3] == '.' &&
@ -2138,9 +2138,75 @@ namespace Nikse.SubtitleEdit.Forms
} }
if (noOfFixes > 0) if (noOfFixes > 0)
LogStatus(_language.StartWithUppercaseLetterAfterPeriodInsideParagraph, noOfFixes.ToString()); 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("<i>"))
skipCount = 2;
else if (p.Text.Substring(j).StartsWith("<b>"))
skipCount = 2;
else if (p.Text.Substring(j).StartsWith("<u>"))
skipCount = 2;
else if (p.Text.Substring(j).StartsWith("<font ") && p.Text.Substring(j).Contains(">"))
skipCount = p.Text.Substring(j).IndexOf(">") - p.Text.Substring(j).IndexOf("<font ");
else if (s != s.ToUpper())
{
p.Text = p.Text.Remove(j, 1).Insert(j, s.ToUpper());
lastWasColon = false;
}
else if (!(" " + Environment.NewLine).Contains(s))
lastWasColon = false;
}
}
}
if (oldText != p.Text)
{
noOfFixes++;
_totalFixes++;
AddFixToListView(p, fixAction, oldText, p.Text);
}
}
if (noOfFixes > 0)
LogStatus(_language.StartWithUppercaseLetterAfterColon, noOfFixes.ToString());
}
private bool IsAbbreviation(string text, int index) private bool IsAbbreviation(string text, int index)
{ {
if (text[index] != '.' && text[index] != '!' && text[index] != '?') if (text[index] != '.' && text[index] != '!' && text[index] != '?')
@ -3865,6 +3931,7 @@ namespace Nikse.SubtitleEdit.Forms
ce.AddPeriodAfterParagraphTicked = listView1.Items[IndexAddPeriodAfterParagraph].Checked; ce.AddPeriodAfterParagraphTicked = listView1.Items[IndexAddPeriodAfterParagraph].Checked;
ce.StartWithUppercaseLetterAfterParagraphTicked = listView1.Items[IndexStartWithUppercaseLetterAfterParagraph].Checked; ce.StartWithUppercaseLetterAfterParagraphTicked = listView1.Items[IndexStartWithUppercaseLetterAfterParagraph].Checked;
ce.StartWithUppercaseLetterAfterPeriodInsideParagraphTicked = listView1.Items[IndexStartWithUppercaseLetterAfterPeriodInsideParagraph].Checked; ce.StartWithUppercaseLetterAfterPeriodInsideParagraphTicked = listView1.Items[IndexStartWithUppercaseLetterAfterPeriodInsideParagraph].Checked;
ce.StartWithUppercaseLetterAfterColonTicked = listView1.Items[IndexStartWithUppercaseLetterAfterColon].Checked;
ce.AddMissingQuotesTicked = listView1.Items[IndexAddMissingQuotes].Checked; ce.AddMissingQuotesTicked = listView1.Items[IndexAddMissingQuotes].Checked;
ce.FixHyphensTicked = listView1.Items[IndexFixHyphens].Checked; ce.FixHyphensTicked = listView1.Items[IndexFixHyphens].Checked;
ce.Fix3PlusLinesTicked = listView1.Items[IndexFix3PlusLines].Checked; ce.Fix3PlusLinesTicked = listView1.Items[IndexFix3PlusLines].Checked;

View File

@ -414,6 +414,7 @@ namespace Nikse.SubtitleEdit.Logic
AddPeriods = "Add period after lines where next line start with uppercase letter", AddPeriods = "Add period after lines where next line start with uppercase letter",
StartWithUppercaseLetterAfterParagraph = "Start with uppercase letter after paragraph", StartWithUppercaseLetterAfterParagraph = "Start with uppercase letter after paragraph",
StartWithUppercaseLetterAfterPeriodInsideParagraph = "Start with uppercase letter after period inside 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}", CommonOcrErrorsFixed = "Common OCR errors fixed (OcrReplaceList file used): {0}",
RemoveSpaceBetweenNumber = "Remove space between numbers", RemoveSpaceBetweenNumber = "Remove space between numbers",
FixDialogsOnOneLine = "Fix dialogs on one line", FixDialogsOnOneLine = "Fix dialogs on one line",

View File

@ -355,6 +355,7 @@
public string AddPeriods { get; set; } public string AddPeriods { get; set; }
public string StartWithUppercaseLetterAfterParagraph { get; set; } public string StartWithUppercaseLetterAfterParagraph { get; set; }
public string StartWithUppercaseLetterAfterPeriodInsideParagraph { get; set; } public string StartWithUppercaseLetterAfterPeriodInsideParagraph { get; set; }
public string StartWithUppercaseLetterAfterColon { get; set; }
public string FixLowercaseIToUppercaseI { get; set; } public string FixLowercaseIToUppercaseI { get; set; }
public string FixCommonOcrErrors { get; set; } public string FixCommonOcrErrors { get; set; }
public string CommonOcrErrorsFixed { get; set; } public string CommonOcrErrorsFixed { get; set; }

View File

@ -203,6 +203,7 @@ namespace Nikse.SubtitleEdit.Logic
public bool AddPeriodAfterParagraphTicked { get; set; } public bool AddPeriodAfterParagraphTicked { get; set; }
public bool StartWithUppercaseLetterAfterParagraphTicked { get; set; } public bool StartWithUppercaseLetterAfterParagraphTicked { get; set; }
public bool StartWithUppercaseLetterAfterPeriodInsideParagraphTicked { get; set; } public bool StartWithUppercaseLetterAfterPeriodInsideParagraphTicked { get; set; }
public bool StartWithUppercaseLetterAfterColonTicked { get; set; }
public bool AloneLowercaseIToUppercaseIEnglishTicked { get; set; } public bool AloneLowercaseIToUppercaseIEnglishTicked { get; set; }
public bool FixOcrErrorsViaReplaceListTicked { get; set; } public bool FixOcrErrorsViaReplaceListTicked { get; set; }
public bool RemoveSpaceBetweenNumberTicked { get; set; } public bool RemoveSpaceBetweenNumberTicked { get; set; }
@ -232,6 +233,7 @@ namespace Nikse.SubtitleEdit.Logic
AddPeriodAfterParagraphTicked = false; AddPeriodAfterParagraphTicked = false;
StartWithUppercaseLetterAfterParagraphTicked = true; StartWithUppercaseLetterAfterParagraphTicked = true;
StartWithUppercaseLetterAfterPeriodInsideParagraphTicked = false; StartWithUppercaseLetterAfterPeriodInsideParagraphTicked = false;
StartWithUppercaseLetterAfterColonTicked = false;
AloneLowercaseIToUppercaseIEnglishTicked = false; AloneLowercaseIToUppercaseIEnglishTicked = false;
DanishLetterITicked = false; DanishLetterITicked = false;
FixDoubleDashTicked = true; FixDoubleDashTicked = true;
@ -1233,6 +1235,9 @@ namespace Nikse.SubtitleEdit.Logic
subNode = node.SelectSingleNode("StartWithUppercaseLetterAfterPeriodInsideParagraphTicked"); subNode = node.SelectSingleNode("StartWithUppercaseLetterAfterPeriodInsideParagraphTicked");
if (subNode != null) if (subNode != null)
settings.CommonErrors.StartWithUppercaseLetterAfterPeriodInsideParagraphTicked = Convert.ToBoolean(subNode.InnerText); 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"); subNode = node.SelectSingleNode("AloneLowercaseIToUppercaseIEnglishTicked");
if (subNode != null) if (subNode != null)
settings.CommonErrors.AloneLowercaseIToUppercaseIEnglishTicked = Convert.ToBoolean(subNode.InnerText); settings.CommonErrors.AloneLowercaseIToUppercaseIEnglishTicked = Convert.ToBoolean(subNode.InnerText);
@ -1823,6 +1828,7 @@ namespace Nikse.SubtitleEdit.Logic
textWriter.WriteElementString("AddPeriodAfterParagraphTicked", settings.CommonErrors.AddPeriodAfterParagraphTicked.ToString()); textWriter.WriteElementString("AddPeriodAfterParagraphTicked", settings.CommonErrors.AddPeriodAfterParagraphTicked.ToString());
textWriter.WriteElementString("StartWithUppercaseLetterAfterParagraphTicked", settings.CommonErrors.StartWithUppercaseLetterAfterParagraphTicked.ToString()); textWriter.WriteElementString("StartWithUppercaseLetterAfterParagraphTicked", settings.CommonErrors.StartWithUppercaseLetterAfterParagraphTicked.ToString());
textWriter.WriteElementString("StartWithUppercaseLetterAfterPeriodInsideParagraphTicked", settings.CommonErrors.StartWithUppercaseLetterAfterPeriodInsideParagraphTicked.ToString()); textWriter.WriteElementString("StartWithUppercaseLetterAfterPeriodInsideParagraphTicked", settings.CommonErrors.StartWithUppercaseLetterAfterPeriodInsideParagraphTicked.ToString());
textWriter.WriteElementString("StartWithUppercaseLetterAfterColonTicked", settings.CommonErrors.StartWithUppercaseLetterAfterColonTicked.ToString());
textWriter.WriteElementString("AloneLowercaseIToUppercaseIEnglishTicked", settings.CommonErrors.AloneLowercaseIToUppercaseIEnglishTicked.ToString()); textWriter.WriteElementString("AloneLowercaseIToUppercaseIEnglishTicked", settings.CommonErrors.AloneLowercaseIToUppercaseIEnglishTicked.ToString());
textWriter.WriteElementString("FixOcrErrorsViaReplaceListTicked", settings.CommonErrors.FixOcrErrorsViaReplaceListTicked.ToString()); textWriter.WriteElementString("FixOcrErrorsViaReplaceListTicked", settings.CommonErrors.FixOcrErrorsViaReplaceListTicked.ToString());
textWriter.WriteElementString("RemoveSpaceBetweenNumberTicked", settings.CommonErrors.RemoveSpaceBetweenNumberTicked.ToString()); textWriter.WriteElementString("RemoveSpaceBetweenNumberTicked", settings.CommonErrors.RemoveSpaceBetweenNumberTicked.ToString());