コード例 #1
0
        public FullAnalysisResult Analyze(string input)
        {
            var result  = new FullAnalysisResult();
            var stemmer = new Porter2();

            var wordSplit     = input.Split(new[] { ' ', ',', '"', ':' }, StringSplitOptions.RemoveEmptyEntries);
            var sentenceIndex = 0;

            foreach (var word in wordSplit)
            {
                Action nextSentenceIndexIfApplicable = () => { };
                var    currentWord = word.ToLowerInvariant();

                if (currentWord.EndsWith("."))
                {
                    currentWord = word.Remove(word.Length - 1, 1);
                    nextSentenceIndexIfApplicable = () => { sentenceIndex++; };

                    if (String.IsNullOrWhiteSpace(currentWord))
                    {
                        nextSentenceIndexIfApplicable();
                        continue;
                    }
                }

                if (WordExceptions.Contains(currentWord))
                {
                    continue;
                }

                var stem = stemmer.Stem(currentWord);

                result.LogOccurrence(stem, sentenceIndex);
                nextSentenceIndexIfApplicable();
            }

            return(result);
        }
コード例 #2
0
        private void AssertWord(string testWord, string expectedResult)
        {
            var result = subject.Stem(testWord);

            Assert.AreEqual(expectedResult, result, "Test: '{0}'. Expected '{1}' but got '{2}' .", testWord, expectedResult, result);
        }