public string generateSentence() { StringBuilder s = new StringBuilder(); DoubleChain currentString = head.getNextWord(); if (currentString == null) { return(generateSentence()); } DoubleChain nextString = head.getNextNextWord(currentString); DoubleChain nextNextString = currentString.getNextNextWord(nextString); s.Append(currentString.text); s.Append(" "); s.Append(nextString.text); while (nextNextString.text != "!" && nextNextString.text != "?" && nextNextString.text != ".") { s.Append(" "); s.Append(nextNextString.text); currentString = nextString; nextString = nextNextString; nextNextString = currentString.getNextNextWord(nextString); if (nextNextString == null) { break; } } s.Append(nextNextString.text); //Add punctuation s[0] = char.ToUpper(s[0]); return(s.ToString()); }
public DeepMarkovChain() { chains = new Dictionary <string, DoubleChain>(); head = new DoubleChain() { text = "[]" }; chains.Add("[]", head); }
public bool readyToGenerate() { DoubleChain next = head.getNextWord(); if (next == null) { return(false); } return(head.getNextNextWord(next) != null); }
public DoubleChain Push(string title) { DoubleChain link = new DoubleChain(title); link.NextChain = first; if (first != null) { first.PreviousChain = link; } first = link; return(link); }
public override string ToString() { DoubleChain currentLink = first; StringBuilder builder = new StringBuilder(); while (currentLink != null) { builder.Append(currentLink); currentLink = currentLink.NextChain; } return(builder.ToString()); }
public void addWord(DoubleChain c) { fullCount++; if (nextNodes.ContainsKey(c.text)) { nextNodes[c.text].count++; } else { nextNodes.Add(c.text, new ChainProbability(c, 1)); nextNextNodes.Add(c.text, new Dictionary <string, ChainProbability>()); } }
public DoubleChain Pop() { DoubleChain temp = first; if (first != null) { first = first.NextChain; if (first != null) { first.PreviousChain = null; } } return(temp); }
public void addNextWord(DoubleChain n, DoubleChain nn) { Dictionary <string, ChainProbability> d = nextNextNodes[n.text]; if (d.ContainsKey(nn.text)) { d[nn.text].count++; } else { d.Add(nn.text, new ChainProbability(nn, 1)); } //Add to n as a normal word n.addWord(nn); }
public DoubleChain getNextNextWord(DoubleChain c) { Dictionary <string, ChainProbability> d = nextNextNodes[c.text]; int fullCount = 0; foreach (string key in d.Keys) { fullCount += d[key].count; } int currentCount = RandomHandler.random.Next(fullCount); foreach (string key in d.Keys) { for (int i = 0; i < d[key].count; i++) { if (currentCount == 0) { return(d[key].chain); } currentCount--; } } return(null); }
public ChainProbability(DoubleChain c, int co) { chain = c; count = co; }
public DoubleChainedList() { first = null; }
public DeepMarkovChain() { chains = new Dictionary<string, DoubleChain>(); head = new DoubleChain() { text = "[]" }; chains.Add("[]", head); }
public DoubleChain getNextNextWord(DoubleChain c) { Dictionary<string, ChainProbability> d = nextNextNodes[c.text]; int fullCount = 0; foreach (string key in d.Keys) fullCount += d[key].count; int currentCount = RandomHandler.random.Next(fullCount); foreach (string key in d.Keys) { for (int i = 0; i < d[key].count; i++) { if (currentCount == 0) return d[key].chain; currentCount--; } } return null; }
public void addWord(DoubleChain c) { fullCount++; if (nextNodes.ContainsKey(c.text)) nextNodes[c.text].count++; else { nextNodes.Add(c.text, new ChainProbability(c, 1)); nextNextNodes.Add(c.text, new Dictionary<string, ChainProbability>()); } }
public void addNextWord(DoubleChain n, DoubleChain nn) { Dictionary<string, ChainProbability> d = nextNextNodes[n.text]; if(d.ContainsKey(nn.text)) d[nn.text].count++; else d.Add(nn.text, new ChainProbability(nn, 1)); //Add to n as a normal word n.addWord(nn); }