Skip to content

Commit

Permalink
Accept fourty as 40... probably can't mean anything else, after all
Browse files Browse the repository at this point in the history
  • Loading branch information
AngledLuffa committed Aug 31, 2023
1 parent d5daf7c commit 7fbb7b8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
8 changes: 5 additions & 3 deletions itest/src/edu/stanford/nlp/ie/NumberNormalizerITest.java
Expand Up @@ -67,15 +67,17 @@ public void testNumbers() {
"a dozen bagels\n" +
"five dozen\n" +
"An IQ score of 161.\n" + // only 161, not 20 for score
"thirty two"
"thirty two\n" +
"I hope Jennifer would let me lick her antennae even though I am forty-five\n" +
"I hope Jennifer would let me lick her antennae even though I am fourty-five"
;

// set up expected results
Iterator<? extends Number> expectedNumbers = Arrays.asList(
24.0, 405, 600.0, 412.0, 4650211.0, 600005650376.0, 5786345, 25.0,
/* 1500000.0, */
1300000.0, 1224.0, 10000000000.0, 3.625,
0, -15.0, 1, 2, 3, 4, 155.0, 101.0 /*504.0, */, 80.0, 12, 60.0, 161, 32.0 ).iterator();
0, -15.0, 1, 2, 3, 4, 155.0, 101.0 /*504.0, */, 80.0, 12, 60.0, 161, 32.0, 45.0, 45.0 ).iterator();
Iterator<String> expectedTexts = Arrays.asList(
"two dozen", "405", "six hundred", "four hundred, and twelve",
"4 million six hundred fifty thousand, two hundred and eleven",
Expand All @@ -93,7 +95,7 @@ public void testNumbers() {
"four score",
"dozen",
"five dozen",
"161", "thirty two").iterator();
"161", "thirty two", "forty-five", "fourty-five").iterator();

// create document
Annotation document = createDocument(testText);
Expand Down
3 changes: 2 additions & 1 deletion src/edu/stanford/nlp/ie/NumberNormalizer.java
Expand Up @@ -78,7 +78,7 @@ public static void setVerbose(boolean verbose) {

/***********************/

private static final Pattern numberTermPattern = Pattern.compile("(?i)(zero|one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve|thirteen|fourteen|fifteen|sixteen|seventeen|eighteen|nineteen|twenty|thirty|forty|fifty|sixty|seventy|eighty|ninety|hundred|thousand|million|billion|trillion|first|second|third|fourth|fifth|sixth|seventh|eighth|ninth|tenth|eleventh|twelfth|thirteenth|fourteenth|fifteenth|sixteenth|seventeenth|eighteenth|nineteenth|twentieth|thirtieth|fortieth|fiftieth|sixtieth|seventieth|eightieth|ninetieth|hundred?th|thousandth|millionth|billionth|trillionth)");
private static final Pattern numberTermPattern = Pattern.compile("(?i)(zero|one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve|thirteen|fourteen|fifteen|sixteen|seventeen|eighteen|nineteen|twenty|thirty|forty|fourty|fifty|sixty|seventy|eighty|ninety|hundred|thousand|million|billion|trillion|first|second|third|fourth|fifth|sixth|seventh|eighth|ninth|tenth|eleventh|twelfth|thirteenth|fourteenth|fifteenth|sixteenth|seventeenth|eighteenth|nineteenth|twentieth|thirtieth|fortieth|fiftieth|sixtieth|seventieth|eightieth|ninetieth|hundred?th|thousandth|millionth|billionth|trillionth)");
private static final Pattern numberTermPattern2 = Pattern.compile("(?i)(" + numberTermPattern.pattern() + "(-" + numberTermPattern.pattern() + ")?)");
private static final Pattern ordinalUnitPattern = Pattern.compile("(?i)(hundredth|thousandth|millionth)");

Expand Down Expand Up @@ -147,6 +147,7 @@ public static void setVerbose(boolean verbose) {
word2NumMap.put("twenty", 20);
word2NumMap.put("thirty", 30);
word2NumMap.put("forty", 40);
word2NumMap.put("fourty", 40);
word2NumMap.put("fifty", 50);
word2NumMap.put("sixty", 60);
word2NumMap.put("seventy", 70);
Expand Down

0 comments on commit 7fbb7b8

Please sign in to comment.