OCR italic fix again - thx Zoltan :)

This commit is contained in:
Nikolaj Olsson 2024-10-14 20:16:59 +02:00
parent d12b632fb7
commit 0d45a60a75
2 changed files with 38 additions and 1 deletions

View File

@ -75,6 +75,41 @@ namespace Test.Logic.Ocr
Assert.AreEqual("He said: <i>''Go now!''</i>", result);
}
[TestMethod]
public void TestColonInItalic()
{
var matches = new List<VobSubOcr.CompareMatch>
{
new VobSubOcr.CompareMatch("[", true, 0, Guid.NewGuid().ToString()),
new VobSubOcr.CompareMatch("O", true, 0, Guid.NewGuid().ToString()),
new VobSubOcr.CompareMatch("v", true, 0, Guid.NewGuid().ToString()),
new VobSubOcr.CompareMatch("e", true, 0, Guid.NewGuid().ToString()),
new VobSubOcr.CompareMatch("r", true, 0, Guid.NewGuid().ToString()),
new VobSubOcr.CompareMatch(" ", true, 0, Guid.NewGuid().ToString()),
new VobSubOcr.CompareMatch("c", true, 0, Guid.NewGuid().ToString()),
new VobSubOcr.CompareMatch("o", true, 0, Guid.NewGuid().ToString()),
new VobSubOcr.CompareMatch("m", true, 0, Guid.NewGuid().ToString()),
new VobSubOcr.CompareMatch("s", true, 0, Guid.NewGuid().ToString()),
new VobSubOcr.CompareMatch("]", true, 0, Guid.NewGuid().ToString()),
new VobSubOcr.CompareMatch(" ", true, 0, Guid.NewGuid().ToString()),
new VobSubOcr.CompareMatch("H", true, 0, Guid.NewGuid().ToString()),
new VobSubOcr.CompareMatch("o", true, 0, Guid.NewGuid().ToString()),
new VobSubOcr.CompareMatch("w", true, 0, Guid.NewGuid().ToString()),
new VobSubOcr.CompareMatch(" ", true, 0, Guid.NewGuid().ToString()),
new VobSubOcr.CompareMatch("a", true, 0, Guid.NewGuid().ToString()),
new VobSubOcr.CompareMatch("r", true, 0, Guid.NewGuid().ToString()),
new VobSubOcr.CompareMatch("e", true, 0, Guid.NewGuid().ToString()),
new VobSubOcr.CompareMatch(" ", true, 0, Guid.NewGuid().ToString()),
new VobSubOcr.CompareMatch("y", true, 0, Guid.NewGuid().ToString()),
new VobSubOcr.CompareMatch("o", true, 0, Guid.NewGuid().ToString()),
new VobSubOcr.CompareMatch("u", true, 0, Guid.NewGuid().ToString()),
new VobSubOcr.CompareMatch("?", true, 0, Guid.NewGuid().ToString()),
};
var result = MatchesToItalicStringConverter.GetStringWithItalicTags(matches);
Assert.AreEqual("<i>[Over coms] How are you?</i>", result);
}
[TestMethod]
public void TestItalicAndColon()
{

View File

@ -30,7 +30,8 @@ namespace Nikse.SubtitleEdit.Logic.Ocr
var numberOfItalicLetters = GetNumberOfItalicLetters(lineMatches.Matches);
if (numberOfItalicLetters == numberOfLetters || numberOfItalicLetters > 3 && numberOfLetters - numberOfItalicLetters < 2 && ItalicIsInsideWord(matches))
{
sb.AppendLine("<i>" + GetRawString(lineMatches.Matches) + "</i>");
sb.Append("<i>" + GetRawString(lineMatches.Matches) + "</i>");
sb.Append(lineMatches.Separator);
}
else if (numberOfItalicLetters == 0 || numberOfLetters > 2 && numberOfItalicLetters < 2)
{
@ -49,6 +50,7 @@ namespace Nikse.SubtitleEdit.Logic.Ocr
text = text.Replace(" ", " ");
text = text.Replace("<i> ", " <i>");
text = text.Replace(" </i>", "</i> ");
text = text.Replace("</i> <i>", " ");
text = text.Replace(" ", " ");
return text.Trim();