test_normalizer.py 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import pytest
  2. from whisper.normalizers import EnglishTextNormalizer
  3. from whisper.normalizers.english import EnglishNumberNormalizer, EnglishSpellingNormalizer
  4. @pytest.mark.parametrize("std", [EnglishNumberNormalizer(), EnglishTextNormalizer()])
  5. def test_number_normalizer(std):
  6. assert std("two") == "2"
  7. assert std("thirty one") == "31"
  8. assert std("five twenty four") == "524"
  9. assert std("nineteen ninety nine") == "1999"
  10. assert std("twenty nineteen") == "2019"
  11. assert std("two point five million") == "2500000"
  12. assert std("four point two billions") == "4200000000s"
  13. assert std("200 thousand") == "200000"
  14. assert std("200 thousand dollars") == "$200000"
  15. assert std("$20 million") == "$20000000"
  16. assert std("€52.4 million") == "€52400000"
  17. assert std("£77 thousands") == "£77000s"
  18. assert std("two double o eight") == "2008"
  19. assert std("three thousand twenty nine") == "3029"
  20. assert std("forty three thousand two hundred sixty") == "43260"
  21. assert std("forty three thousand two hundred and sixty") == "43260"
  22. assert std("nineteen fifties") == "1950s"
  23. assert std("thirty first") == "31st"
  24. assert std("thirty three thousand and three hundred and thirty third") == "33333rd"
  25. assert std("three billion") == "3000000000"
  26. assert std("millions") == "1000000s"
  27. assert std("july third twenty twenty") == "july 3rd 2020"
  28. assert std("august twenty sixth twenty twenty one") == "august 26th 2021"
  29. assert std("3 14") == "3 14"
  30. assert std("3.14") == "3.14"
  31. assert std("3 point 2") == "3.2"
  32. assert std("3 point 14") == "3.14"
  33. assert std("fourteen point 4") == "14.4"
  34. assert std("two point two five dollars") == "$2.25"
  35. assert std("two hundred million dollars") == "$200000000"
  36. assert std("$20.1 million") == "$20100000"
  37. assert std("ninety percent") == "90%"
  38. assert std("seventy six per cent") == "76%"
  39. assert std("double oh seven") == "007"
  40. assert std("double zero seven") == "007"
  41. assert std("nine one one") == "911"
  42. assert std("nine double one") == "911"
  43. assert std("one triple oh one") == "10001"
  44. assert std("two thousandth") == "2000th"
  45. assert std("thirty two thousandth") == "32000th"
  46. assert std("minus 500") == "-500"
  47. assert std("positive twenty thousand") == "+20000"
  48. assert std("two dollars and seventy cents") == "$2.70"
  49. assert std("3 cents") == "¢3"
  50. assert std("$0.36") == "¢36"
  51. assert std("three euros and sixty five cents") == "€3.65"
  52. assert std("three and a half million") == "3500000"
  53. assert std("forty eight and a half dollars") == "$48.5"
  54. assert std("b747") == "b 747"
  55. assert std("10 th") == "10th"
  56. assert std("10th") == "10th"
  57. def test_spelling_normalizer():
  58. std = EnglishSpellingNormalizer()
  59. assert std("mobilisation") == "mobilization"
  60. assert std("cancelation") == "cancellation"
  61. def test_text_normalizer():
  62. std = EnglishTextNormalizer()
  63. assert std("Let's") == "let us"
  64. assert std("he's like") == "he is like"
  65. assert std("she's been like") == "she has been like"
  66. assert std("10km") == "10 km"
  67. assert std("RC232") == "rc 232"
  68. assert (
  69. std("Mr. Park visited Assoc. Prof. Kim Jr.")
  70. == "mister park visited associate professor kim junior"
  71. )