protected String expandNumber(double number) { this.rbnf.setDefaultRuleSet(cardinalRule); return this.rbnf.format(number); }
BufferedInputStream bis = new BufferedInputStream(input); CharsetDetector cd = new CharsetDetector(); cd.setText(bis); CharsetMatch cm = cd.detect(); if (cm != null) { reader = cm.getReader(); charset = cm.getName(); }else { throw new UnsupportedCharsetException() }
ArabicShaping as = new ArabicShaping(ArabicShaping.LETTERS_SHAPE | ArabicShaping.LENGTH_GROW_SHRINK); try { s = as.shape(s); } catch (ArabicShapingException e) { LOG.error(e.getMessage(), e); Bidi line = new Bidi(s.length(), s.length()); line.setPara(s, Bidi.LEVEL_DEFAULT_LTR, null); byte direction = line.getDirection(); if (direction != Bidi.MIXED) { if(line.isLeftToRight()) { return s; } else { int count = line.countRuns(); BidiRun run = line.getVisualRun(i); int st = run.getStart(); int e = run.getLimit(); int j = run.getDirection() == Bidi.LTR ? st : e - 1; int l = run.getDirection() == Bidi.LTR ? e : st - 1; boolean plus = run.getDirection() == Bidi.LTR; while (j != l) { res.append(s.charAt(j));
protected String expandDate(String date) throws ParseException { // date format is "month/day/year" Date humanDate = df.getPatternInstance("MM.dd.yyyy", ULocale.ENGLISH).parse(date); String[] dateParts = df.format(humanDate).replaceAll(",", "").split("\\s"); dateParts[1] = expandOrdinal(Double.parseDouble(dateParts[1])); dateParts[2] = expandYear(Double.parseDouble(dateParts[2])); return Arrays.toString(dateParts).replaceAll("[,\\]\\[]", ""); }
final ThreadLocal<Function<String, String>> threadLocal = ThreadLocal.withInitial( () -> { final SimpleDateFormat parser = new SimpleDateFormat(timeFormat); final SimpleDateFormat formatter = new SimpleDateFormat(resultFormat); parser.setLenient(true); date = parser.parse(value); return formatter.format(date); };
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(); } }
private void init(PluralRules rules, PluralType type, ULocale locale, NumberFormat numberFormat) { ulocale = locale; pluralRules = (rules == null) ? PluralRules.forLocale(ulocale, type) : rules; resetPattern(); this.numberFormat = (numberFormat == null) ? NumberFormat.getInstance(ulocale) : numberFormat; }
/** * Try to extract the rule name for "expand year" from the given RuleBasedNumberFormat. * <p> * The rule name is locale sensitive, but usually starts with "%spellout-numbering-year". * * @param rbnf * The RuleBasedNumberFormat from where we will try to extract the rule name. * @return The rule name for "year spell out". */ protected static String getYearRuleName(final RuleBasedNumberFormat rbnf) { List<String> l = Arrays.asList(rbnf.getRuleSetNames()); if (l.contains("%spellout-numbering-year")) { return "%spellout-numbering-year"; } else { for (String string : l) { if (string.startsWith("%spellout-numbering-year")) { return string; } } } throw new UnsupportedOperationException("The locale " + rbnf.getLocale(ULocale.ACTUAL_LOCALE) + " doesn't support year spelling."); }
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); }
@Implementation(maxSdk = LOLLIPOP_MR1) public static long createDateIntervalFormat(String skeleton, String localeName, String tzName) { address++; INTERVAL_CACHE.put(address, com.ibm.icu.text.DateIntervalFormat.getInstance(skeleton, new Locale(localeName))); return address; }
@Implementation(maxSdk = LOLLIPOP_MR1) @SuppressWarnings("JdkObsolete") public static String formatDateInterval(long address, long fromDate, long toDate) { StringBuffer buffer = new StringBuffer(); FieldPosition pos = new FieldPosition(0); INTERVAL_CACHE.get(address).format(new com.ibm.icu.util.DateInterval(fromDate, toDate), buffer, pos); return buffer.toString(); } }
private boolean handleNextCommonImpl() { int textOffset = textIter_.getOffset(); Match match = new Match(); if (search(textOffset, match)) { search_.matchedIndex_ = match.start_; search_.setMatchedLength(match.limit_ - match.start_); return true; } else { setMatchNotFound(); return false; } }
/** * {@inheritDoc} * @stable ICU 2.8 */ @Override public int getIndex() { int result = textIter_.getOffset(); if (isOutOfBounds(search_.beginIndex(), search_.endIndex(), result)) { return DONE; } return result; }
protected String expandYear(double number) { this.rbnf.setDefaultRuleSet(yearRule); return this.rbnf.format(number); }
/** * Try to extract the rule name for "expand ordinal" from the given RuleBasedNumberFormat. * <p> * The rule name is locale sensitive, but usually starts with "%spellout-ordinal". * * @param rbnf * The RuleBasedNumberFormat from where we will try to extract the rule name. * @return The rule name for "ordinal spell out". */ protected static String getOrdinalRuleName(final RuleBasedNumberFormat rbnf) { List<String> l = Arrays.asList(rbnf.getRuleSetNames()); if (l.contains("%spellout-ordinal")) { return "%spellout-ordinal"; } else if (l.contains("%spellout-ordinal-masculine")) { return "%spellout-ordinal-masculine"; } else { for (String string : l) { if (string.startsWith("%spellout-ordinal")) { return string; } } } throw new UnsupportedOperationException("The locale " + rbnf.getLocale(ULocale.ACTUAL_LOCALE) + " doesn't support ordinal spelling."); }
protected String expandNumber(double number) { this.rbnf.setDefaultRuleSet(cardinalRule); return this.rbnf.format(number); }
/** * Try to extract the rule name for "expand ordinal" from the given RuleBasedNumberFormat. * <p> * The rule name is locale sensitive, but usually starts with "%spellout-ordinal". * * @param rbnf * The RuleBasedNumberFormat from where we will try to extract the rule name. * @return The rule name for "ordinal spell out". */ protected static String getOrdinalRuleName(final RuleBasedNumberFormat rbnf) { List<String> l = Arrays.asList(rbnf.getRuleSetNames()); if (l.contains("%spellout-ordinal")) { return "%spellout-ordinal"; } else if (l.contains("%spellout-ordinal-masculine")) { return "%spellout-ordinal-masculine"; } else { for (String string : l) { if (string.startsWith("%spellout-ordinal")) { return string; } } } throw new UnsupportedOperationException("The locale " + rbnf.getLocale(ULocale.ACTUAL_LOCALE) + " doesn't supports ordinal spelling."); } }
protected String expandOrdinal(double number) { this.rbnf.setDefaultRuleSet(ordinalRule); return this.rbnf.format(number); }
protected String expandOrdinal(double number) { this.rbnf.setDefaultRuleSet(ordinalRule); return this.rbnf.format(number); }