Exemplo n.º 1
0
        /// <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);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Lookups synonyms for the specified word.
        /// </summary>
        /// <param name="word">
        /// The word to lookup
        /// </param>
        /// <returns>
        /// list of synonyms
        /// </returns>
        public ThesResult Lookup(string word)
        {
            if (this.synonyms.Count == 0)
            {
                throw new InvalidOperationException("Thesaurus not loaded");
            }

            word = word.ToLower();
            ThesMeaning[] meanings;
            lock (this.dictionaryLock)
            {
                if (!this.synonyms.TryGetValue(word, out meanings))
                {
                    return(null);
                }
            }

            var result = new ThesResult(new List <ThesMeaning>(meanings), false);

            return(result);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Lookups synonyms for the specified word.
        /// </summary>
        /// <param name="word">
        /// The word to lookup 
        /// </param>
        /// <returns>
        /// list of synonyms 
        /// </returns>
        public ThesResult Lookup(string word)
        {
            if (this.synonyms.Count == 0)
            {
                throw new InvalidOperationException("Thesaurus not loaded");
            }

            word = word.ToLower();
            ThesMeaning[] meanings;
            lock (this.dictionaryLock)
            {
                if (!this.synonyms.TryGetValue(word, out meanings))
                {
                    return null;
                }
            }

            var result = new ThesResult(new List<ThesMeaning>(meanings), false);
            return result;
        }