private void LoadHunspellDictionaries() { #region #LoadHunspellDictionaries checker.Dictionaries.Clear(); Stream dict_en_US = Assembly.GetExecutingAssembly(). GetManifestResourceStream("SpellingDictionaryExample.Dictionaries.Hunspell.en_US.en_US.dic"); Stream grammar_en_US = Assembly.GetExecutingAssembly(). GetManifestResourceStream("SpellingDictionaryExample.Dictionaries.Hunspell.en_US.en_US.aff"); HunspellDictionary hunspellDictionaryEnglish = new HunspellDictionary(); hunspellDictionaryEnglish.LoadFromStream(dict_en_US, grammar_en_US); hunspellDictionaryEnglish.Culture = new CultureInfo("en-US"); checker.Dictionaries.Add(hunspellDictionaryEnglish); #endregion #LoadHunspellDictionaries Stream dict_es_ES = Assembly.GetExecutingAssembly(). GetManifestResourceStream("SpellingDictionaryExample.Dictionaries.Hunspell.es_ES.es_ANY.dic"); Stream grammar_es_ES = Assembly.GetExecutingAssembly(). GetManifestResourceStream("SpellingDictionaryExample.Dictionaries.Hunspell.es_ES.es_ANY.aff"); HunspellDictionary openOfficeDictionarySpanish = new HunspellDictionary(); openOfficeDictionarySpanish.LoadFromStream(dict_es_ES, grammar_es_ES); openOfficeDictionarySpanish.Culture = new CultureInfo("es-ES"); checker.Dictionaries.Add(openOfficeDictionarySpanish); LoadCustomDictionary(); }
public virtual void Setup(BenchmarkContext context) { var testAssemblyPath = Path.GetFullPath(GetType().Assembly.Location); var filesDirectory = Path.Combine(Path.GetDirectoryName(testAssemblyPath), "files/"); Task.WhenAll( new[] { new Func <Task>(async() => { Checker = await HunspellDictionary.FromFileAsync(Path.Combine(filesDirectory, "English (American).dic")).ConfigureAwait(false); }), new Func <Task>(async() => { Words = new List <string>(); using (var reader = new StreamReader(Path.Combine(filesDirectory, "List_of_common_misspellings.txt"), Encoding.UTF8, true)) { string line; while ((line = await reader.ReadLineAsync().ConfigureAwait(false)) != null) { line = line.Trim(); if (line.Length == 0 || line.StartsWith("#") || line.StartsWith("[")) { continue; } Words.AddRange(line.Split(WordSplitChars, StringSplitOptions.RemoveEmptyEntries)); } } }) } .Select(f => f()) ).Wait(); }
public async Task words_without_suggestions_offer_no_suggestions(string dictionaryFilePath, string word) { var hunspell = await HunspellDictionary.FromFileAsync(dictionaryFilePath); var actual = hunspell.Suggest(word); actual.Should().BeEmpty(); }
public async Task cant_find_wrong_words_in_dictionary(string dictionaryFilePath, string word) { var hunspell = await HunspellDictionary.FromFileAsync(dictionaryFilePath); var checkResult = hunspell.Check(word); checkResult.Should().BeFalse(); }
public void WhenParsingAffFileWithAliases_ThenItWorks() { var dico = new HunspellDictionary( ResourceToFile.RscToStream("Lucene.Net.Analysis.Hunspell.Tests.Content.fr-moderne.aff"), ResourceToFile.RscToStream("Lucene.Net.Analysis.Hunspell.Tests.Content.fr-moderne.dic") ); Assert.True(true); }
public void cant_find_words_in_empty_dictioanry(string word) { var dictionary = new WordList.Builder().ToImmutable(); var hunspell = new HunspellDictionary(dictionary); var actual = hunspell.Check(word); actual.Should().BeFalse(); }
public async Task words_offer_at_least_suggestions_in_any_order(string dictionaryFilePath, string word, string[] expectedSuggestions) { var hunspell = await HunspellDictionary.FromFileAsync(dictionaryFilePath); var actual = hunspell.Suggest(word); actual.Should().NotBeNullOrEmpty(); actual.Should().Contain(expectedSuggestions); }
public async Task can_find_correct_best_suggestion(string dictionaryFilePath, string givenWord, string[] expectedSuggestions) { var hunspell = await HunspellDictionary.FromFileAsync(dictionaryFilePath); var actual = hunspell.Suggest(givenWord); actual.Should().NotBeNullOrEmpty(); actual.ShouldBeEquivalentTo(expectedSuggestions); }
public void Benchmark(BenchmarkContext context) { foreach (var filePair in TestFiles) { var checker = HunspellDictionary.FromFileAsync(filePair.DictionaryFilePath, filePair.AffixFilePath).Result; checker.Check(TestWord); FilePairsLoaded.Increment(); } }
public async Task words_offer_specific_suggestions(string dictionaryFilePath, string word, string[] expectedSuggestions) { var hunspell = await HunspellDictionary.FromFileAsync(dictionaryFilePath); var actual = hunspell.Suggest(word); actual.Should().NotBeNullOrEmpty(); actual.ShouldBeEquivalentTo(expectedSuggestions); }
public async Task checking_large_word_does_not_cause_errors(string filePath) { // attampt to reproduce https://github.com/hunspell/hunspell/issues/446 var largeInput = new string('X', 102); var hunspell = await HunspellDictionary.FromFileAsync(filePath); var actual = hunspell.Check(largeInput); actual.Should().BeFalse(); }
public override void Setup(BenchmarkContext context) { base.Setup(context); var testAssemblyPath = Path.GetFullPath(GetType().Assembly.Location); var filesDirectory = Path.Combine(Path.GetDirectoryName(testAssemblyPath), "files/"); Checker = HunspellDictionary.FromFileAsync(Path.Combine(filesDirectory, "English (American).dic")).Result; WordsChecked = context.GetCounter(nameof(WordsChecked)); }
static void Suggestions() { var hunspell = HunspellDictionary.FromFile("files/English (American).dic"); var words = ReadWords() .Take(500) .ToList(); foreach (var word in words) { var isFound = hunspell.Check(word); var suggestions = hunspell.Suggest(word); } }
static void Checks() { var hunspell = HunspellDictionary.FromFile("files/English (American).dic"); var words = ReadWords().ToList(); for (var i = 0; i < 1000; i++) { foreach (var word in words) { hunspell.Check(word); } } }
public override TokenStream TokenStream(string fieldName, TextReader reader) { TokenStream stream = base.TokenStream(fieldName, reader); using (var affixStream = GenerateStreamFromString(Encoding.UTF8.GetString(Properties.Resources.sk_SK_aff))) using (var dictionaryStream = GenerateStreamFromString(Properties.Resources.sk_SK_dic)) { var dict = new HunspellDictionary(affixStream, dictionaryStream); stream = new HunspellStemFilter(stream, dict); } return(stream); }
static HunspellDictionary CreateHunspellDictionaries(CultureInfo culture) { string[] parts = culture.Name.Split('-'); HunspellDictionary result = new HunspellDictionary(); string uriPath = String.Format("pack://application:,,,/SpellCheckerDemo;component//Data/Dictionaries/{0}/", parts[0]); Stream dictionaryStream = Application.GetResourceStream(new Uri(String.Format("{0}{1}_{2}.dic", uriPath, parts[0], parts[1]))).Stream; Stream grammarStream = Application.GetResourceStream(new Uri(String.Format("{0}{1}_{2}.aff", uriPath, parts[0], parts[1]))).Stream; try { result.LoadFromStream(dictionaryStream, grammarStream); } catch { } finally { dictionaryStream.Close(); grammarStream.Close(); } result.Culture = culture; return(result); }
public void can_find_words_in_single_word_dictioanry(string searchWord, string dictionaryWord) { var expected = searchWord == dictionaryWord; var dictionaryBuilder = new WordList.Builder(); dictionaryBuilder.InitializeEntriesByRoot(1); dictionaryBuilder.EntriesByRoot[dictionaryWord] = WordEntrySet.TakeArray(new[] { new WordEntry( dictionaryWord, FlagSet.Empty, MorphSet.Empty, WordEntryOptions.None) }); var dictionary = dictionaryBuilder.ToImmutable(); var hunspell = new HunspellDictionary(dictionary); var actual = hunspell.Check(searchWord); actual.Should().Be(expected); }
private void LoadHunspellDictionaries() { #region #LoadHunspellDictionaries spellChecker1.Dictionaries.Clear(); HunspellDictionary hunspellDictionaryEnglish = new HunspellDictionary(); hunspellDictionaryEnglish.DictionaryPath = @"Dictionaries\Hunspell\en_US\en_US.dic"; hunspellDictionaryEnglish.GrammarPath = @"Dictionaries\Hunspell\en_US\en_US.aff"; hunspellDictionaryEnglish.Culture = new CultureInfo("en-US"); hunspellDictionaryEnglish.Load(); spellChecker1.Dictionaries.Add(hunspellDictionaryEnglish); #endregion #LoadHunspellDictionaries HunspellDictionary hunspellDictionarySpanish = new HunspellDictionary(); hunspellDictionarySpanish.DictionaryPath = @"Dictionaries\Hunspell\es_ES\es_ANY.dic"; hunspellDictionarySpanish.GrammarPath = @"Dictionaries\Hunspell\es_ES\es_ANY.aff"; hunspellDictionarySpanish.Culture = new CultureInfo("es-ES"); hunspellDictionarySpanish.Load(); spellChecker1.Dictionaries.Add(hunspellDictionarySpanish); LoadCustomDictionary(); }
public DutchAnalyzer() { _dictionary = ContentHelper.Dictionary("nl_NL"); }
protected Task <HunspellDictionary> LoadEnUsAsync() { return(HunspellDictionary.FromFileAsync("files/English (American).dic")); }
public DutchAnalyzer() { _dictionary = HunspellDictionaryLoader.Dictionary("nl_NL"); }