Example #1
0
        public ActionResult LoremIpsum()
        {
            Dialect dialect = Dialect.LooseyGoosey;

            dialect.IncludeApocrypha = false;
            TextGenerator   tg        = new TextGenerator(dialect);
            List <Sentence> sentences = new List <Sentence>();

            for (int i = 0; i < 1000; i++)
            {
                Sentence s = tg.GenerateSentence();
                sentences.Add(s);
            }
            StringBuilder spitBackSb = new StringBuilder();
            StringBuilder bracketSb  = new StringBuilder();
            StringBuilder posSb      = new StringBuilder();
            StringBuilder glossSb    = new StringBuilder();
            StringBuilder colorized  = new StringBuilder();
            StringBuilder errors     = new StringBuilder();
            HtmlFormatter hf         = new HtmlFormatter();

            StringBuilder sb = new StringBuilder();

            foreach (Sentence s in sentences)
            {
                Sentence parsedSentence = s;
                string   normalized;
                //////// TP
                try
                {
                    normalized = parsedSentence.ToString("g", dialect);
                    spitBackSb.AppendLine(normalized.ToHtml() + "<br/>");
                }
                catch (Exception ex)
                {
                    string error = "[[CANNOT REPEAT BACK:  " + ex.Message + "]]";
                    spitBackSb.AppendLine(hf.BoldTheWords(error.ToHtml()) + "<br/>");
                    errors.Append(error);
                }

                try
                {
                    string result = parsedSentence.ToString("html", dialect);
                    //if (result.Replace("<span", "").Contains("<"))
                    //{
                    //    throw new InvalidOperationException("No HTML allowed in input");
                    //}
                    colorized.AppendLine(result + "<br/>");
                }
                catch (Exception ex)
                {
                    string error = "[[CANNOT COLORIZE:  " + ex.Message + "]]";
                    spitBackSb.AppendLine(hf.BoldTheWords(error.ToHtml()) + "<br/>");
                    errors.Append(error);
                }

                //////// TP
                try
                {
                    string diagrammed = parsedSentence.ToString("b", dialect);
                    bracketSb.AppendLine(hf.BoldTheWords(diagrammed.ToHtml()) + "<br/>");
                }
                catch (Exception ex)
                {
                    string error = "[[CANNOT BRACKET:  " + ex.Message + "]]";
                    bracketSb.AppendLine(hf.BoldTheWords(error.ToHtml()) + "<br/>");
                    errors.Append(error);
                }


                //////// ENGLISH
                try
                {
                    dialect.TargetGloss = "en";
                    GlossMaker gm      = new GlossMaker();
                    string     glossed = gm.GlossOneSentence(false, s, dialect);
                    glossSb.AppendLine(glossed.ToHtml() + "<br/>");
                    glossed = gm.GlossOneSentence(true, s, dialect);
                    posSb.AppendLine(glossed.ToHtml() + "<br/>"); //bs doesn't do anything.
                }
                catch (Exception ex)
                {
                    string error = "[[CANNOT GLOSS:  " + ex.Message.ToHtml() + "]]";
                    glossSb.AppendLine(hf.BoldTheWords(error.ToHtml()) + "<br/>");
                    errors.Append(error);
                }


                sb.Append(colorized.ToString());
                //sb.Append("<br/>");
                sb.Append(bracketSb.ToString());
                //sb.Append("<br/>");
                sb.Append(glossSb.ToString());
                sb.Append(hf.SubThePartsOfSpeech(posSb.ToString()));
                //sb.Append("<br/>");
                sb.Append("<br/>");

                spitBackSb.Clear();
                bracketSb.Clear();
                posSb.Clear();
                glossSb.Clear();
                colorized.Clear();
            }

            return(View(new LoremIpsumModel {
                Html = sb.ToString()
            }));
        }