getStems() public method

public getStems ( string word ) : List
word string
return List
示例#1
0
        /// <summary>
        /// Get all possible stems for each word in the string
        /// </summary>
        /// <param name="question">String (question) to find its words stems</param>
        /// <returns>Dictionary of each word and its stems</returns>
        public Dictionary <string, List <string> > GetStemmedWords(string question)
        {
            //Dictionary to hold word and a list of its stemmed words.
            Dictionary <string, List <string> > stemmedWords = new Dictionary <string, List <string> >();

            //Create Language class object to use its stemming method
            Language Stemmer = new Language();

            //Temp list of strings to hold intermediate results
            List <string> tempStemmedWords;

            //Trimming the string
            question = question.Trim();
            //Removing Extra spaces
            while (question.Contains("  "))
            {
                question = question.Replace("  ", " ");
            }

            //parsing the input string
            List <string> input = new List <string>();

            input = question.Split(' ').ToList <string>();

            foreach (string word in input)
            {
                tempStemmedWords = Stemmer.getStems(word);

                if (tempStemmedWords.Contains(word))
                {
                    tempStemmedWords.Remove(word);
                }

                if (tempStemmedWords.Count > 0)
                {
                    stemmedWords.Add(word, tempStemmedWords);
                }
            }

            return(stemmedWords);
        }
示例#2
0
        /// <summary>
        /// Get all possible stems for each word in the string
        /// </summary>
        /// <param name="question">String (question) to find its words stems</param>
        /// <returns>Dictionary of each word and its stems</returns>
        public Dictionary<string, List<string>> GetStemmedWords(string question)
        {
            //Dictionary to hold word and a list of its stemmed words.
            Dictionary<string, List<string>> stemmedWords = new Dictionary<string, List<string>>();

            //Create Language class object to use its stemming method
            Language Stemmer = new Language();

            //Temp list of strings to hold intermediate results
            List<string> tempStemmedWords;

            //Trimming the string
            question = question.Trim();
            //Removing Extra spaces
            while (question.Contains("  "))
                question = question.Replace("  ", " ");

            //parsing the input string
            List<string> input = new List<string>();
            input = question.Split(' ').ToList<string>();

            foreach (string word in input)
            {
                tempStemmedWords = Stemmer.getStems(word);

                if(tempStemmedWords.Contains(word))
                {
                    tempStemmedWords.Remove(word);
                }

                if (tempStemmedWords.Count > 0)
                {
                    stemmedWords.Add(word, tempStemmedWords);
                }
            }

            return stemmedWords;
        }