public IEnumerable <string> GetOptions(MarkovDatum token, int optionCount)
 {
     if (optionCount <= 0)
     {
         throw new ArgumentException("You must require at least one option.", "optionCount");
     }
     if (token.TrailingTokens.Count <= optionCount) //uncommon token, very few trailing tokens
     {
         foreach (var Trailing in token.TrailingTokens.Keys)
         {
             yield return(Trailing);
         }
     }
     else
     {
         HashSet <string> Options = new HashSet <string>();
         do
         {
             var Option = GetOption(token);
             if (Options.TryAdd(Option))
             {
                 yield return(Option);
             }
         } while (Options.Count < optionCount);
     }
 }
        public string GetOption(MarkovDatum token)
        {
            long   target       = _rand.Next(token.TotalCount);
            string NextTokenKey = token.TrailingTokens.Last().Key;

            foreach (var nextToken in token.TrailingTokens)
            {
                target -= nextToken.Value;
                if (target <= 0)
                {
                    NextTokenKey = nextToken.Key;
                    break;
                }
            }
            return(NextTokenKey);
        }
Exemple #3
0
 public void RecordTrailing(MarkovDatum trailing)
 {
     TrailingTokens[trailing.Name] = (TrailingTokens.ContainsKey(trailing.Name) ? TrailingTokens[trailing.Name] + 1 : 1);
     TotalCount++;
 }