Ejemplo n.º 1
0
        public IEnumerable <SentenceWord> Analyse(string sentence)
        {
            var words = new List <SentenceWord>();

            var sentenceWords = sentence.Split(Convert.ToChar(" "));

            for (var wordIndex = 0; wordIndex < sentenceWords.Count(); wordIndex++)
            {
                var wordInSentence = sentenceWords[wordIndex];

                var isFirstWord = sentenceWords.First() == wordInSentence;
                var isLastWord  = sentenceWords.Last() == wordInSentence;

                var sentenceWord  = new SentenceWord(wordInSentence, isFirstWord, isLastWord);
                var nextWordIndex = wordIndex + 1;

                if (nextWordIndex < sentenceWords.Count())
                {
                    sentenceWord.AddPossibleFollowingWord(sentenceWords[wordIndex + 1]);
                }

                words.Add(sentenceWord);
            }

            return(words);
        }
Ejemplo n.º 2
0
        public void ManageWord(SentenceWord sentenceWord)
        {
            var word = sentenceWord.Word;

            if (words.ContainsKey(word))
            {
                var existingWord = words[word];

                existingWord.CanStartSentence = existingWord.CanStartSentence ? existingWord.CanStartSentence : sentenceWord.CanStartSentence;
                existingWord.CanEndSentence   = existingWord.CanEndSentence ? existingWord.CanEndSentence : sentenceWord.CanEndSentence;

                foreach (var followingWord in sentenceWord.GetPossibleFollowingWords())
                {
                    existingWord.AddPossibleFollowingWord(followingWord);
                }

                words[word] = existingWord;
            }
            else
            {
                words.Add(word, sentenceWord);
            }
        }