예제 #1
0
        static public string BuildString(TDict t, int len, bool exact)
        {
            string        last;
            List <string> ucStr = new List <string>();
            StringBuilder sb    = new StringBuilder();

            foreach (string word in t.Keys.Skip(1))
            {
                if (char.IsUpper(word.First()))
                {
                    ucStr.Add(word);
                }
            }

            if (ucStr.Count > 0)
            {
                sb.Append(ucStr.ElementAt(Program.r.Next(0, ucStr.Count)));
            }

            last = sb.ToString();
            sb.Append(" ");

            WDict w = new WDict();

            for (uint i = 0; i < len; ++i)
            {
                if (t.ContainsKey(last))
                {
                    w = t[last];
                }
                else
                {
                    w = t[""];
                }

                last = MarkovHelper.Choose(w);
                sb.Append(last.Split(' ').Last()).Append(" ");
            }

            if (!exact)
            {
                while (last.Last() != '.')
                {
                    if (t.ContainsKey(last))
                    {
                        w = t[last];
                    }
                    else
                    {
                        w = t[""];
                    }

                    last = MarkovHelper.Choose(w);
                    sb.Append(last.Split(' ').Last()).Append(" ");
                }
            }

            return(sb.ToString());
        }