Esempio n. 1
0
        public List <string> WordNetSynonymsList(List <string> query)
        {
            List <string> WordNetSynonymsList = new List <string>();

            foreach (string term in query)
            {
                string[] a = Lexicon.FindSynonyms(term, PartsOfSpeech.Noun, true);
                if (a != null)
                {
                    WordNetSynonymsList.AddRange(a);
                }
                string[] b = Lexicon.FindSynonyms(term, PartsOfSpeech.Verb, true);
                if (b != null)
                {
                    WordNetSynonymsList.AddRange(b);
                }
                string[] c = Lexicon.FindSynonyms(term, PartsOfSpeech.Adj, true);
                if (c != null)
                {
                    WordNetSynonymsList.AddRange(c);
                }
                WordNetSynonymsList = WordNetSynonymsList.Take(2).ToList();
                foreach (var VARIABLE in WordNetSynonymsList)
                {
                    VARIABLE.Trim(' ');
                }
            }
            return(WordNetSynonymsList.Distinct().ToList());
        }
Esempio n. 2
0
        /// <summary>
        /// method which updates the current query with semantic words
        /// </summary>
        /// <param name="query">content of query</param>
        /// <returns>new query with semantics</returns>
        private string UpdateQueryBySemantics(string query)
        {
            string[]      wordsBeforeSemantic, adjWords, advWords, nounWords, verbWords;
            StringBuilder extendQuery = new StringBuilder();

            wordsBeforeSemantic = query.Split(' ');
            for (int i = 0; i < wordsBeforeSemantic.Length; i++)
            {
                adjWords  = Lexicon.FindSynonyms(wordsBeforeSemantic[i], Wnlib.PartsOfSpeech.Adj, false);
                advWords  = Lexicon.FindSynonyms(wordsBeforeSemantic[i], Wnlib.PartsOfSpeech.Adv, false);
                nounWords = Lexicon.FindSynonyms(wordsBeforeSemantic[i], Wnlib.PartsOfSpeech.Noun, false);
                verbWords = Lexicon.FindSynonyms(wordsBeforeSemantic[i], Wnlib.PartsOfSpeech.Verb, false);
                extendQuery.Append(updateByPartOfSpeech(adjWords));
                extendQuery.Append(updateByPartOfSpeech(advWords));
                extendQuery.Append(updateByPartOfSpeech(nounWords));
                extendQuery.Append(updateByPartOfSpeech(verbWords));
            }
            return(extendQuery.ToString());
        }
Esempio n. 3
0
        /// <summary>
        /// Gets all synonyms of the given word in the given part of speech and finds the most complex word in the set.
        /// Uses WordNet as thesaurus and weighted scores to determine which is most complex.
        /// </summary>
        /// <param name="word">Word to get synonyms of.</param>
        /// <param name="pos">Part of speech of the given word. Used to find more accurate synonyms.</param>
        /// <returns>The most complex synonym of the given word in the given part of speech.</returns>
        public static string GetMostComplexSynyonymScoredWN(string word, Wnlib.PartsOfSpeech pos)
        {
            // TODO: Lemmatization?

            if (pos == Wnlib.PartsOfSpeech.Unknown)
            {
                // We're gonna have some serious problems (namely, a NullReferenceException) if we don't back out of this right now.
                return(word);
            }

            string[] synonymsArr = Lexicon.FindSynonyms(word, pos, false);

            if (synonymsArr == null || synonymsArr.Length == 0)
            {
                return(word);
            }

            List <string> synonyms            = new List <string>(synonymsArr);
            string        mostComplexSynyonym = "";
            double        mostComplexScore    = 0.0;

            #region Synonym collection setup
            if (!synonyms.Contains <string>(word))
            {
                synonyms.Add(word);
            }
            #endregion

            #region Most complex synonym find
            foreach (string cs in synonyms)
            {
                double csScore = WordRater.GetTotalScore(cs);
                if (mostComplexSynyonym == "" || csScore > mostComplexScore)
                {
                    mostComplexSynyonym = cs;
                    mostComplexScore    = csScore;
                }
            }
            #endregion

            return(mostComplexSynyonym);
        }