Esempio n. 1
0
        public void Train(string text)
        {
            //RingBuffer buffer = new RingBuffer(_depth);
            IEnumerable <string> tokens     = Tokenizer.Tokenize(text);
            IEnumerator <string> enumerator = tokens.GetEnumerator();

            enumerator.MoveNext();
            string token = enumerator.Current;

            SimpleStringMarkovNode currentNode = GetNode(token);

            while (enumerator.MoveNext())
            {
                // Get the next node.
                token = enumerator.Current;
                SimpleStringMarkovNode node = GetNode(token);

                // Point the current node to the next node

                //string key = buffer.GetKey();
                string key = token;
                //currentNode.AddNext(buffer.GetAll().ToList(), key);
                currentNode.AddNext(token);
                //buffer.Add(token);

                // Update the current node
                currentNode = node;
            }
        }
Esempio n. 2
0
        private IEnumerable <string> GenerateSentenceInternalFrom(SimpleStringMarkovNode start)
        {
            //RingBuffer buffer = new RingBuffer(_depth);
            SimpleStringMarkovNode current = start;

            //buffer.Add(start.Value);
            while (true)
            {
                // TODO: If the character is a quote, comma or semi-colon, the previous word should
                // be used instead
                //string nextKey = current.GetRandomNext(buffer.GetAll().ToList());
                string nextKey = current.GetRandomNext();
                if (nextKey == Constants.SentenceBreak || nextKey == Constants.ParagraphBreak || nextKey == Constants.TextEnd)
                {
                    break;
                }

                string word = nextKey.Split('|').First();

                yield return(word);

                //buffer.Add(word);
                //string key = buffer.GetKey();
                string key = word;
                current = GetNode(key);
            }
        }
Esempio n. 3
0
        public string GenerateSentence()
        {
            SimpleStringMarkovNode node = GetNode(Constants.SentenceStart);

            while (true)
            {
                List <string> s = GenerateSentenceInternalFrom(node).ToList();
                if (s.Count < 3)
                {
                    continue;
                }

                //s[0] = Capitalize(s[0]);

                return(string.Join(" ", s));
            }
        }