Beispiel #1
0
        /// <summary>
        /// Converts the given Roman numeral string into (word) Items in the WordRelation.
        /// </summary>
        /// <param name="romanString">The roman numeral string.</param>
        private void romanToWords(string romanString)
        {
            string punctuation = (string)tokenItem.findFeature("p.punc");

            if (punctuation.Equals(""))
            {
                /* no preceeding punctuation */
                //string n = String.valueOf(NumberExpander.expandRoman(romanString));
                var n = NumberExpander.expandRoman(romanString).ToString(CultureInfo.InvariantCulture);

                if (kingLike(tokenItem))
                {
                    wordRelation.addWord("the");
                    NumberExpander.expandOrdinal(n, wordRelation);
                }
                else if (sectionLike(tokenItem))
                {
                    NumberExpander.expandNumber(n, wordRelation);
                }
                else
                {
                    NumberExpander.expandLetters(romanString, wordRelation);
                }
            }
            else
            {
                NumberExpander.expandLetters(romanString, wordRelation);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Convert the given digit token into (word) Items in the WordRelation.
        /// </summary>
        /// <param name="tokenVal">The digit string.</param>
        private void digitsToWords(string tokenVal)
        {
            FeatureSet featureSet = tokenItem.getFeatures();
            string     nsw        = "";

            if (featureSet.isPresent("nsw"))
            {
                nsw = featureSet.getString("nsw");
            }

            if (nsw.Equals("nide"))
            {
                NumberExpander.expandID(tokenVal, wordRelation);
            }
            else
            {
                string rName      = featureSet.getString("name");
                string digitsType = null;

                if (tokenVal.Equals(rName))
                {
                    digitsType = (string)cart.interpret(tokenItem);
                }
                else
                {
                    featureSet.setString("name", tokenVal);
                    digitsType = (string)cart.interpret(tokenItem);
                    featureSet.setString("name", rName);
                }

                if (digitsType.Equals("ordinal"))
                {
                    NumberExpander.expandOrdinal(tokenVal, wordRelation);
                }
                else if (digitsType.Equals("digits"))
                {
                    NumberExpander.expandDigits(tokenVal, wordRelation);
                }
                else if (digitsType.Equals("year"))
                {
                    NumberExpander.expandID(tokenVal, wordRelation);
                }
                else
                {
                    NumberExpander.expandNumber(tokenVal, wordRelation);
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Convert the given digits/digits string into word (Items) in the WordRelation.
        /// </summary>
        /// <param name="tokenVal">The digits/digits string.</param>
        private void digitsSlashDigitsToWords([In] string tokenVal)
        {
            /* might be fraction, or not */
            int    index = tokenVal.IndexOf('/');
            string aaa   = tokenVal.Substring(0, index);
            string bbb   = tokenVal.Substring(index + 1);
            int    a;

            // if the previous token is a number, add an "and"
            if (matches(digitsPattern, (string)tokenItem.findFeature("p.name")) &&
                tokenItem.getPrevious() != null)
            {
                wordRelation.addWord("and");
            }

            if (aaa.Equals("1") && bbb.Equals("2"))
            {
                wordRelation.addWord("a");
                wordRelation.addWord("half");
            }
            else if ((a = int.Parse(aaa)) < (int.Parse(bbb)))
            {
                NumberExpander.expandNumber(aaa, wordRelation);
                NumberExpander.expandOrdinal(bbb, wordRelation);
                if (a > 1)
                {
                    wordRelation.addWord("'s");
                }
            }
            else
            {
                NumberExpander.expandNumber(aaa, wordRelation);
                wordRelation.addWord("slash");
                NumberExpander.expandNumber(bbb, wordRelation);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Converts US money string into (word) Items in the WordRelation.
        /// </summary>
        /// <param name="tokenVal">The US money string.</param>
        private void usMoneyToWords(string tokenVal)
        {
            int dotIndex = tokenVal.IndexOf('.');

            if (matches(illionPattern, (string)tokenItem.findFeature("n.name")))
            {
                NumberExpander.expandReal(tokenVal.Substring(1), wordRelation);
            }
            else if (dotIndex == -1)
            {
                string aaa = tokenVal.Substring(1);
                tokenToWords(aaa);
                if (aaa.Equals("1"))
                {
                    wordRelation.addWord("dollar");
                }
                else
                {
                    wordRelation.addWord("dollars");
                }
            }
            else if (dotIndex == (tokenVal.Length - 1) ||
                     (tokenVal.Length - dotIndex) > 3)
            {
                // Simply read as mumble point mumble.
                NumberExpander.expandReal(tokenVal.Substring(1), wordRelation);
                wordRelation.addWord("dollars");
            }
            else
            {
                string aaa = tokenVal.Substring(1, dotIndex).Replace(",", "");
                string bbb = tokenVal.Substring(dotIndex + 1);

                NumberExpander.expandNumber(aaa, wordRelation);

                if (aaa.Equals("1"))
                {
                    wordRelation.addWord("dollar");
                }
                else
                {
                    wordRelation.addWord("dollars");
                }

                if (bbb.Equals("00"))
                {
                    // Add nothing to the word list.
                }
                else
                {
                    NumberExpander.expandNumber(bbb, wordRelation);
                    if (bbb.Equals("01"))
                    {
                        wordRelation.addWord("cent");
                    }
                    else
                    {
                        wordRelation.addWord("cents");
                    }
                }
            }
        }
Beispiel #5
0
        /// <summary>
        /// Converts the given Token into (word) Items in the WordRelation.
        /// </summary>
        /// <param name="tokenVal">the string value of the token, which may or may not be
        /// same as the one in called "name" in flite</param>
        private void tokenToWords(string tokenVal)
        {
            FeatureSet tokenFeatures = tokenItem.getFeatures();
            string     itemName      = tokenFeatures.getString("name");
            int        tokenLength   = tokenVal.Length;

            if (tokenFeatures.isPresent("phones"))
            {
                wordRelation.addWord(tokenVal);
            }
            else if ((tokenVal.Equals("a") || tokenVal.Equals("A")) &&
                     ((tokenItem.getNext() == null) ||
                      !(tokenVal.Equals(itemName)) || !(((string)tokenItem
                                                         .findFeature("punc")).Equals(""))))
            {
                /* if A is a sub part of a token, then its ey not ah */
                wordRelation.addWord("_a");
            }
            else if (matches(alphabetPattern, tokenVal))
            {
                if (matches(romanNumbersPattern, tokenVal))
                {
                    /* XVIII */
                    romanToWords(tokenVal);
                }
                else if (matches(illionPattern, tokenVal) &&
                         matches(usMoneyPattern,
                                 (string)tokenItem.findFeature("p.name")))
                {
                    /* $ X -illion */
                    wordRelation.addWord(tokenVal);
                    wordRelation.addWord("dollars");
                }
                else if (matches(drStPattern, tokenVal))
                {
                    /* St Andrew's St, Dr King Dr */
                    drStToWords(tokenVal);
                }
                else if (tokenVal.Equals("Mr"))
                {
                    tokenItem.getFeatures().setString("punc", "");
                    wordRelation.addWord("mister");
                }
                else if (tokenVal.Equals("Mrs"))
                {
                    tokenItem.getFeatures().setString("punc", "");
                    wordRelation.addWord("missus");
                }
                else if (tokenLength == 1 &&
                         char.IsUpper(tokenVal[0]) &&
                         ((string)tokenItem.findFeature("n.whitespace"))
                         .Equals(" ") &&
                         char.IsUpper(((string)tokenItem
                                       .findFeature("n.name"))[0]))
                {
                    tokenFeatures.setString("punc", "");
                    string aaa = tokenVal.ToLower();
                    if (aaa.Equals("a"))
                    {
                        wordRelation.addWord("_a");
                    }
                    else
                    {
                        wordRelation.addWord(aaa);
                    }
                }
                else if (isStateName(tokenVal))
                {
                    /*
                     * The name of a US state isStateName() has already added the
                     * full name of the state, so we're all set.
                     */
                }
                else if (tokenLength > 1 && !isPronounceable(tokenVal))
                {
                    /* Need common exception list */
                    /* unpronouncable list of alphas */
                    NumberExpander.expandLetters(tokenVal, wordRelation);
                }
                else
                {
                    /* just a word */
                    wordRelation.addWord(tokenVal.ToLower());
                }
            }
            else if (matches(dottedAbbrevPattern, tokenVal))
            {
                /* U.S.A. */
                // remove all dots
                NumberExpander.expandLetters(tokenVal.Replace(".", ""),
                                             wordRelation);
            }
            else if (matches(commaIntPattern, tokenVal))
            {
                /* 99,999,999 */
                NumberExpander.expandReal(tokenVal.Replace(",", "").Replace("'", ""), wordRelation);
            }
            else if (matches(sevenPhoneNumberPattern, tokenVal))
            {
                /* 234-3434 telephone numbers */
                int    dashIndex = tokenVal.IndexOf('-');
                string aaa       = tokenVal.Substring(0, dashIndex);
                string bbb       = tokenVal.Substring(dashIndex + 1);

                NumberExpander.expandDigits(aaa, wordRelation);
                wordRelation.addBreak();
                NumberExpander.expandDigits(bbb, wordRelation);
            }
            else if (matchesPartPhoneNumber(tokenVal))
            {
                /* part of a telephone number */
                string punctuation = (string)tokenItem.findFeature("punc");
                if (punctuation.Equals(""))
                {
                    tokenItem.getFeatures().setString("punc", ",");
                }
                NumberExpander.expandDigits(tokenVal, wordRelation);
                wordRelation.addBreak();
            }
            else if (matches(numberTimePattern, tokenVal))
            {
                /* 12:35 */
                int    colonIndex = tokenVal.IndexOf(':');
                string aaa        = tokenVal.Substring(0, colonIndex);
                string bbb        = tokenVal.Substring(colonIndex + 1);

                NumberExpander.expandNumber(aaa, wordRelation);
                if (!(bbb.Equals("00")))
                {
                    NumberExpander.expandID(bbb, wordRelation);
                }
            }
            else if (matches(digits2DashPattern, tokenVal))
            {
                /* 999-999-999 */
                digitsDashToWords(tokenVal);
            }
            else if (matches(digitsPattern, tokenVal))
            {
                digitsToWords(tokenVal);
            }
            else if (tokenLength == 1 &&
                     char.IsUpper(tokenVal[0]) &&
                     ((string)tokenItem.findFeature("n.whitespace"))
                     .Equals(" ") &&
                     char.IsUpper(((string)tokenItem
                                   .findFeature("n.name"))[0]))
            {
                tokenFeatures.setString("punc", "");
                string aaa = tokenVal.ToLower();
                if (aaa.Equals("a"))
                {
                    wordRelation.addWord("_a");
                }
                else
                {
                    wordRelation.addWord(aaa);
                }
            }
            else if (matches(doublePattern, tokenVal))
            {
                NumberExpander.expandReal(tokenVal, wordRelation);
            }
            else if (matches(ordinalPattern, tokenVal))
            {
                /* explicit ordinals */
                string aaa = tokenVal.Substring(0, tokenLength - 2);
                NumberExpander.expandOrdinal(aaa, wordRelation);
            }
            else if (matches(usMoneyPattern, tokenVal))
            {
                /* US money */
                usMoneyToWords(tokenVal);
            }
            else if (tokenLength > 0 && tokenVal[tokenLength - 1] == '%')
            {
                /* Y% */
                tokenToWords(tokenVal.Substring(0, tokenLength - 1));
                wordRelation.addWord("percent");
            }
            else if (matches(numessPattern, tokenVal))
            {
                NumberExpander.expandNumess(tokenVal.Substring(0, tokenLength - 1), wordRelation);
            }
            else if (matches(digitsSlashDigitsPattern, tokenVal) &&
                     tokenVal.Equals(itemName))
            {
                digitsSlashDigitsToWords(tokenVal);
            }
            else if (tokenVal.IndexOf('-') != -1)
            {
                dashToWords(tokenVal);
            }
            else if (tokenLength > 1 && !matches(alphabetPattern, tokenVal))
            {
                notJustAlphasToWords(tokenVal);
            }
            else if (tokenVal.Equals("&"))
            {
                // &
                wordRelation.addWord("and");
            }
            else if (tokenVal.Equals("-"))
            {
                // Skip it
            }
            else
            {
                // Just a word.
                wordRelation.addWord(tokenVal.ToLower());
            }
        }