/// <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"); } } } }
/// <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()); } }