/// <summary> /// Routine to create random documents. /// </summary> /// <param name="numRows">Number of data rows to generate containing random sentences.</param> /// <param name="minNumParagraphs">Minimum number of paragraphs in a data row.</param> /// <param name="maxNumParagraphs">Maximum number of paragraphs in a data row.</param> /// <param name="minNumSentencesPerParagraph">Minimum number of sentences per paragraph.</param> /// <param name="maxNumSentencesPerParagraph">Maximum number of sentences per paragraph.</param> /// <param name="includeDocumentTitle">If true, a line containing a random phrase that serves as document title is included at the beginning of each random document. If false, no title is generated.</param> /// <returns>ADO.NET DataTable containing the random documents.</returns> public DataTable CreateRandomDocumentDataTable(int numRows, string minNumParagraphs, string maxNumParagraphs, string minNumSentencesPerParagraph, string maxNumSentencesPerParagraph, bool includeDocumentTitle) { DataTable dt = new DataTable(); RandomNumber rn = new RandomNumber(); PFRandomWord randWord = new PFRandomWord(); RandomDocument randDocument = new RandomDocument(); StringBuilder title = new StringBuilder(); try { int minimumNumberOfParagraphs = Convert.ToInt32(minNumParagraphs); int maximumNumberOfParagraphs = Convert.ToInt32(maxNumParagraphs); int minimumNumberOfSentencesPerParagraph = Convert.ToInt32(minNumSentencesPerParagraph); int maximumNumberOfSentencesPerParagraph = Convert.ToInt32(maxNumSentencesPerParagraph); DataColumn dc = new DataColumn("RandomValue"); dc.DataType = Type.GetType("System.String"); dt.Columns.Add(dc); for (int i = 0; i < numRows; i++) { DataRow dr = dt.NewRow(); title.Length = 0; if (includeDocumentTitle) { int numWordsInTitle = rn.GenerateRandomInt((int)3, (int)7); for (int t = 0; t < numWordsInTitle; t++) { if (t > 0) { title.Append(" "); } string temp = randWord.GetWord(); temp = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(temp.ToLower()); title.Append(temp); } } int numParagraphs = rn.GenerateRandomInt(minimumNumberOfParagraphs, maximumNumberOfParagraphs); string str = randDocument.GenerateDocument(numParagraphs, minimumNumberOfSentencesPerParagraph, maximumNumberOfSentencesPerParagraph, title.ToString()); dr[0] = str; dt.Rows.Add(dr); } } catch (System.Exception ex) { _msg.Length = 0; _msg.Append("Error in CreateRandomDocumentDataTable routine.\r\n"); _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex)); throw new System.Exception(_msg.ToString()); } finally { ; } return(dt); }
/// <summary> /// Creates DataTable containing list of random words. /// </summary> /// <param name="numRows">Number of rows containg random words to generate.</param> /// <param name="minNumWords">Minimum number of random words per row.</param> /// <param name="maxNumWords">Maximum number of random words per row.</param> /// <param name="randWordOutputFormat">Format for the random words (upper and lower case formats).</param> /// <returns>ADO.NET DataTable.</returns> public DataTable CreateRandomWordsDataTable(int numRows, string minNumWords, string maxNumWords, enRandomWordOutputFormat randWordOutputFormat) { DataTable dt = new DataTable(); RandomNumber rn = new RandomNumber(); PFRandomWord randWord = new PFRandomWord(); StringBuilder words = new StringBuilder(); try { int minimumNumberOfWords = Convert.ToInt32(minNumWords); int maximumNumberOfWords = Convert.ToInt32(maxNumWords); DataColumn dc = new DataColumn("RandomValue"); dc.DataType = Type.GetType("System.String"); dt.Columns.Add(dc); for (int i = 0; i < numRows; i++) { DataRow dr = dt.NewRow(); int numWords = rn.GenerateRandomInt(minimumNumberOfWords, maximumNumberOfWords); words.Length = 0; for (int s = 0; s < numWords; s++) { string str = randWord.GetWord(); switch (randWordOutputFormat) { case enRandomWordOutputFormat.enUCLC: if (str.Length > 1) { str = str.Substring(0, 1).ToUpper() + str.Substring(1, str.Length - 1); } else { str = str.Substring(0, 1).ToUpper(); } break; case enRandomWordOutputFormat.enLC: str = str.ToLower(); break; case enRandomWordOutputFormat.enUC: str = str.ToUpper(); break; default: break; } words.Append(str); words.Append(" "); } dr[0] = words.ToString(); dt.Rows.Add(dr); } } catch (System.Exception ex) { _msg.Length = 0; _msg.Append("Error in CreateRandomStringsDataTable routine.\r\n"); _msg.Append(AppGlobals.AppMessages.FormatErrorMessage(ex)); throw new System.Exception(_msg.ToString()); } finally { ; } return(dt); }