/// <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); }
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); }
public static SimpleWord FromXElement(XElement x) { SimpleWord word = new SimpleWord(); foreach (XElement xSyllable in x.Elements("Syllable")) { word.Syllables.Add(Syllable.FromXElement(xSyllable)); } return(word); }
public SimpleWord GetSimpleWord(int nLength) { SimpleWord sw = new SimpleWord(); while (sw.ToString().Length <= nLength) { Syllable s = GetSyllable(); sw.Syllables.Add(s); } return(sw); }