Exemple #1
0
 private void ReadDigitsInto(HebrewPromptBuilder builder, string numberString)
 {
     foreach (var c in numberString.ToCharArray())
     {
         builder.AppendTextWithPronunciation(WordsHeFemaleUnits[c - '0'], HebrewLexicon);
     }
 }
 private void ReadDigitsInto(HebrewPromptBuilder builder, string numberString)
 {
     foreach (var c in numberString.ToCharArray())
     {
         builder.AppendTextWithPronunciation(WordsHeFemaleUnits[c - '0'], HebrewLexicon);
     }
 }
 public void ReadInto(HebrewPromptBuilder builder, string input)
 {
     //TODO: HebrewPromptWordReader
     if (HebrewWord.IsMatch(input))
         builder.AppendTextWithPronunciation(input, WordLexicon);
     else
         builder.BaseAppendText(input);
 }
 public void ReadInto(HebrewPromptBuilder builder, string input)
 {
     if (input.Length > MaxLengthToReadNumber || input.StartsWith("0"))
     {
         ReadDigitsInto(builder, input);
     }
     else
     {
         ReadNumberInto(builder, int.Parse(input));
     }
 }
Exemple #5
0
 public void ReadInto(HebrewPromptBuilder builder, string input)
 {
     if (input.Length > MaxLengthToReadNumber || input.StartsWith("0"))
     {
         ReadDigitsInto(builder, input);
     }
     else
     {
         ReadNumberInto(builder, int.Parse(input));
     }
 }
Exemple #6
0
 public void ReadInto(HebrewPromptBuilder builder, string input)
 {
     //TODO: HebrewPromptWordReader
     if (HebrewWord.IsMatch(input))
     {
         builder.AppendTextWithPronunciation(input, WordLexicon);
     }
     else
     {
         builder.BaseAppendText(input);
     }
 }
 public static void ReadInto(HebrewPromptBuilder builder, string textToSpeak)
 {
     foreach (var word in from Match m in Tokenizer.Matches(textToSpeak) select m.Value)
     {
         if (Token.IsMatch(word))
         {
             builder.BaseAppendText(word);
         }
         else
         {
             var reader = NumberRegex.IsMatch(word)
                 ? (IHebrewPromptReader)NumberReader
                 : (IHebrewPromptReader)WordReader;
             reader.ReadInto(builder, word);
         }
     }
 }
 public static void ReadInto(HebrewPromptBuilder builder, string textToSpeak)
 {
     foreach (var word in from Match m in Tokenizer.Matches(textToSpeak) select m.Value)
     {
         if (Token.IsMatch(word))
         {
             builder.BaseAppendText(word);
         }
         else
         {
             var reader = NumberRegex.IsMatch(word)
                 ? (IHebrewPromptReader)NumberReader
                 : (IHebrewPromptReader)WordReader;
             reader.ReadInto(builder, word);
         }
     }
 }
        private void ReadNumberInto(HebrewPromptBuilder builder, int number)
        {
            if (number < 0)
            {
                builder.AppendTextWithPronunciation(WordHeMinus, HebrewLexicon);
                number = -number;
            }

            var remaining = number;
            var digits = new List<int>();

            while (remaining >= 1)
            {
                digits.Add(remaining % 10); //i.e for 1234: digits = [4,3,2,1]
                remaining = remaining/10;
            }

            if (number < 20)
            {
                builder.AppendTextWithPronunciation(WordsHeFemaleUnits[number], HebrewLexicon);
            }
            else
            {
                var i = digits.Count;
                while (i > 0)
                {
                    var digitsHandled = 1;
                    switch (i)
                    {
                        case 4: //1,xxx-9,xxx
                            builder.AppendTextWithPronunciation(WordsHeThousands[digits[i - 1]], HebrewLexicon);
                            break;
                        case 7: //1,xxx,xxx-9,xxx,xxx
                            if (digits[i-1] > 1)
                                builder.AppendTextWithPronunciation(WordsHeMaleCount[digits[i - 1]], HebrewLexicon);
                            builder.AppendTextWithPronunciation(WordHeMillion, HebrewLexicon);
                            break;
                        default: //handle triplets of hundreds/tens/units
                            digitsHandled = (i % 3 == 2 ? 2 : 3);

                            var f100 = digitsHandled == 3 ? digits[i - 1] : 0;
                            var f10 = digitsHandled == 3 ? digits[i - 2] : digits[i - 1];
                            var f1 = digitsHandled == 3 ? digits[i - 3] : digits[i - 2];
                            var f11 = f10 * 10 + f1;

                            if (f100 > 0) //1xx-9xx
                            {
                                builder.AppendTextWithPronunciation(WordsHeHundreds[f100], HebrewLexicon);
                            }

                            if (f11 > 0) //not 00
                            {
                                if (f10 < 2) //0x-1x
                                {
                                    if ((i < digits.Count && i < 4) || f100 > 0)
                                        builder.AppendTextWithPronunciation(WordHeAnd, HebrewLexicon); // And

                                    if (i < 4) //the right most digits are female
                                    {
                                        builder.AppendTextWithPronunciation(WordsHeFemaleUnits[f11], HebrewLexicon);
                                    }
                                    else if (i < 7 && f100 == 0 && f11 == 10) //010,xxx
                                    {
                                        builder.AppendTextWithPronunciation(WordHeTensOf, HebrewLexicon);
                                    }
                                    else //anywhere else is male
                                    {
                                        builder.AppendTextWithPronunciation(WordsHeMaleUnits[f11], HebrewLexicon);
                                    }
                                }
                                else //2x-9x
                                {
                                    builder.AppendTextWithPronunciation(WordsHeTens[f10], HebrewLexicon); // X0

                                    if (f1 > 0) //1-9
                                    {
                                        builder.AppendTextWithPronunciation(WordHeAnd, HebrewLexicon); // And

                                        if (i < 4) //the right most digits are female
                                        {
                                            builder.AppendTextWithPronunciation(WordsHeFemaleUnits[f1], HebrewLexicon);
                                        }
                                        else //anywhere else is male
                                        {
                                            builder.AppendTextWithPronunciation(WordsHeMaleUnits[f1], HebrewLexicon);
                                        }
                                    }
                                }
                            }

                            if (i > 3 && f1 + f10 + f100 > 0)
                            {
                                if (i < 7) //001,000-999,000
                                {
                                    if (f1 == 0 && f10 == 1 && f100 == 0) // 10,000
                                    {
                                        builder.AppendTextWithPronunciation(WordHeThousands, HebrewLexicon);
                                    }
                                    else
                                    {
                                        builder.AppendTextWithPronunciation(WordHeThousand, HebrewLexicon);
                                    }
                                }
                                else if (i <= MaxLengthToReadNumber) //001,000,000-999,000,000
                                {
                                    builder.AppendTextWithPronunciation(WordHeMillion, HebrewLexicon);
                                }
                            }
                            break;
                    }
                    i -= digitsHandled;
                }
            }
        }
Exemple #10
0
        private void ReadNumberInto(HebrewPromptBuilder builder, int number)
        {
            if (number < 0)
            {
                builder.AppendTextWithPronunciation(WordHeMinus, HebrewLexicon);
                number = -number;
            }

            var remaining = number;
            var digits    = new List <int>();

            while (remaining >= 1)
            {
                digits.Add(remaining % 10); //i.e for 1234: digits = [4,3,2,1]
                remaining = remaining / 10;
            }

            if (number < 20)
            {
                builder.AppendTextWithPronunciation(WordsHeFemaleUnits[number], HebrewLexicon);
            }
            else
            {
                var i = digits.Count;
                while (i > 0)
                {
                    var digitsHandled = 1;
                    switch (i)
                    {
                    case 4:     //1,xxx-9,xxx
                        builder.AppendTextWithPronunciation(WordsHeThousands[digits[i - 1]], HebrewLexicon);
                        break;

                    case 7:     //1,xxx,xxx-9,xxx,xxx
                        if (digits[i - 1] > 1)
                        {
                            builder.AppendTextWithPronunciation(WordsHeMaleCount[digits[i - 1]], HebrewLexicon);
                        }
                        builder.AppendTextWithPronunciation(WordHeMillion, HebrewLexicon);
                        break;

                    default:     //handle triplets of hundreds/tens/units
                        digitsHandled = (i % 3 == 2 ? 2 : 3);

                        var f100 = digitsHandled == 3 ? digits[i - 1] : 0;
                        var f10  = digitsHandled == 3 ? digits[i - 2] : digits[i - 1];
                        var f1   = digitsHandled == 3 ? digits[i - 3] : digits[i - 2];
                        var f11  = f10 * 10 + f1;

                        if (f100 > 0)     //1xx-9xx
                        {
                            builder.AppendTextWithPronunciation(WordsHeHundreds[f100], HebrewLexicon);
                        }

                        if (f11 > 0)     //not 00
                        {
                            if (f10 < 2) //0x-1x
                            {
                                if ((i < digits.Count && i < 4) || f100 > 0)
                                {
                                    builder.AppendTextWithPronunciation(WordHeAnd, HebrewLexicon); // And
                                }
                                if (i < 4)                                                         //the right most digits are female
                                {
                                    builder.AppendTextWithPronunciation(WordsHeFemaleUnits[f11], HebrewLexicon);
                                }
                                else if (i < 7 && f100 == 0 && f11 == 10)     //010,xxx
                                {
                                    builder.AppendTextWithPronunciation(WordHeTensOf, HebrewLexicon);
                                }
                                else     //anywhere else is male
                                {
                                    builder.AppendTextWithPronunciation(WordsHeMaleUnits[f11], HebrewLexicon);
                                }
                            }
                            else                                                                      //2x-9x
                            {
                                builder.AppendTextWithPronunciation(WordsHeTens[f10], HebrewLexicon); // X0

                                if (f1 > 0)                                                           //1-9
                                {
                                    builder.AppendTextWithPronunciation(WordHeAnd, HebrewLexicon);    // And

                                    if (i < 4)                                                        //the right most digits are female
                                    {
                                        builder.AppendTextWithPronunciation(WordsHeFemaleUnits[f1], HebrewLexicon);
                                    }
                                    else     //anywhere else is male
                                    {
                                        builder.AppendTextWithPronunciation(WordsHeMaleUnits[f1], HebrewLexicon);
                                    }
                                }
                            }
                        }

                        if (i > 3 && f1 + f10 + f100 > 0)
                        {
                            if (i < 7)                                //001,000-999,000
                            {
                                if (f1 == 0 && f10 == 1 && f100 == 0) // 10,000
                                {
                                    builder.AppendTextWithPronunciation(WordHeThousands, HebrewLexicon);
                                }
                                else
                                {
                                    builder.AppendTextWithPronunciation(WordHeThousand, HebrewLexicon);
                                }
                            }
                            else if (i <= MaxLengthToReadNumber)     //001,000,000-999,000,000
                            {
                                builder.AppendTextWithPronunciation(WordHeMillion, HebrewLexicon);
                            }
                        }
                        break;
                    }
                    i -= digitsHandled;
                }
            }
        }