Remember ocr spell check dic for tesseract

This commit is contained in:
Nikolaj Olsson 2018-03-15 20:25:13 +01:00
parent 631f58c544
commit 33feaf4f05
2 changed files with 48 additions and 40 deletions

View File

@ -875,6 +875,7 @@ namespace Nikse.SubtitleEdit.Core
public bool GuessUnknownWords { get; set; }
public bool AutoBreakSubtitleIfMoreThanTwoLines { get; set; }
public double ItalicFactor { get; set; }
public bool LineOcrDraw { get; set; }
public bool LineOcrAdvancedItalic { get; set; }
public string LineOcrLastLanguages { get; set; }
@ -884,6 +885,7 @@ namespace Nikse.SubtitleEdit.Core
public int LineOcrMaxLineHeight { get; set; }
public string LastBinaryImageCompareDb { get; set; }
public string LastBinaryImageSpellCheck { get; set; }
public string LastTesseractSpellCheck { get; set; }
public VobSubOcrSettings()
{
@ -2735,41 +2737,9 @@ namespace Nikse.SubtitleEdit.Core
subNode = node.SelectSingleNode("LastBinaryImageSpellCheck");
if (subNode != null)
settings.VobSubOcr.LastBinaryImageSpellCheck = subNode.InnerText;
// TODO: Remove future version (like SE 3.4.15)
//BEGIN OLD
var oldReplaceItems = doc.DocumentElement.SelectNodes("MultipleSearchAndReplaceList/MultipleSearchAndReplaceItem");
if (oldReplaceItems.Count > 0)
{
var group = new MultipleSearchAndReplaceGroup();
group.Rules = new List<MultipleSearchAndReplaceSetting>();
group.Name = "Default";
group.Enabled = true;
settings.MultipleSearchAndReplaceGroups.Add(group);
foreach (XmlNode listNode in oldReplaceItems)
{
var item = new MultipleSearchAndReplaceSetting();
subNode = listNode.SelectSingleNode("Enabled");
if (subNode != null)
item.Enabled = Convert.ToBoolean(subNode.InnerText);
subNode = listNode.SelectSingleNode("FindWhat");
if (subNode != null)
item.FindWhat = subNode.InnerText;
subNode = listNode.SelectSingleNode("ReplaceWith");
if (subNode != null)
item.ReplaceWith = subNode.InnerText;
subNode = listNode.SelectSingleNode("SearchType");
if (subNode != null)
item.SearchType = subNode.InnerText;
subNode = listNode.SelectSingleNode("Description");
if (subNode != null)
item.Description = subNode.InnerText;
group.Rules.Add(item);
}
}
//END OLD
subNode = node.SelectSingleNode("LastTesseractSpellCheck");
if (subNode != null)
settings.VobSubOcr.LastTesseractSpellCheck = subNode.InnerText;
foreach (XmlNode groupNode in doc.DocumentElement.SelectNodes("MultipleSearchAndReplaceGroups/Group"))
{
@ -3857,6 +3827,8 @@ namespace Nikse.SubtitleEdit.Core
textWriter.WriteElementString("LineOcrMaxLineHeight", settings.VobSubOcr.LineOcrMaxLineHeight.ToString(CultureInfo.InvariantCulture));
textWriter.WriteElementString("LastBinaryImageCompareDb", settings.VobSubOcr.LastBinaryImageCompareDb);
textWriter.WriteElementString("LastBinaryImageSpellCheck", settings.VobSubOcr.LastBinaryImageSpellCheck);
textWriter.WriteElementString("LastTesseractSpellCheck", settings.VobSubOcr.LastTesseractSpellCheck);
textWriter.WriteEndElement();
textWriter.WriteStartElement("MultipleSearchAndReplaceGroups", string.Empty);

View File

@ -904,7 +904,10 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
for (int i = 0; i < comboBoxCharacterDatabase.Items.Count; i++)
{
if (comboBoxCharacterDatabase.Items[i].ToString().Equals(_vobSubOcrSettings.LastImageCompareFolder, StringComparison.OrdinalIgnoreCase))
{
comboBoxCharacterDatabase.SelectedIndex = i;
break;
}
}
if (comboBoxCharacterDatabase.SelectedIndex < 0)
comboBoxCharacterDatabase.SelectedIndex = 0;
@ -7475,14 +7478,39 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
if (_ocrFixEngine.IsDictionaryLoaded)
{
string loadedDictionaryName = _ocrFixEngine.SpellCheckDictionaryName;
int i = 0;
var found = false;
comboBoxDictionaries.SelectedIndexChanged -= comboBoxDictionaries_SelectedIndexChanged;
foreach (string item in comboBoxDictionaries.Items)
if (_ocrMethodIndex == _ocrMethodTesseract &&
!string.IsNullOrEmpty(Configuration.Settings.VobSubOcr.LastTesseractSpellCheck) &&
Configuration.Settings.VobSubOcr.LastTesseractSpellCheck.Length > 1 &&
loadedDictionaryName.Length > 1 &&
Configuration.Settings.VobSubOcr.LastTesseractSpellCheck.StartsWith(loadedDictionaryName.Substring(0, 2), StringComparison.OrdinalIgnoreCase))
{
if (item.Contains("[" + loadedDictionaryName + "]"))
comboBoxDictionaries.SelectedIndex = i;
i++;
for (var index = 0; index < comboBoxDictionaries.Items.Count; index++)
{
var item = (string)comboBoxDictionaries.Items[index];
if (item.Contains("[" + Configuration.Settings.VobSubOcr.LastTesseractSpellCheck + "]"))
{
comboBoxDictionaries.SelectedIndex = index;
found = true;
break;
}
}
}
if (!found)
{
for (var index = 0; index < comboBoxDictionaries.Items.Count; index++)
{
var item = (string)comboBoxDictionaries.Items[index];
if (item.Contains("[" + loadedDictionaryName + "]"))
{
comboBoxDictionaries.SelectedIndex = index;
break;
}
}
}
comboBoxDictionaries.SelectedIndexChanged += comboBoxDictionaries_SelectedIndexChanged;
comboBoxDictionaries.Left = labelDictionaryLoaded.Left + labelDictionaryLoaded.Width;
comboBoxDictionaries.Width = groupBoxOcrAutoFix.Width - (comboBoxDictionaries.Left + 10 + buttonSpellCheckDownload.Width);
@ -7868,6 +7896,9 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
private void comboBoxDictionaries_SelectedIndexChanged(object sender, EventArgs e)
{
Configuration.Settings.General.SpellCheckLanguage = LanguageString;
if (_ocrMethodIndex == _ocrMethodTesseract)
Configuration.Settings.VobSubOcr.LastTesseractSpellCheck = LanguageString;
string threeLetterIsoLanguageName = string.Empty;
if (LanguageString == null)
{
@ -8414,6 +8445,11 @@ namespace Nikse.SubtitleEdit.Forms.Ocr
Configuration.Settings.VobSubOcr.LastBinaryImageSpellCheck = comboBoxDictionaries.SelectedItem.ToString();
}
if (_ocrMethodIndex == _ocrMethodTesseract)
{
Configuration.Settings.VobSubOcr.LastTesseractSpellCheck = LanguageString;
}
if (_bluRaySubtitlesOriginal != null)
Configuration.Settings.VobSubOcr.BlurayAllowDifferenceInPercent = (double)numericUpDownMaxErrorPct.Value;
else