Improve "Fix uppercase 'i' nside lowercase words - thx

taxen :)
This commit is contained in:
Nikolaj Olsson 2019-02-21 23:41:44 +01:00
parent 53b7338e91
commit 8d173b8d47
36 changed files with 100 additions and 16 deletions

View File

@ -1,4 +1,5 @@
using System;
using Nikse.SubtitleEdit.Core.Interfaces;
namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
{

View File

@ -1,6 +1,7 @@
using Nikse.SubtitleEdit.Core.SubtitleFormats;
using System.Collections.Generic;
using System.Text;
using Nikse.SubtitleEdit.Core.Interfaces;
namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
{
@ -67,5 +68,9 @@ namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
return new HashSet<string>();
}
public bool DoSpell(string word)
{
return false;
}
}
}

View File

@ -1,4 +1,5 @@
using System;
using Nikse.SubtitleEdit.Core.Interfaces;
namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
{

View File

@ -1,5 +1,6 @@
using System;
using System.Text.RegularExpressions;
using Nikse.SubtitleEdit.Core.Interfaces;
namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
{

View File

@ -1,4 +1,5 @@
using System.Text.RegularExpressions;
using Nikse.SubtitleEdit.Core.Interfaces;
namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
{

View File

@ -1,4 +1,6 @@
namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
using Nikse.SubtitleEdit.Core.Interfaces;
namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
{
public class FixDialogsOnOneLine : IFixCommonError
{

View File

@ -1,4 +1,6 @@
namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
using Nikse.SubtitleEdit.Core.Interfaces;
namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
{
public class FixDoubleApostrophes : IFixCommonError
{

View File

@ -1,4 +1,5 @@
using System;
using Nikse.SubtitleEdit.Core.Interfaces;
namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
{

View File

@ -1,4 +1,5 @@
using System;
using Nikse.SubtitleEdit.Core.Interfaces;
namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
{

View File

@ -1,4 +1,5 @@
using System;
using Nikse.SubtitleEdit.Core.Interfaces;
namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
{

View File

@ -1,4 +1,5 @@
using System;
using Nikse.SubtitleEdit.Core.Interfaces;
namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
{

View File

@ -1,4 +1,6 @@
namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
using Nikse.SubtitleEdit.Core.Interfaces;
namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
{
public class FixHyphensAdd : IFixCommonError
{

View File

@ -1,4 +1,6 @@
namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
using Nikse.SubtitleEdit.Core.Interfaces;
namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
{
public class FixHyphensRemove : IFixCommonError
{

View File

@ -1,4 +1,6 @@
namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
using Nikse.SubtitleEdit.Core.Interfaces;
namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
{
public class FixInvalidItalicTags : IFixCommonError
{

View File

@ -1,4 +1,6 @@
namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
using Nikse.SubtitleEdit.Core.Interfaces;
namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
{
public class FixLongDisplayTimes : IFixCommonError
{

View File

@ -1,4 +1,6 @@
namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
using Nikse.SubtitleEdit.Core.Interfaces;
namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
{
public class FixLongLines : IFixCommonError
{

View File

@ -1,4 +1,5 @@
using System;
using Nikse.SubtitleEdit.Core.Interfaces;
namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
{

View File

@ -1,4 +1,5 @@
using System;
using Nikse.SubtitleEdit.Core.Interfaces;
namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
{

View File

@ -1,5 +1,6 @@
using System;
using System.Text.RegularExpressions;
using Nikse.SubtitleEdit.Core.Interfaces;
namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
{

View File

@ -1,4 +1,5 @@
using System;
using Nikse.SubtitleEdit.Core.Interfaces;
namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
{

View File

@ -1,5 +1,6 @@
using Nikse.SubtitleEdit.Core.SubtitleFormats;
using System;
using Nikse.SubtitleEdit.Core.Interfaces;
namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
{

View File

@ -1,4 +1,6 @@
namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
using Nikse.SubtitleEdit.Core.Interfaces;
namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
{
public class FixShortDisplayTimes : IFixCommonError
{

View File

@ -1,4 +1,6 @@
namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
using Nikse.SubtitleEdit.Core.Interfaces;
namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
{
public class FixShortLines : IFixCommonError
{

View File

@ -1,4 +1,5 @@
using System;
using Nikse.SubtitleEdit.Core.Interfaces;
namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
{

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using Nikse.SubtitleEdit.Core.Interfaces;
namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
{

View File

@ -1,5 +1,6 @@
using System;
using System.Globalization;
using Nikse.SubtitleEdit.Core.Interfaces;
namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
{

View File

@ -1,6 +1,7 @@
using System;
using System.Globalization;
using System.Text;
using Nikse.SubtitleEdit.Core.Interfaces;
namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
{

View File

@ -1,4 +1,5 @@
using System.Globalization;
using Nikse.SubtitleEdit.Core.Interfaces;
namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
{

View File

@ -1,4 +1,6 @@
namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
using Nikse.SubtitleEdit.Core.Interfaces;
namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
{
public class FixTurkishAnsiToUnicode : IFixCommonError
{

View File

@ -1,4 +1,5 @@
using System;
using Nikse.SubtitleEdit.Core.Interfaces;
namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
{

View File

@ -1,4 +1,5 @@
using System;
using Nikse.SubtitleEdit.Core.Interfaces;
namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
{

View File

@ -1,5 +1,6 @@
using System;
using System.Text.RegularExpressions;
using Nikse.SubtitleEdit.Core.Interfaces;
namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
{
@ -8,6 +9,7 @@ namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
private static readonly Regex ReAfterLowercaseLetter = new Regex(@"[a-zæøåäöéùáàìéóúñüéíóúñü]I", RegexOptions.Compiled);
private static readonly Regex ReBeforeLowercaseLetter = new Regex(@"I[a-zæøåäöéùáàìéóúñüéíóúñü]", RegexOptions.Compiled);
public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
{
var l = Configuration.Settings.Language.FixCommonErrors;
@ -68,6 +70,10 @@ namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
word.Equals("islands", StringComparison.OrdinalIgnoreCase))
{
}
else if (word.StartsWith("I") && !callbacks.DoSpell("l" + word.Remove(0,1)))
{
// word starting with "I", replaced by "l" is not spell check correct, so we skip it (probably a name)
}
else if (match.Index == 0)
{ // first letter in paragraph

View File

@ -1,4 +1,6 @@
namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
using Nikse.SubtitleEdit.Core.Interfaces;
namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
{
public class RemoveSpaceBetweenNumbers : IFixCommonError
{

View File

@ -1,10 +1,10 @@
using Nikse.SubtitleEdit.Core.SubtitleFormats;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Text;
using Nikse.SubtitleEdit.Core.SubtitleFormats;
namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
namespace Nikse.SubtitleEdit.Core.Interfaces
{
public interface IFixCallbacks
public interface IFixCallbacks : IDoSpell
{
bool AllowFix(Paragraph p, string action);
void AddFixToListView(Paragraph p, string action, string before, string after);

View File

@ -1,4 +1,4 @@
namespace Nikse.SubtitleEdit.Core.Forms.FixCommonErrors
namespace Nikse.SubtitleEdit.Core.Interfaces
{
public interface IFixCommonError
{

View File

@ -12,6 +12,8 @@ using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Nikse.SubtitleEdit.Core.Interfaces;
using Nikse.SubtitleEdit.Logic.SpellCheck;
namespace Nikse.SubtitleEdit.Forms
{
@ -1825,5 +1827,34 @@ namespace Nikse.SubtitleEdit.Forms
e.SuppressKeyPress = true;
}
}
private Hunspell _hunspell;
public bool DoSpell(string word)
{
if (_hunspell == null && Language != null)
{
var fileMatches = Directory.GetFiles(Utilities.DictionaryFolder, Language + "*.dic");
if (fileMatches.Length > 0)
{
var dictionary = fileMatches[0].Substring(0, fileMatches[0].Length - 4);
try
{
_hunspell = Hunspell.GetHunspell(dictionary);
}
catch
{
_hunspell = null;
}
}
}
if (_hunspell == null)
{
return false;
}
return _hunspell.Spell(word);
}
}
}