-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
attempt to integrate WeCantSpell into liblcm, there's currently issue…
…s with modifying the word list at runtime.
- Loading branch information
Showing
7 changed files
with
86 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/SIL.LCModel.Core/SpellChecking/SpellEngineWeCantSpell.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using WeCantSpell.Hunspell; | ||
|
||
namespace SIL.LCModel.Core.SpellChecking | ||
{ | ||
internal class SpellEngineWeCantSpell: SpellEngine | ||
{ | ||
private readonly WordList _wordList; | ||
private readonly WordList.Builder _customWordsBuilder; | ||
private WordList _customWordList; | ||
private readonly HashSet<string> _badWords = new HashSet<string>(); | ||
|
||
public SpellEngineWeCantSpell(string affixPath, string dictPath, string exceptionPath) : base(exceptionPath) | ||
{ | ||
_wordList = WordList.CreateFromFiles(dictPath, affixPath); | ||
_customWordsBuilder = new WordList.Builder(_wordList.Affix); | ||
_customWordList = _customWordsBuilder.ToImmutable(); | ||
} | ||
|
||
public override bool Check(string word) | ||
{ | ||
if (_badWords.Contains(word)) return false; | ||
if (_customWordList.Check(word)) return true; | ||
return _wordList.Check(word); | ||
} | ||
|
||
public override ICollection<string> Suggest(string badWord) | ||
{ | ||
var suggestions = _wordList.Suggest(badWord).Union(_customWordList.Suggest(badWord)); | ||
return suggestions.Where(suggestion => !_badWords.Contains(suggestion)).ToArray(); | ||
} | ||
|
||
protected override void SetStatusInternal(string word1, bool isCorrect) | ||
{ | ||
// WeCantSpell does not support modifying the word list, so we have to use 2 and merge them. | ||
if (isCorrect) | ||
{ | ||
var detail = IsVernacular | ||
? new WordEntryDetail(FlagSet.Empty, | ||
MorphSet.Create(new []{SpellingHelper.PrototypeWord}), | ||
WordEntryOptions.None) | ||
: WordEntryDetail.Default; | ||
_customWordsBuilder.Add(word1, detail); | ||
_customWordList = _customWordsBuilder.ToImmutable(); | ||
} | ||
else | ||
{ | ||
_badWords.Add(word1); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters