public static String numerize(String str) {
    String numerizedStr = str;
    
    // preprocess
    numerizedStr = Numerizer.DEHYPHENATOR.matcher(numerizedStr).replaceAll("$1 $2"); // will mutilate hyphenated-words but shouldn't matter for date extraction
    numerizedStr = Numerizer.DEHALFER.matcher(numerizedStr).replaceAll("haAlf"); // take the 'a' out so it doesn't turn into a 1, save the half for the end
    
    // easy/direct replacements
    for (DirectNum dn : Numerizer.DIRECT_NUMS) {
      numerizedStr = dn.getName().matcher(numerizedStr).replaceAll(dn.getNumber());
    }
    
    // ten, twenty, etc.
    for (Prefix tp : Numerizer.TEN_PREFIXES) {
      Matcher matcher = tp.getName().matcher(numerizedStr);
      if (matcher.find()) {
        StringBuffer matcherBuffer = new StringBuffer();
        do {
          if (matcher.group(1) == null) {
            matcher.appendReplacement(matcherBuffer, String.valueOf(tp.getNumber()));
          }
          else {
            matcher.appendReplacement(matcherBuffer, String.valueOf(tp.getNumber() + Long.parseLong(matcher.group(1).trim())));
          }
        } while (matcher.find());
        matcher.appendTail(matcherBuffer);
        numerizedStr = matcherBuffer.toString();
      }
    }
    
    // hundreds, thousands, millions, etc.
    for (Prefix bp : Numerizer.BIG_PREFIXES) {
      Matcher matcher = bp.getName().matcher(numerizedStr);
      if (matcher.find()) {
        StringBuffer matcherBuffer = new StringBuffer();
        do {
          if (matcher.group(1) == null) {
            matcher.appendReplacement(matcherBuffer, String.valueOf(bp.getNumber()));
          }
          else {
            matcher.appendReplacement(matcherBuffer, String.valueOf(bp.getNumber() * Long.parseLong(matcher.group(1).trim())));
          }
        } while (matcher.find());
        matcher.appendTail(matcherBuffer);
        numerizedStr = matcherBuffer.toString();
        numerizedStr = Numerizer.andition(numerizedStr);
        // combine_numbers(string) // Should to be more efficient way to do this
      }
    }

    // fractional addition
    // I'm not combining this with the previous block as using float addition complicates the strings
    // (with extraneous .0's and such )
    Matcher matcher = Numerizer.DEHAALFER.matcher(numerizedStr);
    if (matcher.find()) {
      StringBuffer matcherBuffer = new StringBuffer();
      do {
        matcher.appendReplacement(matcherBuffer, String.valueOf(Float.parseFloat(matcher.group(1).trim()) + 0.5f));
      } while (matcher.find());
      matcher.appendTail(matcherBuffer);
      numerizedStr = matcherBuffer.toString();
    }
    //string.gsub!(/(\d+)(?: | and |-)*haAlf/i) { ($1.to_f + 0.5).to_s }

    return numerizedStr;
  }
public static String numerize ( String str ) { String numerizedStr = str ; numerizedStr = Numerizer . DEHYPHENATOR . matcher ( numerizedStr ) . replaceAll ( "$1 $2" ) ; numerizedStr = Numerizer . DEHALFER . matcher ( numerizedStr ) . replaceAll ( "haAlf" ) ; for ( DirectNum dn : Numerizer . DIRECT_NUMS ) { numerizedStr = dn . getName ( ) . matcher ( numerizedStr ) . replaceAll ( dn . getNumber ( ) ) ; } for ( Prefix tp : Numerizer . TEN_PREFIXES ) { Matcher matcher = tp . getName ( ) . matcher ( numerizedStr ) ; if ( matcher . find ( ) ) { StringBuffer matcherBuffer = new StringBuffer ( ) ; do { if ( matcher . group ( 1 ) == null ) { matcher . appendReplacement ( matcherBuffer , String . valueOf ( tp . getNumber ( ) ) ) ; } else { matcher . appendReplacement ( matcherBuffer , String . valueOf ( tp . getNumber ( ) + Long . parseLong ( matcher . group ( 1 ) . trim ( ) ) ) ) ; } } while ( matcher . find ( ) ) ; matcher . appendTail ( matcherBuffer ) ; numerizedStr = matcherBuffer . toString ( ) ; } } for ( Prefix bp : Numerizer . BIG_PREFIXES ) { Matcher matcher = bp . getName ( ) . matcher ( numerizedStr ) ; if ( matcher . find ( ) ) { StringBuffer matcherBuffer = new StringBuffer ( ) ; do { if ( matcher . group ( 1 ) == null ) { matcher . appendReplacement ( matcherBuffer , String . valueOf ( bp . getNumber ( ) ) ) ; } else { matcher . appendReplacement ( matcherBuffer , String . valueOf ( bp . getNumber ( ) * Long . parseLong ( matcher . group ( 1 ) . trim ( ) ) ) ) ; } } while ( matcher . find ( ) ) ; matcher . appendTail ( matcherBuffer ) ; numerizedStr = matcherBuffer . toString ( ) ; numerizedStr = Numerizer . andition ( numerizedStr ) ; } } Matcher matcher = Numerizer . DEHAALFER . matcher ( numerizedStr ) ; if ( matcher . find ( ) ) { StringBuffer matcherBuffer = new StringBuffer ( ) ; do { matcher . appendReplacement ( matcherBuffer , String . valueOf ( Float . parseFloat ( matcher . group ( 1 ) . trim ( ) ) + 0.5f ) ) ; } while ( matcher . find ( ) ) ; matcher . appendTail ( matcherBuffer ) ; numerizedStr = matcherBuffer . toString ( ) ; } return numerizedStr ; }
string.gsub!(/ +|([^\d])-([^\\d])/, '\1 \2') # will mutilate hyphenated-words but shouldn't matter for date extraction