コード例 #1
0
        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());
        }
コード例 #2
0
 public DeepMarkovChain()
 {
     chains = new Dictionary <string, DoubleChain>();
     head   = new DoubleChain()
     {
         text = "[]"
     };
     chains.Add("[]", head);
 }
コード例 #3
0
        public bool readyToGenerate()
        {
            DoubleChain next = head.getNextWord();

            if (next == null)
            {
                return(false);
            }
            return(head.getNextNextWord(next) != null);
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: Remgax/Algoritmusok_2
            public DoubleChain Push(string title)
            {
                DoubleChain link = new DoubleChain(title);

                link.NextChain = first;
                if (first != null)
                {
                    first.PreviousChain = link;
                }
                first = link;
                return(link);
            }
コード例 #5
0
ファイル: Program.cs プロジェクト: Remgax/Algoritmusok_2
            public override string ToString()
            {
                DoubleChain   currentLink = first;
                StringBuilder builder     = new StringBuilder();

                while (currentLink != null)
                {
                    builder.Append(currentLink);
                    currentLink = currentLink.NextChain;
                }
                return(builder.ToString());
            }
コード例 #6
0
 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>());
     }
 }
コード例 #7
0
ファイル: Program.cs プロジェクト: Remgax/Algoritmusok_2
            public DoubleChain Pop()
            {
                DoubleChain temp = first;

                if (first != null)
                {
                    first = first.NextChain;
                    if (first != null)
                    {
                        first.PreviousChain = null;
                    }
                }
                return(temp);
            }
コード例 #8
0
            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);
            }
コード例 #9
0
            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);
            }
コード例 #10
0
 public ChainProbability(DoubleChain c, int co)
 {
     chain = c;
     count = co;
 }
コード例 #11
0
ファイル: Program.cs プロジェクト: Remgax/Algoritmusok_2
 public DoubleChainedList()
 {
     first = null;
 }
コード例 #12
0
 public DeepMarkovChain()
 {
     chains = new Dictionary<string, DoubleChain>();
     head = new DoubleChain() { text = "[]" };
     chains.Add("[]", head);
 }
コード例 #13
0
 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;
 }
コード例 #14
0
 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>());
     }
 }
コード例 #15
0
            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);
            }
コード例 #16
0
 public ChainProbability(DoubleChain c, int co)
 {
     chain = c;
     count = co;
 }