Class NumberConverter

java.lang.Object
amadeus.perception.NumberConverter

public class NumberConverter extends Object
A utility class for converting written number words into their numeric equivalents.

This implementation follows a rule-based approach without relying on a hash map to allow flexibility and expansion. It supports numbers up to the thousands and handles compound numbers like "twenty-one" or "three hundred and five."

  • Constructor Details

    • NumberConverter

      public NumberConverter()
  • Method Details

    • wordToNumber

      public static int wordToNumber(String input)
      Converts a number written in words into its integer representation.

      Supports numbers from "one" to "nine thousand nine hundred ninety-nine." Handles compound numbers like "twenty-one" or "three hundred and five." Ignores the word "and" for natural language compatibility. Returns -1 if input is invalid or contains unrecognized words.

      Parameters:
      input - the number written in words (e.g., "two hundred forty-five"); must not be null.
      Returns:
      the integer representation of the input word, or -1 for invalid input.
    • extractIndex

      public static int extractIndex(String argument)
      Extracts a task index from the provided argument.

      The argument can be either a numeric string (e.g., "1") or a word representing a number (e.g., "one"). If the argument is invalid or cannot be converted to a number, -1 is returned.

      Parameters:
      argument - the string containing the task index (numeric or word format); must not be null.
      Returns:
      the task index as an integer, or -1 if the argument is invalid.
    • main

      public static void main(String[] args)
      Main method for testing the NumberConverter class.
      Parameters:
      args - command-line arguments (not used).