Improve OCR replace list guessses

This commit is contained in:
Nikolaj Olsson 2020-06-14 20:23:35 +02:00
parent a1c35e349e
commit c78dda9571
4 changed files with 18 additions and 9 deletions

View File

@ -2820,7 +2820,7 @@
</PartialWordsAlways> </PartialWordsAlways>
<PartialWords> <PartialWords>
<!-- Will be used to check words not in dictionary. <!-- Will be used to check words not in dictionary.
If new word(s) and longer than 5 chars and exists in spelling dictionary, it is (or they are) accepted --> If new word(s) and longer than 4 chars and exists in spelling dictionary, it is (or they are) accepted -->
<WordPart from="IVI" to="M" /> <WordPart from="IVI" to="M" />
<WordPart from="/" to="l" /> <WordPart from="/" to="l" />
<WordPart from="|" to="I" /> <WordPart from="|" to="I" />

View File

@ -4,7 +4,7 @@
<PartialWordsAlways /> <PartialWordsAlways />
<PartialWords> <PartialWords>
<!-- Will be used to check words not in dictionary. <!-- Will be used to check words not in dictionary.
If new word(s) and longer than 5 chars and exists If new word(s) and longer than 4 chars and exists
in spelling dictionary, it is (or they are) accepted --> in spelling dictionary, it is (or they are) accepted -->
<!-- "f " will be two words --> <!-- "f " will be two words -->
<WordPart from="f" to="f " /> <WordPart from="f" to="f " />

View File

@ -363,7 +363,7 @@ namespace Nikse.SubtitleEdit.Core.Dictionaries
if (word.Substring(i).StartsWith(letter, StringComparison.Ordinal)) if (word.Substring(i).StartsWith(letter, StringComparison.Ordinal))
{ {
if (i == word.Length - letter.Length && !_partialWordReplaceList[letter].Contains(" ")) if (i == word.Length - letter.Length && !_partialWordReplaceList[letter].Contains(' '))
{ {
var guess = word.Remove(i, letter.Length).Insert(i, _partialWordReplaceList[letter]); var guess = word.Remove(i, letter.Length).Insert(i, _partialWordReplaceList[letter]);
AddToGuessList(list, guess); AddToGuessList(list, guess);
@ -378,6 +378,8 @@ namespace Nikse.SubtitleEdit.Core.Dictionaries
} }
if (indexes.Count > 1) if (indexes.Count > 1)
{
if (!_partialWordReplaceList[letter].Contains(' '))
{ {
var multiGuess = word; var multiGuess = word;
for (int i = indexes.Count - 1; i >= 0; i--) for (int i = indexes.Count - 1; i >= 0; i--)
@ -386,6 +388,13 @@ namespace Nikse.SubtitleEdit.Core.Dictionaries
multiGuess = multiGuess.Remove(idx, letter.Length).Insert(idx, _partialWordReplaceList[letter]); multiGuess = multiGuess.Remove(idx, letter.Length).Insert(idx, _partialWordReplaceList[letter]);
AddToGuessList(list, multiGuess); AddToGuessList(list, multiGuess);
} }
AddToGuessList(list, word.Replace(letter, _partialWordReplaceList[letter]));
}
}
else if (indexes.Count > 0)
{
AddToGuessList(list, word.Replace(letter, _partialWordReplaceList[letter]));
} }
if (indexes.Count > 0) if (indexes.Count > 0)

View File

@ -1592,7 +1592,7 @@ namespace Nikse.SubtitleEdit.Logic.Ocr
guesses.Add(wordWithVerticalLine); guesses.Add(wordWithVerticalLine);
} }
if (word.Length > 5 && autoGuess == AutoGuessLevel.Aggressive) if (word.Length > 4 && autoGuess == AutoGuessLevel.Aggressive)
{ {
guesses.AddRange((List<string>)_ocrFixReplaceList.CreateGuessesFromLetters(word)); guesses.AddRange((List<string>)_ocrFixReplaceList.CreateGuessesFromLetters(word));