java.lang.Object
de.uni_mannheim.informatik.dws.melt.matching_jena_matchers.util.NumberToWordsConverter

public class NumberToWordsConverter extends Object
Converts number to words like 1 to one and 3 to three.
  • Field Details

    • numberPattern

      private static final Pattern numberPattern
    • replacementMap

      private Map<String,String> replacementMap
    • specialNames

      private static final String[] specialNames
    • tensNames

      private static final String[] tensNames
    • numNames

      private static final String[] numNames
  • Constructor Details

    • NumberToWordsConverter

      public NumberToWordsConverter(int from, int to)
      Specify a range in which numbers should be converted to
      Parameters:
      from - from value (inclusive)
      to - to value (inclusive)
    • NumberToWordsConverter

      public NumberToWordsConverter(int to)
      Specify a range in which numbers should be converted to
      Parameters:
      to - to value (inclusive)
    • NumberToWordsConverter

      public NumberToWordsConverter()
      Default constructor which only replaces numbers between 0 and 9 (both inclusive). Thus "11" is not converted to words.
  • Method Details

    • replaceNumbersInText

      public String replaceNumbersInText(String text)
      Replace numbers in arbirary text like "hello 42 nice2have". It will return "hello fourty two nicetwohave" (only in case the numbers are in the specified range).
      Parameters:
      text - any text containing numbers
      Returns:
      text with numbers replaced as words.
    • replaceNumberToken

      public String replaceNumberToken(String number)
      Returns the number (like "1" or "42") as words ("one" or "fourty two"). The parameter should only contain the number as single token and nothing more. If you want to replace numbers in text use replaceNumbersInText(java.lang.String).
      Parameters:
      number - a string containing only a number like "1" or "42"
      Returns:
      the number as words
    • getReplacementMap

      public Map<String,String> getReplacementMap()
    • replaceAllNumbersInText

      public static String replaceAllNumbersInText(String text)
      Replaces all number in text with corresponding words. "hello 42 nice2have" will be converted to "hello fourty two nicetwohave".
      Parameters:
      text - any text containing numbers
      Returns:
      text with numbers replaced as words.
    • convert

      public static String convert(String numberAsString)
    • convert

      public static String convert(int number)
    • convertLessThanOneThousand

      private static String convertLessThanOneThousand(int number)