コード例 #1
0
        public void GenerateRandomChapter()
        {
            RandomDocument randDoc = new RandomDocument();
            int            numParagraphsToGenerate  = 3;
            int            numSentencesPerParagraph = 10;

            try
            {
                _msg.Length = 0;
                _msg.Append("GenerateRandomChapter started ...\r\n");
                Program._messageLog.WriteLine(_msg.ToString());

                numParagraphsToGenerate  = Convert.ToInt32(_frm.txtNumParagraphsToOutput.Text);
                numSentencesPerParagraph = Convert.ToInt32(_frm.txtNumSentencesToOutput.Text);

                if (numSentencesPerParagraph < 5)
                {
                    numSentencesPerParagraph = 5;
                }


                string chapter = randDoc.GenerateChapter("Test Program Chapter", numParagraphsToGenerate, numSentencesPerParagraph - 2, numSentencesPerParagraph + 3);



                _msg.Length = 0;
                _msg.Append(chapter);
                Program._messageLog.WriteLine(_msg.ToString());
            }
            catch (System.Exception ex)
            {
                _msg.Length = 0;
                _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex));
                Program._messageLog.WriteLine(_msg.ToString());
                AppMessages.DisplayErrorMessage(_msg.ToString(), _saveErrorMessagesToAppLog);
            }
            finally
            {
                _msg.Length = 0;
                _msg.Append("\r\n... GenerateRandomChapter finished.");
                Program._messageLog.WriteLine(_msg.ToString());
            }
        }
コード例 #2
0
        public void RandomChaptersTest(int numChapters, int minNumParagraphsPerChapter, int maxNumParagraphsPerChapter,
                                       int minNumSentencesPerParagraph, int maxNumSentencesPerParagraph,
                                       string pChapterHeadings)
        {
            RandomNumber   rn            = new RandomNumber();
            RandomDocument rd            = new RandomDocument();
            int            numParagraphs = 0;
            string         chap          = string.Empty;

            string[] chapterHeadings   = null;
            int      chapHeadingInx    = -1;
            int      chapHeadingMaxInx = -1;

            try
            {
                _msg.Length = 0;
                _msg.Append("RandomChaptersTest started ...\r\n");
                Program._messageLog.WriteLine(_msg.ToString());

                if (pChapterHeadings.Trim().Length > 0)
                {
                    chapterHeadings   = pChapterHeadings.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
                    chapHeadingMaxInx = chapterHeadings.Length - 1;
                }

                chapHeadingInx = -1;
                for (int ch = 0; ch < numChapters; ch++)
                {
                    numParagraphs = rn.GenerateRandomInt(minNumParagraphsPerChapter, maxNumParagraphsPerChapter);
                    if (chapterHeadings == null)
                    {
                        _str.Length = 0;
                        _str.Append("Chapter ");
                        _str.Append((ch + 1).ToString());
                        _str.Append(Environment.NewLine);
                        _str.Append(Environment.NewLine);
                        chap = rd.GenerateChapter(numParagraphs, minNumSentencesPerParagraph, maxNumSentencesPerParagraph);
                        _str.Append(chap);
                        chap = _str.ToString();
                    }
                    else
                    {
                        chapHeadingInx++;
                        if (chapHeadingInx > chapHeadingMaxInx)
                        {
                            //More chapters are being generated than there are defined chapter headings
                            _str.Length = 0;
                            _str.Append("Chapter ");
                            _str.Append((ch + 1).ToString());
                            chap = rd.GenerateChapter(_str.ToString(), numParagraphs, minNumSentencesPerParagraph, maxNumSentencesPerParagraph);
                        }
                        else
                        {
                            chap = rd.GenerateChapter(chapterHeadings[chapHeadingInx], numParagraphs, minNumSentencesPerParagraph, maxNumSentencesPerParagraph);
                        }
                    }
                    Program._messageLog.WriteLine(chap);
                }
            }
            catch (System.Exception ex)
            {
                _msg.Length = 0;
                _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex));
                Program._messageLog.WriteLine(_msg.ToString());
                AppMessages.DisplayErrorMessage(_msg.ToString(), _saveErrorMessagesToAppLog);
            }
            finally
            {
                _msg.Length = 0;
                _msg.Append("\r\n... RandomChaptersTest finished.");
                Program._messageLog.WriteLine(_msg.ToString());
            }
        }