First refactor of "names etc list"

This commit is contained in:
niksedk 2014-10-02 18:26:45 +02:00
parent 80d11ac294
commit 4547e9590c
9 changed files with 529 additions and 663 deletions

View File

@ -3,6 +3,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Windows.Forms; using System.Windows.Forms;
using Nikse.SubtitleEdit.Logic.Dictionaries;
namespace Nikse.SubtitleEdit.Forms namespace Nikse.SubtitleEdit.Forms
{ {
@ -132,7 +133,9 @@ namespace Nikse.SubtitleEdit.Forms
if (string.IsNullOrEmpty(languageName)) if (string.IsNullOrEmpty(languageName))
languageName = "en_US"; languageName = "en_US";
if (Nikse.SubtitleEdit.Logic.Dictionaries.NamesList.AddWordToLocalNamesEtcList(textBoxAddName.Text, languageName))
var namesList = new NamesList(Configuration.DictionariesFolder, languageName, Configuration.Settings.WordLists.UseOnlineNamesEtc, Configuration.Settings.WordLists.NamesEtcUrl);
if (namesList.Add(textBoxAddName.Text, languageName))
DialogResult = DialogResult.OK; DialogResult = DialogResult.OK;
else else
DialogResult = DialogResult.Cancel; DialogResult = DialogResult.Cancel;

View File

@ -69,14 +69,8 @@ namespace Nikse.SubtitleEdit.Forms
internal void FixCasing(Subtitle subtitle, string language) internal void FixCasing(Subtitle subtitle, string language)
{ {
var namesEtc = new List<string>(); var namesList = new NamesList(Configuration.DictionariesFolder, language, Configuration.Settings.WordLists.UseOnlineNamesEtc, Configuration.Settings.WordLists.NamesEtcUrl);
var tmp = new List<string>(); var namesEtc = namesList.GetAllNames();
NamesList.LoadNamesEtcWordLists(tmp, tmp, language);
foreach (string s in tmp)
{
if (s.Contains('.'))
namesEtc.Add(s);
}
// Longer names must be first // Longer names must be first
namesEtc.Sort((s1, s2) => s2.Length.CompareTo(s1.Length)); namesEtc.Sort((s1, s2) => s2.Length.CompareTo(s1.Length));

View File

@ -124,16 +124,16 @@ namespace Nikse.SubtitleEdit.Forms
private void FindAllNames() private void FindAllNames()
{ {
var namesEtcList = new List<string>(); string language = Utilities.AutoDetectLanguageName("en_US", _subtitle);
if (string.IsNullOrEmpty(language))
language = "en_US";
var namesList = new NamesList(Configuration.DictionariesFolder, language, Configuration.Settings.WordLists.UseOnlineNamesEtc, Configuration.Settings.WordLists.NamesEtcUrl);
// Will contains both one word names and multi names // Will contains both one word names and multi names
var namesEtcList = namesList.GetAllNames();
//string languageCode = Utilities.AutoDetectGoogleLanguage(_subtitle); if (language.StartsWith("en"))
string languageCode = Utilities.AutoDetectLanguageName("en_US", _subtitle);
if (string.IsNullOrEmpty(languageCode))
languageCode = "en_US";
NamesList.LoadNamesEtcWordLists(namesEtcList, namesEtcList, languageCode);
if (languageCode.StartsWith("en"))
{ {
if (namesEtcList.Contains("Black")) if (namesEtcList.Contains("Black"))
namesEtcList.Remove("Black"); namesEtcList.Remove("Black");

View File

@ -1,4 +1,9 @@
using System; using Nikse.SubtitleEdit.Logic;
using Nikse.SubtitleEdit.Logic.Dictionaries;
using Nikse.SubtitleEdit.Logic.Forms;
using Nikse.SubtitleEdit.Logic.Ocr;
using Nikse.SubtitleEdit.Logic.SubtitleFormats;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using System.Globalization; using System.Globalization;
@ -6,10 +11,6 @@ using System.IO;
using System.Text; using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Windows.Forms; using System.Windows.Forms;
using Nikse.SubtitleEdit.Logic;
using Nikse.SubtitleEdit.Logic.Ocr;
using Nikse.SubtitleEdit.Logic.SubtitleFormats;
using Nikse.SubtitleEdit.Logic.Forms;
namespace Nikse.SubtitleEdit.Forms namespace Nikse.SubtitleEdit.Forms
{ {
@ -127,7 +128,7 @@ namespace Nikse.SubtitleEdit.Forms
public bool Descending { get; set; } public bool Descending { get; set; }
} }
public Subtitle _subtitle; public Subtitle Subtitle;
private SubtitleFormat _format; private SubtitleFormat _format;
private Encoding _encoding = Encoding.UTF8; private Encoding _encoding = Encoding.UTF8;
private Subtitle _originalSubtitle; private Subtitle _originalSubtitle;
@ -136,12 +137,12 @@ namespace Nikse.SubtitleEdit.Forms
private List<FixItem> _fixActions; private List<FixItem> _fixActions;
private int _subtitleListViewIndex = -1; private int _subtitleListViewIndex = -1;
private bool _onlyListFixes = true; private bool _onlyListFixes = true;
private bool _batchMode = false; private bool _batchMode;
private string _autoDetectGoogleLanguage; private string _autoDetectGoogleLanguage;
private List<string> _namesEtcList; private List<string> _namesEtcList;
private List<string> _abbreviationList; private List<string> _abbreviationList;
private StringBuilder _newLog = new StringBuilder(); private StringBuilder _newLog = new StringBuilder();
private StringBuilder _appliedLog = new StringBuilder(); private readonly StringBuilder _appliedLog = new StringBuilder();
private int _numberOfImportantLogMessages = 0; private int _numberOfImportantLogMessages = 0;
private List<int> _deleteIndices = new List<int>(); private List<int> _deleteIndices = new List<int>();
@ -154,7 +155,7 @@ namespace Nikse.SubtitleEdit.Forms
{ {
_autoDetectGoogleLanguage = language; _autoDetectGoogleLanguage = language;
var ci = CultureInfo.GetCultureInfo(_autoDetectGoogleLanguage); var ci = CultureInfo.GetCultureInfo(_autoDetectGoogleLanguage);
string threeLetterISOLanguageName = ci.ThreeLetterISOLanguageName; string threeLetterIsoLanguageName = ci.ThreeLetterISOLanguageName;
comboBoxLanguage.Items.Clear(); comboBoxLanguage.Items.Clear();
foreach (CultureInfo x in CultureInfo.GetCultures(CultureTypes.NeutralCultures)) foreach (CultureInfo x in CultureInfo.GetCultures(CultureTypes.NeutralCultures))
@ -170,16 +171,16 @@ namespace Nikse.SubtitleEdit.Forms
languageIndex = j; languageIndex = j;
break; break;
} }
else if (xci.TwoLetterISOLanguageName == "en") if (xci.TwoLetterISOLanguageName == "en")
{ {
languageIndex = j; languageIndex = j;
} }
j++; j++;
} }
comboBoxLanguage.SelectedIndex = languageIndex; comboBoxLanguage.SelectedIndex = languageIndex;
AddFixActions(threeLetterISOLanguageName); AddFixActions(threeLetterIsoLanguageName);
_originalSubtitle = new Subtitle(subtitle); // copy constructor _originalSubtitle = new Subtitle(subtitle); // copy constructor
_subtitle = new Subtitle(subtitle); // copy constructor Subtitle = new Subtitle(subtitle); // copy constructor
_format = format; _format = format;
_encoding = encoding; _encoding = encoding;
_onlyListFixes = false; _onlyListFixes = false;
@ -205,7 +206,7 @@ namespace Nikse.SubtitleEdit.Forms
{ {
_autoDetectGoogleLanguage = language; _autoDetectGoogleLanguage = language;
var ci = CultureInfo.GetCultureInfo(_autoDetectGoogleLanguage); var ci = CultureInfo.GetCultureInfo(_autoDetectGoogleLanguage);
string threeLetterISOLanguageName = ci.ThreeLetterISOLanguageName; string threeLetterIsoLanguageName = ci.ThreeLetterISOLanguageName;
comboBoxLanguage.Items.Clear(); comboBoxLanguage.Items.Clear();
foreach (CultureInfo x in CultureInfo.GetCultures(CultureTypes.NeutralCultures)) foreach (CultureInfo x in CultureInfo.GetCultures(CultureTypes.NeutralCultures))
@ -221,7 +222,7 @@ namespace Nikse.SubtitleEdit.Forms
languageIndex = j; languageIndex = j;
break; break;
} }
else if (xci.TwoLetterISOLanguageName == "en") if (xci.TwoLetterISOLanguageName == "en")
{ {
languageIndex = j; languageIndex = j;
} }
@ -229,10 +230,10 @@ namespace Nikse.SubtitleEdit.Forms
} }
comboBoxLanguage.SelectedIndex = languageIndex; comboBoxLanguage.SelectedIndex = languageIndex;
AddFixActions(threeLetterISOLanguageName); AddFixActions(threeLetterIsoLanguageName);
_originalSubtitle = new Subtitle(subtitle); // copy constructor _originalSubtitle = new Subtitle(subtitle); // copy constructor
_subtitle = new Subtitle(subtitle); // copy constructor Subtitle = new Subtitle(subtitle); // copy constructor
_format = format; _format = format;
_encoding = encoding; _encoding = encoding;
_onlyListFixes = true; _onlyListFixes = true;
@ -243,7 +244,7 @@ namespace Nikse.SubtitleEdit.Forms
_totalErrors = 0; _totalErrors = 0;
_batchMode = true; _batchMode = true;
RunSelectedActions(); RunSelectedActions();
_originalSubtitle = _subtitle; _originalSubtitle = Subtitle;
} }
public void Initialize(Subtitle subtitle, SubtitleFormat format, Encoding encoding) public void Initialize(Subtitle subtitle, SubtitleFormat format, Encoding encoding)
@ -254,7 +255,7 @@ namespace Nikse.SubtitleEdit.Forms
if (_autoDetectGoogleLanguage.Equals("zh", StringComparison.OrdinalIgnoreCase)) if (_autoDetectGoogleLanguage.Equals("zh", StringComparison.OrdinalIgnoreCase))
_autoDetectGoogleLanguage = "zh-CHS"; // Note that "zh-CHS" (Simplified Chinese) and "zh-CHT" (Traditional Chinese) are neutral cultures _autoDetectGoogleLanguage = "zh-CHS"; // Note that "zh-CHS" (Simplified Chinese) and "zh-CHT" (Traditional Chinese) are neutral cultures
CultureInfo ci = CultureInfo.GetCultureInfo(_autoDetectGoogleLanguage); CultureInfo ci = CultureInfo.GetCultureInfo(_autoDetectGoogleLanguage);
string threeLetterISOLanguageName = ci.ThreeLetterISOLanguageName; string threeLetterIsoLanguageName = ci.ThreeLetterISOLanguageName;
comboBoxLanguage.Items.Clear(); comboBoxLanguage.Items.Clear();
foreach (CultureInfo x in CultureInfo.GetCultures(CultureTypes.NeutralCultures)) foreach (CultureInfo x in CultureInfo.GetCultures(CultureTypes.NeutralCultures))
@ -270,7 +271,7 @@ namespace Nikse.SubtitleEdit.Forms
languageIndex = j; languageIndex = j;
break; break;
} }
else if (xci.TwoLetterISOLanguageName == "en") if (xci.TwoLetterISOLanguageName == "en")
{ {
languageIndex = j; languageIndex = j;
} }
@ -278,10 +279,10 @@ namespace Nikse.SubtitleEdit.Forms
} }
comboBoxLanguage.SelectedIndex = languageIndex; comboBoxLanguage.SelectedIndex = languageIndex;
AddFixActions(threeLetterISOLanguageName); AddFixActions(threeLetterIsoLanguageName);
_originalSubtitle = new Subtitle(subtitle); // copy constructor _originalSubtitle = new Subtitle(subtitle); // copy constructor
_subtitle = new Subtitle(subtitle); // copy constructor Subtitle = new Subtitle(subtitle); // copy constructor
_format = format; _format = format;
_encoding = encoding; _encoding = encoding;
InitUI(); InitUI();
@ -340,7 +341,7 @@ namespace Nikse.SubtitleEdit.Forms
Activate(); Activate();
} }
private void AddFixActions(string threeLetterISOLanguageName) private void AddFixActions(string threeLetterIsoLanguageName)
{ {
_turkishAnsiIndex = -1; _turkishAnsiIndex = -1;
_danishLetterIIndex = -1; _danishLetterIIndex = -1;
@ -375,9 +376,9 @@ namespace Nikse.SubtitleEdit.Forms
_fixActions.Add(new FixItem(_language.FixMissingOpenBracket, _language.FixMissingOpenBracketExample, delegate { FixMissingOpenBracket(); }, ce.FixMissingOpenBracketTicked)); _fixActions.Add(new FixItem(_language.FixMissingOpenBracket, _language.FixMissingOpenBracketExample, delegate { FixMissingOpenBracket(); }, ce.FixMissingOpenBracketTicked));
if (string.IsNullOrEmpty(_language.FixOcrErrorExample)) if (string.IsNullOrEmpty(_language.FixOcrErrorExample))
_fixActions.Add(new FixItem(_language.FixCommonOcrErrors, "D0n't -> Don't", delegate { FixOcrErrorsViaReplaceList(threeLetterISOLanguageName); }, ce.FixOcrErrorsViaReplaceListTicked)); _fixActions.Add(new FixItem(_language.FixCommonOcrErrors, "D0n't -> Don't", delegate { FixOcrErrorsViaReplaceList(threeLetterIsoLanguageName); }, ce.FixOcrErrorsViaReplaceListTicked));
else else
_fixActions.Add(new FixItem(_language.FixCommonOcrErrors, _language.FixOcrErrorExample, delegate { FixOcrErrorsViaReplaceList(threeLetterISOLanguageName); }, ce.FixOcrErrorsViaReplaceListTicked)); _fixActions.Add(new FixItem(_language.FixCommonOcrErrors, _language.FixOcrErrorExample, delegate { FixOcrErrorsViaReplaceList(threeLetterIsoLanguageName); }, ce.FixOcrErrorsViaReplaceListTicked));
_fixActions.Add(new FixItem(_language.FixUppercaseIInsindeLowercaseWords, _language.FixUppercaseIInsindeLowercaseWordsExample, delegate { FixUppercaseIInsideWords(); }, ce.UppercaseIInsideLowercaseWordTicked)); _fixActions.Add(new FixItem(_language.FixUppercaseIInsindeLowercaseWords, _language.FixUppercaseIInsindeLowercaseWordsExample, delegate { FixUppercaseIInsideWords(); }, ce.UppercaseIInsideLowercaseWordTicked));
_fixActions.Add(new FixItem(_language.FixLowercaseIToUppercaseI, _language.FixLowercaseIToUppercaseIExample, delegate { FixAloneLowercaseIToUppercaseI(); }, ce.AloneLowercaseIToUppercaseIEnglishTicked)); _fixActions.Add(new FixItem(_language.FixLowercaseIToUppercaseI, _language.FixLowercaseIToUppercaseIExample, delegate { FixAloneLowercaseIToUppercaseI(); }, ce.AloneLowercaseIToUppercaseIEnglishTicked));
@ -467,8 +468,8 @@ namespace Nikse.SubtitleEdit.Forms
private void FixLargeFonts() private void FixLargeFonts()
{ {
Graphics graphics = this.CreateGraphics(); var graphics = CreateGraphics();
SizeF textSize = graphics.MeasureString(buttonCancel.Text, this.Font); var textSize = graphics.MeasureString(buttonCancel.Text, Font);
if (textSize.Height > buttonCancel.Height - 4) if (textSize.Height > buttonCancel.Height - 4)
{ {
subtitleListView1.InitializeTimestampColumnWidths(this); subtitleListView1.InitializeTimestampColumnWidths(this);
@ -497,7 +498,7 @@ namespace Nikse.SubtitleEdit.Forms
{ {
var item = new ListViewItem(string.Empty) { Checked = true }; var item = new ListViewItem(string.Empty) { Checked = true };
var subItem = new ListViewItem.ListViewSubItem(item, p.Number.ToString()); var subItem = new ListViewItem.ListViewSubItem(item, p.Number.ToString(CultureInfo.InvariantCulture));
item.SubItems.Add(subItem); item.SubItems.Add(subItem);
subItem = new ListViewItem.ListViewSubItem(item, action); subItem = new ListViewItem.ListViewSubItem(item, action);
item.SubItems.Add(subItem); item.SubItems.Add(subItem);
@ -518,7 +519,7 @@ namespace Nikse.SubtitleEdit.Forms
if (_onlyListFixes || _batchMode) if (_onlyListFixes || _batchMode)
return true; return true;
string ln = p.Number.ToString(); string ln = p.Number.ToString(CultureInfo.InvariantCulture);
foreach (ListViewItem item in listViewFixes.Items) foreach (ListViewItem item in listViewFixes.Items)
{ {
if (item.SubItems[1].Text == ln && item.SubItems[2].Text == action) if (item.SubItems[1].Text == ln && item.SubItems[2].Text == action)
@ -561,16 +562,16 @@ namespace Nikse.SubtitleEdit.Forms
string fixAction1 = _language.RemovedEmptyLineAtTop; string fixAction1 = _language.RemovedEmptyLineAtTop;
string fixAction2 = _language.RemovedEmptyLineAtBottom; string fixAction2 = _language.RemovedEmptyLineAtBottom;
if (_subtitle.Paragraphs.Count == 0) if (Subtitle.Paragraphs.Count == 0)
return; return;
int emptyLinesRemoved = 0; int emptyLinesRemoved = 0;
int firstNumber = _subtitle.Paragraphs[0].Number; int firstNumber = Subtitle.Paragraphs[0].Number;
listViewFixes.BeginUpdate(); listViewFixes.BeginUpdate();
for (int i = _subtitle.Paragraphs.Count - 1; i >= 0; i--) for (int i = Subtitle.Paragraphs.Count - 1; i >= 0; i--)
{ {
Paragraph p = _subtitle.Paragraphs[i]; Paragraph p = Subtitle.Paragraphs[i];
if (!string.IsNullOrEmpty(p.Text)) if (!string.IsNullOrEmpty(p.Text))
{ {
string text = p.Text.Trim(' '); string text = p.Text.Trim(' ');
@ -596,14 +597,14 @@ namespace Nikse.SubtitleEdit.Forms
} }
// this must be the very last action done, or line numbers will be messed up!!! // this must be the very last action done, or line numbers will be messed up!!!
for (int i = _subtitle.Paragraphs.Count - 1; i >= 0; i--) for (int i = Subtitle.Paragraphs.Count - 1; i >= 0; i--)
{ {
Paragraph p = _subtitle.Paragraphs[i]; Paragraph p = Subtitle.Paragraphs[i];
if (string.IsNullOrEmpty(p.Text)) if (string.IsNullOrEmpty(p.Text))
{ {
if (AllowFix(p, fixAction0)) if (AllowFix(p, fixAction0))
{ {
_subtitle.Paragraphs.RemoveAt(i); Subtitle.Paragraphs.RemoveAt(i);
emptyLinesRemoved++; emptyLinesRemoved++;
AddFixToListView(p, fixAction0, p.Text, string.Format("[{0}]", _language.RemovedEmptyLine)); AddFixToListView(p, fixAction0, p.Text, string.Format("[{0}]", _language.RemovedEmptyLine));
_deleteIndices.Add(i); _deleteIndices.Add(i);
@ -616,7 +617,7 @@ namespace Nikse.SubtitleEdit.Forms
{ {
LogStatus(_language.RemovedEmptyLinesUnsedLineBreaks, string.Format(_language.EmptyLinesRemovedX, emptyLinesRemoved)); LogStatus(_language.RemovedEmptyLinesUnsedLineBreaks, string.Format(_language.EmptyLinesRemovedX, emptyLinesRemoved));
_totalFixes += emptyLinesRemoved; _totalFixes += emptyLinesRemoved;
_subtitle.Renumber(firstNumber); Subtitle.Renumber(firstNumber);
} }
} }
@ -625,9 +626,9 @@ namespace Nikse.SubtitleEdit.Forms
// negative display time // negative display time
string fixAction = _language.FixOverlappingDisplayTime; string fixAction = _language.FixOverlappingDisplayTime;
int noOfOverlappingDisplayTimesFixed = 0; int noOfOverlappingDisplayTimesFixed = 0;
for (int i = 0; i < _subtitle.Paragraphs.Count; i++) for (int i = 0; i < Subtitle.Paragraphs.Count; i++)
{ {
Paragraph p = _subtitle.Paragraphs[i]; Paragraph p = Subtitle.Paragraphs[i];
Paragraph oldP = new Paragraph(p); Paragraph oldP = new Paragraph(p);
if (p.Duration.TotalMilliseconds < 0) // negative display time... if (p.Duration.TotalMilliseconds < 0) // negative display time...
{ {
@ -635,8 +636,8 @@ namespace Nikse.SubtitleEdit.Forms
string status = string.Format(_language.StartTimeLaterThanEndTime, string status = string.Format(_language.StartTimeLaterThanEndTime,
i + 1, p.StartTime, p.EndTime, p.Text, Environment.NewLine); i + 1, p.StartTime, p.EndTime, p.Text, Environment.NewLine);
Paragraph prev = _subtitle.GetParagraphOrDefault(i - 1); Paragraph prev = Subtitle.GetParagraphOrDefault(i - 1);
Paragraph next = _subtitle.GetParagraphOrDefault(i + 1); Paragraph next = Subtitle.GetParagraphOrDefault(i + 1);
double wantedDisplayTime = Utilities.GetOptimalDisplayMilliseconds(p.Text) * 0.9; double wantedDisplayTime = Utilities.GetOptimalDisplayMilliseconds(p.Text) * 0.9;
@ -684,10 +685,10 @@ namespace Nikse.SubtitleEdit.Forms
} }
// overlapping display time // overlapping display time
for (int i = 1; i < _subtitle.Paragraphs.Count; i++) for (int i = 1; i < Subtitle.Paragraphs.Count; i++)
{ {
Paragraph p = _subtitle.Paragraphs[i]; Paragraph p = Subtitle.Paragraphs[i];
Paragraph prev = _subtitle.GetParagraphOrDefault(i - 1); Paragraph prev = Subtitle.GetParagraphOrDefault(i - 1);
Paragraph target = prev; Paragraph target = prev;
string oldCurrent = p.ToString(); string oldCurrent = p.ToString();
string oldPrevious = prev.ToString(); string oldPrevious = prev.ToString();
@ -864,15 +865,15 @@ namespace Nikse.SubtitleEdit.Forms
{ {
string fixAction = _language.FixShortDisplayTime; string fixAction = _language.FixShortDisplayTime;
int noOfShortDisplayTimes = 0; int noOfShortDisplayTimes = 0;
for (int i = 0; i < _subtitle.Paragraphs.Count; i++) for (int i = 0; i < Subtitle.Paragraphs.Count; i++)
{ {
Paragraph p = _subtitle.Paragraphs[i]; Paragraph p = Subtitle.Paragraphs[i];
var skip = p.StartTime.IsMaxTime || p.EndTime.IsMaxTime; var skip = p.StartTime.IsMaxTime || p.EndTime.IsMaxTime;
double displayTime = p.Duration.TotalMilliseconds; double displayTime = p.Duration.TotalMilliseconds;
if (!skip && displayTime < Configuration.Settings.General.SubtitleMinimumDisplayMilliseconds) if (!skip && displayTime < Configuration.Settings.General.SubtitleMinimumDisplayMilliseconds)
{ {
Paragraph next = _subtitle.GetParagraphOrDefault(i + 1); Paragraph next = Subtitle.GetParagraphOrDefault(i + 1);
Paragraph prev = _subtitle.GetParagraphOrDefault(i - 1); Paragraph prev = Subtitle.GetParagraphOrDefault(i - 1);
if (next == null || (p.StartTime.TotalMilliseconds + Configuration.Settings.General.SubtitleMinimumDisplayMilliseconds) < next.StartTime.TotalMilliseconds) if (next == null || (p.StartTime.TotalMilliseconds + Configuration.Settings.General.SubtitleMinimumDisplayMilliseconds) < next.StartTime.TotalMilliseconds)
{ {
Paragraph temp = new Paragraph(p); Paragraph temp = new Paragraph(p);
@ -920,9 +921,9 @@ namespace Nikse.SubtitleEdit.Forms
{ {
temp.EndTime.TotalMilliseconds++; temp.EndTime.TotalMilliseconds++;
} }
Paragraph next = _subtitle.GetParagraphOrDefault(i + 1); Paragraph next = Subtitle.GetParagraphOrDefault(i + 1);
Paragraph nextNext = _subtitle.GetParagraphOrDefault(i + 2); Paragraph nextNext = Subtitle.GetParagraphOrDefault(i + 2);
Paragraph prev = _subtitle.GetParagraphOrDefault(i - 1); Paragraph prev = Subtitle.GetParagraphOrDefault(i - 1);
double diffMs = temp.Duration.TotalMilliseconds - p.Duration.TotalMilliseconds; double diffMs = temp.Duration.TotalMilliseconds - p.Duration.TotalMilliseconds;
// Normal - just make current subtitle duration longer // Normal - just make current subtitle duration longer
@ -1041,9 +1042,9 @@ namespace Nikse.SubtitleEdit.Forms
string fixAction = _language.FixInvalidItalicTag; string fixAction = _language.FixInvalidItalicTag;
int noOfInvalidHtmlTags = 0; int noOfInvalidHtmlTags = 0;
listViewFixes.BeginUpdate(); listViewFixes.BeginUpdate();
for (int i = 0; i < _subtitle.Paragraphs.Count; i++) for (int i = 0; i < Subtitle.Paragraphs.Count; i++)
{ {
var text = _subtitle.Paragraphs[i].Text; var text = Subtitle.Paragraphs[i].Text;
if (text.Contains('<')) if (text.Contains('<'))
{ {
text = text.Replace(beginTag.ToUpper(), beginTag).Replace(endTag.ToUpper(), endTag); text = text.Replace(beginTag.ToUpper(), beginTag).Replace(endTag.ToUpper(), endTag);
@ -1052,12 +1053,12 @@ namespace Nikse.SubtitleEdit.Forms
text = Utilities.FixInvalidItalicTags(text); text = Utilities.FixInvalidItalicTags(text);
if (text != oldText) if (text != oldText)
{ {
if (AllowFix(_subtitle.Paragraphs[i], fixAction)) if (AllowFix(Subtitle.Paragraphs[i], fixAction))
{ {
_subtitle.Paragraphs[i].Text = text; Subtitle.Paragraphs[i].Text = text;
_totalFixes++; _totalFixes++;
noOfInvalidHtmlTags++; noOfInvalidHtmlTags++;
AddFixToListView(_subtitle.Paragraphs[i], fixAction, oldText, text); AddFixToListView(Subtitle.Paragraphs[i], fixAction, oldText, text);
} }
} }
} }
@ -1072,9 +1073,9 @@ namespace Nikse.SubtitleEdit.Forms
{ {
string fixAction = _language.FixLongDisplayTime; string fixAction = _language.FixLongDisplayTime;
int noOfLongDisplayTimes = 0; int noOfLongDisplayTimes = 0;
for (int i = 0; i < _subtitle.Paragraphs.Count; i++) for (int i = 0; i < Subtitle.Paragraphs.Count; i++)
{ {
Paragraph p = _subtitle.Paragraphs[i]; Paragraph p = Subtitle.Paragraphs[i];
double maxDisplayTime = Utilities.GetOptimalDisplayMilliseconds(p.Text) * 8.0; double maxDisplayTime = Utilities.GetOptimalDisplayMilliseconds(p.Text) * 8.0;
if (maxDisplayTime > Configuration.Settings.General.SubtitleMaximumDisplayMilliseconds) if (maxDisplayTime > Configuration.Settings.General.SubtitleMaximumDisplayMilliseconds)
maxDisplayTime = Configuration.Settings.General.SubtitleMaximumDisplayMilliseconds; maxDisplayTime = Configuration.Settings.General.SubtitleMaximumDisplayMilliseconds;
@ -1111,9 +1112,9 @@ namespace Nikse.SubtitleEdit.Forms
{ {
string fixAction = _language.BreakLongLine; string fixAction = _language.BreakLongLine;
int noOfLongLines = 0; int noOfLongLines = 0;
for (int i = 0; i < _subtitle.Paragraphs.Count; i++) for (int i = 0; i < Subtitle.Paragraphs.Count; i++)
{ {
Paragraph p = _subtitle.Paragraphs[i]; Paragraph p = Subtitle.Paragraphs[i];
string[] lines = p.Text.Split(Utilities.NewLineChars, StringSplitOptions.RemoveEmptyEntries); string[] lines = p.Text.Split(Utilities.NewLineChars, StringSplitOptions.RemoveEmptyEntries);
bool tooLong = false; bool tooLong = false;
foreach (string line in lines) foreach (string line in lines)
@ -1151,9 +1152,9 @@ namespace Nikse.SubtitleEdit.Forms
{ {
string fixAction = _language.MergeShortLine; string fixAction = _language.MergeShortLine;
int noOfShortLines = 0; int noOfShortLines = 0;
for (int i = 0; i < _subtitle.Paragraphs.Count; i++) for (int i = 0; i < Subtitle.Paragraphs.Count; i++)
{ {
Paragraph p = _subtitle.Paragraphs[i]; Paragraph p = Subtitle.Paragraphs[i];
string s = Utilities.RemoveHtmlTags(p.Text); string s = Utilities.RemoveHtmlTags(p.Text);
if (s.Replace(Environment.NewLine, " ").Replace(" ", " ").Length < Configuration.Settings.Tools.MergeLinesShorterThan && p.Text.Contains(Environment.NewLine)) if (s.Replace(Environment.NewLine, " ").Replace(" ", " ").Length < Configuration.Settings.Tools.MergeLinesShorterThan && p.Text.Contains(Environment.NewLine))
@ -1190,9 +1191,9 @@ namespace Nikse.SubtitleEdit.Forms
{ {
string fixAction = _language.MergeShortLineAll; string fixAction = _language.MergeShortLineAll;
int noOfShortLines = 0; int noOfShortLines = 0;
for (int i = 0; i < _subtitle.Paragraphs.Count; i++) for (int i = 0; i < Subtitle.Paragraphs.Count; i++)
{ {
Paragraph p = _subtitle.Paragraphs[i]; Paragraph p = Subtitle.Paragraphs[i];
string s = Utilities.RemoveHtmlTags(p.Text); string s = Utilities.RemoveHtmlTags(p.Text);
if (s.Replace(Environment.NewLine, " ").Replace(" ", " ").Length < Configuration.Settings.Tools.MergeLinesShorterThan && p.Text.Contains(Environment.NewLine)) if (s.Replace(Environment.NewLine, " ").Replace(" ", " ").Length < Configuration.Settings.Tools.MergeLinesShorterThan && p.Text.Contains(Environment.NewLine))
@ -1221,9 +1222,9 @@ namespace Nikse.SubtitleEdit.Forms
string fixAction = _language.UnneededSpace; string fixAction = _language.UnneededSpace;
int doubleSpaces = 0; int doubleSpaces = 0;
for (int i = 0; i < _subtitle.Paragraphs.Count; i++) for (int i = 0; i < Subtitle.Paragraphs.Count; i++)
{ {
Paragraph p = _subtitle.Paragraphs[i]; Paragraph p = Subtitle.Paragraphs[i];
string oldText = p.Text; string oldText = p.Text;
p.Text = Utilities.RemoveUnneededSpaces(p.Text, Language); p.Text = Utilities.RemoveUnneededSpaces(p.Text, Language);
@ -1255,9 +1256,9 @@ namespace Nikse.SubtitleEdit.Forms
{ {
string fixAction = _language.UnneededPeriod; string fixAction = _language.UnneededPeriod;
int unneededPeriods = 0; int unneededPeriods = 0;
for (int i = 0; i < _subtitle.Paragraphs.Count; i++) for (int i = 0; i < Subtitle.Paragraphs.Count; i++)
{ {
Paragraph p = _subtitle.Paragraphs[i]; Paragraph p = Subtitle.Paragraphs[i];
if (p.Text.Contains("!." + Environment.NewLine)) if (p.Text.Contains("!." + Environment.NewLine))
{ {
if (AllowFix(p, fixAction)) if (AllowFix(p, fixAction))
@ -1335,9 +1336,9 @@ namespace Nikse.SubtitleEdit.Forms
{ {
string fixAction = _language.FixMissingSpace; string fixAction = _language.FixMissingSpace;
int missingSpaces = 0; int missingSpaces = 0;
for (int i = 0; i < _subtitle.Paragraphs.Count; i++) for (int i = 0; i < Subtitle.Paragraphs.Count; i++)
{ {
Paragraph p = _subtitle.Paragraphs[i]; Paragraph p = Subtitle.Paragraphs[i];
// missing space after comma "," // missing space after comma ","
Match match = FixMissingSpacesReComma.Match(p.Text); Match match = FixMissingSpacesReComma.Match(p.Text);
@ -1698,13 +1699,13 @@ namespace Nikse.SubtitleEdit.Forms
{ {
string fixAction = _language.AddMissingQuote; string fixAction = _language.AddMissingQuote;
int noOfFixes = 0; int noOfFixes = 0;
for (int i = 0; i < _subtitle.Paragraphs.Count; i++) for (int i = 0; i < Subtitle.Paragraphs.Count; i++)
{ {
Paragraph p = _subtitle.Paragraphs[i]; Paragraph p = Subtitle.Paragraphs[i];
if (Utilities.CountTagInText(p.Text, "\"") == 1) if (Utilities.CountTagInText(p.Text, "\"") == 1)
{ {
Paragraph next = _subtitle.GetParagraphOrDefault(i + 1); Paragraph next = Subtitle.GetParagraphOrDefault(i + 1);
if (next != null) if (next != null)
{ {
double betweenMilliseconds = next.StartTime.TotalMilliseconds - p.EndTime.TotalMilliseconds; double betweenMilliseconds = next.StartTime.TotalMilliseconds - p.EndTime.TotalMilliseconds;
@ -1716,7 +1717,7 @@ namespace Nikse.SubtitleEdit.Forms
next = null; // seems to have valid quotes, so no spanning next = null; // seems to have valid quotes, so no spanning
} }
Paragraph prev = _subtitle.GetParagraphOrDefault(i - 1); Paragraph prev = Subtitle.GetParagraphOrDefault(i - 1);
if (prev != null) if (prev != null)
{ {
double betweenMilliseconds = p.StartTime.TotalMilliseconds - prev.EndTime.TotalMilliseconds; double betweenMilliseconds = p.StartTime.TotalMilliseconds - prev.EndTime.TotalMilliseconds;
@ -1880,9 +1881,9 @@ namespace Nikse.SubtitleEdit.Forms
string fixAction = _language.FixUppercaseIInsideLowercaseWord; string fixAction = _language.FixUppercaseIInsideLowercaseWord;
int uppercaseIsInsideLowercaseWords = 0; int uppercaseIsInsideLowercaseWords = 0;
// bool isLineContinuation = false; // bool isLineContinuation = false;
for (int i = 0; i < _subtitle.Paragraphs.Count; i++) for (int i = 0; i < Subtitle.Paragraphs.Count; i++)
{ {
Paragraph p = _subtitle.Paragraphs[i]; Paragraph p = Subtitle.Paragraphs[i];
string oldText = p.Text; string oldText = p.Text;
Match match = ReAfterLowercaseLetter.Match(p.Text); Match match = ReAfterLowercaseLetter.Match(p.Text);
@ -2006,9 +2007,9 @@ namespace Nikse.SubtitleEdit.Forms
{ {
string fixAction = _language.FixDoubleApostrophes; string fixAction = _language.FixDoubleApostrophes;
int fixCount = 0; int fixCount = 0;
for (int i = 0; i < _subtitle.Paragraphs.Count; i++) for (int i = 0; i < Subtitle.Paragraphs.Count; i++)
{ {
Paragraph p = _subtitle.Paragraphs[i]; Paragraph p = Subtitle.Paragraphs[i];
if (p.Text.Contains("''")) if (p.Text.Contains("''"))
{ {
@ -2030,10 +2031,10 @@ namespace Nikse.SubtitleEdit.Forms
{ {
string fixAction = _language.FixMissingPeriodAtEndOfLine; string fixAction = _language.FixMissingPeriodAtEndOfLine;
int missigPeriodsAtEndOfLine = 0; int missigPeriodsAtEndOfLine = 0;
for (int i = 0; i < _subtitle.Paragraphs.Count; i++) for (int i = 0; i < Subtitle.Paragraphs.Count; i++)
{ {
Paragraph p = _subtitle.Paragraphs[i]; Paragraph p = Subtitle.Paragraphs[i];
Paragraph next = _subtitle.GetParagraphOrDefault(i + 1); Paragraph next = Subtitle.GetParagraphOrDefault(i + 1);
string nextText = string.Empty; string nextText = string.Empty;
if (next != null) if (next != null)
nextText = Utilities.RemoveHtmlTags(next.Text).TrimStart('-', '"', '„').TrimStart(); nextText = Utilities.RemoveHtmlTags(next.Text).TrimStart('-', '"', '„').TrimStart();
@ -2190,10 +2191,11 @@ namespace Nikse.SubtitleEdit.Forms
if (_namesEtcList == null) if (_namesEtcList == null)
{ {
_namesEtcList = new List<string>(); _namesEtcList = new List<string>();
string languageTwoLetterCode = Utilities.AutoDetectGoogleLanguage(_subtitle); string languageTwoLetterCode = Utilities.AutoDetectGoogleLanguage(Subtitle);
// Will contains both one word names and multi names // Will contains both one word names and multi names
Nikse.SubtitleEdit.Logic.Dictionaries.NamesList.LoadNamesEtcWordLists(_namesEtcList, _namesEtcList, languageTwoLetterCode); var namesList = new NamesList(Configuration.DictionariesFolder, languageTwoLetterCode, Configuration.Settings.WordLists.UseOnlineNamesEtc, Configuration.Settings.WordLists.NamesEtcUrl);
_namesEtcList = namesList.GetAllNames();
} }
} }
@ -2217,10 +2219,10 @@ namespace Nikse.SubtitleEdit.Forms
listViewFixes.BeginUpdate(); listViewFixes.BeginUpdate();
string fixAction = _language.FixFirstLetterToUppercaseAfterParagraph; string fixAction = _language.FixFirstLetterToUppercaseAfterParagraph;
int fixedStartWithUppercaseLetterAfterParagraphTicked = 0; int fixedStartWithUppercaseLetterAfterParagraphTicked = 0;
for (int i = 0; i < _subtitle.Paragraphs.Count; i++) for (int i = 0; i < Subtitle.Paragraphs.Count; i++)
{ {
Paragraph p = _subtitle.Paragraphs[i]; Paragraph p = Subtitle.Paragraphs[i];
Paragraph prev = _subtitle.GetParagraphOrDefault(i - 1); Paragraph prev = Subtitle.GetParagraphOrDefault(i - 1);
string oldText = p.Text; string oldText = p.Text;
string fixedText = FixStartWithUppercaseLetterAfterParagraph(p, prev, _encoding, Language); string fixedText = FixStartWithUppercaseLetterAfterParagraph(p, prev, _encoding, Language);
@ -2548,9 +2550,9 @@ namespace Nikse.SubtitleEdit.Forms
{ {
string fixAction = _language.StartWithUppercaseLetterAfterPeriodInsideParagraph; string fixAction = _language.StartWithUppercaseLetterAfterPeriodInsideParagraph;
int noOfFixes = 0; int noOfFixes = 0;
for (int i = 0; i < _subtitle.Paragraphs.Count; i++) for (int i = 0; i < Subtitle.Paragraphs.Count; i++)
{ {
Paragraph p = _subtitle.Paragraphs[i]; Paragraph p = Subtitle.Paragraphs[i];
string oldText = p.Text; string oldText = p.Text;
StripableText st = new StripableText(p.Text); StripableText st = new StripableText(p.Text);
if (p.Text.Length > 3) if (p.Text.Length > 3)
@ -2606,7 +2608,7 @@ namespace Nikse.SubtitleEdit.Forms
} }
} }
if (noOfFixes > 0) if (noOfFixes > 0)
LogStatus(_language.StartWithUppercaseLetterAfterPeriodInsideParagraph, noOfFixes.ToString()); LogStatus(_language.StartWithUppercaseLetterAfterPeriodInsideParagraph, noOfFixes.ToString(CultureInfo.InvariantCulture));
} }
private void FixStartWithUppercaseLetterAfterColon() private void FixStartWithUppercaseLetterAfterColon()
@ -2614,10 +2616,10 @@ namespace Nikse.SubtitleEdit.Forms
string fixAction = _language.StartWithUppercaseLetterAfterColon; string fixAction = _language.StartWithUppercaseLetterAfterColon;
int noOfFixes = 0; int noOfFixes = 0;
listViewFixes.BeginUpdate(); listViewFixes.BeginUpdate();
for (int i = 0; i < _subtitle.Paragraphs.Count; i++) for (int i = 0; i < Subtitle.Paragraphs.Count; i++)
{ {
Paragraph p = _subtitle.Paragraphs[i]; Paragraph p = Subtitle.Paragraphs[i];
Paragraph last = _subtitle.GetParagraphOrDefault(i - 1); Paragraph last = Subtitle.GetParagraphOrDefault(i - 1);
string oldText = p.Text; string oldText = p.Text;
int skipCount = 0; int skipCount = 0;
@ -2656,12 +2658,12 @@ namespace Nikse.SubtitleEdit.Forms
skipCount = p.Text.Substring(j).IndexOf('>') - p.Text.Substring(j).IndexOf("<font ", StringComparison.Ordinal); skipCount = p.Text.Substring(j).IndexOf('>') - p.Text.Substring(j).IndexOf("<font ", StringComparison.Ordinal);
else if (IsTurkishLittleI(s, _encoding, Language)) else if (IsTurkishLittleI(s, _encoding, Language))
{ {
p.Text = p.Text.Remove(j, 1).Insert(j, GetTurkishUppercaseLetter(s, _encoding).ToString()); p.Text = p.Text.Remove(j, 1).Insert(j, GetTurkishUppercaseLetter(s, _encoding).ToString(CultureInfo.InvariantCulture));
lastWasColon = false; lastWasColon = false;
} }
else if (char.IsLower(s)) else if (char.IsLower(s))
{ {
p.Text = p.Text.Remove(j, 1).Insert(j, char.ToUpper(s).ToString()); p.Text = p.Text.Remove(j, 1).Insert(j, char.ToUpper(s).ToString(CultureInfo.InvariantCulture));
lastWasColon = false; lastWasColon = false;
} }
else if (!(" " + Environment.NewLine).Contains(s)) else if (!(" " + Environment.NewLine).Contains(s))
@ -2679,7 +2681,7 @@ namespace Nikse.SubtitleEdit.Forms
} }
listViewFixes.EndUpdate(); listViewFixes.EndUpdate();
if (noOfFixes > 0) if (noOfFixes > 0)
LogStatus(_language.StartWithUppercaseLetterAfterColon, noOfFixes.ToString()); LogStatus(_language.StartWithUppercaseLetterAfterColon, noOfFixes.ToString(CultureInfo.InvariantCulture));
} }
private bool IsAbbreviation(string text, int index) private bool IsAbbreviation(string text, int index)
@ -2702,15 +2704,15 @@ namespace Nikse.SubtitleEdit.Forms
return abbreviations.Contains(word + "."); return abbreviations.Contains(word + ".");
} }
public void FixOcrErrorsViaReplaceList(string threeLetterISOLanguageName) public void FixOcrErrorsViaReplaceList(string threeLetterIsoLanguageName)
{ {
var ocrFixEngine = new OcrFixEngine(threeLetterISOLanguageName, null, this); var ocrFixEngine = new OcrFixEngine(threeLetterIsoLanguageName, null, this);
string fixAction = _language.FixCommonOcrErrors; string fixAction = _language.FixCommonOcrErrors;
int noOfFixes = 0; int noOfFixes = 0;
string lastLine = string.Empty; string lastLine = string.Empty;
for (int i = 0; i < _subtitle.Paragraphs.Count; i++) for (int i = 0; i < Subtitle.Paragraphs.Count; i++)
{ {
var p = _subtitle.Paragraphs[i]; var p = Subtitle.Paragraphs[i];
string text = ocrFixEngine.FixOcrErrors(p.Text, i, lastLine, false, OcrFixEngine.AutoGuessLevel.Cautious); string text = ocrFixEngine.FixOcrErrors(p.Text, i, lastLine, false, OcrFixEngine.AutoGuessLevel.Cautious);
lastLine = text; lastLine = text;
if (p.Text != text) if (p.Text != text)
@ -2734,9 +2736,9 @@ namespace Nikse.SubtitleEdit.Forms
{ {
string fixAction = _language.RemoveSpaceBetweenNumber; string fixAction = _language.RemoveSpaceBetweenNumber;
int noOfFixes = 0; int noOfFixes = 0;
for (int i = 0; i < _subtitle.Paragraphs.Count; i++) for (int i = 0; i < Subtitle.Paragraphs.Count; i++)
{ {
Paragraph p = _subtitle.Paragraphs[i]; Paragraph p = Subtitle.Paragraphs[i];
string text = p.Text; string text = p.Text;
Match match = RemoveSpaceBetweenNumbersRegEx.Match(text); Match match = RemoveSpaceBetweenNumbersRegEx.Match(text);
int counter = 0; int counter = 0;
@ -2776,9 +2778,9 @@ namespace Nikse.SubtitleEdit.Forms
{ {
string fixAction = _language.FixDialogsOnOneLine; string fixAction = _language.FixDialogsOnOneLine;
int noOfFixes = 0; int noOfFixes = 0;
for (int i = 0; i < _subtitle.Paragraphs.Count; i++) for (int i = 0; i < Subtitle.Paragraphs.Count; i++)
{ {
Paragraph p = _subtitle.Paragraphs[i]; Paragraph p = Subtitle.Paragraphs[i];
string text = p.Text; string text = p.Text;
string oldText = text; string oldText = text;
if (text.Contains(" - ") && !text.Contains(Environment.NewLine)) if (text.Contains(" - ") && !text.Contains(Environment.NewLine))
@ -2858,9 +2860,9 @@ namespace Nikse.SubtitleEdit.Forms
{ {
string fixAction = _language.FixTurkishAnsi; string fixAction = _language.FixTurkishAnsi;
int noOfFixes = 0; int noOfFixes = 0;
for (int i = 0; i < _subtitle.Paragraphs.Count; i++) for (int i = 0; i < Subtitle.Paragraphs.Count; i++)
{ {
Paragraph p = _subtitle.Paragraphs[i]; Paragraph p = Subtitle.Paragraphs[i];
string text = p.Text; string text = p.Text;
string oldText = text; string oldText = text;
text = text.Replace("Ý", "İ"); text = text.Replace("Ý", "İ");
@ -2888,9 +2890,9 @@ namespace Nikse.SubtitleEdit.Forms
{ {
string fixAction = _language.FixLowercaseIToUppercaseI; string fixAction = _language.FixLowercaseIToUppercaseI;
int iFixes = 0; int iFixes = 0;
for (int i = 0; i < _subtitle.Paragraphs.Count; i++) for (int i = 0; i < Subtitle.Paragraphs.Count; i++)
{ {
Paragraph p = _subtitle.Paragraphs[i]; Paragraph p = Subtitle.Paragraphs[i];
string oldText = p.Text; string oldText = p.Text;
string s = p.Text; string s = p.Text;
@ -2976,9 +2978,9 @@ namespace Nikse.SubtitleEdit.Forms
{ {
string fixAction = _language.FixHyphen; string fixAction = _language.FixHyphen;
int iFixes = 0; int iFixes = 0;
for (int i = 0; i < _subtitle.Paragraphs.Count; i++) for (int i = 0; i < Subtitle.Paragraphs.Count; i++)
{ {
Paragraph p = _subtitle.Paragraphs[i]; Paragraph p = Subtitle.Paragraphs[i];
string text = p.Text; string text = p.Text;
if (text.TrimStart().StartsWith('-') || if (text.TrimStart().StartsWith('-') ||
@ -2993,7 +2995,7 @@ namespace Nikse.SubtitleEdit.Forms
text.Contains(Environment.NewLine + "<I>-") || text.Contains(Environment.NewLine + "<I>-") ||
text.Contains(Environment.NewLine + "<I> -")) text.Contains(Environment.NewLine + "<I> -"))
{ {
Paragraph prev = _subtitle.GetParagraphOrDefault(i - 1); Paragraph prev = Subtitle.GetParagraphOrDefault(i - 1);
if (prev == null || !Utilities.RemoveHtmlTags(prev.Text).TrimEnd().EndsWith('-')) if (prev == null || !Utilities.RemoveHtmlTags(prev.Text).TrimEnd().EndsWith('-'))
{ {
@ -3081,7 +3083,7 @@ namespace Nikse.SubtitleEdit.Forms
} }
else if (text.StartsWith("<font ", StringComparison.Ordinal)) else if (text.StartsWith("<font ", StringComparison.Ordinal))
{ {
Paragraph prev = _subtitle.GetParagraphOrDefault(i - 1); Paragraph prev = Subtitle.GetParagraphOrDefault(i - 1);
if (prev == null || !Utilities.RemoveHtmlTags(prev.Text).TrimEnd().EndsWith('-')) if (prev == null || !Utilities.RemoveHtmlTags(prev.Text).TrimEnd().EndsWith('-'))
{ {
string oldText = p.Text; string oldText = p.Text;
@ -3111,9 +3113,9 @@ namespace Nikse.SubtitleEdit.Forms
{ {
string fixAction = _language.FixHyphen; string fixAction = _language.FixHyphen;
int iFixes = 0; int iFixes = 0;
for (int i = 0; i < _subtitle.Paragraphs.Count; i++) for (int i = 0; i < Subtitle.Paragraphs.Count; i++)
{ {
Paragraph p = _subtitle.Paragraphs[i]; Paragraph p = Subtitle.Paragraphs[i];
string text = p.Text; string text = p.Text;
if (text.TrimStart().StartsWith('-') || if (text.TrimStart().StartsWith('-') ||
@ -3128,7 +3130,7 @@ namespace Nikse.SubtitleEdit.Forms
text.Contains(Environment.NewLine + "<I>-") || text.Contains(Environment.NewLine + "<I>-") ||
text.Contains(Environment.NewLine + "<I> -")) text.Contains(Environment.NewLine + "<I> -"))
{ {
Paragraph prev = _subtitle.GetParagraphOrDefault(i - 1); Paragraph prev = Subtitle.GetParagraphOrDefault(i - 1);
if (prev == null || !Utilities.RemoveHtmlTags(prev.Text).TrimEnd().EndsWith('-')) if (prev == null || !Utilities.RemoveHtmlTags(prev.Text).TrimEnd().EndsWith('-'))
{ {
@ -3203,9 +3205,9 @@ namespace Nikse.SubtitleEdit.Forms
{ {
string fixAction = _language.Fix3PlusLine; string fixAction = _language.Fix3PlusLine;
int iFixes = 0; int iFixes = 0;
for (int i = 0; i < _subtitle.Paragraphs.Count; i++) for (int i = 0; i < Subtitle.Paragraphs.Count; i++)
{ {
Paragraph p = _subtitle.Paragraphs[i]; Paragraph p = Subtitle.Paragraphs[i];
string text = p.Text; string text = p.Text;
if (Utilities.CountTagInText(text, Environment.NewLine) > 1) if (Utilities.CountTagInText(text, Environment.NewLine) > 1)
@ -3230,9 +3232,9 @@ namespace Nikse.SubtitleEdit.Forms
{ {
string fixAction = _language.FixMusicNotation; string fixAction = _language.FixMusicNotation;
int fixCount = 0; int fixCount = 0;
for (int i = 0; i < _subtitle.Paragraphs.Count; i++) for (int i = 0; i < Subtitle.Paragraphs.Count; i++)
{ {
Paragraph p = _subtitle.Paragraphs[i]; Paragraph p = Subtitle.Paragraphs[i];
string[] musicSymbols = Configuration.Settings.Tools.MusicSymbolToReplace.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); string[] musicSymbols = Configuration.Settings.Tools.MusicSymbolToReplace.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
string oldText = p.Text; string oldText = p.Text;
@ -3269,9 +3271,9 @@ namespace Nikse.SubtitleEdit.Forms
{ {
string fixAction = _language.FixDoubleDash; string fixAction = _language.FixDoubleDash;
int fixCount = 0; int fixCount = 0;
for (int i = 0; i < _subtitle.Paragraphs.Count; i++) for (int i = 0; i < Subtitle.Paragraphs.Count; i++)
{ {
Paragraph p = _subtitle.Paragraphs[i]; Paragraph p = Subtitle.Paragraphs[i];
string text = p.Text; string text = p.Text;
string oldText = p.Text; string oldText = p.Text;
@ -3334,9 +3336,9 @@ namespace Nikse.SubtitleEdit.Forms
{ {
string fixAction = _language.FixDoubleGreaterThan; string fixAction = _language.FixDoubleGreaterThan;
int fixCount = 0; int fixCount = 0;
for (int i = 0; i < _subtitle.Paragraphs.Count; i++) for (int i = 0; i < Subtitle.Paragraphs.Count; i++)
{ {
Paragraph p = _subtitle.Paragraphs[i]; Paragraph p = Subtitle.Paragraphs[i];
if (p.Text.StartsWith(">> ")) if (p.Text.StartsWith(">> "))
{ {
@ -3370,9 +3372,9 @@ namespace Nikse.SubtitleEdit.Forms
string fixAction = _language.FixEllipsesStart; string fixAction = _language.FixEllipsesStart;
int fixCount = 0; int fixCount = 0;
listViewFixes.BeginUpdate(); listViewFixes.BeginUpdate();
for (int i = 0; i < _subtitle.Paragraphs.Count; i++) for (int i = 0; i < Subtitle.Paragraphs.Count; i++)
{ {
Paragraph p = _subtitle.Paragraphs[i]; Paragraph p = Subtitle.Paragraphs[i];
var text = p.Text; var text = p.Text;
if (text.Contains("..") && AllowFix(p, fixAction)) if (text.Contains("..") && AllowFix(p, fixAction))
{ {
@ -3462,9 +3464,9 @@ namespace Nikse.SubtitleEdit.Forms
{ {
string fixAction = _language.FixMissingOpenBracket; string fixAction = _language.FixMissingOpenBracket;
int fixCount = 0; int fixCount = 0;
for (int i = 0; i < _subtitle.Paragraphs.Count; i++) for (int i = 0; i < Subtitle.Paragraphs.Count; i++)
{ {
Paragraph p = _subtitle.Paragraphs[i]; Paragraph p = Subtitle.Paragraphs[i];
if (AllowFix(p, fixAction)) if (AllowFix(p, fixAction))
{ {
@ -4116,9 +4118,9 @@ namespace Nikse.SubtitleEdit.Forms
Regex regExIStand = new Regex(@"\bistand\b", RegexOptions.Compiled); Regex regExIStand = new Regex(@"\bistand\b", RegexOptions.Compiled);
Regex regExIOevrigt = new Regex(@"\biøvrigt\b", RegexOptions.Compiled); Regex regExIOevrigt = new Regex(@"\biøvrigt\b", RegexOptions.Compiled);
for (int i = 0; i < _subtitle.Paragraphs.Count; i++) for (int i = 0; i < Subtitle.Paragraphs.Count; i++)
{ {
string text = _subtitle.Paragraphs[i].Text; string text = Subtitle.Paragraphs[i].Text;
string oldText = text; string oldText = text;
if (littleIRegex.IsMatch(text)) if (littleIRegex.IsMatch(text))
@ -4167,10 +4169,10 @@ namespace Nikse.SubtitleEdit.Forms
if (text != oldText) if (text != oldText)
{ {
_subtitle.Paragraphs[i].Text = text; Subtitle.Paragraphs[i].Text = text;
fixCount++; fixCount++;
_totalFixes++; _totalFixes++;
AddFixToListView(_subtitle.Paragraphs[i], fixAction, oldText, text); AddFixToListView(Subtitle.Paragraphs[i], fixAction, oldText, text);
} }
} }
if (fixCount > 0) if (fixCount > 0)
@ -4186,10 +4188,10 @@ namespace Nikse.SubtitleEdit.Forms
{ {
string fixAction = _language.FixSpanishInvertedQuestionAndExclamationMarks; string fixAction = _language.FixSpanishInvertedQuestionAndExclamationMarks;
int fixCount = 0; int fixCount = 0;
for (int i = 0; i < _subtitle.Paragraphs.Count; i++) for (int i = 0; i < Subtitle.Paragraphs.Count; i++)
{ {
Paragraph p = _subtitle.Paragraphs[i]; Paragraph p = Subtitle.Paragraphs[i];
Paragraph last = _subtitle.GetParagraphOrDefault(i - 1); Paragraph last = Subtitle.GetParagraphOrDefault(i - 1);
bool wasLastLineClosed = last == null || last.Text.EndsWith('?') || last.Text.EndsWith('!') || last.Text.EndsWith('.') || bool wasLastLineClosed = last == null || last.Text.EndsWith('?') || last.Text.EndsWith('!') || last.Text.EndsWith('.') ||
last.Text.EndsWith(':') || last.Text.EndsWith(')') || last.Text.EndsWith(']'); last.Text.EndsWith(':') || last.Text.EndsWith(')') || last.Text.EndsWith(']');
@ -4213,7 +4215,7 @@ namespace Nikse.SubtitleEdit.Forms
} }
if (fixCount > 0) if (fixCount > 0)
LogStatus(_language.FixSpanishInvertedQuestionAndExclamationMarks, fixCount.ToString()); LogStatus(_language.FixSpanishInvertedQuestionAndExclamationMarks, fixCount.ToString(CultureInfo.InvariantCulture));
} }
private void FixSpanishInvertedLetter(char mark, string inverseMark, Paragraph p, Paragraph last, ref bool wasLastLineClosed, string fixAction, ref int fixCount) private void FixSpanishInvertedLetter(char mark, string inverseMark, Paragraph p, Paragraph last, ref bool wasLastLineClosed, string fixAction, ref int fixCount)
@ -4358,7 +4360,7 @@ namespace Nikse.SubtitleEdit.Forms
} }
if (idx < p.Text.Length) if (idx < p.Text.Length)
{ {
p.Text = p.Text.Insert(idx, mark.ToString()); p.Text = p.Text.Insert(idx, mark.ToString(CultureInfo.InvariantCulture));
if (p.Text.Contains("¡¿") && p.Text.Contains("!?")) if (p.Text.Contains("¡¿") && p.Text.Contains("!?"))
p.Text = p.Text.Replace("!?", "?!"); p.Text = p.Text.Replace("!?", "?!");
if (p.Text.Contains("¿¡") && p.Text.Contains("?!")) if (p.Text.Contains("¿¡") && p.Text.Contains("?!"))
@ -4456,7 +4458,7 @@ namespace Nikse.SubtitleEdit.Forms
_newLog = new StringBuilder(); _newLog = new StringBuilder();
_deleteIndices = new List<int>(); _deleteIndices = new List<int>();
_subtitle = new Subtitle(_originalSubtitle); Subtitle = new Subtitle(_originalSubtitle);
foreach (ListViewItem item in listView1.Items) foreach (ListViewItem item in listView1.Items)
{ {
if (item.Checked && item.Index != IndexRemoveEmptyLines) if (item.Checked && item.Index != IndexRemoveEmptyLines)
@ -4726,7 +4728,7 @@ namespace Nikse.SubtitleEdit.Forms
} }
} }
return new string[] { sb.ToString(), sb2.ToString() }; return new[] { sb.ToString(), sb2.ToString() };
} }
private void SaveConfiguration() private void SaveConfiguration()
@ -4881,12 +4883,12 @@ namespace Nikse.SubtitleEdit.Forms
_originalSubtitle.Paragraphs[_subtitleListViewIndex].Text = text; _originalSubtitle.Paragraphs[_subtitleListViewIndex].Text = text;
subtitleListView1.SetText(_subtitleListViewIndex, text); subtitleListView1.SetText(_subtitleListViewIndex, text);
EnableOKButton(); EnableOkButton();
UpdateListSyntaxColoring(); UpdateListSyntaxColoring();
} }
} }
private void EnableOKButton() private void EnableOkButton()
{ {
if (!_hasFixesBeenMade) if (!_hasFixesBeenMade)
{ {
@ -4976,13 +4978,13 @@ namespace Nikse.SubtitleEdit.Forms
private void UpdateListSyntaxColoring() private void UpdateListSyntaxColoring()
{ {
if (_subtitle == null || _subtitle.Paragraphs.Count == 0 || _subtitleListViewIndex < 0 || _subtitleListViewIndex >= _subtitle.Paragraphs.Count) if (Subtitle == null || Subtitle.Paragraphs.Count == 0 || _subtitleListViewIndex < 0 || _subtitleListViewIndex >= Subtitle.Paragraphs.Count)
return; return;
subtitleListView1.SyntaxColorLine(_subtitle.Paragraphs, _subtitleListViewIndex, _subtitle.Paragraphs[_subtitleListViewIndex]); subtitleListView1.SyntaxColorLine(Subtitle.Paragraphs, _subtitleListViewIndex, Subtitle.Paragraphs[_subtitleListViewIndex]);
Paragraph next = _subtitle.GetParagraphOrDefault(_subtitleListViewIndex + 1); Paragraph next = Subtitle.GetParagraphOrDefault(_subtitleListViewIndex + 1);
if (next != null) if (next != null)
subtitleListView1.SyntaxColorLine(_subtitle.Paragraphs, _subtitleListViewIndex + 1, _subtitle.Paragraphs[_subtitleListViewIndex + 1]); subtitleListView1.SyntaxColorLine(Subtitle.Paragraphs, _subtitleListViewIndex + 1, Subtitle.Paragraphs[_subtitleListViewIndex + 1]);
} }
private void MaskedTextBox_TextChanged(object sender, EventArgs e) private void MaskedTextBox_TextChanged(object sender, EventArgs e)
@ -5062,7 +5064,7 @@ namespace Nikse.SubtitleEdit.Forms
_totalFixes = 0; _totalFixes = 0;
_totalErrors = 0; _totalErrors = 0;
RunSelectedActions(); RunSelectedActions();
_originalSubtitle = new Subtitle(_subtitle); _originalSubtitle = new Subtitle(Subtitle);
subtitleListView1.Fill(_originalSubtitle); subtitleListView1.Fill(_originalSubtitle);
RefreshFixes(); RefreshFixes();
if (listViewFixes.Items.Count == 0) if (listViewFixes.Items.Count == 0)
@ -5142,7 +5144,7 @@ namespace Nikse.SubtitleEdit.Forms
string oldText = textBoxListViewText.Text; string oldText = textBoxListViewText.Text;
textBoxListViewText.Text = Utilities.AutoBreakLine(textBoxListViewText.Text, Language); textBoxListViewText.Text = Utilities.AutoBreakLine(textBoxListViewText.Text, Language);
if (oldText != textBoxListViewText.Text) if (oldText != textBoxListViewText.Text)
EnableOKButton(); EnableOkButton();
} }
} }
@ -5151,7 +5153,7 @@ namespace Nikse.SubtitleEdit.Forms
string oldText = textBoxListViewText.Text; string oldText = textBoxListViewText.Text;
textBoxListViewText.Text = Utilities.UnbreakLine(textBoxListViewText.Text); textBoxListViewText.Text = Utilities.UnbreakLine(textBoxListViewText.Text);
if (oldText != textBoxListViewText.Text) if (oldText != textBoxListViewText.Text)
EnableOKButton(); EnableOkButton();
} }
private void ToolStripMenuItemDeleteClick(object sender, EventArgs e) private void ToolStripMenuItemDeleteClick(object sender, EventArgs e)
@ -5424,7 +5426,7 @@ namespace Nikse.SubtitleEdit.Forms
private void comboBoxLanguage_SelectedIndexChanged(object sender, EventArgs e) private void comboBoxLanguage_SelectedIndexChanged(object sender, EventArgs e)
{ {
if (_subtitle != null) if (Subtitle != null)
{ {
var ci = (CultureInfo)comboBoxLanguage.SelectedItem; var ci = (CultureInfo)comboBoxLanguage.SelectedItem;
_autoDetectGoogleLanguage = ci.TwoLetterISOLanguageName; _autoDetectGoogleLanguage = ci.TwoLetterISOLanguageName;

View File

@ -22,7 +22,7 @@ namespace Nikse.SubtitleEdit.Forms
private int _ssaFontColor; private int _ssaFontColor;
private string _listBoxSearchString = string.Empty; private string _listBoxSearchString = string.Empty;
private DateTime _listBoxSearchStringLastUsed = DateTime.Now; private DateTime _listBoxSearchStringLastUsed = DateTime.Now;
private readonly List<string> _wordListNamesEtc = new List<string>(); private List<string> _wordListNamesEtc = new List<string>();
private List<string> _userWordList = new List<string>(); private List<string> _userWordList = new List<string>();
private OcrFixReplaceList _ocrFixReplaceList; private OcrFixReplaceList _ocrFixReplaceList;
private readonly string _oldVlcLocation; private readonly string _oldVlcLocation;
@ -1803,8 +1803,8 @@ namespace Nikse.SubtitleEdit.Forms
var task = Task.Factory.StartNew(() => var task = Task.Factory.StartNew(() =>
{ {
// names etc // names etc
_wordListNamesEtc.Clear(); var namesList = new NamesList(Configuration.DictionariesFolder, language, Configuration.Settings.WordLists.UseOnlineNamesEtc, Configuration.Settings.WordLists.NamesEtcUrl);
NamesList.LoadNamesEtcWordLists(_wordListNamesEtc, _wordListNamesEtc, language); _wordListNamesEtc = namesList.GetAllNames();
_wordListNamesEtc.Sort(); _wordListNamesEtc.Sort();
return _wordListNamesEtc; return _wordListNamesEtc;
}); });
@ -1841,7 +1841,8 @@ namespace Nikse.SubtitleEdit.Forms
string text = textBoxNameEtc.Text.Trim(); string text = textBoxNameEtc.Text.Trim();
if (!string.IsNullOrEmpty(language) && text.Length > 1 && !_wordListNamesEtc.Contains(text)) if (!string.IsNullOrEmpty(language) && text.Length > 1 && !_wordListNamesEtc.Contains(text))
{ {
NamesList.AddWordToLocalNamesEtcList(text, language); var namesList = new NamesList(Configuration.DictionariesFolder, language, Configuration.Settings.WordLists.UseOnlineNamesEtc, Configuration.Settings.WordLists.NamesEtcUrl);
namesList.Add(text, language);
LoadNamesEtc(language, true); LoadNamesEtc(language, true);
labelStatus.Text = string.Format(Configuration.Settings.Language.Settings.WordAddedX, text); labelStatus.Text = string.Format(Configuration.Settings.Language.Settings.WordAddedX, text);
textBoxNameEtc.Text = string.Empty; textBoxNameEtc.Text = string.Empty;
@ -1891,51 +1892,18 @@ namespace Nikse.SubtitleEdit.Forms
int removeCount = 0; int removeCount = 0;
var namesEtc = new List<string>(); var namesEtc = new List<string>();
var globalNamesEtc = new List<string>(); var globalNamesEtc = new List<string>();
string localNamesEtcFileName = NamesList.LoadLocalNamesEtc(namesEtc, namesEtc, language); var namesList = new NamesList(Configuration.DictionariesFolder, language, Configuration.Settings.WordLists.UseOnlineNamesEtc, Configuration.Settings.WordLists.NamesEtcUrl);
NamesList.LoadGlobalNamesEtc(globalNamesEtc, globalNamesEtc);
for (int idx = listBoxNamesEtc.SelectedIndices.Count - 1; idx >= 0; idx--) for (int idx = listBoxNamesEtc.SelectedIndices.Count - 1; idx >= 0; idx--)
{ {
index = listBoxNamesEtc.SelectedIndices[idx]; index = listBoxNamesEtc.SelectedIndices[idx];
text = listBoxNamesEtc.Items[index].ToString(); text = listBoxNamesEtc.Items[index].ToString();
if (namesEtc.Contains(text)) namesList.Remove(text, language);
{ removeCount++;
namesEtc.Remove(text);
removeCount++;
}
if (globalNamesEtc.Contains(text))
{
globalNamesEtc.Remove(text);
removeCount++;
}
listBoxNamesEtc.Items.RemoveAt(index); listBoxNamesEtc.Items.RemoveAt(index);
} }
if (removeCount > 0) if (removeCount > 0)
{ {
namesEtc.Sort();
var doc = new XmlDocument();
doc.Load(localNamesEtcFileName);
doc.DocumentElement.RemoveAll();
foreach (string name in namesEtc)
{
XmlNode node = doc.CreateElement("name");
node.InnerText = name;
doc.DocumentElement.AppendChild(node);
}
doc.Save(localNamesEtcFileName);
LoadNamesEtc(language, false); // reload
globalNamesEtc.Sort();
doc = new XmlDocument();
doc.Load(Utilities.DictionaryFolder + "names_etc.xml");
doc.DocumentElement.RemoveAll();
foreach (string name in globalNamesEtc)
{
XmlNode node = doc.CreateElement("name");
node.InnerText = name;
doc.DocumentElement.AppendChild(node);
}
doc.Save(Utilities.DictionaryFolder + "names_etc.xml");
LoadNamesEtc(language, true); // reload LoadNamesEtc(language, true); // reload
if (index < listBoxNamesEtc.Items.Count) if (index < listBoxNamesEtc.Items.Count)
@ -2498,7 +2466,7 @@ namespace Nikse.SubtitleEdit.Forms
MessageBox.Show(string.Format(Configuration.Settings.Language.Settings.ShortcutIsNotValid, sb)); MessageBox.Show(string.Format(Configuration.Settings.Language.Settings.ShortcutIsNotValid, sb));
return; return;
} }
else if (sb.ToString() == "[CapsLock]") if (sb.ToString() == "[CapsLock]")
{ {
MessageBox.Show(string.Format(Configuration.Settings.Language.Settings.ShortcutIsNotValid, sb)); MessageBox.Show(string.Format(Configuration.Settings.Language.Settings.ShortcutIsNotValid, sb));
return; return;

View File

@ -32,7 +32,7 @@ namespace Nikse.SubtitleEdit.Forms
private SpellCheckAction _action = SpellCheckAction.Skip; private SpellCheckAction _action = SpellCheckAction.Skip;
private List<string> _suggestions; private List<string> _suggestions;
private string _currentAction = null; private string _currentAction;
public SpellCheckAction Action { get { return _action; } set { _action = value; } } public SpellCheckAction Action { get { return _action; } set { _action = value; } }
public string ChangeWord { get { return textBoxWord.Text; } set { textBoxWord.Text = value; } } public string ChangeWord { get { return textBoxWord.Text; } set { textBoxWord.Text = value; } }
public string ChangeWholeText { get { return textBoxWholeText.Text; } } public string ChangeWholeText { get { return textBoxWholeText.Text; } }
@ -42,8 +42,9 @@ namespace Nikse.SubtitleEdit.Forms
get { return _currentIndex; } get { return _currentIndex; }
} }
private List<string> _namesEtcList = new List<string>(); private NamesList _namesList;
private List<string> _namesEtcMultiWordList = new List<string>(); private HashSet<string> _namesEtcList = new HashSet<string>();
private HashSet<string> _namesEtcMultiWordList = new HashSet<string>();
private List<string> _namesEtcListUppercase = new List<string>(); private List<string> _namesEtcListUppercase = new List<string>();
private List<string> _namesEtcListWithApostrophe = new List<string>(); private List<string> _namesEtcListWithApostrophe = new List<string>();
private List<string> _skipAllList = new List<string>(); private List<string> _skipAllList = new List<string>();
@ -64,16 +65,16 @@ namespace Nikse.SubtitleEdit.Forms
private Subtitle _subtitle; private Subtitle _subtitle;
private string _originalWord; private string _originalWord;
private int _noOfSkippedWords = 0; private int _noOfSkippedWords;
private int _noOfChangedWords = 0; private int _noOfChangedWords;
private int _noOfCorrectWords = 0; private int _noOfCorrectWords;
private int _noOfNamesEtc = 0; private int _noOfNamesEtc;
private int _noOfAddedWords = 0; private int _noOfAddedWords;
private bool _firstChange = true; private bool _firstChange = true;
private string _languageName; private string _languageName;
private Main _mainWindow; private Main _mainWindow;
private string _currentDictionary = null; private string _currentDictionary;
public class SuggestionParameter public class SuggestionParameter
{ {
@ -137,8 +138,8 @@ namespace Nikse.SubtitleEdit.Forms
private void FixLargeFonts() private void FixLargeFonts()
{ {
Graphics graphics = this.CreateGraphics(); var graphics = CreateGraphics();
SizeF textSize = graphics.MeasureString(buttonAbort.Text, this.Font); var textSize = graphics.MeasureString(buttonAbort.Text, Font);
if (textSize.Height > buttonAbort.Height - 4) if (textSize.Height > buttonAbort.Height - 4)
{ {
int newButtonHeight = (int)(textSize.Height + 7 + 0.5); int newButtonHeight = (int)(textSize.Height + 7 + 0.5);
@ -499,7 +500,9 @@ namespace Nikse.SubtitleEdit.Forms
} }
if (!ChangeWord.EndsWith('\'')) if (!ChangeWord.EndsWith('\''))
_namesEtcListWithApostrophe.Add(ChangeWord + "'"); _namesEtcListWithApostrophe.Add(ChangeWord + "'");
NamesList.AddWordToLocalNamesEtcList(ChangeWord, _languageName);
var namesList = new NamesList(Configuration.DictionariesFolder, _languageName, Configuration.Settings.WordLists.UseOnlineNamesEtc, Configuration.Settings.WordLists.NamesEtcUrl);
namesList.Add(ChangeWord, _languageName);
} }
break; break;
case SpellCheckAction.ChangeWholeText: case SpellCheckAction.ChangeWholeText:
@ -507,8 +510,6 @@ namespace Nikse.SubtitleEdit.Forms
_currentParagraph.Text = ChangeWholeText; _currentParagraph.Text = ChangeWholeText;
_mainWindow.ChangeWholeTextMainPart(ref _noOfChangedWords, ref _firstChange, _currentIndex, _currentParagraph); _mainWindow.ChangeWholeTextMainPart(ref _noOfChangedWords, ref _firstChange, _currentIndex, _currentParagraph);
break;
default:
break; break;
} }
labelActionInfo.Text = string.Empty; labelActionInfo.Text = string.Empty;
@ -656,7 +657,7 @@ namespace Nikse.SubtitleEdit.Forms
} }
else if (_namesEtcListUppercase.Contains(_currentWord) else if (_namesEtcListUppercase.Contains(_currentWord)
|| _namesEtcListWithApostrophe.Contains(_currentWord) || _namesEtcListWithApostrophe.Contains(_currentWord)
|| NamesList.IsInNamesEtcMultiWordList(_namesEtcMultiWordList, _currentParagraph.Text, _currentWord)) //TODO: verify this! || _namesList.IsInNamesEtcMultiWordList(_currentParagraph.Text, _currentWord)) //TODO: verify this!
{ {
_noOfNamesEtc++; _noOfNamesEtc++;
} }
@ -756,47 +757,44 @@ namespace Nikse.SubtitleEdit.Forms
DoAction(SpellCheckAction.ChangeAll); DoAction(SpellCheckAction.ChangeAll);
return; return;
} }
else if (AutoFixNames && _currentWord.Length > 3 && suggestions.Contains(_currentWord.ToUpper())) if (AutoFixNames && _currentWord.Length > 3 && suggestions.Contains(_currentWord.ToUpper()))
{ // does not work well with two letter words like "da" and "de" which get auto-corrected to "DA" and "DE" { // does not work well with two letter words like "da" and "de" which get auto-corrected to "DA" and "DE"
ChangeWord = _currentWord.ToUpper(); ChangeWord = _currentWord.ToUpper();
DoAction(SpellCheckAction.ChangeAll); DoAction(SpellCheckAction.ChangeAll);
return; return;
} }
else if (AutoFixNames && _currentWord.Length > 1 && _namesEtcList.Contains(char.ToUpper(_currentWord[0]) + _currentWord.Substring(1))) if (AutoFixNames && _currentWord.Length > 1 && _namesEtcList.Contains(char.ToUpper(_currentWord[0]) + _currentWord.Substring(1)))
{ {
ChangeWord = char.ToUpper(_currentWord[0]) + _currentWord.Substring(1); ChangeWord = char.ToUpper(_currentWord[0]) + _currentWord.Substring(1);
DoAction(SpellCheckAction.ChangeAll); DoAction(SpellCheckAction.ChangeAll);
return; return;
} }
if (_prefix != null && _prefix == "''" && _currentWord.EndsWith("''"))
{
_prefix = string.Empty;
_currentSpellCheckWord.Index += 2;
_currentWord = _currentWord.Trim('\'');
}
if (_prefix != null && _prefix == "'" && _currentWord.EndsWith('\''))
{
_prefix = string.Empty;
_currentSpellCheckWord.Index++;
_currentWord = _currentWord.Trim('\'');
}
if (_postfix != null && _postfix == "'")
{
_currentSpellCheckWord.Text = _currentWord + _postfix;
Initialize(_languageName, _currentSpellCheckWord, suggestions, _currentParagraph.Text, string.Format(Configuration.Settings.Language.Main.LineXOfY, (_currentIndex + 1), _subtitle.Paragraphs.Count));
}
else else
{ {
if (_prefix != null && _prefix == "''" && _currentWord.EndsWith("''")) _currentSpellCheckWord.Text = _currentWord;
{ Initialize(_languageName, _currentSpellCheckWord, suggestions, _currentParagraph.Text, string.Format(Configuration.Settings.Language.Main.LineXOfY, (_currentIndex + 1), _subtitle.Paragraphs.Count));
_prefix = string.Empty;
_currentSpellCheckWord.Index += 2;
_currentWord = _currentWord.Trim('\'');
}
if (_prefix != null && _prefix == "'" && _currentWord.EndsWith('\''))
{
_prefix = string.Empty;
_currentSpellCheckWord.Index++;
_currentWord = _currentWord.Trim('\'');
}
if (_postfix != null && _postfix == "'")
{
_currentSpellCheckWord.Text = _currentWord + _postfix;
Initialize(_languageName, _currentSpellCheckWord, suggestions, _currentParagraph.Text, string.Format(Configuration.Settings.Language.Main.LineXOfY, (_currentIndex + 1), _subtitle.Paragraphs.Count));
}
else
{
_currentSpellCheckWord.Text = _currentWord;
Initialize(_languageName, _currentSpellCheckWord, suggestions, _currentParagraph.Text, string.Format(Configuration.Settings.Language.Main.LineXOfY, (_currentIndex + 1), _subtitle.Paragraphs.Count));
}
if (!this.Visible)
this.ShowDialog(_mainWindow);
return; // wait for user input
} }
if (!Visible)
ShowDialog(_mainWindow);
return; // wait for user input
} }
} }
@ -806,15 +804,15 @@ namespace Nikse.SubtitleEdit.Forms
private static List<SpellCheckWord> Split(string s) private static List<SpellCheckWord> Split(string s)
{ {
const string SplitChars = " -.,?!:;\"“”()[]{}|<>/+\r\n¿¡…—♪♫„“"; const string splitChars = " -.,?!:;\"“”()[]{}|<>/+\r\n¿¡…—♪♫„“";
var list = new List<SpellCheckWord>(); var list = new List<SpellCheckWord>();
var sb = new StringBuilder(); var sb = new StringBuilder();
for (int i = 0; i < s.Length; i++) for (int i = 0; i < s.Length; i++)
{ {
if (SplitChars.Contains(s[i])) if (splitChars.Contains(s[i]))
{ {
if (sb.Length > 0) if (sb.Length > 0)
list.Add(new SpellCheckWord() { Text = sb.ToString(), Index = i - sb.Length }); list.Add(new SpellCheckWord { Text = sb.ToString(), Index = i - sb.Length });
sb = new StringBuilder(); sb = new StringBuilder();
} }
else else
@ -823,7 +821,7 @@ namespace Nikse.SubtitleEdit.Forms
} }
} }
if (sb.Length > 0) if (sb.Length > 0)
list.Add(new SpellCheckWord() { Text = sb.ToString(), Index = s.Length - 1 - sb.Length }); list.Add(new SpellCheckWord { Text = sb.ToString(), Index = s.Length - 1 - sb.Length });
return list; return list;
} }
@ -901,7 +899,6 @@ namespace Nikse.SubtitleEdit.Forms
if (text.Contains('.') || text.Contains('-')) if (text.Contains('.') || text.Contains('-'))
{ {
int i = 0; int i = 0;
string id = string.Format("_@{0}_", i);
foreach (string wordWithDashesOrPeriods in _wordsWithDashesOrPeriods) foreach (string wordWithDashesOrPeriods in _wordsWithDashesOrPeriods)
{ {
bool found = true; bool found = true;
@ -912,7 +909,6 @@ namespace Nikse.SubtitleEdit.Forms
if (indexStart >= 0) if (indexStart >= 0)
{ {
found = true;
int endIndexPlus = indexStart + wordWithDashesOrPeriods.Length; int endIndexPlus = indexStart + wordWithDashesOrPeriods.Length;
bool startOk = indexStart == 0 || (@" (['""" + Environment.NewLine).Contains(text[indexStart - 1]); bool startOk = indexStart == 0 || (@" (['""" + Environment.NewLine).Contains(text[indexStart - 1]);
bool endOk = endIndexPlus == text.Length; bool endOk = endIndexPlus == text.Length;
@ -921,7 +917,7 @@ namespace Nikse.SubtitleEdit.Forms
if (startOk && endOk) if (startOk && endOk)
{ {
i++; i++;
id = string.Format("_@{0}_", i); string id = string.Format("_@{0}_", i);
replaceIds.Add(id); replaceIds.Add(id);
replaceNames.Add(wordWithDashesOrPeriods); replaceNames.Add(wordWithDashesOrPeriods);
text = text.Remove(indexStart, wordWithDashesOrPeriods.Length).Insert(indexStart, id); text = text.Remove(indexStart, wordWithDashesOrPeriods.Length).Insert(indexStart, id);
@ -946,7 +942,7 @@ namespace Nikse.SubtitleEdit.Forms
LanguageStructure.Main mainLanguage = Configuration.Settings.Language.Main; LanguageStructure.Main mainLanguage = Configuration.Settings.Language.Main;
if (_noOfChangedWords > 0 || _noOfAddedWords > 0 || _noOfSkippedWords > 0 || completedMessage == Configuration.Settings.Language.SpellCheck.SpellCheckCompleted) if (_noOfChangedWords > 0 || _noOfAddedWords > 0 || _noOfSkippedWords > 0 || completedMessage == Configuration.Settings.Language.SpellCheck.SpellCheckCompleted)
{ {
this.Hide(); Hide();
if (Configuration.Settings.Tools.SpellCheckShowCompletedMessage) if (Configuration.Settings.Tools.SpellCheckShowCompletedMessage)
{ {
var form = new DialogDoNotShowAgain(_mainWindow.Title + " - " + mainLanguage.SpellCheck, var form = new DialogDoNotShowAgain(_mainWindow.Title + " - " + mainLanguage.SpellCheck,
@ -996,8 +992,6 @@ namespace Nikse.SubtitleEdit.Forms
LanguageStructure.Main mainLanguage = Configuration.Settings.Language.Main; LanguageStructure.Main mainLanguage = Configuration.Settings.Language.Main;
_mainWindow = mainWindow; _mainWindow = mainWindow;
_namesEtcList = new List<string>();
_namesEtcMultiWordList = new List<string>();
_namesEtcListUppercase = new List<string>(); _namesEtcListUppercase = new List<string>();
_namesEtcListWithApostrophe = new List<string>(); _namesEtcListWithApostrophe = new List<string>();
@ -1035,7 +1029,10 @@ namespace Nikse.SubtitleEdit.Forms
_languageName = Utilities.AutoDetectLanguageName(_languageName, subtitle); _languageName = Utilities.AutoDetectLanguageName(_languageName, subtitle);
string dictionary = Utilities.DictionaryFolder + _languageName; string dictionary = Utilities.DictionaryFolder + _languageName;
NamesList.LoadNamesEtcWordLists(_namesEtcList, _namesEtcMultiWordList, _languageName); _namesList = new NamesList(Configuration.DictionariesFolder, _languageName, Configuration.Settings.WordLists.UseOnlineNamesEtc, Configuration.Settings.WordLists.NamesEtcUrl);
_namesEtcList = _namesList.GetNames();
_namesEtcMultiWordList = _namesList.GetMultiNames();
foreach (string namesItem in _namesEtcList) foreach (string namesItem in _namesEtcList)
_namesEtcListUppercase.Add(namesItem.ToUpper()); _namesEtcListUppercase.Add(namesItem.ToUpper());
@ -1200,7 +1197,7 @@ namespace Nikse.SubtitleEdit.Forms
format = "Undo: {0}"; format = "Undo: {0}";
string undoText = string.Format(format, text); string undoText = string.Format(format, text);
_undoList.Add(new UndoObject() _undoList.Add(new UndoObject
{ {
CurrentIndex = _currentIndex, CurrentIndex = _currentIndex,
UndoText = undoText, UndoText = undoText,
@ -1270,14 +1267,12 @@ namespace Nikse.SubtitleEdit.Forms
if (!undo.UndoWord.EndsWith('\'')) if (!undo.UndoWord.EndsWith('\''))
_namesEtcListWithApostrophe.Remove(undo.UndoWord + "'"); _namesEtcListWithApostrophe.Remove(undo.UndoWord + "'");
NamesList.RemoveFromLocalNamesEtcList(undo.UndoWord, _languageName); _namesList.Remove(undo.UndoWord, _languageName);
} }
break; break;
case SpellCheckAction.ChangeWholeText: case SpellCheckAction.ChangeWholeText:
_subtitle = _mainWindow.UndoFromSpellCheck(undo.Subtitle); _subtitle = _mainWindow.UndoFromSpellCheck(undo.Subtitle);
break; break;
default:
break;
} }
_undoList.RemoveAt(_undoList.Count - 1); _undoList.RemoveAt(_undoList.Count - 1);

View File

@ -1,338 +1,241 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Windows.Forms;
using System.Xml; using System.Xml;
namespace Nikse.SubtitleEdit.Logic.Dictionaries namespace Nikse.SubtitleEdit.Logic.Dictionaries
{ {
public class NamesList public class NamesList
{ {
private readonly string _dictionaryFolder;
private readonly HashSet<string> _namesList;
private readonly HashSet<string> _namesMultiList;
private readonly string _languageName;
//private string _dictionaryFolder; public NamesList(string dictionaryFolder, string languageName, bool useOnlineNamesEtc, string namesEtcUrl)
//private List<string> _namesList;
//private List<string> _namesMultiList;
//public NamesList(string dictionaryFolder, string languageName)
//{
// _dictionaryFolder = dictionaryFolder;
// _namesList = new List<string>();
// _namesMultiList = new List<string>();
// LoadNamesList(Path.Combine(_dictionaryFolder, "names_etc.xml"), _namesList, _namesMultiList);
// LoadNamesList(Path.Combine(_dictionaryFolder, GetLocalNamesFileName(languageName)), _namesList, _namesMultiList);
// LoadNamesList(Path.Combine(_dictionaryFolder, GetLocalNamesUserFileName(languageName)), _namesList, _namesMultiList);
//}
//private string GetLocalNamesFileName(string languageName)
//{
// if (languageName.Length == 2)
// {
// string[] files = Directory.GetFiles(_dictionaryFolder, languageName + "_??_names_etc.xml");
// if (files.Length > 0)
// return localNamesFileName = files[0];
// }
// return Path.Combine(_dictionaryFolder, languageName + "_names_etc.xml");
//}
//private string GetLocalNamesUserFileName(string languageName)
//{
// if (languageName.Length == 2)
// {
// string[] files = Directory.GetFiles(_dictionaryFolder, languageName + "_??_names_etc_user.xml");
// if (files.Length > 0)
// return localNamesFileName = files[0];
// }
// return Path.Combine(_dictionaryFolder, languageName + "_names_etc_user.xml");
//}
//private void LoadNamesList(string fileName, List<string> _namesList, List<string> _namesMultiList)
//{
// if (string.IsNullOrEmpty(fileName) || !File.Exists(fileName))
// return;
// var namesDoc = new XmlDocument();
// namesDoc.Load(fileName)
// if (namesDoc == null || namesDoc.DocumentElement == null)
// return;
// foreach (XmlNode node in namesDoc.DocumentElement.SelectNodes("name"))
// {
// string s = node.InnerText.Trim();
// if (s.Contains(' '))
// {
// if (!namesEtcMultiWordList.Contains(s))
// namesEtcMultiWordList.Add(s);
// }
// else
// {
// if (!namesEtcList.Contains(s))
// namesEtcList.Add(s);
// }
// }
//}
public static bool RemoveFromLocalNamesEtcList(string word, string languageName)
{ {
word = word.Trim(); _dictionaryFolder = dictionaryFolder;
if (word.Length > 1) _languageName = languageName;
_namesList = new HashSet<string>();
_namesMultiList = new HashSet<string>();
if (useOnlineNamesEtc && !string.IsNullOrEmpty(namesEtcUrl))
{ {
var localNamesEtc = new List<string>(); try
string userNamesEtcXmlFileName = LoadLocalNamesEtc(localNamesEtc, localNamesEtc, languageName); {
var xml = Utilities.DownloadString(Configuration.Settings.WordLists.NamesEtcUrl);
var namesDoc = new XmlDocument();
namesDoc.LoadXml(xml);
LoadNames(_namesList, _namesMultiList, namesDoc);
}
catch (Exception exception)
{
LoadNamesList(Path.Combine(_dictionaryFolder, "names_etc.xml"), _namesList, _namesMultiList);
System.Diagnostics.Debug.WriteLine(exception.Message);
}
}
if (!localNamesEtc.Contains(word)) LoadNamesList(GetLocalNamesFileName(), _namesList, _namesMultiList);
return false;
localNamesEtc.Remove(word);
localNamesEtc.Sort();
var userFile = GetLocalNamesUserFileName();
LoadNamesList(userFile, _namesList, _namesMultiList);
UnloadRemovedNames(userFile);
}
public List<string> GetAllNames()
{
var list = new List<string>();
foreach (var name in _namesList)
{
list.Add(name);
}
foreach (var name in _namesMultiList)
{
list.Add(name);
}
return list;
}
public HashSet<string> GetNames()
{
return _namesList;
}
public HashSet<string> GetMultiNames()
{
return _namesMultiList;
}
private void UnloadRemovedNames(string fileName)
{
if (string.IsNullOrEmpty(fileName) || !File.Exists(fileName))
return;
var namesDoc = new XmlDocument();
namesDoc.Load(fileName);
if (namesDoc.DocumentElement == null)
return;
foreach (XmlNode node in namesDoc.DocumentElement.SelectNodes("removed_name"))
{
string s = node.InnerText.Trim();
if (s.Contains(' '))
{
if (_namesMultiList.Contains(s))
_namesMultiList.Remove(s);
}
else if (_namesList.Contains(s))
{
_namesList.Remove(s);
}
}
}
private string GetLocalNamesFileName()
{
if (_languageName.Length == 2)
{
string[] files = Directory.GetFiles(_dictionaryFolder, _languageName + "_??_names_etc.xml");
if (files.Length > 0)
return files[0];
}
return Path.Combine(_dictionaryFolder, _languageName + "_names_etc.xml");
}
private string GetLocalNamesUserFileName()
{
if (_languageName.Length == 2)
{
string[] files = Directory.GetFiles(_dictionaryFolder, _languageName + "_??_names_etc_user.xml");
if (files.Length > 0)
return files[0];
}
return Path.Combine(_dictionaryFolder, _languageName + "_names_etc_user.xml");
}
private void LoadNamesList(string fileName, HashSet<string> namesList, HashSet<string> namesMultiList)
{
if (string.IsNullOrEmpty(fileName) || !File.Exists(fileName))
return;
var namesDoc = new XmlDocument();
namesDoc.Load(fileName);
if (namesDoc.DocumentElement == null)
return;
LoadNames(namesList, namesMultiList, namesDoc);
}
private static void LoadNames(HashSet<string> namesList, HashSet<string> namesMultiList, XmlDocument namesDoc)
{
foreach (XmlNode node in namesDoc.DocumentElement.SelectNodes("name"))
{
string s = node.InnerText.Trim();
if (s.Contains(' '))
{
if (!namesMultiList.Contains(s))
namesMultiList.Add(s);
}
else if (!namesList.Contains(s))
{
namesList.Add(s);
}
}
}
public bool Remove(string name, string languageName)
{
name = name.Trim();
if (name.Length > 1 && _namesList.Contains(name) || _namesMultiList.Contains(name))
{
if (_namesList.Contains(name))
_namesList.Remove(name);
if (_namesMultiList.Contains(name))
_namesMultiList.Remove(name);
var userList = new HashSet<string>();
var fileName = GetLocalNamesUserFileName();
LoadNamesList(fileName, userList, userList);
var namesDoc = new XmlDocument();
if (File.Exists(fileName))
{
namesDoc.Load(fileName);
}
else
{
namesDoc.LoadXml("<ignore_words />");
}
if (userList.Contains(name))
{
userList.Remove(name);
XmlNode nodeToRemove = null;
foreach (XmlNode node in namesDoc.DocumentElement.SelectNodes("name"))
{
if (node.InnerText == name)
{
nodeToRemove = node;
break;
}
}
if (nodeToRemove != null)
namesDoc.DocumentElement.RemoveChild(nodeToRemove);
}
else
{
XmlNode node = namesDoc.CreateElement("removed_name");
node.InnerText = name;
namesDoc.DocumentElement.AppendChild(node);
}
namesDoc.Save(fileName);
return true;
}
return false;
}
public bool Add(string name, string languageName)
{
name = name.Trim();
if (name.Length > 1)
{
if (name.Contains(' '))
{
if (!_namesMultiList.Contains(name))
_namesMultiList.Add(name);
}
else if (!_namesList.Contains(name))
{
_namesList.Add(name);
}
var fileName = GetLocalNamesUserFileName();
var namesEtcDoc = new XmlDocument(); var namesEtcDoc = new XmlDocument();
if (File.Exists(userNamesEtcXmlFileName)) if (File.Exists(fileName))
namesEtcDoc.Load(userNamesEtcXmlFileName); namesEtcDoc.Load(fileName);
else else
namesEtcDoc.LoadXml("<ignore_words />"); namesEtcDoc.LoadXml("<ignore_words />");
XmlNode de = namesEtcDoc.DocumentElement; XmlNode de = namesEtcDoc.DocumentElement;
if (de != null) if (de != null)
{ {
de.RemoveAll(); XmlNode node = namesEtcDoc.CreateElement("name");
foreach (var name in localNamesEtc) node.InnerText = name;
{ de.AppendChild(node);
XmlNode node = namesEtcDoc.CreateElement("name"); namesEtcDoc.Save(fileName);
node.InnerText = name;
de.AppendChild(node);
}
namesEtcDoc.Save(userNamesEtcXmlFileName);
} }
return true; return true;
} }
return false; return false;
} }
public static bool AddWordToLocalNamesEtcList(string word, string languageName) public bool IsInNamesEtcMultiWordList(string line, string word)
{
word = word.Trim();
if (word.Length > 1)
{
var localNamesEtc = new List<string>();
string userNamesEtcXmlFileName = LoadLocalNamesEtc(localNamesEtc, localNamesEtc, languageName);
if (localNamesEtc.Contains(word))
return false;
localNamesEtc.Add(word);
localNamesEtc.Sort();
var namesEtcDoc = new XmlDocument();
if (File.Exists(userNamesEtcXmlFileName))
namesEtcDoc.Load(userNamesEtcXmlFileName);
else
namesEtcDoc.LoadXml("<ignore_words />");
XmlNode de = namesEtcDoc.DocumentElement;
if (de != null)
{
de.RemoveAll();
foreach (var name in localNamesEtc)
{
XmlNode node = namesEtcDoc.CreateElement("name");
node.InnerText = name;
de.AppendChild(node);
}
namesEtcDoc.Save(userNamesEtcXmlFileName);
}
return true;
}
return false;
}
public static string LoadNamesEtcWordLists(List<string> namesEtcList, List<string> namesEtcMultiWordList, string languageName)
{
namesEtcList.Clear();
namesEtcMultiWordList.Clear();
LoadGlobalNamesEtc(namesEtcList, namesEtcMultiWordList);
string userNamesEtcXmlFileName = LoadLocalNamesEtc(namesEtcList, namesEtcMultiWordList, languageName);
return userNamesEtcXmlFileName;
}
public static string LoadNamesEtcWordLists(HashSet<string> namesEtcList, HashSet<string> namesEtcMultiWordList, string languageName)
{
namesEtcList.Clear();
namesEtcMultiWordList.Clear();
LoadGlobalNamesEtc(namesEtcList, namesEtcMultiWordList);
string userNamesEtcXmlFileName = LoadLocalNamesEtc(namesEtcList, namesEtcMultiWordList, languageName);
return userNamesEtcXmlFileName;
}
public static void LoadGlobalNamesEtc(List<string> namesEtcList, List<string> namesEtcMultiWordList)
{
// Load names etc list (names/noise words)
var namesEtcDoc = new XmlDocument();
bool loaded = false;
if (Configuration.Settings.WordLists.UseOnlineNamesEtc && !string.IsNullOrEmpty(Configuration.Settings.WordLists.NamesEtcUrl))
{
try
{
var xml = Utilities.DownloadString(Configuration.Settings.WordLists.NamesEtcUrl);
namesEtcDoc.LoadXml(xml);
loaded = true;
}
catch (Exception exception)
{
MessageBox.Show(exception.Message + Environment.NewLine + exception.StackTrace);
}
}
if (!loaded && File.Exists(Utilities.DictionaryFolder + "names_etc.xml"))
{
namesEtcDoc.Load(Utilities.DictionaryFolder + "names_etc.xml");
}
if (namesEtcDoc.DocumentElement != null)
foreach (XmlNode node in namesEtcDoc.DocumentElement.SelectNodes("name"))
{
string s = node.InnerText.Trim();
if (s.Contains(' '))
{
if (!namesEtcMultiWordList.Contains(s))
namesEtcMultiWordList.Add(s);
}
else
{
if (!namesEtcList.Contains(s))
namesEtcList.Add(s);
}
}
}
public static void LoadGlobalNamesEtc(HashSet<string> namesEtcList, HashSet<string> namesEtcMultiWordList)
{
// Load names etc list (names/noise words)
var namesEtcDoc = new XmlDocument();
bool loaded = false;
if (Configuration.Settings.WordLists.UseOnlineNamesEtc && !string.IsNullOrEmpty(Configuration.Settings.WordLists.NamesEtcUrl))
{
try
{
var xml = Utilities.DownloadString(Configuration.Settings.WordLists.NamesEtcUrl);
namesEtcDoc.LoadXml(xml);
loaded = true;
}
catch (Exception exception)
{
MessageBox.Show(exception.Message + Environment.NewLine + exception.StackTrace);
}
}
if (!loaded && File.Exists(Utilities.DictionaryFolder + "names_etc.xml"))
{
namesEtcDoc.Load(Utilities.DictionaryFolder + "names_etc.xml");
}
if (namesEtcDoc.DocumentElement != null)
foreach (XmlNode node in namesEtcDoc.DocumentElement.SelectNodes("name"))
{
string s = node.InnerText.Trim();
if (s.Contains(' '))
{
if (!namesEtcMultiWordList.Contains(s))
namesEtcMultiWordList.Add(s);
}
else
{
if (!namesEtcList.Contains(s))
namesEtcList.Add(s);
}
}
}
public static string LoadLocalNamesEtc(List<string> namesEtcList, List<string> namesEtcMultiWordList, string languageName)
{
string userNamesEtcXmlFileName = Utilities.DictionaryFolder + languageName + "_names_etc.xml";
if (languageName.Length == 2)
{
string[] files = Directory.GetFiles(Utilities.DictionaryFolder, languageName + "_??_names_etc.xml");
if (files.Length > 0)
userNamesEtcXmlFileName = files[0];
}
if (File.Exists(userNamesEtcXmlFileName))
{
var namesEtcDoc = new XmlDocument();
namesEtcDoc.Load(userNamesEtcXmlFileName);
foreach (XmlNode node in namesEtcDoc.DocumentElement.SelectNodes("name"))
{
string s = node.InnerText.Trim();
if (s.Contains(' '))
{
if (!namesEtcMultiWordList.Contains(s))
namesEtcMultiWordList.Add(s);
}
else
{
if (!namesEtcList.Contains(s))
namesEtcList.Add(s);
}
}
}
return userNamesEtcXmlFileName;
}
public static string LoadLocalNamesEtc(HashSet<string> namesEtcList, HashSet<string> namesEtcMultiWordList, string languageName)
{
string userNamesEtcXmlFileName = Utilities.DictionaryFolder + languageName + "_names_etc.xml";
if (languageName.Length == 2)
{
string[] files = Directory.GetFiles(Utilities.DictionaryFolder, languageName + "_??_names_etc.xml");
if (files.Length > 0)
userNamesEtcXmlFileName = files[0];
}
if (File.Exists(userNamesEtcXmlFileName))
{
var namesEtcDoc = new XmlDocument();
namesEtcDoc.Load(userNamesEtcXmlFileName);
foreach (XmlNode node in namesEtcDoc.DocumentElement.SelectNodes("name"))
{
string s = node.InnerText.Trim();
if (s.Contains(' '))
{
if (!namesEtcMultiWordList.Contains(s))
namesEtcMultiWordList.Add(s);
}
else
{
if (!namesEtcList.Contains(s))
namesEtcList.Add(s);
}
}
}
return userNamesEtcXmlFileName;
}
public static bool IsInNamesEtcMultiWordList(List<string> namesEtcMultiWordList, string line, string word)
{ {
string text = line.Replace(Environment.NewLine, " "); string text = line.Replace(Environment.NewLine, " ");
text = text.Replace(" ", " "); text = text.Replace(" ", " ");
foreach (string s in namesEtcMultiWordList) foreach (string s in _namesMultiList)
{
if (s.Contains(word) && text.Contains(s))
{
if (s.StartsWith(word + " ", StringComparison.Ordinal) || s.EndsWith(" " + word, StringComparison.Ordinal) || s.Contains(" " + word + " "))
return true;
if (word == s)
return true;
}
}
return false;
}
public static bool IsInNamesEtcMultiWordList(HashSet<string> namesEtcMultiWordList, string line, string word)
{
string text = line.Replace(Environment.NewLine, " ");
text = text.Replace(" ", " ");
foreach (string s in namesEtcMultiWordList)
{ {
if (s.Contains(word) && text.Contains(s)) if (s.Contains(word) && text.Contains(s))
{ {

View File

@ -26,6 +26,7 @@ namespace Nikse.SubtitleEdit.Logic.Ocr
private string _fiveLetterWordListLanguageName; private string _fiveLetterWordListLanguageName;
private readonly OcrFixReplaceList _ocrFixReplaceList; private readonly OcrFixReplaceList _ocrFixReplaceList;
private NamesList _namesList;
private HashSet<string> _namesEtcList = new HashSet<string>(); private HashSet<string> _namesEtcList = new HashSet<string>();
private HashSet<string> _namesEtcListUppercase = new HashSet<string>(); private HashSet<string> _namesEtcListUppercase = new HashSet<string>();
private HashSet<string> _namesEtcListWithApostrophe = new HashSet<string>(); private HashSet<string> _namesEtcListWithApostrophe = new HashSet<string>();
@ -89,22 +90,22 @@ namespace Nikse.SubtitleEdit.Logic.Ocr
LoadSpellingDictionariesViaDictionaryFileName("eng", new CultureInfo("en-GB"), "en_GB.dic", true); LoadSpellingDictionariesViaDictionaryFileName("eng", new CultureInfo("en-GB"), "en_GB.dic", true);
return; return;
} }
else if (!string.IsNullOrEmpty(hunspellName) && threeLetterIsoLanguageName == "eng" && hunspellName.Equals("en_ca", StringComparison.OrdinalIgnoreCase) && File.Exists(Path.Combine(dictionaryFolder, "en_CA.dic"))) if (!string.IsNullOrEmpty(hunspellName) && threeLetterIsoLanguageName == "eng" && hunspellName.Equals("en_ca", StringComparison.OrdinalIgnoreCase) && File.Exists(Path.Combine(dictionaryFolder, "en_CA.dic")))
{ {
LoadSpellingDictionariesViaDictionaryFileName("eng", new CultureInfo("en-CA"), "en_CA.dic", true); LoadSpellingDictionariesViaDictionaryFileName("eng", new CultureInfo("en-CA"), "en_CA.dic", true);
return; return;
} }
else if (!string.IsNullOrEmpty(hunspellName) && threeLetterIsoLanguageName == "eng" && hunspellName.Equals("en_au", StringComparison.OrdinalIgnoreCase) && File.Exists(Path.Combine(dictionaryFolder, "en_AU.dic"))) if (!string.IsNullOrEmpty(hunspellName) && threeLetterIsoLanguageName == "eng" && hunspellName.Equals("en_au", StringComparison.OrdinalIgnoreCase) && File.Exists(Path.Combine(dictionaryFolder, "en_AU.dic")))
{ {
LoadSpellingDictionariesViaDictionaryFileName("eng", new CultureInfo("en-AU"), "en_AU.dic", true); LoadSpellingDictionariesViaDictionaryFileName("eng", new CultureInfo("en-AU"), "en_AU.dic", true);
return; return;
} }
else if (!string.IsNullOrEmpty(hunspellName) && threeLetterIsoLanguageName == "eng" && hunspellName.Equals("en_za", StringComparison.OrdinalIgnoreCase) && File.Exists(Path.Combine(dictionaryFolder, "en_ZA.dic"))) if (!string.IsNullOrEmpty(hunspellName) && threeLetterIsoLanguageName == "eng" && hunspellName.Equals("en_za", StringComparison.OrdinalIgnoreCase) && File.Exists(Path.Combine(dictionaryFolder, "en_ZA.dic")))
{ {
LoadSpellingDictionariesViaDictionaryFileName("eng", new CultureInfo("en-ZA"), "en_ZA.dic", true); LoadSpellingDictionariesViaDictionaryFileName("eng", new CultureInfo("en-ZA"), "en_ZA.dic", true);
return; return;
} }
else if (threeLetterIsoLanguageName == "eng" && File.Exists(Path.Combine(dictionaryFolder, "en_US.dic"))) if (threeLetterIsoLanguageName == "eng" && File.Exists(Path.Combine(dictionaryFolder, "en_US.dic")))
{ {
LoadSpellingDictionariesViaDictionaryFileName("eng", new CultureInfo("en-US"), "en_US.dic", true); LoadSpellingDictionariesViaDictionaryFileName("eng", new CultureInfo("en-US"), "en_US.dic", true);
return; return;
@ -199,10 +200,9 @@ namespace Nikse.SubtitleEdit.Logic.Ocr
} }
// Load names etc list (names/noise words) // Load names etc list (names/noise words)
_namesEtcList = new HashSet<string>(); _namesList = new NamesList(Configuration.DictionariesFolder, _fiveLetterWordListLanguageName, Configuration.Settings.WordLists.UseOnlineNamesEtc, Configuration.Settings.WordLists.NamesEtcUrl);
_namesEtcMultiWordList = new HashSet<string>(); _namesEtcList = _namesList.GetNames();
NamesList.LoadNamesEtcWordLists(_namesEtcList, _namesEtcMultiWordList, _fiveLetterWordListLanguageName); _namesEtcMultiWordList = _namesList.GetMultiNames();
_namesEtcListUppercase = new HashSet<string>(); _namesEtcListUppercase = new HashSet<string>();
foreach (string name in _namesEtcList) foreach (string name in _namesEtcList)
_namesEtcListUppercase.Add(name.ToUpper()); _namesEtcListUppercase.Add(name.ToUpper());
@ -1237,7 +1237,8 @@ namespace Nikse.SubtitleEdit.Logic.Ocr
} }
} }
NamesList.AddWordToLocalNamesEtcList(s, _fiveLetterWordListLanguageName); if (_namesList != null)
_namesList.Add(s, _fiveLetterWordListLanguageName);
} }
catch catch
{ {
@ -1387,7 +1388,7 @@ namespace Nikse.SubtitleEdit.Logic.Ocr
if (word.Length > 2 && _namesEtcListWithApostrophe.Contains(word)) if (word.Length > 2 && _namesEtcListWithApostrophe.Contains(word))
return true; return true;
if (NamesList.IsInNamesEtcMultiWordList(_namesEtcMultiWordList, line, word)) if (_namesList != null && _namesList.IsInNamesEtcMultiWordList(line, word))
return true; return true;
return false; return false;

View File

@ -22,19 +22,19 @@ namespace Test
///</summary> ///</summary>
public TestContext TestContext { get; set; } public TestContext TestContext { get; set; }
private static Nikse.SubtitleEdit.Forms.FixCommonErrors GetFixCommonErrorsLib() private static FixCommonErrors GetFixCommonErrorsLib()
{ {
return new Nikse.SubtitleEdit.Forms.FixCommonErrors(); return new FixCommonErrors();
} }
private static void InitializeFixCommonErrorsLine(Nikse.SubtitleEdit.Forms.FixCommonErrors target, string line) private static void InitializeFixCommonErrorsLine(FixCommonErrors target, string line)
{ {
var subtitle = new Subtitle(); var subtitle = new Subtitle();
subtitle.Paragraphs.Add(new Paragraph(line, 100, 10000)); subtitle.Paragraphs.Add(new Paragraph(line, 100, 10000));
target.Initialize(subtitle, new SubRip(), System.Text.Encoding.UTF8); target.Initialize(subtitle, new SubRip(), System.Text.Encoding.UTF8);
} }
private static void InitializeFixCommonErrorsLine(Nikse.SubtitleEdit.Forms.FixCommonErrors target, string line, string line2) private static void InitializeFixCommonErrorsLine(FixCommonErrors target, string line, string line2)
{ {
var subtitle = new Subtitle(); var subtitle = new Subtitle();
subtitle.Paragraphs.Add(new Paragraph(line, 100, 10000)); subtitle.Paragraphs.Add(new Paragraph(line, 100, 10000));
@ -53,7 +53,7 @@ namespace Test
/// </summary> /// </summary>
public static void CopyStream(Stream input, Stream output) public static void CopyStream(Stream input, Stream output)
{ {
byte[] buffer = new byte[8 * 1024]; var buffer = new byte[8 * 1024];
int len; int len;
while ((len = input.Read(buffer, 0, buffer.Length)) > 0) while ((len = input.Read(buffer, 0, buffer.Length)) > 0)
{ {
@ -62,7 +62,7 @@ namespace Test
} }
//Use ClassInitialize to run code before running the first test in the class //Use ClassInitialize to run code before running the first test in the class
[ClassInitialize()] [ClassInitialize]
public static void MyClassInitialize(TestContext testContext) public static void MyClassInitialize(TestContext testContext)
{ {
System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly(); System.Reflection.Assembly asm = System.Reflection.Assembly.GetExecutingAssembly();
@ -129,7 +129,7 @@ namespace Test
{ {
InitializeFixCommonErrorsLine(target, "This is" + Environment.NewLine + "short!"); InitializeFixCommonErrorsLine(target, "This is" + Environment.NewLine + "short!");
target.FixShortLines(); target.FixShortLines();
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "This is short!"); Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "This is short!");
} }
} }
@ -141,7 +141,7 @@ namespace Test
{ {
InitializeFixCommonErrorsLine(target, "This I'm pretty sure is not a" + Environment.NewLine + "short line, that should be merged!!!"); InitializeFixCommonErrorsLine(target, "This I'm pretty sure is not a" + Environment.NewLine + "short line, that should be merged!!!");
target.FixShortLines(); target.FixShortLines();
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "This I'm pretty sure is not a" + Environment.NewLine + "short line, that should be merged!!!"); Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "This I'm pretty sure is not a" + Environment.NewLine + "short line, that should be merged!!!");
} }
} }
@ -153,7 +153,7 @@ namespace Test
{ {
InitializeFixCommonErrorsLine(target, "<i>This is" + Environment.NewLine + "short!</i>"); InitializeFixCommonErrorsLine(target, "<i>This is" + Environment.NewLine + "short!</i>");
target.FixShortLines(); target.FixShortLines();
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "<i>This is short!</i>"); Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "<i>This is short!</i>");
} }
} }
@ -165,7 +165,7 @@ namespace Test
{ {
InitializeFixCommonErrorsLine(target, "- Hallo!" + Environment.NewLine + "- Hi"); InitializeFixCommonErrorsLine(target, "- Hallo!" + Environment.NewLine + "- Hi");
target.FixShortLines(); target.FixShortLines();
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "- Hallo!" + Environment.NewLine + "- Hi"); Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "- Hallo!" + Environment.NewLine + "- Hi");
} }
} }
@ -177,7 +177,7 @@ namespace Test
{ {
InitializeFixCommonErrorsLine(target, "<i>- Hallo!" + Environment.NewLine + "- Hi</i>"); InitializeFixCommonErrorsLine(target, "<i>- Hallo!" + Environment.NewLine + "- Hi</i>");
target.FixShortLines(); target.FixShortLines();
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "<i>- Hallo!" + Environment.NewLine + "- Hi</i>"); Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "<i>- Hallo!" + Environment.NewLine + "- Hi</i>");
} }
} }
@ -192,7 +192,7 @@ namespace Test
{ {
InitializeFixCommonErrorsLine(target, "<i>- Hallo!</i>" + Environment.NewLine + "<i>- Hi<i>"); InitializeFixCommonErrorsLine(target, "<i>- Hallo!</i>" + Environment.NewLine + "<i>- Hi<i>");
target.FixShortLines(); target.FixShortLines();
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "<i>- Hallo!</i>" + Environment.NewLine + "<i>- Hi<i>"); Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "<i>- Hallo!</i>" + Environment.NewLine + "<i>- Hi<i>");
} }
} }
@ -208,7 +208,7 @@ namespace Test
{ {
InitializeFixCommonErrorsLine(target, "<i>Hey!" + Environment.NewLine + "<i>Boy!"); InitializeFixCommonErrorsLine(target, "<i>Hey!" + Environment.NewLine + "<i>Boy!");
target.FixInvalidItalicTags(); target.FixInvalidItalicTags();
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "<i>Hey!</i>" + Environment.NewLine + "<i>Boy!</i>"); Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "<i>Hey!</i>" + Environment.NewLine + "<i>Boy!</i>");
} }
} }
@ -220,7 +220,7 @@ namespace Test
{ {
InitializeFixCommonErrorsLine(target, "<i>(jones) seems their attackers headed north." + Environment.NewLine + "<i>Hi!</i>"); InitializeFixCommonErrorsLine(target, "<i>(jones) seems their attackers headed north." + Environment.NewLine + "<i>Hi!</i>");
target.FixInvalidItalicTags(); target.FixInvalidItalicTags();
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "<i>(jones) seems their attackers headed north." + Environment.NewLine + "Hi!</i>"); Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "<i>(jones) seems their attackers headed north." + Environment.NewLine + "Hi!</i>");
} }
} }
@ -232,7 +232,7 @@ namespace Test
{ {
InitializeFixCommonErrorsLine(target, "Seems their <i>attackers headed north."); InitializeFixCommonErrorsLine(target, "Seems their <i>attackers headed north.");
target.FixInvalidItalicTags(); target.FixInvalidItalicTags();
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "Seems their attackers headed north."); Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "Seems their attackers headed north.");
} }
} }
@ -244,7 +244,7 @@ namespace Test
{ {
InitializeFixCommonErrorsLine(target, "<i></i>test"); InitializeFixCommonErrorsLine(target, "<i></i>test");
target.FixInvalidItalicTags(); target.FixInvalidItalicTags();
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "test"); Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "test");
} }
} }
@ -256,7 +256,7 @@ namespace Test
{ {
InitializeFixCommonErrorsLine(target, "- And..." + Environment.NewLine + "<i>Awesome it is!"); InitializeFixCommonErrorsLine(target, "- And..." + Environment.NewLine + "<i>Awesome it is!");
target.FixInvalidItalicTags(); target.FixInvalidItalicTags();
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "- And..." + Environment.NewLine + "<i>Awesome it is!</i>"); Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "- And..." + Environment.NewLine + "<i>Awesome it is!</i>");
} }
} }
@ -268,7 +268,7 @@ namespace Test
{ {
InitializeFixCommonErrorsLine(target, "Awesome it is!</i>"); InitializeFixCommonErrorsLine(target, "Awesome it is!</i>");
target.FixInvalidItalicTags(); target.FixInvalidItalicTags();
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "<i>Awesome it is!</i>"); Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "<i>Awesome it is!</i>");
} }
} }
@ -280,7 +280,7 @@ namespace Test
{ {
InitializeFixCommonErrorsLine(target, "Awesome it is!<i></i>"); InitializeFixCommonErrorsLine(target, "Awesome it is!<i></i>");
target.FixInvalidItalicTags(); target.FixInvalidItalicTags();
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "Awesome it is!"); Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "Awesome it is!");
} }
} }
@ -292,7 +292,7 @@ namespace Test
{ {
InitializeFixCommonErrorsLine(target, "Awesome it is!<i>"); InitializeFixCommonErrorsLine(target, "Awesome it is!<i>");
target.FixInvalidItalicTags(); target.FixInvalidItalicTags();
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "Awesome it is!"); Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "Awesome it is!");
} }
} }
@ -304,7 +304,7 @@ namespace Test
{ {
InitializeFixCommonErrorsLine(target, "Awesome it is!</i><i>"); InitializeFixCommonErrorsLine(target, "Awesome it is!</i><i>");
target.FixInvalidItalicTags(); target.FixInvalidItalicTags();
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "Awesome it is!"); Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "Awesome it is!");
} }
} }
@ -316,7 +316,7 @@ namespace Test
{ {
InitializeFixCommonErrorsLine(target, "</i>What do i care.</i>"); InitializeFixCommonErrorsLine(target, "</i>What do i care.</i>");
target.FixInvalidItalicTags(); target.FixInvalidItalicTags();
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "<i>What do i care.</i>"); Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "<i>What do i care.</i>");
} }
} }
@ -328,7 +328,7 @@ namespace Test
{ {
InitializeFixCommonErrorsLine(target, "<i>To be a life-changing weekend</i>" + Environment.NewLine + "<i>for all of us."); InitializeFixCommonErrorsLine(target, "<i>To be a life-changing weekend</i>" + Environment.NewLine + "<i>for all of us.");
target.FixInvalidItalicTags(); target.FixInvalidItalicTags();
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "<i>To be a life-changing weekend" + Environment.NewLine + "for all of us.</i>"); Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "<i>To be a life-changing weekend" + Environment.NewLine + "for all of us.</i>");
} }
} }
@ -344,7 +344,7 @@ namespace Test
{ {
InitializeFixCommonErrorsLine(target, "This is line one!" + Environment.NewLine + "<i>Boy!</i>", "This is line one!" + Environment.NewLine + "<i>Boy!</i>"); InitializeFixCommonErrorsLine(target, "This is line one!" + Environment.NewLine + "<i>Boy!</i>", "This is line one!" + Environment.NewLine + "<i>Boy!</i>");
target.FixMissingPeriodsAtEndOfLine(); target.FixMissingPeriodsAtEndOfLine();
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "This is line one!" + Environment.NewLine + "<i>Boy!</i>"); Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "This is line one!" + Environment.NewLine + "<i>Boy!</i>");
} }
} }
@ -356,7 +356,7 @@ namespace Test
{ {
InitializeFixCommonErrorsLine(target, "This is line one!" + Environment.NewLine + "<i>Boy</i>", "This is line one!" + Environment.NewLine + "<i>Boy!</i>"); InitializeFixCommonErrorsLine(target, "This is line one!" + Environment.NewLine + "<i>Boy</i>", "This is line one!" + Environment.NewLine + "<i>Boy!</i>");
target.FixMissingPeriodsAtEndOfLine(); target.FixMissingPeriodsAtEndOfLine();
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "This is line one!" + Environment.NewLine + "<i>Boy.</i>"); Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "This is line one!" + Environment.NewLine + "<i>Boy.</i>");
} }
} }
@ -368,7 +368,7 @@ namespace Test
{ {
InitializeFixCommonErrorsLine(target, "<i>This is line one!" + Environment.NewLine + "Boy</i>", "This is line one!" + Environment.NewLine + "<i>Boy!</i>"); InitializeFixCommonErrorsLine(target, "<i>This is line one!" + Environment.NewLine + "Boy</i>", "This is line one!" + Environment.NewLine + "<i>Boy!</i>");
target.FixMissingPeriodsAtEndOfLine(); target.FixMissingPeriodsAtEndOfLine();
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "<i>This is line one!" + Environment.NewLine + "Boy.</i>"); Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "<i>This is line one!" + Environment.NewLine + "Boy.</i>");
} }
} }
@ -380,7 +380,7 @@ namespace Test
{ {
InitializeFixCommonErrorsLine(target, "”... and gently down I laid her. ”"); InitializeFixCommonErrorsLine(target, "”... and gently down I laid her. ”");
target.FixMissingPeriodsAtEndOfLine(); target.FixMissingPeriodsAtEndOfLine();
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "”... and gently down I laid her. ”"); Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "”... and gently down I laid her. ”");
} }
} }
@ -396,7 +396,7 @@ namespace Test
{ {
InitializeFixCommonErrorsLine(target, "Hi Joe!" + Environment.NewLine + "- Hi Pete!"); InitializeFixCommonErrorsLine(target, "Hi Joe!" + Environment.NewLine + "- Hi Pete!");
target.FixHyphensAdd(); target.FixHyphensAdd();
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "- Hi Joe!" + Environment.NewLine + "- Hi Pete!"); Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "- Hi Joe!" + Environment.NewLine + "- Hi Pete!");
} }
} }
@ -408,7 +408,7 @@ namespace Test
{ {
InitializeFixCommonErrorsLine(target, "- Hi Joe!" + Environment.NewLine + "Hi Pete!"); InitializeFixCommonErrorsLine(target, "- Hi Joe!" + Environment.NewLine + "Hi Pete!");
target.FixHyphensAdd(); target.FixHyphensAdd();
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "- Hi Joe!" + Environment.NewLine + "- Hi Pete!"); Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "- Hi Joe!" + Environment.NewLine + "- Hi Pete!");
} }
} }
@ -420,7 +420,7 @@ namespace Test
{ {
InitializeFixCommonErrorsLine(target, "<i>- Hi Joe!" + Environment.NewLine + "Hi Pete!</i>"); InitializeFixCommonErrorsLine(target, "<i>- Hi Joe!" + Environment.NewLine + "Hi Pete!</i>");
target.FixHyphensAdd(); target.FixHyphensAdd();
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "<i>- Hi Joe!" + Environment.NewLine + "- Hi Pete!</i>"); Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "<i>- Hi Joe!" + Environment.NewLine + "- Hi Pete!</i>");
} }
} }
@ -432,7 +432,7 @@ namespace Test
{ {
InitializeFixCommonErrorsLine(target, "- Hi Joe!" + Environment.NewLine + "- Hi Pete!"); InitializeFixCommonErrorsLine(target, "- Hi Joe!" + Environment.NewLine + "- Hi Pete!");
target.FixHyphensAdd(); target.FixHyphensAdd();
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "- Hi Joe!" + Environment.NewLine + "- Hi Pete!"); Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "- Hi Joe!" + Environment.NewLine + "- Hi Pete!");
} }
} }
@ -444,7 +444,7 @@ namespace Test
{ {
InitializeFixCommonErrorsLine(target, "- Hi!" + Environment.NewLine + "- Hi Pete!"); InitializeFixCommonErrorsLine(target, "- Hi!" + Environment.NewLine + "- Hi Pete!");
target.FixHyphensAdd(); target.FixHyphensAdd();
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "- Hi!" + Environment.NewLine + "- Hi Pete!"); Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "- Hi!" + Environment.NewLine + "- Hi Pete!");
} }
} }
@ -456,7 +456,7 @@ namespace Test
{ {
InitializeFixCommonErrorsLine(target, "Five-Both?" + Environment.NewLine + "- T... T... Ten..."); InitializeFixCommonErrorsLine(target, "Five-Both?" + Environment.NewLine + "- T... T... Ten...");
target.FixHyphensAdd(); target.FixHyphensAdd();
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "- Five-Both?" + Environment.NewLine + "- T... T... Ten..."); Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "- Five-Both?" + Environment.NewLine + "- T... T... Ten...");
} }
} }
@ -472,7 +472,7 @@ namespace Test
{ {
InitializeFixCommonErrorsLine(target, "(laughing/clapping)"); InitializeFixCommonErrorsLine(target, "(laughing/clapping)");
target.FixOcrErrorsViaReplaceList("eng"); target.FixOcrErrorsViaReplaceList("eng");
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "(laughing/clapping)"); Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "(laughing/clapping)");
} }
} }
@ -484,7 +484,7 @@ namespace Test
{ {
InitializeFixCommonErrorsLine(target, "The font is ita/ic!"); InitializeFixCommonErrorsLine(target, "The font is ita/ic!");
target.FixOcrErrorsViaReplaceList("eng"); target.FixOcrErrorsViaReplaceList("eng");
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "The font is italic!"); // will fail if English dictionary is not found Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "The font is italic!"); // will fail if English dictionary is not found
} }
} }
@ -496,7 +496,7 @@ namespace Test
{ {
InitializeFixCommonErrorsLine(target, "The clock is 12 a.m."); InitializeFixCommonErrorsLine(target, "The clock is 12 a.m.");
target.FixOcrErrorsViaReplaceList("eng"); target.FixOcrErrorsViaReplaceList("eng");
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "The clock is 12 a.m."); Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "The clock is 12 a.m.");
} }
} }
@ -508,7 +508,7 @@ namespace Test
{ {
InitializeFixCommonErrorsLine(target, "- I'll ring her." + Environment.NewLine + "- ...in a lot of trouble."); InitializeFixCommonErrorsLine(target, "- I'll ring her." + Environment.NewLine + "- ...in a lot of trouble.");
target.FixOcrErrorsViaReplaceList("eng"); target.FixOcrErrorsViaReplaceList("eng");
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "- I'll ring her." + Environment.NewLine + "- ...in a lot of trouble."); Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "- I'll ring her." + Environment.NewLine + "- ...in a lot of trouble.");
} }
} }
@ -524,7 +524,7 @@ namespace Test
{ {
InitializeFixCommonErrorsLine(target, "The<i>Bombshell</i> will gone."); InitializeFixCommonErrorsLine(target, "The<i>Bombshell</i> will gone.");
target.FixMissingSpaces(); target.FixMissingSpaces();
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "The <i>Bombshell</i> will gone."); Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "The <i>Bombshell</i> will gone.");
} }
} }
@ -536,7 +536,7 @@ namespace Test
{ {
InitializeFixCommonErrorsLine(target, "The <i>Bombshell</i>will gone."); InitializeFixCommonErrorsLine(target, "The <i>Bombshell</i>will gone.");
target.FixMissingSpaces(); target.FixMissingSpaces();
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "The <i>Bombshell</i> will gone."); Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "The <i>Bombshell</i> will gone.");
} }
} }
@ -548,7 +548,7 @@ namespace Test
{ {
InitializeFixCommonErrorsLine(target, "It will be okay.It surely will be!"); InitializeFixCommonErrorsLine(target, "It will be okay.It surely will be!");
target.FixMissingSpaces(); target.FixMissingSpaces();
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "It will be okay. It surely will be!"); Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "It will be okay. It surely will be!");
} }
} }
@ -560,7 +560,7 @@ namespace Test
{ {
InitializeFixCommonErrorsLine(target, "you can't get out.Alright?"); InitializeFixCommonErrorsLine(target, "you can't get out.Alright?");
target.FixMissingSpaces(); target.FixMissingSpaces();
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "you can't get out. Alright?"); Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "you can't get out. Alright?");
} }
} }
@ -572,7 +572,7 @@ namespace Test
{ {
InitializeFixCommonErrorsLine(target, "What did Dr. Gey say?"); InitializeFixCommonErrorsLine(target, "What did Dr. Gey say?");
target.FixMissingSpaces(); target.FixMissingSpaces();
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "What did Dr. Gey say?"); Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "What did Dr. Gey say?");
} }
} }
@ -584,7 +584,7 @@ namespace Test
{ {
InitializeFixCommonErrorsLine(target, "Go to the O.R. now!"); InitializeFixCommonErrorsLine(target, "Go to the O.R. now!");
target.FixMissingSpaces(); target.FixMissingSpaces();
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "Go to the O.R. now!"); Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "Go to the O.R. now!");
} }
} }
@ -596,7 +596,7 @@ namespace Test
{ {
InitializeFixCommonErrorsLine(target, "Email niksedk@gmail.Com now!"); InitializeFixCommonErrorsLine(target, "Email niksedk@gmail.Com now!");
target.FixMissingSpaces(); target.FixMissingSpaces();
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "Email niksedk@gmail.Com now!"); Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "Email niksedk@gmail.Com now!");
} }
} }
@ -608,7 +608,7 @@ namespace Test
{ {
InitializeFixCommonErrorsLine(target, "Go to www.nikse.dk for more info"); InitializeFixCommonErrorsLine(target, "Go to www.nikse.dk for more info");
target.FixMissingSpaces(); target.FixMissingSpaces();
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "Go to www.nikse.dk for more info"); Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "Go to www.nikse.dk for more info");
} }
} }
@ -624,7 +624,7 @@ namespace Test
{ {
InitializeFixCommonErrorsLine(target, "♪ you like to move it..."); InitializeFixCommonErrorsLine(target, "♪ you like to move it...");
target.FixStartWithUppercaseLetterAfterParagraph(); target.FixStartWithUppercaseLetterAfterParagraph();
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "♪ You like to move it..."); Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "♪ You like to move it...");
} }
} }
@ -632,8 +632,8 @@ namespace Test
[DeploymentItem("SubtitleEdit.exe")] [DeploymentItem("SubtitleEdit.exe")]
public void StartWithUppercaseAfterParagraphNormal1() public void StartWithUppercaseAfterParagraphNormal1()
{ {
Paragraph prev = new Paragraph("Bye.", 0, 1000); var prev = new Paragraph("Bye.", 0, 1000);
Paragraph p = new Paragraph("bye.", 1200, 5000); var p = new Paragraph("bye.", 1200, 5000);
var fixedText = FixCommonErrors.FixStartWithUppercaseLetterAfterParagraph(p, prev, System.Text.Encoding.UTF8, "en"); var fixedText = FixCommonErrors.FixStartWithUppercaseLetterAfterParagraph(p, prev, System.Text.Encoding.UTF8, "en");
Assert.AreEqual(fixedText, "Bye."); Assert.AreEqual(fixedText, "Bye.");
} }
@ -642,8 +642,8 @@ namespace Test
[DeploymentItem("SubtitleEdit.exe")] [DeploymentItem("SubtitleEdit.exe")]
public void StartWithUppercaseAfterParagraphNormal2() public void StartWithUppercaseAfterParagraphNormal2()
{ {
Paragraph prev = new Paragraph("Bye.", 0, 1000); var prev = new Paragraph("Bye.", 0, 1000);
Paragraph p = new Paragraph("<i>bye.</i>", 1200, 5000); var p = new Paragraph("<i>bye.</i>", 1200, 5000);
var fixedText = FixCommonErrors.FixStartWithUppercaseLetterAfterParagraph(p, prev, System.Text.Encoding.UTF8, "en"); var fixedText = FixCommonErrors.FixStartWithUppercaseLetterAfterParagraph(p, prev, System.Text.Encoding.UTF8, "en");
Assert.AreEqual(fixedText, "<i>Bye.</i>"); Assert.AreEqual(fixedText, "<i>Bye.</i>");
} }
@ -652,8 +652,8 @@ namespace Test
[DeploymentItem("SubtitleEdit.exe")] [DeploymentItem("SubtitleEdit.exe")]
public void StartWithUppercaseAfterParagraphNormal3() public void StartWithUppercaseAfterParagraphNormal3()
{ {
Paragraph prev = new Paragraph("<i>Bye.</i>", 0, 1000); var prev = new Paragraph("<i>Bye.</i>", 0, 1000);
Paragraph p = new Paragraph("<i>bye.</i>", 1200, 5000); var p = new Paragraph("<i>bye.</i>", 1200, 5000);
var fixedText = FixCommonErrors.FixStartWithUppercaseLetterAfterParagraph(p, prev, System.Text.Encoding.UTF8, "en"); var fixedText = FixCommonErrors.FixStartWithUppercaseLetterAfterParagraph(p, prev, System.Text.Encoding.UTF8, "en");
Assert.AreEqual(fixedText, "<i>Bye.</i>"); Assert.AreEqual(fixedText, "<i>Bye.</i>");
} }
@ -662,8 +662,8 @@ namespace Test
[DeploymentItem("SubtitleEdit.exe")] [DeploymentItem("SubtitleEdit.exe")]
public void StartWithUppercaseAfterParagraphNormal4() public void StartWithUppercaseAfterParagraphNormal4()
{ {
Paragraph prev = new Paragraph("Bye.", 0, 1000); var prev = new Paragraph("Bye.", 0, 1000);
Paragraph p = new Paragraph("bye." + Environment.NewLine + "bye.", 1200, 5000); var p = new Paragraph("bye." + Environment.NewLine + "bye.", 1200, 5000);
var fixedText = FixCommonErrors.FixStartWithUppercaseLetterAfterParagraph(p, prev, System.Text.Encoding.UTF8, "en"); var fixedText = FixCommonErrors.FixStartWithUppercaseLetterAfterParagraph(p, prev, System.Text.Encoding.UTF8, "en");
Assert.AreEqual(fixedText, "Bye." + Environment.NewLine + "Bye."); Assert.AreEqual(fixedText, "Bye." + Environment.NewLine + "Bye.");
} }
@ -672,8 +672,8 @@ namespace Test
[DeploymentItem("SubtitleEdit.exe")] [DeploymentItem("SubtitleEdit.exe")]
public void StartWithUppercaseAfterParagraphNormalNoChange1() public void StartWithUppercaseAfterParagraphNormalNoChange1()
{ {
Paragraph prev = new Paragraph("Bye,", 0, 1000); var prev = new Paragraph("Bye,", 0, 1000);
Paragraph p = new Paragraph("bye.", 1200, 5000); var p = new Paragraph("bye.", 1200, 5000);
var fixedText = FixCommonErrors.FixStartWithUppercaseLetterAfterParagraph(p, prev, System.Text.Encoding.UTF8, "en"); var fixedText = FixCommonErrors.FixStartWithUppercaseLetterAfterParagraph(p, prev, System.Text.Encoding.UTF8, "en");
Assert.AreEqual(fixedText, "bye."); Assert.AreEqual(fixedText, "bye.");
} }
@ -682,8 +682,8 @@ namespace Test
[DeploymentItem("SubtitleEdit.exe")] [DeploymentItem("SubtitleEdit.exe")]
public void StartWithUppercaseAfterParagraphNormalDialog1() public void StartWithUppercaseAfterParagraphNormalDialog1()
{ {
Paragraph prev = new Paragraph("Bye.", 0, 1000); var prev = new Paragraph("Bye.", 0, 1000);
Paragraph p = new Paragraph("- Moss! Jesus Christ!" + Environment.NewLine + "- what is it?", 1200, 5000); var p = new Paragraph("- Moss! Jesus Christ!" + Environment.NewLine + "- what is it?", 1200, 5000);
var fixedText = FixCommonErrors.FixStartWithUppercaseLetterAfterParagraph(p, prev, System.Text.Encoding.UTF8, "en"); var fixedText = FixCommonErrors.FixStartWithUppercaseLetterAfterParagraph(p, prev, System.Text.Encoding.UTF8, "en");
Assert.AreEqual(fixedText, "- Moss! Jesus Christ!" + Environment.NewLine + "- What is it?"); Assert.AreEqual(fixedText, "- Moss! Jesus Christ!" + Environment.NewLine + "- What is it?");
} }
@ -692,8 +692,8 @@ namespace Test
[DeploymentItem("SubtitleEdit.exe")] [DeploymentItem("SubtitleEdit.exe")]
public void StartWithUppercaseAfterParagraphNormalDialog2() public void StartWithUppercaseAfterParagraphNormalDialog2()
{ {
Paragraph prev = new Paragraph("Bye.", 0, 1000); var prev = new Paragraph("Bye.", 0, 1000);
Paragraph p = new Paragraph("<i>- Moss! Jesus Christ!" + Environment.NewLine + "- what is it?</i>", 1200, 5000); var p = new Paragraph("<i>- Moss! Jesus Christ!" + Environment.NewLine + "- what is it?</i>", 1200, 5000);
var fixedText = FixCommonErrors.FixStartWithUppercaseLetterAfterParagraph(p, prev, System.Text.Encoding.UTF8, "en"); var fixedText = FixCommonErrors.FixStartWithUppercaseLetterAfterParagraph(p, prev, System.Text.Encoding.UTF8, "en");
Assert.AreEqual(fixedText, "<i>- Moss! Jesus Christ!" + Environment.NewLine + "- What is it?</i>"); Assert.AreEqual(fixedText, "<i>- Moss! Jesus Christ!" + Environment.NewLine + "- What is it?</i>");
} }
@ -702,8 +702,8 @@ namespace Test
[DeploymentItem("SubtitleEdit.exe")] [DeploymentItem("SubtitleEdit.exe")]
public void StartWithUppercaseAfterParagraphNormalDialog3() public void StartWithUppercaseAfterParagraphNormalDialog3()
{ {
Paragraph prev = new Paragraph("Bye.", 0, 1000); var prev = new Paragraph("Bye.", 0, 1000);
Paragraph p = new Paragraph("<i>- Moss! Jesus Christ!</i>" + Environment.NewLine + "<i>- what is it?</i>", 1200, 5000); var p = new Paragraph("<i>- Moss! Jesus Christ!</i>" + Environment.NewLine + "<i>- what is it?</i>", 1200, 5000);
var fixedText = FixCommonErrors.FixStartWithUppercaseLetterAfterParagraph(p, prev, System.Text.Encoding.UTF8, "en"); var fixedText = FixCommonErrors.FixStartWithUppercaseLetterAfterParagraph(p, prev, System.Text.Encoding.UTF8, "en");
Assert.AreEqual(fixedText, "<i>- Moss! Jesus Christ!</i>" + Environment.NewLine + "<i>- What is it?</i>"); Assert.AreEqual(fixedText, "<i>- Moss! Jesus Christ!</i>" + Environment.NewLine + "<i>- What is it?</i>");
} }
@ -712,8 +712,8 @@ namespace Test
[DeploymentItem("SubtitleEdit.exe")] [DeploymentItem("SubtitleEdit.exe")]
public void StartWithUppercaseAfterParagraphNormalDialog4() public void StartWithUppercaseAfterParagraphNormalDialog4()
{ {
Paragraph prev = new Paragraph("Bye.", 0, 1000); var prev = new Paragraph("Bye.", 0, 1000);
Paragraph p = new Paragraph("<i>- moss! Jesus Christ!</i>" + Environment.NewLine + "<i>- what is it?</i>", 1200, 5000); var p = new Paragraph("<i>- moss! Jesus Christ!</i>" + Environment.NewLine + "<i>- what is it?</i>", 1200, 5000);
var fixedText = FixCommonErrors.FixStartWithUppercaseLetterAfterParagraph(p, prev, System.Text.Encoding.UTF8, "en"); var fixedText = FixCommonErrors.FixStartWithUppercaseLetterAfterParagraph(p, prev, System.Text.Encoding.UTF8, "en");
Assert.AreEqual(fixedText, "<i>- Moss! Jesus Christ!</i>" + Environment.NewLine + "<i>- What is it?</i>"); Assert.AreEqual(fixedText, "<i>- Moss! Jesus Christ!</i>" + Environment.NewLine + "<i>- What is it?</i>");
} }
@ -722,8 +722,8 @@ namespace Test
[DeploymentItem("SubtitleEdit.exe")] [DeploymentItem("SubtitleEdit.exe")]
public void StartWithUppercaseAfterParagraphNormalNoChange2() public void StartWithUppercaseAfterParagraphNormalNoChange2()
{ {
Paragraph prev = new Paragraph("Bye", 0, 1000); var prev = new Paragraph("Bye", 0, 1000);
Paragraph p = new Paragraph("bye.", 1200, 5000); var p = new Paragraph("bye.", 1200, 5000);
var fixedText = FixCommonErrors.FixStartWithUppercaseLetterAfterParagraph(p, prev, System.Text.Encoding.UTF8, "en"); var fixedText = FixCommonErrors.FixStartWithUppercaseLetterAfterParagraph(p, prev, System.Text.Encoding.UTF8, "en");
Assert.AreEqual(fixedText, "bye."); Assert.AreEqual(fixedText, "bye.");
} }
@ -732,8 +732,8 @@ namespace Test
[DeploymentItem("SubtitleEdit.exe")] [DeploymentItem("SubtitleEdit.exe")]
public void StartWithUppercaseAfterParagraphNormalDialogNoChange1() public void StartWithUppercaseAfterParagraphNormalDialogNoChange1()
{ {
Paragraph prev = new Paragraph("Bye -", 0, 1000); var prev = new Paragraph("Bye -", 0, 1000);
Paragraph p = new Paragraph("- moss!", 1200, 5000); var p = new Paragraph("- moss!", 1200, 5000);
var fixedText = FixCommonErrors.FixStartWithUppercaseLetterAfterParagraph(p, prev, System.Text.Encoding.UTF8, "en"); var fixedText = FixCommonErrors.FixStartWithUppercaseLetterAfterParagraph(p, prev, System.Text.Encoding.UTF8, "en");
Assert.AreEqual(fixedText, "- moss!"); Assert.AreEqual(fixedText, "- moss!");
} }
@ -742,8 +742,8 @@ namespace Test
[DeploymentItem("SubtitleEdit.exe")] [DeploymentItem("SubtitleEdit.exe")]
public void StartWithUppercaseAfterParagraphNormalDialogNoChange2() public void StartWithUppercaseAfterParagraphNormalDialogNoChange2()
{ {
Paragraph prev = new Paragraph("Bye -", 0, 1000); var prev = new Paragraph("Bye -", 0, 1000);
Paragraph p = new Paragraph("- moss!" + Environment.NewLine + " - Bye.", 1200, 5000); var p = new Paragraph("- moss!" + Environment.NewLine + " - Bye.", 1200, 5000);
var fixedText = FixCommonErrors.FixStartWithUppercaseLetterAfterParagraph(p, prev, System.Text.Encoding.UTF8, "en"); var fixedText = FixCommonErrors.FixStartWithUppercaseLetterAfterParagraph(p, prev, System.Text.Encoding.UTF8, "en");
Assert.AreEqual(fixedText, "- moss!" + Environment.NewLine + " - Bye."); Assert.AreEqual(fixedText, "- moss!" + Environment.NewLine + " - Bye.");
} }
@ -760,7 +760,7 @@ namespace Test
{ {
InitializeFixCommonErrorsLine(target, "Cómo estás?"); InitializeFixCommonErrorsLine(target, "Cómo estás?");
target.FixSpanishInvertedQuestionAndExclamationMarks(); target.FixSpanishInvertedQuestionAndExclamationMarks();
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "¿Cómo estás?"); Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "¿Cómo estás?");
} }
} }
@ -772,7 +772,7 @@ namespace Test
{ {
InitializeFixCommonErrorsLine(target, "Cómo estás!"); InitializeFixCommonErrorsLine(target, "Cómo estás!");
target.FixSpanishInvertedQuestionAndExclamationMarks(); target.FixSpanishInvertedQuestionAndExclamationMarks();
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "¡Cómo estás!"); Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "¡Cómo estás!");
} }
} }
@ -784,7 +784,7 @@ namespace Test
{ {
InitializeFixCommonErrorsLine(target, "¡¡PARA!!"); InitializeFixCommonErrorsLine(target, "¡¡PARA!!");
target.FixSpanishInvertedQuestionAndExclamationMarks(); target.FixSpanishInvertedQuestionAndExclamationMarks();
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "¡¡PARA!!"); Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "¡¡PARA!!");
} }
} }
@ -796,7 +796,7 @@ namespace Test
{ {
InitializeFixCommonErrorsLine(target, "¡¡¡PARA!!!"); InitializeFixCommonErrorsLine(target, "¡¡¡PARA!!!");
target.FixSpanishInvertedQuestionAndExclamationMarks(); target.FixSpanishInvertedQuestionAndExclamationMarks();
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "¡¡¡PARA!!!"); Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "¡¡¡PARA!!!");
} }
} }
@ -808,7 +808,7 @@ namespace Test
{ {
InitializeFixCommonErrorsLine(target, "¿Cómo estás?!"); InitializeFixCommonErrorsLine(target, "¿Cómo estás?!");
target.FixSpanishInvertedQuestionAndExclamationMarks(); target.FixSpanishInvertedQuestionAndExclamationMarks();
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "¡¿Cómo estás?!"); Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "¡¿Cómo estás?!");
} }
} }
@ -820,7 +820,7 @@ namespace Test
{ {
InitializeFixCommonErrorsLine(target, "<i>Chanchita, ¡¿copias?! Chanchita!!</i>"); InitializeFixCommonErrorsLine(target, "<i>Chanchita, ¡¿copias?! Chanchita!!</i>");
target.FixSpanishInvertedQuestionAndExclamationMarks(); target.FixSpanishInvertedQuestionAndExclamationMarks();
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "<i>Chanchita, ¡¿copias?! ¡¡Chanchita!!</i>"); Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "<i>Chanchita, ¡¿copias?! ¡¡Chanchita!!</i>");
} }
} }
@ -832,7 +832,7 @@ namespace Test
{ {
InitializeFixCommonErrorsLine(target, "¡Cómo estás?"); InitializeFixCommonErrorsLine(target, "¡Cómo estás?");
target.FixSpanishInvertedQuestionAndExclamationMarks(); target.FixSpanishInvertedQuestionAndExclamationMarks();
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "¿¡Cómo estás!?"); Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "¿¡Cómo estás!?");
} }
} }
@ -848,7 +848,7 @@ namespace Test
{ {
InitializeFixCommonErrorsLine(target, "<i>- Mm-hmm.</i>"); InitializeFixCommonErrorsLine(target, "<i>- Mm-hmm.</i>");
target.FixHyphens(); target.FixHyphens();
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "<i>Mm-hmm.</i>"); Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "<i>Mm-hmm.</i>");
} }
} }
@ -860,7 +860,7 @@ namespace Test
{ {
InitializeFixCommonErrorsLine(target, "<font color='red'>- Mm-hmm.</font>"); InitializeFixCommonErrorsLine(target, "<font color='red'>- Mm-hmm.</font>");
target.FixHyphens(); target.FixHyphens();
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "<font color='red'>Mm-hmm.</font>"); Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "<font color='red'>Mm-hmm.</font>");
} }
} }
@ -872,7 +872,7 @@ namespace Test
{ {
InitializeFixCommonErrorsLine(target, "- Mm-hmm."); InitializeFixCommonErrorsLine(target, "- Mm-hmm.");
target.FixHyphens(); target.FixHyphens();
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "Mm-hmm."); Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "Mm-hmm.");
} }
} }
@ -884,7 +884,7 @@ namespace Test
{ {
InitializeFixCommonErrorsLine(target, "- I-I never thought of that."); InitializeFixCommonErrorsLine(target, "- I-I never thought of that.");
target.FixHyphens(); target.FixHyphens();
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "I-I never thought of that."); Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "I-I never thought of that.");
} }
} }
@ -896,7 +896,7 @@ namespace Test
{ {
InitializeFixCommonErrorsLine(target, "- Uh-huh."); InitializeFixCommonErrorsLine(target, "- Uh-huh.");
target.FixHyphens(); target.FixHyphens();
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "Uh-huh."); Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "Uh-huh.");
} }
} }
@ -978,7 +978,7 @@ namespace Test
{ {
InitializeFixCommonErrorsLine(target, "This is no troubIe!"); InitializeFixCommonErrorsLine(target, "This is no troubIe!");
target.FixUppercaseIInsideWords(); target.FixUppercaseIInsideWords();
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "This is no trouble!"); Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "This is no trouble!");
} }
} }
@ -990,7 +990,7 @@ namespace Test
{ {
InitializeFixCommonErrorsLine(target, "- I'll ring her." + Environment.NewLine + "- ...In a lot of trouble."); InitializeFixCommonErrorsLine(target, "- I'll ring her." + Environment.NewLine + "- ...In a lot of trouble.");
target.FixUppercaseIInsideWords(); target.FixUppercaseIInsideWords();
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "- I'll ring her." + Environment.NewLine + "- ...In a lot of trouble."); Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "- I'll ring her." + Environment.NewLine + "- ...In a lot of trouble.");
} }
} }
@ -1002,7 +1002,7 @@ namespace Test
{ {
InitializeFixCommonErrorsLine(target, "Yeah, see, that's not mine."); InitializeFixCommonErrorsLine(target, "Yeah, see, that's not mine.");
target.FixOcrErrorsViaReplaceList("eng"); target.FixOcrErrorsViaReplaceList("eng");
Assert.AreEqual(target._subtitle.Paragraphs[0].Text, "Yeah, see, that's not mine."); Assert.AreEqual(target.Subtitle.Paragraphs[0].Text, "Yeah, see, that's not mine.");
} }
} }
@ -1013,8 +1013,8 @@ namespace Test
var form = new GoToLine(); var form = new GoToLine();
Configuration.Settings.Tools.OcrFixUseHardcodedRules = true; Configuration.Settings.Tools.OcrFixUseHardcodedRules = true;
//string input = "i'I'll see you."; //string input = "i'I'll see you.";
string input = "l-l'll see you."; const string input = "l-l'll see you.";
Nikse.SubtitleEdit.Logic.Ocr.OcrFixEngine ofe = new Nikse.SubtitleEdit.Logic.Ocr.OcrFixEngine("eng", "us_en", form); var ofe = new Nikse.SubtitleEdit.Logic.Ocr.OcrFixEngine("eng", "us_en", form);
var res = ofe.FixOcrErrorsViaHardcodedRules(input, "Previous line.", new HashSet<string>()); var res = ofe.FixOcrErrorsViaHardcodedRules(input, "Previous line.", new HashSet<string>());
Assert.AreEqual(res, "I-I'll see you."); Assert.AreEqual(res, "I-I'll see you.");
} }