Пример #1
0
        public static PunctuationSign FromXElement(XElement x)
        {
            PunctuationSign sign = new PunctuationSign();

            sign.Value = XmlTools.GetStringAttributeValue(x, "Value");
            return(sign);
        }
Пример #2
0
        public static SimplePhrase FromXElement(XElement x)
        {
            SimplePhrase phrase = new SimplePhrase();

            foreach (XElement xItem in x.Elements())
            {
                IPhrasePart phrasePart = null;

                switch (xItem.Name.ToString())
                {
                case "Word":
                    phrasePart = SimpleWord.FromXElement(xItem);
                    break;

                case "PunctuationSign":
                    phrasePart = PunctuationSign.FromXElement(xItem);
                    break;

                default:
                    break;
                }

                if (phrasePart != null)
                {
                    phrase.Parts.Add(phrasePart);
                }
            }

            return(phrase);
        }
Пример #3
0
        /// <summary>
        /// Creates a simple phrase with a given number of words.
        /// </summary>
        /// <param name="words">The words.</param>
        /// <param name="wordLengthDistribution">The word length distribution.</param>
        /// <returns></returns>
        public SimplePhrase CreateSimplePhrase(int nWords, Dictionary <int, int> wordLengthDistribution)
        {
            SimplePhrase sp = new SimplePhrase();

            for (int i = 0; i < nWords; i++)
            {
                SimpleWord sw = GetSimpleWord(wordLengthDistribution);
                sp.Parts.Add(sw);

                if (i < nWords - 1)
                {
                    int             iInnerPunctuation = _randomizerInnerPunctuation.Random();
                    PunctuationSign ps = new PunctuationSign();
                    ps.Value = _innerPunctuation.Keys.ToArray()[iInnerPunctuation];
                    sp.Parts.Add(ps);
                }
            }

            int             iFinalPunctuation = _randomizerFinalPunctuation.Random();
            PunctuationSign psFinal           = new PunctuationSign();

            psFinal.Value = _finalPunctuation.Keys.ToArray()[iFinalPunctuation];

            sp.Parts.Add(psFinal);

            return(sp);
        }