Beispiel #1
0
        public string GenerateSentence()
        {
            if (WordModelsNotNullOrEmpty())
            {
                IWordModel currentWord    = GetRandomWord();
                string     returnSentence = currentWord.Word;

                for (int i = 0; i < 10; ++i)
                {
                    string[] wordPool = null;
                    wordPool = GenerateWordPool(currentWord);
                    while (wordPool?.Length == 0)
                    {
                        currentWord = GetRandomWord();
                        wordPool    = GenerateWordPool(currentWord);
                    }

                    string chosenWord = wordPool[rand.Next(0, wordPool.Length)];
                    returnSentence += " " + chosenWord;
                    currentWord     = GetNextWordModel(chosenWord);
                }

                return(returnSentence);
            }
            return(null);
        }
Beispiel #2
0
        private string[] GenerateWordPool(IWordModel word)
        {
            List <string> wordPool = new List <string>();

            foreach (KeyValuePair <string, int> wordAndOccurance in word.WordAndOccurance)
            {
                for (int i = 0; i < wordAndOccurance.Value; ++i)
                {
                    wordPool.Add(wordAndOccurance.Key);
                }
            }
            return(wordPool.ToArray());
        }
 internal SearchHandler(IWordModel wordModel, Func <IList <string>, Task> searcher, Func <Task> resetter)
 {
     Model        = wordModel;
     SearchAction = searcher;
     ResetAction  = resetter;
 }
 internal WordHandler(IWordModel WordModel, Func <IList <string>, Task> searcher, Func <Task> resetter)
 {
     this.WordModel     = WordModel;
     SearchBehaviors    = new SearchHandler(WordModel, searcher, resetter);
     SuggestionIterator = new SuggestionIterator(this.WordModel.AvailableWordList.ToList());
 }