Exemplo n.º 1
0
        public Dictionary <string, int> GetWords(string content)
        {
            var result       = new Dictionary <string, int>();
            var stopwordList = new StopwordList().GetGermanStopwords();

            var words = content.Split(' ');

            foreach (var word in words)
            {
                if (string.IsNullOrEmpty(word) || stopwordList.Contains(word.ToLower()))
                {
                    continue;
                }

                if (!result.Keys.Contains(word.ToLower()))
                {
                    result.Add(word.ToLower(), 1);
                }
                else
                {
                    result[word.ToLower()]++;
                }
            }

            return(result.OrderByDescending(x => x.Value).ToDictionary(x => x.Key, y => y.Value));
        }
Exemplo n.º 2
0
        public Dictionary <string, int> GetWords(List <string> sentences, bool removeHtmlTags = false)
        {
            var result       = new Dictionary <string, int>();
            var stopwordList = new StopwordList().GetGermanStopwords();

            foreach (var sentence in sentences)
            {
                var temp = sentence;

                if (removeHtmlTags)
                {
                    temp = RemoveHtmlTags(sentence);
                }

                var words = GetCleanContent(temp).Split(' ');


                foreach (var word in words)
                {
                    if (string.IsNullOrEmpty(word) || stopwordList.Contains(word.ToLower()))
                    {
                        continue;
                    }

                    if (!result.Keys.Contains(word.ToLower()))
                    {
                        result.Add(word.ToLower(), 1);
                    }
                    else
                    {
                        result[word.ToLower()]++;
                    }
                }
            }
            ;

            return(result.OrderByDescending(x => x.Value).ToDictionary(x => x.Key, y => y.Value));
        }