Пример #1
0
        public void T_GetNext_SimpleLongChain()
        {
            ChainGenerator chainGenerator = TestUtils.Create2WordGen(_simpleSentence);
            WordGenerator  wordGenerator  = InitSimpleWordGen();

            wordGenerator.ResetSubchains(new ChainCondition(ck => ck.Words[0] == null && ck.Words[1] == null), null);

            chainGenerator.GenerateChains();
            ChainMap origChains = chainGenerator.Chains;

            StringBuilder sb = new StringBuilder();

            sb.Append(wordGenerator.CurrentWord);
            for (int i = 0; i < 200; i++)
            {
                sb.Append(" ");
                sb.Append(wordGenerator.GetNextWord());
            }

            chainGenerator = TestUtils.Create2WordGen(sb.ToString());
            chainGenerator.GenerateChains();
            ChainMap resultChains = chainGenerator.Chains;

            //When we get to the end we should start from the beginning
            origChains.AddToChain(new ChainKey(new string[] { "two", "?" }), "hello");
            origChains.AddToChain(new ChainKey(new string[] { "?", "hello" }), "world");

            TestUtils.CompareChainTablesNoDuplicates(origChains, resultChains);
        }
Пример #2
0
        /// <summary>
        /// Create a word generator with constant Random seed
        /// </summary>
        /// <returns></returns>
        private WordGenerator InitSimpleWordGen()
        {
            ChainGenerator chainGen =
                new ChainGenerator(_simpleSentence, TestUtils.StandardDelims.ToArray(), 2);

            chainGen.GenerateChains();
            return(new WordGenerator(chainGen.Chains, new Random(1000)));
        }
        public void T_Chains_2()
        {
            ChainGenerator chainGenerator = new ChainGenerator(_advancedChainString, _delims, 2);

            chainGenerator.GenerateChains();

            Dictionary <ChainKey, List <string> > correctChains =
                new Dictionary <ChainKey, List <string> > {
                { new ChainKey(new string[] { null, null }), new List <string> {
                      "words"
                  } },
                { new ChainKey(new string[] { null, "words" }), new List <string> {
                      "from"
                  } },
                { new ChainKey(new string[] { "words", "from" }), new List <string> {
                      ".", "sentence"
                  } },
                { new ChainKey(new string[] { "from", "." }), new List <string> {
                      "sentence"
                  } },
                { new ChainKey(new string[] { ".", "sentence" }), new List <string> {
                      ","
                  } },
                { new ChainKey(new string[] { "sentence", "," }), new List <string> {
                      "will"
                  } },
                { new ChainKey(new string[] { ",", "will" }), new List <string> {
                      "never"
                  } },
                { new ChainKey(new string[] { "will", "never" }), new List <string> {
                      "end"
                  } },
                { new ChainKey(new string[] { "never", "end" }), new List <string> {
                      "?"
                  } },
                { new ChainKey(new string[] { "end", "?" }), new List <string> {
                      "because"
                  } },
                { new ChainKey(new string[] { "?", "because" }), new List <string> {
                      "words"
                  } },
                { new ChainKey(new string[] { "because", "words" }), new List <string> {
                      "from"
                  } },
                { new ChainKey(new string[] { "from", "sentence" }), new List <string> {
                      "is"
                  } },
                { new ChainKey(new string[] { "sentence", "is" }), new List <string> {
                      "good"
                  } },
                { new ChainKey(new string[] { "is", "good" }), new List <string> {
                      "."
                  } }
            };

            TestUtils.CompareChainTables(chainGenerator.Chains, correctChains);
        }