internal List <ChainProbability> getPossibleNextWords(string[] words) { List <ChainProbability> results = new List <ChainProbability>(); if (words.Length == 0) { foreach (string key in nextNodes.Keys) { results.Add(nextNodes[key]); } return(results); } ChainProbability currentChain = nextNodes[words[0]]; for (int i = 1; i < words.Length; i++) { currentChain = currentChain.getNextNode(words[i]); } foreach (string key in currentChain.nextNodes.Keys) { results.Add(currentChain.nextNodes[key]); } return(results); }
internal void addWords(Chain[] c, int count = 1) { if (c.Length == 0) { throw new ArgumentException("The array of chains passed in is of zero length."); } if (c.Length == 1) { this.fullCount += count; if (!this.nextNodes.ContainsKey(c[0].text)) { this.nextNodes.Add(c[0].text, new ChainProbability(c[0], count)); } else { this.nextNodes[c[0].text].count += count; } return; } ChainProbability nextChain = nextNodes[c[0].text]; for (int i = 1; i < c.Length - 1; i++) { nextChain = nextChain.getNextNode(c[i].text); } nextChain.addWord(c[c.Length - 1], count); }
internal Chain getNextWord(string[] words) { ChainProbability currentChain = nextNodes[words[0]]; for (int i = 1; i < words.Length; i++) { currentChain = currentChain.getNextNode(words[i]); } List <string> list = new List <string>(); foreach (string key in currentChain.nextNodes.Keys) { for (int i = 0; i < currentChain.nextNodes[key].count; i++) { list.Add(key); } } return(currentChain.nextNodes[list[RandomHandler.random.Next(list.Count)]].chain); }
internal Chain getNextWord(string[] words) { ChainProbability currentChain = nextNodes[words[0]]; for (int i = 1; i < words.Length; i++) { currentChain = currentChain.getNextNode(words[i]); } int currentCount = RandomHandler.random.Next(currentChain.count) + 1; foreach (string key in currentChain.nextNodes.Keys) { currentCount -= currentChain.nextNodes[key].count; if (currentCount <= 0) { return(currentChain.nextNodes[key].chain); } } return(null); }