예제 #1
0
        protected int MakeSentencesCount(List <string> Text, TokenType Type, SentencesType SType)
        {
            int sentences = 0;

            switch (SType)
            {
            case SentencesType.Random:
            {
                sentences = this.Random.Next((this.Settings as TextSettings).SentencesMin,
                                             (this.Settings as TextSettings).SentencesMax);

                switch (Type)
                {
                case TokenType.Mini:
                {
                    sentences /= 2;
                    break;
                }

                case TokenType.Micro:
                {
                    sentences /= 5;
                    break;
                }
                }

                break;
            }

            case SentencesType.Step:
            {
                sentences = Text.Count / (this.Settings as TextSettings).SentencesLength;
                break;
            }
            }

            return(sentences);
        }
예제 #2
0
        protected void MakeSentences(List <string> Text, TokenType Type, SentencesType SType)
        {
            int position = 0;

            int sentences = this.MakeSentencesCount(Text, Type, SType);

            string[] marks = (this.Settings as TextSettings).PunctuationMarksList
                             .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            for (int i = 0; i < sentences; i++)
            {
                switch (SType)
                {
                case SentencesType.Random:
                {
                    if (!Text[position].Contains(StringContainsType.Any, ".", "?", "!"))
                    {
                        position = this.Random.Next(Text.Count);

                        // Search for punctuation marks
                        if ((this.Settings as TextSettings).PunctuationMarks)
                        {
                            if (Text[position].Contains(StringContainsType.Any, marks))
                            {
                                continue;
                            }
                        }
                    }

                    break;
                }

                case SentencesType.Step:
                {
                    position += (this.Settings as TextSettings).SentencesLength;

                    // Infelicity
                    position += ((this.Random.Next(0, 2) == 0) ? 1 : -1) *
                                (this.Settings as TextSettings).SentencesLengthInfelicity;

                    if (!Text[position].Contains(StringContainsType.Any, ".", "!", "?"))
                    {
                        // Search for punctuation marks
                        if ((this.Settings as TextSettings).PunctuationMarks)
                        {
                            if (Text[position].Contains(StringContainsType.Any, marks))
                            {
                                continue;
                            }
                        }
                    }

                    break;
                }
                }

                if (Text[position].Contains(StringContainsType.Any, ".", "!", "?"))
                {
                    continue;
                }

                string mark = ".";
                switch (this.Random.Next(10))
                {
                case 0:
                {
                    mark = "!";
                    break;
                }

                case 1:
                {
                    mark = "?";
                    break;
                }
                }

                if (Text[position].EndsWith("</p>"))
                {
                    Text[position] = Text[position].Substring(0, Text[position].Length - 4) + mark + "</p>";
                }
                else
                {
                    Text[position] += mark;
                }
            }
        }