コード例 #1
0
        public void ForEachCircularGraph_DoesNotEnd()
        {
            var chain = new MarkovChain();

            chain.AddWord("A");
            chain.AddWord("B");
            chain.AddWord("A");
            chain.AddWord("C");
            chain.AddWord("A");

            int iterations = 0;

            foreach (var word in chain)
            {
                Debug.Write(string.Concat(word, " "));

                iterations++;

                if (iterations > 100)
                {
                    break;
                }
            }

            Assert.AreEqual(101, iterations);
        }
コード例 #2
0
        public void AddRepeatedWords()
        {
            var chain = new MarkovChain();

            chain.AddWord("A");
            chain.AddWord("B");
            chain.AddWord("A");
            chain.AddWord("C");

            Assert.AreEqual(2, chain.RootNode.Children[0].Children.Count);
            Assert.AreEqual(1, chain.RootNode.Children[0].NodeIndex);
            Assert.AreEqual(3, chain.RootNode.Children[0].Children[1].NodeIndex);
        }
コード例 #3
0
        private List <MarkovChain> GetMarkovChains()
        {
            var sessionObject = System.Web.HttpContext.Current.Application["MarkovChain"];

            if (sessionObject is List <MarkovChain> )
            {
                return(sessionObject as List <MarkovChain>);
            }

            var allDishes = _repository.GetAllDishes();

            var markovChains = new List <MarkovChain>();

            foreach (var dishesGroupedByRestaurant in allDishes.GroupBy(d => d.RestaurantId).OrderBy(g => g.Key))
            {
                var dishes = dishesGroupedByRestaurant.Select(d => d.Description);

                var markov = new MarkovChain();
                dishes.ForEach(txt =>
                {
                    markov.AddMultipleWords(txt);
                    markov.AddWord(".");
                });

                markovChains.Add(markov);
            }

            System.Web.HttpContext.Current.Application.Lock();
            System.Web.HttpContext.Current.Application["MarkovChain"] = markovChains;
            System.Web.HttpContext.Current.Application.UnLock();

            return(markovChains);
        }
コード例 #4
0
        public void ForEachDistinctWords()
        {
            var chain = new MarkovChain();

            chain.AddWord("A");
            chain.AddWord("B");
            chain.AddWord("C");

            var listOfWords = new List <string>();

            foreach (var word in chain)
            {
                listOfWords.Add(word);
            }

            CollectionAssert.AreEqual(new[] { "A", "B", "C" }, listOfWords);
        }