@Test public void testText2number() { System.out.println("text2number"); instance = new Numek(new Locale("en","US")); assertEquals("25", instance.text2number("twenty five")); assertEquals("0.01", instance.text2number("00.010")); assertEquals("2000025", instance.text2number("two million twenty five")); assertEquals("2000025", instance.text2number("two million and twenty five")); instance=null; instance = new Numek(new Locale("es","ES")); assertEquals("23002105", instance.text2number("VEINTITRÉS MILLONES DOS MIL CIENTO CINCO")); assertEquals("24", instance.text2number("DoS doceNas")); instance=null; }
public String text2number(String snumber) { Number number = new Number(); try { snumber = snumber.trim().toLowerCase(locale); Integer magnitude = 0; Integer max_magn = MAX_NUMBERS_ORDER; String[] elements = snumber.split("(\\s*-\\s*|\\s+" + delimiters.getRE() + "\\s+|\\s+)"); if (group_separators != null) { snumber = snumber.replaceAll(group_separators.getRE(), ""); } if (decimal_point_separator != null) { snumber = snumber.replaceAll(decimal_point_separator.getRE(), "."); } if (snumber.matches("(-)?[0-9]+(\\.[0-9]+)?")) { return prettyFormat(Double.parseDouble(snumber)); } if (snumber.matches("(-)?[0-9]+%")) { return "" + (Double.parseDouble(snumber.substring(0, snumber.length() - 1)) / 100); } if (snumber.matches("([0-9]+ )?[0-9]+/[0-9]+")) { return "" + calc_and_sum_frac(snumber); } for (int i = 0; i < elements.length; i++) { if (i == 0 && !elements[i].matches("[0-9]+("+ordinal_suffixes.getRE()+")?") && !all_keys.contains(elements[i])) { throw new Exception("Unknown element (0): " + elements[i] + " in " + snumber); } if (i != 0 && !all_keys.contains(elements[i])) { throw new Exception("Unknown element (" + i + "): " + elements[i] + " in " + snumber); } } if (elements.length == 1 && ordinal_units.getMap().containsKey(elements[0])) { return "" + ordinal_units.getMapValue(elements[0]); } if (ordinal_irregular_tens!=null && elements.length == 1 && ordinal_irregular_tens.getMap().containsKey(elements[0])) { return "" + ordinal_irregular_tens.getMapValue(elements[0]); } if (ordinal_tens!=null && elements.length == 2 && ordinal_tens.getMap().containsKey(elements[0]) && ordinal_units.getMap().containsKey(elements[1])) { return "ord__" + (Integer.parseInt(ordinal_tens.getMapValue(elements[0]).replace("ord__", ""))+Integer.parseInt(ordinal_units.getMapValue(elements[1]).replace("ord__", ""))); } if(snumber.matches("[0-9]+\\s*"+ordinal_suffixes.getRE())){ return "ord__"+snumber.replaceAll(ordinal_suffixes.getRE(), ""); } if (snumber.matches(".*" + special_groups.getRE() + ".*")) { if (elements.length == 1 && special_groups.getMap().containsKey(elements[0])) { return "" + special_groups.getMapValue(elements[0]); } if (elements.length == 2 && units.getMap().containsKey(elements[0]) && special_groups.getMap().containsKey(elements[1])) { return "" + (Integer.parseInt(units.getMapValue(elements[0])) * Integer.parseInt(special_groups.getMapValue(elements[1]))); } if (elements.length == 2 && irregular_tens.getMap().containsKey(elements[0]) && special_groups.getMap().containsKey(elements[1])) { return "" + (Integer.parseInt(irregular_tens.getMapValue(elements[0])) * Integer.parseInt(special_groups.getMapValue(elements[1]))); } if (elements.length == 2 && tens.getMap().containsKey(elements[0]) && special_groups.getMap().containsKey(elements[1])) { return "" + (Integer.parseInt(tens.getMapValue(elements[0])) * Integer.parseInt(special_groups.getMapValue(elements[1]))); } if (elements.length == 2 && special_groups.getMap().containsKey(elements[0]) && magnitudes.getMap().containsKey(elements[1])) { return "" + (Integer.parseInt(special_groups.getMapValue(elements[0])) * Integer.parseInt(magnitudes.getMapValue(elements[1]))); } if (elements.length == 3 && units.getMap().containsKey(elements[0]) && special_groups.getMap().containsKey(elements[1]) && magnitudes.getMap().containsKey(elements[2])) { return "" + (Integer.parseInt(units.getMapValue(elements[0])) * Integer.parseInt(special_groups.getMapValue(elements[1])) * Integer.parseInt(magnitudes.getMapValue(elements[2]))); } } if (elements[0].matches("([0-9]+|([0-9]*.[0-9]+))")) { if (elements.length != 2) { if (System.getProperty("DEBUG") != null && System.getProperty("DEBUG").equalsIgnoreCase("true")) { System.err.println("(UNDER CONSTRUCTION) Only the number and the first magnitude will be normalized: " + snumber); } } Integer magn = Integer.parseInt(magnitudes.getMapValue(elements[1])); if (magn == null) { if (System.getProperty("DEBUG") != null && System.getProperty("DEBUG").equalsIgnoreCase("true")) { System.err.println("In [0-9]+ magnitude numbers the second component must be a valid magnitude. Found: " + elements[1] + " from: " + snumber); } magn = 1; } return prettyFormat((Double.parseDouble(elements[0]) * magn)); } else { Integer i = elements.length - 1; while (i >= 0) { String element = elements[i].trim(); magnitude = null; if (magnitudes.getMapValue(element) != null) { magnitude = Integer.parseInt(magnitudes.getMapValue(element)); } if (magnitude != null) { if (magnitude <= (((int) Math.pow(10, number.value.toString().substring(0, number.value.toString().lastIndexOf('.')).length()) - 1))) { throw new Exception("Greater magnitude expected in " + element + " (" + snumber + ")"); } i = operateMagnitude(elements, i, number); } else { if (i != (elements.length - 1)) { throw new Exception("Unexpected number when looking for a magnitude. Found: " + element + " (" + snumber + ")"); } i = getNumber(elements, i, number, max_magn); } } } } catch (Exception e) { if (System.getProperty("DEBUG") != null && System.getProperty("DEBUG").equalsIgnoreCase("true")) { System.err.println("Errors found (NUMEK):\n\t" + e.toString()); e.printStackTrace(System.err); System.exit(1); } return snumber; } return prettyFormat(number.value); }
Numek { public String text2number(String snumber) { Number number = new Number(); try { snumber = snumber.trim().toLowerCase(locale); Integer magnitude = 0; Integer max_magn = MAX_NUMBERS_ORDER; String[] elements = snumber.split("(\\s*-\\s*|\\s+" + delimiters.getRE() + "\\s+|\\s+)"); if (group_separators != null) { snumber = snumber.replaceAll(group_separators.getRE(), ""); } if (decimal_point_separator != null) { snumber = snumber.replaceAll(decimal_point_separator.getRE(), "."); } if (snumber.matches("(-)?[0-9]+(\\.[0-9]+)?")) { return prettyFormat(Double.parseDouble(snumber)); } if (snumber.matches("(-)?[0-9]+%")) { return "" + (Double.parseDouble(snumber.substring(0, snumber.length() - 1)) / 100); } if (snumber.matches("([0-9]+ )?[0-9]+/[0-9]+")) { return "" + calc_and_sum_frac(snumber); } for (int i = 0; i < elements.length; i++) { if (i == 0 && !elements[i].matches("[0-9]+("+ordinal_suffixes.getRE()+")?") && !all_keys.contains(elements[i])) { throw new Exception("Unknown element (0): " + elements[i] + " in " + snumber); } if (i != 0 && !all_keys.contains(elements[i])) { throw new Exception("Unknown element (" + i + "): " + elements[i] + " in " + snumber); } } if (elements.length == 1 && ordinal_units.getMap().containsKey(elements[0])) { return "" + ordinal_units.getMapValue(elements[0]); } if (ordinal_irregular_tens!=null && elements.length == 1 && ordinal_irregular_tens.getMap().containsKey(elements[0])) { return "" + ordinal_irregular_tens.getMapValue(elements[0]); } if (ordinal_tens!=null && elements.length == 2 && ordinal_tens.getMap().containsKey(elements[0]) && ordinal_units.getMap().containsKey(elements[1])) { return "ord__" + (Integer.parseInt(ordinal_tens.getMapValue(elements[0]).replace("ord__", ""))+Integer.parseInt(ordinal_units.getMapValue(elements[1]).replace("ord__", ""))); } if(snumber.matches("[0-9]+\\s*"+ordinal_suffixes.getRE())){ return "ord__"+snumber.replaceAll(ordinal_suffixes.getRE(), ""); } if (snumber.matches(".*" + special_groups.getRE() + ".*")) { if (elements.length == 1 && special_groups.getMap().containsKey(elements[0])) { return "" + special_groups.getMapValue(elements[0]); } if (elements.length == 2 && units.getMap().containsKey(elements[0]) && special_groups.getMap().containsKey(elements[1])) { return "" + (Integer.parseInt(units.getMapValue(elements[0])) * Integer.parseInt(special_groups.getMapValue(elements[1]))); } if (elements.length == 2 && irregular_tens.getMap().containsKey(elements[0]) && special_groups.getMap().containsKey(elements[1])) { return "" + (Integer.parseInt(irregular_tens.getMapValue(elements[0])) * Integer.parseInt(special_groups.getMapValue(elements[1]))); } if (elements.length == 2 && tens.getMap().containsKey(elements[0]) && special_groups.getMap().containsKey(elements[1])) { return "" + (Integer.parseInt(tens.getMapValue(elements[0])) * Integer.parseInt(special_groups.getMapValue(elements[1]))); } if (elements.length == 2 && special_groups.getMap().containsKey(elements[0]) && magnitudes.getMap().containsKey(elements[1])) { return "" + (Integer.parseInt(special_groups.getMapValue(elements[0])) * Integer.parseInt(magnitudes.getMapValue(elements[1]))); } if (elements.length == 3 && units.getMap().containsKey(elements[0]) && special_groups.getMap().containsKey(elements[1]) && magnitudes.getMap().containsKey(elements[2])) { return "" + (Integer.parseInt(units.getMapValue(elements[0])) * Integer.parseInt(special_groups.getMapValue(elements[1])) * Integer.parseInt(magnitudes.getMapValue(elements[2]))); } } if (elements[0].matches("([0-9]+|([0-9]*.[0-9]+))")) { if (elements.length != 2) { if (System.getProperty("DEBUG") != null && System.getProperty("DEBUG").equalsIgnoreCase("true")) { System.err.println("(UNDER CONSTRUCTION) Only the number and the first magnitude will be normalized: " + snumber); } } Integer magn = Integer.parseInt(magnitudes.getMapValue(elements[1])); if (magn == null) { if (System.getProperty("DEBUG") != null && System.getProperty("DEBUG").equalsIgnoreCase("true")) { System.err.println("In [0-9]+ magnitude numbers the second component must be a valid magnitude. Found: " + elements[1] + " from: " + snumber); } magn = 1; } return prettyFormat((Double.parseDouble(elements[0]) * magn)); } else { Integer i = elements.length - 1; while (i >= 0) { String element = elements[i].trim(); magnitude = null; if (magnitudes.getMapValue(element) != null) { magnitude = Integer.parseInt(magnitudes.getMapValue(element)); } if (magnitude != null) { if (magnitude <= (((int) Math.pow(10, number.value.toString().substring(0, number.value.toString().lastIndexOf('.')).length()) - 1))) { throw new Exception("Greater magnitude expected in " + element + " (" + snumber + ")"); } i = operateMagnitude(elements, i, number); } else { if (i != (elements.length - 1)) { throw new Exception("Unexpected number when looking for a magnitude. Found: " + element + " (" + snumber + ")"); } i = getNumber(elements, i, number, max_magn); } } } } catch (Exception e) { if (System.getProperty("DEBUG") != null && System.getProperty("DEBUG").equalsIgnoreCase("true")) { System.err.println("Errors found (NUMEK):\n\t" + e.toString()); e.printStackTrace(System.err); System.exit(1); } return snumber; } return prettyFormat(number.value); } }
Numek { public String text2number(String snumber) { Number number = new Number(); try { snumber = snumber.trim().toLowerCase(locale); Integer magnitude = 0; Integer max_magn = MAX_NUMBERS_ORDER; String[] elements = snumber.split("(\\s*-\\s*|\\s+" + delimiters.getRE() + "\\s+|\\s+)"); if (group_separators != null) { snumber = snumber.replaceAll(group_separators.getRE(), ""); } if (decimal_point_separator != null) { snumber = snumber.replaceAll(decimal_point_separator.getRE(), "."); } if (snumber.matches("(-)?[0-9]+(\\.[0-9]+)?")) { return prettyFormat(Double.parseDouble(snumber)); } if (snumber.matches("(-)?[0-9]+%")) { return "" + (Double.parseDouble(snumber.substring(0, snumber.length() - 1)) / 100); } if (snumber.matches("([0-9]+ )?[0-9]+/[0-9]+")) { return "" + calc_and_sum_frac(snumber); } for (int i = 0; i < elements.length; i++) { if (i == 0 && !elements[i].matches("[0-9]+("+ordinal_suffixes.getRE()+")?") && !all_keys.contains(elements[i])) { throw new Exception("Unknown element (0): " + elements[i] + " in " + snumber); } if (i != 0 && !all_keys.contains(elements[i])) { throw new Exception("Unknown element (" + i + "): " + elements[i] + " in " + snumber); } } if (elements.length == 1 && ordinal_units.getMap().containsKey(elements[0])) { return "" + ordinal_units.getMapValue(elements[0]); } if (ordinal_irregular_tens!=null && elements.length == 1 && ordinal_irregular_tens.getMap().containsKey(elements[0])) { return "" + ordinal_irregular_tens.getMapValue(elements[0]); } if (ordinal_tens!=null && elements.length == 2 && ordinal_tens.getMap().containsKey(elements[0]) && ordinal_units.getMap().containsKey(elements[1])) { return "ord__" + (Integer.parseInt(ordinal_tens.getMapValue(elements[0]).replace("ord__", ""))+Integer.parseInt(ordinal_units.getMapValue(elements[1]).replace("ord__", ""))); } if(snumber.matches("[0-9]+\\s*"+ordinal_suffixes.getRE())){ return "ord__"+snumber.replaceAll(ordinal_suffixes.getRE(), ""); } if (snumber.matches(".*" + special_groups.getRE() + ".*")) { if (elements.length == 1 && special_groups.getMap().containsKey(elements[0])) { return "" + special_groups.getMapValue(elements[0]); } if (elements.length == 2 && units.getMap().containsKey(elements[0]) && special_groups.getMap().containsKey(elements[1])) { return "" + (Integer.parseInt(units.getMapValue(elements[0])) * Integer.parseInt(special_groups.getMapValue(elements[1]))); } if (elements.length == 2 && irregular_tens.getMap().containsKey(elements[0]) && special_groups.getMap().containsKey(elements[1])) { return "" + (Integer.parseInt(irregular_tens.getMapValue(elements[0])) * Integer.parseInt(special_groups.getMapValue(elements[1]))); } if (elements.length == 2 && tens.getMap().containsKey(elements[0]) && special_groups.getMap().containsKey(elements[1])) { return "" + (Integer.parseInt(tens.getMapValue(elements[0])) * Integer.parseInt(special_groups.getMapValue(elements[1]))); } if (elements.length == 2 && special_groups.getMap().containsKey(elements[0]) && magnitudes.getMap().containsKey(elements[1])) { return "" + (Integer.parseInt(special_groups.getMapValue(elements[0])) * Integer.parseInt(magnitudes.getMapValue(elements[1]))); } if (elements.length == 3 && units.getMap().containsKey(elements[0]) && special_groups.getMap().containsKey(elements[1]) && magnitudes.getMap().containsKey(elements[2])) { return "" + (Integer.parseInt(units.getMapValue(elements[0])) * Integer.parseInt(special_groups.getMapValue(elements[1])) * Integer.parseInt(magnitudes.getMapValue(elements[2]))); } } if (elements[0].matches("([0-9]+|([0-9]*.[0-9]+))")) { if (elements.length != 2) { if (System.getProperty("DEBUG") != null && System.getProperty("DEBUG").equalsIgnoreCase("true")) { System.err.println("(UNDER CONSTRUCTION) Only the number and the first magnitude will be normalized: " + snumber); } } Integer magn = Integer.parseInt(magnitudes.getMapValue(elements[1])); if (magn == null) { if (System.getProperty("DEBUG") != null && System.getProperty("DEBUG").equalsIgnoreCase("true")) { System.err.println("In [0-9]+ magnitude numbers the second component must be a valid magnitude. Found: " + elements[1] + " from: " + snumber); } magn = 1; } return prettyFormat((Double.parseDouble(elements[0]) * magn)); } else { Integer i = elements.length - 1; while (i >= 0) { String element = elements[i].trim(); magnitude = null; if (magnitudes.getMapValue(element) != null) { magnitude = Integer.parseInt(magnitudes.getMapValue(element)); } if (magnitude != null) { if (magnitude <= (((int) Math.pow(10, number.value.toString().substring(0, number.value.toString().lastIndexOf('.')).length()) - 1))) { throw new Exception("Greater magnitude expected in " + element + " (" + snumber + ")"); } i = operateMagnitude(elements, i, number); } else { if (i != (elements.length - 1)) { throw new Exception("Unexpected number when looking for a magnitude. Found: " + element + " (" + snumber + ")"); } i = getNumber(elements, i, number, max_magn); } } } } catch (Exception e) { if (System.getProperty("DEBUG") != null && System.getProperty("DEBUG").equalsIgnoreCase("true")) { System.err.println("Errors found (NUMEK):\n\t" + e.toString()); e.printStackTrace(System.err); System.exit(1); } return snumber; } return prettyFormat(number.value); } Numek();  Numek(Locale l);  Numek(Locale l, String resources_dir); }
Numek { public String text2number(String snumber) { Number number = new Number(); try { snumber = snumber.trim().toLowerCase(locale); Integer magnitude = 0; Integer max_magn = MAX_NUMBERS_ORDER; String[] elements = snumber.split("(\\s*-\\s*|\\s+" + delimiters.getRE() + "\\s+|\\s+)"); if (group_separators != null) { snumber = snumber.replaceAll(group_separators.getRE(), ""); } if (decimal_point_separator != null) { snumber = snumber.replaceAll(decimal_point_separator.getRE(), "."); } if (snumber.matches("(-)?[0-9]+(\\.[0-9]+)?")) { return prettyFormat(Double.parseDouble(snumber)); } if (snumber.matches("(-)?[0-9]+%")) { return "" + (Double.parseDouble(snumber.substring(0, snumber.length() - 1)) / 100); } if (snumber.matches("([0-9]+ )?[0-9]+/[0-9]+")) { return "" + calc_and_sum_frac(snumber); } for (int i = 0; i < elements.length; i++) { if (i == 0 && !elements[i].matches("[0-9]+("+ordinal_suffixes.getRE()+")?") && !all_keys.contains(elements[i])) { throw new Exception("Unknown element (0): " + elements[i] + " in " + snumber); } if (i != 0 && !all_keys.contains(elements[i])) { throw new Exception("Unknown element (" + i + "): " + elements[i] + " in " + snumber); } } if (elements.length == 1 && ordinal_units.getMap().containsKey(elements[0])) { return "" + ordinal_units.getMapValue(elements[0]); } if (ordinal_irregular_tens!=null && elements.length == 1 && ordinal_irregular_tens.getMap().containsKey(elements[0])) { return "" + ordinal_irregular_tens.getMapValue(elements[0]); } if (ordinal_tens!=null && elements.length == 2 && ordinal_tens.getMap().containsKey(elements[0]) && ordinal_units.getMap().containsKey(elements[1])) { return "ord__" + (Integer.parseInt(ordinal_tens.getMapValue(elements[0]).replace("ord__", ""))+Integer.parseInt(ordinal_units.getMapValue(elements[1]).replace("ord__", ""))); } if(snumber.matches("[0-9]+\\s*"+ordinal_suffixes.getRE())){ return "ord__"+snumber.replaceAll(ordinal_suffixes.getRE(), ""); } if (snumber.matches(".*" + special_groups.getRE() + ".*")) { if (elements.length == 1 && special_groups.getMap().containsKey(elements[0])) { return "" + special_groups.getMapValue(elements[0]); } if (elements.length == 2 && units.getMap().containsKey(elements[0]) && special_groups.getMap().containsKey(elements[1])) { return "" + (Integer.parseInt(units.getMapValue(elements[0])) * Integer.parseInt(special_groups.getMapValue(elements[1]))); } if (elements.length == 2 && irregular_tens.getMap().containsKey(elements[0]) && special_groups.getMap().containsKey(elements[1])) { return "" + (Integer.parseInt(irregular_tens.getMapValue(elements[0])) * Integer.parseInt(special_groups.getMapValue(elements[1]))); } if (elements.length == 2 && tens.getMap().containsKey(elements[0]) && special_groups.getMap().containsKey(elements[1])) { return "" + (Integer.parseInt(tens.getMapValue(elements[0])) * Integer.parseInt(special_groups.getMapValue(elements[1]))); } if (elements.length == 2 && special_groups.getMap().containsKey(elements[0]) && magnitudes.getMap().containsKey(elements[1])) { return "" + (Integer.parseInt(special_groups.getMapValue(elements[0])) * Integer.parseInt(magnitudes.getMapValue(elements[1]))); } if (elements.length == 3 && units.getMap().containsKey(elements[0]) && special_groups.getMap().containsKey(elements[1]) && magnitudes.getMap().containsKey(elements[2])) { return "" + (Integer.parseInt(units.getMapValue(elements[0])) * Integer.parseInt(special_groups.getMapValue(elements[1])) * Integer.parseInt(magnitudes.getMapValue(elements[2]))); } } if (elements[0].matches("([0-9]+|([0-9]*.[0-9]+))")) { if (elements.length != 2) { if (System.getProperty("DEBUG") != null && System.getProperty("DEBUG").equalsIgnoreCase("true")) { System.err.println("(UNDER CONSTRUCTION) Only the number and the first magnitude will be normalized: " + snumber); } } Integer magn = Integer.parseInt(magnitudes.getMapValue(elements[1])); if (magn == null) { if (System.getProperty("DEBUG") != null && System.getProperty("DEBUG").equalsIgnoreCase("true")) { System.err.println("In [0-9]+ magnitude numbers the second component must be a valid magnitude. Found: " + elements[1] + " from: " + snumber); } magn = 1; } return prettyFormat((Double.parseDouble(elements[0]) * magn)); } else { Integer i = elements.length - 1; while (i >= 0) { String element = elements[i].trim(); magnitude = null; if (magnitudes.getMapValue(element) != null) { magnitude = Integer.parseInt(magnitudes.getMapValue(element)); } if (magnitude != null) { if (magnitude <= (((int) Math.pow(10, number.value.toString().substring(0, number.value.toString().lastIndexOf('.')).length()) - 1))) { throw new Exception("Greater magnitude expected in " + element + " (" + snumber + ")"); } i = operateMagnitude(elements, i, number); } else { if (i != (elements.length - 1)) { throw new Exception("Unexpected number when looking for a magnitude. Found: " + element + " (" + snumber + ")"); } i = getNumber(elements, i, number, max_magn); } } } } catch (Exception e) { if (System.getProperty("DEBUG") != null && System.getProperty("DEBUG").equalsIgnoreCase("true")) { System.err.println("Errors found (NUMEK):\n\t" + e.toString()); e.printStackTrace(System.err); System.exit(1); } return snumber; } return prettyFormat(number.value); } Numek();  Numek(Locale l);  Numek(Locale l, String resources_dir); static Double calc_and_sum_frac(String snumber); String text2number(String snumber); final String disambiguate(String pattern); String getNormTextandPattern(String text, String pattern); static int countOccurrencesOf(String source, char pattern); static String Roman2Decimal(String roman); }
Numek { public String text2number(String snumber) { Number number = new Number(); try { snumber = snumber.trim().toLowerCase(locale); Integer magnitude = 0; Integer max_magn = MAX_NUMBERS_ORDER; String[] elements = snumber.split("(\\s*-\\s*|\\s+" + delimiters.getRE() + "\\s+|\\s+)"); if (group_separators != null) { snumber = snumber.replaceAll(group_separators.getRE(), ""); } if (decimal_point_separator != null) { snumber = snumber.replaceAll(decimal_point_separator.getRE(), "."); } if (snumber.matches("(-)?[0-9]+(\\.[0-9]+)?")) { return prettyFormat(Double.parseDouble(snumber)); } if (snumber.matches("(-)?[0-9]+%")) { return "" + (Double.parseDouble(snumber.substring(0, snumber.length() - 1)) / 100); } if (snumber.matches("([0-9]+ )?[0-9]+/[0-9]+")) { return "" + calc_and_sum_frac(snumber); } for (int i = 0; i < elements.length; i++) { if (i == 0 && !elements[i].matches("[0-9]+("+ordinal_suffixes.getRE()+")?") && !all_keys.contains(elements[i])) { throw new Exception("Unknown element (0): " + elements[i] + " in " + snumber); } if (i != 0 && !all_keys.contains(elements[i])) { throw new Exception("Unknown element (" + i + "): " + elements[i] + " in " + snumber); } } if (elements.length == 1 && ordinal_units.getMap().containsKey(elements[0])) { return "" + ordinal_units.getMapValue(elements[0]); } if (ordinal_irregular_tens!=null && elements.length == 1 && ordinal_irregular_tens.getMap().containsKey(elements[0])) { return "" + ordinal_irregular_tens.getMapValue(elements[0]); } if (ordinal_tens!=null && elements.length == 2 && ordinal_tens.getMap().containsKey(elements[0]) && ordinal_units.getMap().containsKey(elements[1])) { return "ord__" + (Integer.parseInt(ordinal_tens.getMapValue(elements[0]).replace("ord__", ""))+Integer.parseInt(ordinal_units.getMapValue(elements[1]).replace("ord__", ""))); } if(snumber.matches("[0-9]+\\s*"+ordinal_suffixes.getRE())){ return "ord__"+snumber.replaceAll(ordinal_suffixes.getRE(), ""); } if (snumber.matches(".*" + special_groups.getRE() + ".*")) { if (elements.length == 1 && special_groups.getMap().containsKey(elements[0])) { return "" + special_groups.getMapValue(elements[0]); } if (elements.length == 2 && units.getMap().containsKey(elements[0]) && special_groups.getMap().containsKey(elements[1])) { return "" + (Integer.parseInt(units.getMapValue(elements[0])) * Integer.parseInt(special_groups.getMapValue(elements[1]))); } if (elements.length == 2 && irregular_tens.getMap().containsKey(elements[0]) && special_groups.getMap().containsKey(elements[1])) { return "" + (Integer.parseInt(irregular_tens.getMapValue(elements[0])) * Integer.parseInt(special_groups.getMapValue(elements[1]))); } if (elements.length == 2 && tens.getMap().containsKey(elements[0]) && special_groups.getMap().containsKey(elements[1])) { return "" + (Integer.parseInt(tens.getMapValue(elements[0])) * Integer.parseInt(special_groups.getMapValue(elements[1]))); } if (elements.length == 2 && special_groups.getMap().containsKey(elements[0]) && magnitudes.getMap().containsKey(elements[1])) { return "" + (Integer.parseInt(special_groups.getMapValue(elements[0])) * Integer.parseInt(magnitudes.getMapValue(elements[1]))); } if (elements.length == 3 && units.getMap().containsKey(elements[0]) && special_groups.getMap().containsKey(elements[1]) && magnitudes.getMap().containsKey(elements[2])) { return "" + (Integer.parseInt(units.getMapValue(elements[0])) * Integer.parseInt(special_groups.getMapValue(elements[1])) * Integer.parseInt(magnitudes.getMapValue(elements[2]))); } } if (elements[0].matches("([0-9]+|([0-9]*.[0-9]+))")) { if (elements.length != 2) { if (System.getProperty("DEBUG") != null && System.getProperty("DEBUG").equalsIgnoreCase("true")) { System.err.println("(UNDER CONSTRUCTION) Only the number and the first magnitude will be normalized: " + snumber); } } Integer magn = Integer.parseInt(magnitudes.getMapValue(elements[1])); if (magn == null) { if (System.getProperty("DEBUG") != null && System.getProperty("DEBUG").equalsIgnoreCase("true")) { System.err.println("In [0-9]+ magnitude numbers the second component must be a valid magnitude. Found: " + elements[1] + " from: " + snumber); } magn = 1; } return prettyFormat((Double.parseDouble(elements[0]) * magn)); } else { Integer i = elements.length - 1; while (i >= 0) { String element = elements[i].trim(); magnitude = null; if (magnitudes.getMapValue(element) != null) { magnitude = Integer.parseInt(magnitudes.getMapValue(element)); } if (magnitude != null) { if (magnitude <= (((int) Math.pow(10, number.value.toString().substring(0, number.value.toString().lastIndexOf('.')).length()) - 1))) { throw new Exception("Greater magnitude expected in " + element + " (" + snumber + ")"); } i = operateMagnitude(elements, i, number); } else { if (i != (elements.length - 1)) { throw new Exception("Unexpected number when looking for a magnitude. Found: " + element + " (" + snumber + ")"); } i = getNumber(elements, i, number, max_magn); } } } } catch (Exception e) { if (System.getProperty("DEBUG") != null && System.getProperty("DEBUG").equalsIgnoreCase("true")) { System.err.println("Errors found (NUMEK):\n\t" + e.toString()); e.printStackTrace(System.err); System.exit(1); } return snumber; } return prettyFormat(number.value); } Numek();  Numek(Locale l);  Numek(Locale l, String resources_dir); static Double calc_and_sum_frac(String snumber); String text2number(String snumber); final String disambiguate(String pattern); String getNormTextandPattern(String text, String pattern); static int countOccurrencesOf(String source, char pattern); static String Roman2Decimal(String roman); public Locale locale; public HashSet<String> all_keys; public HashSet<String> repeated_keys; public PhraselistFile ambiguous; public PhraselistFile delimiters; public PhraselistFile units; public PhraselistFile tens; public PhraselistFile irregular_tens; public PhraselistFile magnitudes; public PhraselistFile special_groups; public PhraselistFile restrictions; public PhraselistFile ordinal_units; public PhraselistFile ordinal_irregular_tens; public PhraselistFile ordinal_tens; public PhraselistFile ordinal_suffixes; public PhraselistFile decimal_point_separator; public PhraselistFile group_separators; final static Integer MAX_NUMBERS_ORDER; static String romans; static String romans5; final static HashMap<String, Integer> romansMap; }