public Preprocess() { super("Preprocess", MaryDataType.TOKENS, MaryDataType.WORDS, Locale.FRENCH); this.rbnf = new RuleBasedNumberFormat(ULocale.FRENCH, RuleBasedNumberFormat.SPELLOUT); this.cardinalRule = "%spellout-numbering"; this.ordinalRule = getOrdinalRuleName(rbnf); }
public Preprocess() { super("Preprocess", MaryDataType.TOKENS, MaryDataType.WORDS, Locale.ENGLISH); this.rbnf = new RuleBasedNumberFormat(ULocale.ENGLISH, RuleBasedNumberFormat.SPELLOUT); this.cardinalRule = "%spellout-numbering"; this.ordinalRule = getOrdinalRuleName(rbnf); this.yearRule = getYearRuleName(rbnf); this.df = DateFormat.getDateInstance(DateFormat.LONG, ULocale.ENGLISH); try { this.abbrevMap = loadAbbrevMap(); } catch (IOException e) { e.printStackTrace(); } }
@Override public NumberFormat call() throws Exception { return new RuleBasedNumberFormat(locale, type); } });
/** Formats a double into a properly spelled out number string based on Locale * @param amount The amount double to be formatted * @param locale The Locale used to format the number * @return A String with the formatted number */ public static String formatSpelledOutAmount(double amount, Locale locale) { com.ibm.icu.text.NumberFormat nf = new com.ibm.icu.text.RuleBasedNumberFormat(locale, com.ibm.icu.text.RuleBasedNumberFormat.SPELLOUT); return nf.format(amount); }
public Preprocess() { super("Preprocess", MaryDataType.TOKENS, MaryDataType.WORDS, Locale.FRENCH); this.rbnf = new RuleBasedNumberFormat(ULocale.FRENCH, RuleBasedNumberFormat.SPELLOUT); this.cardinalRule = "%spellout-numbering"; this.ordinalRule = getOrdinalRuleName(rbnf); }
RuleBasedNumberFormat temp = new RuleBasedNumberFormat(description, loc); ruleSets = temp.ruleSets; ruleSetsMap = temp.ruleSetsMap;
/** * Method to format an amount using a custom rule set. * Current rule sets available: * * en_US * %dollars-and-cents - 1,225.25 becomes "one thousand two hundred twenty five dollars and twenty five cents" (useful for checks) * %dollars-and-hundreths - 1,225.25 becomes "one thousand two hundred twenty five and 25/00" (alternate for checks) * * @param amount - the amount to format * @param ruleSet - ruleSet to use * @param rule - the name of the rule set to use (e.g., %dollars-and-hundredths) * @param locale - the Locale * @return formatted string or an empty string if there was an error */ public static String formatRuleBasedAmount(double amount, String ruleSet, String rule, Locale locale) { RuleBasedNumberFormat formatter = new RuleBasedNumberFormat(ruleSet, locale); String result = ""; try { result = formatter.format(amount, rule != null ? rule : formatter.getDefaultRuleSetName()); } catch (Exception e) { Debug.logError(e, "Failed to format amount " + amount + " using rule " + rule, module); } return result; }
RuleBasedNumberFormat r = new RuleBasedNumberFormat(nsLoc,desiredRulesType); r.setDefaultRuleSet(nsRuleSetName); format = r;
case TYPE_SPELLOUT: RuleBasedNumberFormat rbnf = new RuleBasedNumberFormat(ulocale, RuleBasedNumberFormat.SPELLOUT); String ruleset = style.trim(); case TYPE_ORDINAL: RuleBasedNumberFormat rbnf = new RuleBasedNumberFormat(ulocale, RuleBasedNumberFormat.ORDINAL); String ruleset = style.trim(); case TYPE_DURATION: RuleBasedNumberFormat rbnf = new RuleBasedNumberFormat(ulocale, RuleBasedNumberFormat.DURATION); String ruleset = style.trim();