Пример #1
0
        public SyllabicOutput CreateSyllables(string Word)
        {
            string         FirstChar    = string.Empty;
            string         LastChar     = String.Empty;
            bool           hasFirstSyll = false;
            bool           hasLastSyll  = false;
            SyllabicOutput objSyllable  = new SyllabicOutput();
            string         glyphForm    = ConvertToGlyph.Glyph_Category(Word);
            string         syllForm     = ConvertToGlyph.Glyph_Category1(Word);


            //Normalization

            //for (int i = 0; i < syllForm.Length - 2; i++)
            //{
            //    string ss = syllForm[i].ToString() + syllForm[i + 1].ToString() + syllForm[i + 2].ToString();
            //    int Count =0;
            //    if (ss == "VCV" || ss == "VC<")
            //    {
            //        for(int j=0;j<i+1;j++)
            //        {
            //            if(syllForm[j].ToString() == "V" || syllForm[j].ToString() == "<" )
            //            {
            //                Count = Count + 1;
            //            }
            //            else
            //            {
            //                Count = Count +2;
            //            }
            //        }



            //        syllForm = syllForm.Insert(i + 1, "C");
            //        glyphForm = glyphForm.Insert(Count, glyphForm.Substring(Count, 2));

            //    }

            //}
            syllForm = syllForm.Replace('<', 'V');
            string syllFormCopy = syllForm;

            if (syllForm.StartsWith("CCV"))
            {
                hasFirstSyll = true;
                FirstChar    = "CC";
                syllFormCopy = syllFormCopy.Remove(0, 2);
            }
            else if (syllForm.StartsWith("CV"))
            {
                hasFirstSyll = true;
                FirstChar    = "C";
                syllFormCopy = syllFormCopy.Remove(0, 1);
            }
            if (syllFormCopy.EndsWith("VCC"))
            {
                hasLastSyll  = true;
                LastChar     = "CC";
                syllFormCopy = syllFormCopy.Remove(syllFormCopy.Length - 2, 2);
            }
            else if (syllFormCopy.EndsWith("VC"))
            {
                hasLastSyll  = true;
                LastChar     = "C";
                syllFormCopy = syllFormCopy.Remove(syllFormCopy.Length - 1, 1);
            }

            int vowelCount = 0;

            for (int i = 0; i < syllFormCopy.Length; i++)
            {
                if (syllFormCopy[i].Equals('V'))
                {
                    vowelCount = vowelCount + 1;
                }
            }

            if (vowelCount > 0 && syllFormCopy.StartsWith("V") && syllFormCopy.EndsWith("V"))
            {
                string[] arrsyllable  = new string[vowelCount];
                string[] arrConsonant = syllFormCopy.Split('V');

                for (int j = 0; j < arrsyllable.Length; j++)
                {
                    arrsyllable[j] = "V";
                }


                for (int i = 0; i < arrConsonant.Length; i++)
                {
                    if (string.IsNullOrEmpty(arrConsonant[i]))
                    {
                        continue;
                    }

                    if (arrConsonant[i] == "C")
                    {
                        arrsyllable[i] = "C" + arrsyllable[i];
                    }
                    else if (arrConsonant[i] == "CC")
                    {
                        arrsyllable[i - 1] = arrsyllable[i - 1] + "C";
                        arrsyllable[i]     = "C" + arrsyllable[i];
                    }
                    else if (arrConsonant[i] == "CCC")
                    {
                        arrsyllable[i - 1] = arrsyllable[i - 1] + "CC";
                        arrsyllable[i]     = "C" + arrsyllable[i];
                    }
                }

                if (hasFirstSyll)
                {
                    arrsyllable[0] = FirstChar + arrsyllable[0];
                }

                if (hasLastSyll)
                {
                    arrsyllable[arrsyllable.Length - 1] = arrsyllable[arrsyllable.Length - 1] + LastChar;
                }

                List <string> lstOutput = new List <string>();

                for (int i = 0; i < arrsyllable.Length; i++)
                {
                    string temp  = arrsyllable[i];
                    int    count = 0;
                    for (int j = 0; j < temp.Length; j++)
                    {
                        if (temp[j].Equals('C'))
                        {
                            count = count + 2;
                        }
                        else if (temp[j].Equals('V'))
                        {
                            count = count + 1;
                        }
                    }
                    lstOutput.Add(glyphForm.Substring(0, count));
                    glyphForm = glyphForm.Remove(0, count);
                }

                objSyllable.Word         = Word;
                objSyllable.lstSyllables = lstOutput;

                List <string> lstTemp = new List <string>();
                foreach (string str in arrsyllable)
                {
                    lstTemp.Add(str);
                }
                objSyllable.lstSyllFormat = lstTemp;
            } //main if ends
            return(objSyllable);
        }     //Fn ends
Пример #2
0
        public List <DisplayForm> CheckPhonemicCharacters(List <string> lstWords)
        {
            List <DisplayForm> lstOutput    = new List <DisplayForm>();
            string             glyphForm    = string.Empty;
            string             syllabicForm = string.Empty;

            foreach (string word in lstWords)
            {
                Regex reg1 = new Regex(@"[A-Za-z0-9]");
                if (reg1.IsMatch(word))
                {
                    continue;
                }
                DisplayForm objForm = new DisplayForm();
                glyphForm    = ConvertToGlyph.Glyph_Category(word);
                syllabicForm = ConvertToGlyph.Glyph_Category1(word);
                syllabicForm = syllabicForm.Replace("<", "V");
                string start = string.Empty;
                string End   = string.Empty;

                objForm.Word = word;

                if (glyphForm.Length > 2)
                {
                    if (syllabicForm.StartsWith("V"))
                    {
                        start = glyphForm.Substring(0, 1);
                    }
                    else
                    {
                        start = glyphForm.Substring(0, 2);
                    }

                    objForm.StartingCharacters = start;



                    if (syllabicForm.EndsWith("V"))
                    {
                        End = glyphForm.Substring(glyphForm.Length - 1, 1);
                    }
                    else
                    {
                        End = glyphForm.Substring(glyphForm.Length - 2, 2);
                    }

                    objForm.EndingCharacters = End;
                }

                if (glyphForm.Length > 4)
                {
                    if (syllabicForm.Contains("CC"))
                    {
                        string temp = syllabicForm;
                        temp = temp.Replace("CC", "&");
                        string[] arr   = temp.Split('&');
                        int      Count = 0;
                        for (int i = 0; i < arr[0].Length; i++)
                        {
                            if (arr[0][i].ToString() == "V")
                            {
                                Count = Count + 1;
                            }
                            else
                            {
                                Count = Count + 2;
                            }
                        }
                        objForm.hasTwoCluster        = true;
                        objForm.TwoConsonantClusters = glyphForm[Count].ToString() + glyphForm[Count + 1].ToString() + glyphForm[Count + 2].ToString() + glyphForm[Count + 3].ToString();
                    }
                }

                if (glyphForm.Length > 6)
                {
                    if (syllabicForm.Contains("CCC"))
                    {
                        string temp1 = syllabicForm;
                        temp1 = temp1.Replace("CCC", "&");
                        string[] arr   = temp1.Split('&');
                        int      Count = 0;
                        for (int i = 0; i < arr[0].Length; i++)
                        {
                            if (arr[0][i].ToString() == "V")
                            {
                                Count = Count + 1;
                            }
                            else
                            {
                                Count = Count + 2;
                            }
                        }
                        objForm.hasThreeCluster       = true;
                        objForm.ThreeConsonantCluster = glyphForm[Count].ToString() + glyphForm[Count + 1].ToString() + glyphForm[Count + 2].ToString() + glyphForm[Count + 3].ToString() + glyphForm[Count + 4].ToString() + glyphForm[Count + 5].ToString();
                    }
                }

                if (objForm.TwoConsonantClusters == null)
                {
                    objForm.TwoConsonantClusters = string.Empty;
                }
                if (objForm.ThreeConsonantCluster == null)
                {
                    objForm.ThreeConsonantCluster = string.Empty;
                }
                if (objForm.StartingCharacters == null)
                {
                    objForm.StartingCharacters = string.Empty;
                }
                if (objForm.EndingCharacters == null)
                {
                    objForm.EndingCharacters = string.Empty;
                }


                lstOutput.Add(objForm);
            }
            return(lstOutput);
        }