/// <summary> /// Generates the specified word by example. /// </summary> /// <param name="word"> /// The word. /// </param> /// <param name="sample"> /// The sample. /// </param> /// <returns> /// List of generated words, one per word stem /// </returns> public List <string> Generate(string word, string sample) { if (this.IsDisposed) { throw new ObjectDisposedException("SpellFactory"); } if (this.hunspells == null) { throw new InvalidOperationException("Hunspell Dictionary isn't loaded"); } this.hunspellSemaphore.WaitOne(); Hunspell current = null; try { current = this.hunspells.Pop(); return(current.Generate(word, sample)); } finally { if (current != null) { this.hunspells.Push(current); } this.hunspellSemaphore.Release(); } }
/// <summary> /// Lookups the specified word with word stemming and generation /// </summary> /// <param name="word"> /// The word. /// </param> /// <param name="stemming"> /// The <see cref="Hunspell"/> object for stemming and generation. /// </param> /// <returns> /// The <see cref="ThesResult"/>. /// </returns> public ThesResult Lookup(string word, Hunspell stemming) { if (this.synonyms.Count == 0) { throw new InvalidOperationException("Thesaurus not loaded"); } ThesResult result = this.Lookup(word); if (result != null) { return(result); } List <string> stems = stemming.Stem(word); if (stems == null || stems.Count == 0) { return(null); } var meanings = new List <ThesMeaning>(); foreach (var stem in stems) { ThesResult stemSynonyms = this.Lookup(stem); if (stemSynonyms != null) { foreach (var meaning in stemSynonyms.Meanings) { var currentSynonyms = new List <string>(); foreach (var synonym in meaning.Synonyms) { List <string> generatedSynonyms = stemming.Generate(synonym, word); foreach (var generatedSynonym in generatedSynonyms) { currentSynonyms.Add(generatedSynonym); } } if (currentSynonyms.Count > 0) { meanings.Add(new ThesMeaning(meaning.Description, currentSynonyms)); } } } } if (meanings.Count > 0) { return(new ThesResult(meanings, true)); } return(null); }
/// <summary> /// Generates the specified word by example. /// </summary> /// <param name="word"> /// The word. /// </param> /// <param name="sample"> /// The sample. /// </param> /// <returns> /// List of generated words, one per word stem /// </returns> public List <string> Generate(string word, string sample) { Hunspell hunspell = this.HunspellsPop(); try { return(hunspell.Generate(word, sample)); } finally { this.HunspellsPush(hunspell); } }
/// <summary> /// Lookups the specified word with word stemming and generation /// </summary> /// <param name="word"> /// The word. /// </param> /// <param name="stemming"> /// The <see cref="Hunspell"/> object for stemming and generation. /// </param> /// <returns> /// The <see cref="ThesResult"/>. /// </returns> public ThesResult Lookup(string word, Hunspell stemming) { if (this.synonyms.Count == 0) { throw new InvalidOperationException("Thesaurus not loaded"); } ThesResult result = this.Lookup(word); if (result != null) { return result; } List<string> stems = stemming.Stem(word); if (stems == null || stems.Count == 0) { return null; } var meanings = new List<ThesMeaning>(); foreach (var stem in stems) { ThesResult stemSynonyms = this.Lookup(stem); if (stemSynonyms != null) { foreach (var meaning in stemSynonyms.Meanings) { var currentSynonyms = new List<string>(); foreach (var synonym in meaning.Synonyms) { List<string> generatedSynonyms = stemming.Generate(synonym, word); foreach (var generatedSynonym in generatedSynonyms) { currentSynonyms.Add(generatedSynonym); } } if (currentSynonyms.Count > 0) { meanings.Add(new ThesMeaning(meaning.Description, currentSynonyms)); } } } } if (meanings.Count > 0) { return new ThesResult(meanings, true); } return null; }