Package amadeus.perception
Class NumberConverter
java.lang.Object
amadeus.perception.NumberConverter
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intextractIndex(String argument) Extracts a task index from the provided argument.static voidMain method for testing theNumberConverterclass.static intwordToNumber(String input) Converts a number written in words into its integer representation.
-
Constructor Details
-
NumberConverter
public NumberConverter()
-
-
Method Details
-
wordToNumber
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 benull.- Returns:
- the integer representation of the input word, or -1 for invalid input.
-
extractIndex
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 benull.- Returns:
- the task index as an integer, or -1 if the argument is invalid.
-
main
Main method for testing theNumberConverterclass.- Parameters:
args- command-line arguments (not used).
-