I need to pre-process a speech transcript for forced-alignment. However, I am having difficulty with replacing year with text representation. For example, 1984 needs to be replaced with "nineteen eighty four". I tried the replace_number function of the qdap package. The package is awesome, but it replaces 1984 with "one thousand nine hundred eighty four" instead. Are there other functions from any R packages that may I try? Thanks!
Asked
Active
Viewed 71 times
3
-
english package by Bill Venables – mdsumner May 12 '17 at 06:42
-
Thanks, this is exactly what I need! – Ninjadog Sep 23 '21 at 23:24
-
also check out https://github.com/coolbutuseless/numberwang – mdsumner Sep 24 '21 at 00:25
1 Answers
5
you can split each into two parts and separately convert each part to a character representation:
year = 1984
paste(
replace_number(substr(as.character(year), 1, 2),
replace_number(substr(as.character(year), 3, 4)
)
this would yield nineteen eightyfour

Quinn Weber
- 927
- 5
- 10
-
But how about the case of 1903? How do I make it "nineteen oh three"? – Ninjadog May 12 '17 at 04:48
-
2you could just add some special logic for the first decade of each century. – Quinn Weber May 12 '17 at 04:50
-