예제 #1
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);
        }
예제 #2
0
        public void AddMultipleWords()
        {
            var chain = new MarkovChain();

            chain.AddMultipleWords("A B C");

            var listOfWords = new List <string>();

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

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