コード例 #1
0
        public void Chain_WithRestrictiveMaximumOrder_DoesntAlwaysQuoteCorpus()
        {
            var chainWithBackoff = new MarkovChainWithBackoff <char>(5, 2);

            chainWithBackoff.Add("fool");
            var deterministicRand = new Random(0);
            var resultWithBackoff = string.Join("", chainWithBackoff.Chain(deterministicRand));

            Assert.Equal("fol", resultWithBackoff);
        }
コード例 #2
0
        static string GenerateQuoteWithBackoff()
        {
            Random rand = new Random();

            // Order 3 is the highest order that actually makes a meaningful difference.
            // Targeting 2 next states seems like it hits a balance of high and low orders.
            MarkovChainWithBackoff <string> chain = GetChainWithBackoff(3, 2);

            IEnumerable <string> result = chain.Chain(rand);
            string generatedQuote       = string.Join(" ", result);

            return(TruncateQuote(generatedQuote));
        }