コード例 #1
0
        /// <summary>
        /// Parses the sentence.
        /// </summary>
        /// <param name="sentence">The sentence to parse.</param>
        private void ParseSentence(string sentence)
        {
            var words = sentence.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            if (words.Length < 2)
            {
                return;
            }

            string lastWord = string.Empty;

            foreach (var word in words)
            {
                bool canBeLast       = word == words.Last();
                bool canBeSecondLast = word == words[words.Length - 2];

                lock (progressSynchronization)
                {
                    SentencePart found = this.wordPairs.FirstOrDefault(part => part.Text == lastWord);

                    if (found != null)
                    {
                        found.Add(word, canBeLast, canBeSecondLast);
                    }
                    else
                    {
                        this.wordPairs.Add(new SentencePart(lastWord, word, canBeLast, canBeSecondLast));
                    }
                }

                lastWord = word;
            }
        }
コード例 #2
0
        /// <summary>
        /// Adds the specified next text.
        /// </summary>
        /// <param name="nextText">The next text.</param>
        /// <param name="canBeLast">part can be a terminator.</param>
        public void Add(string nextText, bool canBeLast, bool canBeSecondLast)
        {
            this.Occurrences++;
            SentencePart found = this.next.FirstOrDefault(part => part.Text == nextText);

            if (found == null)
            {
                this.Next.Add(new SentencePart(nextText, canBeLast, canBeSecondLast));
            }
            else
            {
                found.Occurrences++;
                if (canBeLast)
                {
                    found.CanBeLast = true;
                }
                if (canBeSecondLast)
                {
                    found.CanBeSecondLast = true;
                }
            }
        }