Beispiel #1
0
        private void GetSyllableTypeData(DataGridView dgv, Dictionary <SyllabicType, double> dctData)
        {
            dctData.Clear();
            double dSum = 0;

            foreach (DataGridViewRow row in dgv.Rows)
            {
                double dValue = Convert.ToDouble(row.Cells[1].Value);
                dSum += dValue;
            }

            foreach (DataGridViewRow row in dgv.Rows)
            {
                if (row.Cells[0].Value != null)
                {
                    string       strValue = row.Cells[0].Value.ToString();
                    SyllabicType eKey     = (SyllabicType)Enum.Parse(typeof(SyllabicType), strValue);
                    double       dValue   = Convert.ToDouble(row.Cells[1].Value);

                    try
                    {
                        dctData.Add(eKey, dValue / dSum);
                    }
                    catch (Exception) {}
                }
            }
        }
        public Syllable GetSyllable()
        {
            int          iSyllable    = _randomizerSyllables.Random();
            SyllabicType syllabicType = (SyllabicType)iSyllable;

            switch (syllabicType)
            {
            case SyllabicType.V:
                return(new Syllable(syllabicType, GetVowel()));

            case SyllabicType.CV:
                return(new Syllable(syllabicType, GetConsonant() + GetVowel()));

            case SyllabicType.VC:
                return(new Syllable(syllabicType, GetVowel() + GetConsonant()));

            case SyllabicType.CVC:
                return(new Syllable(syllabicType, GetConsonant() + GetVowel() + GetConsonant()));

            case SyllabicType.Unknown:
            default:
                return(new Syllable());
            }
        }
Beispiel #3
0
 public Syllable(SyllabicType type) : this(type, "")
 {
 }
Beispiel #4
0
 public Syllable(SyllabicType type, string text)
 {
     this.SyllableType = type;
     this.Value        = text;
 }
        public void FromXElement(XElement x)
        {
            this.Name = XmlTools.GetStringAttributeValue(x, "Name");

            XElement xWordLengthDistribution   = x.Element("WordLengthDistribution");
            XElement xPhraseLengthDistribution = x.Element("PhraseLengthDistribution");
            XElement xVowels              = x.Element("Vowels");
            XElement xConsonants          = x.Element("Consonants");
            XElement xSyllables           = x.Element("Syllables");
            XElement xInternalPunctuation = x.Element("InternalPunctuation");
            XElement xFinalPunctuation    = x.Element("FinalPunctuation");

            this._wordLengthDistribution.Clear();
            this._phraseLengthDistribution.Clear();
            this._vowels.Clear();
            this._consonants.Clear();
            this._syllables.Clear();
            this._innerPunctuation.Clear();
            this._finalPunctuation.Clear();

            foreach (XElement xItem in xWordLengthDistribution.Elements("WordLength"))
            {
                try
                {
                    int    value     = Int32.Parse(xItem.Attribute("Value").Value);
                    double frequency = Double.Parse(xItem.Attribute("Frequency").Value);
                    this._wordLengthDistribution.Add(value, frequency);
                }
                catch {}
            }

            foreach (XElement xItem in xPhraseLengthDistribution.Elements("PhraseLength"))
            {
                try
                {
                    int    value     = Int32.Parse(xItem.Attribute("Value").Value);
                    double frequency = Double.Parse(xItem.Attribute("Frequency").Value);
                    this._phraseLengthDistribution.Add(value, frequency);
                }
                catch {}
            }

            foreach (XElement xItem in xVowels.Elements("Vowel"))
            {
                try
                {
                    string value     = xItem.Attribute("Value").Value;
                    double frequency = Double.Parse(xItem.Attribute("Frequency").Value);
                    this._vowels.Add(value, frequency);
                }
                catch {}
            }

            foreach (XElement xItem in xConsonants.Elements("Consonant"))
            {
                try
                {
                    string value     = xItem.Attribute("Value").Value;
                    double frequency = Double.Parse(xItem.Attribute("Frequency").Value);
                    this._consonants.Add(value, frequency);
                }
                catch {}
            }

            foreach (XElement xItem in xSyllables.Elements("Syllable"))
            {
                try
                {
                    SyllabicType type      = (SyllabicType)Enum.Parse(typeof(SyllabicType), xItem.Attribute("Value").Value);
                    double       frequency = Double.Parse(xItem.Attribute("Frequency").Value);
                    this._syllables.Add(type, frequency);
                }
                catch {}
            }

            foreach (XElement xItem in xInternalPunctuation.Elements("Sign"))
            {
                try
                {
                    string value     = xItem.Attribute("Value").Value;
                    double frequency = Double.Parse(xItem.Attribute("Frequency").Value);
                    this._innerPunctuation.Add(value, frequency);
                }
                catch {}
            }

            foreach (XElement xItem in xFinalPunctuation.Elements("Sign"))
            {
                try
                {
                    string value     = xItem.Attribute("Value").Value;
                    double frequency = Double.Parse(xItem.Attribute("Frequency").Value);
                    this._finalPunctuation.Add(value, frequency);
                }
                catch {}
            }

            this.UpdateRandomizers();
        }