Advertisement
Guest User

lab2thinh

a guest
Oct 21st, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. def validWord(word: str) -> bool:
  2. valid_char = ['a', 'e', 'i', 'o', 'u', 'p', 'k', 'h', 'l', 'm', 'n', 'w', '\'', ' ']
  3. for char in word:
  4. if char not in valid_char:
  5. return False
  6. return True
  7.  
  8.  
  9. def pronunciate(phrase: str) -> str:
  10.  
  11. singleLetter = {'a': 'ah', 'e': 'eh', 'i': 'ee', 'o': 'oh', 'u': 'oo'}
  12. doubleLetter = {'ai': 'eye', 'ae': 'eye', 'ao': 'ow', 'au': 'ow', 'ei': 'ay',
  13. 'eu': 'eh - oo', 'iu': 'ew', 'oi': 'oy',
  14. 'ou': 'ow', 'ui': 'ooey'}
  15.  
  16. pronunciation = ''
  17. counter = 0
  18. phrase = phrase.lower()
  19.  
  20. for i in range(len(phrase)):
  21. if counter == 0:
  22. if phrase[i:i + 2] in doubleLetter:
  23. pronunciation += doubleLetter[phrase[i:i + 2]]
  24. counter += 1
  25. if (i < len(phrase) - 2) and (phrase[i + 1] not in (' ', '\'')):
  26. pronunciation += '-'
  27. elif phrase[i] in singleLetter:
  28. pronunciation += singleLetter[phrase[i]]
  29. if (i < len(phrase) - 1) and (phrase[i + 1] not in (' ', '\'')):
  30. pronunciation += '-'
  31. else:
  32. pronunciation += phrase[i]
  33. else:
  34. counter = 0
  35.  
  36.  
  37. if 'w' in pronunciation:
  38. dissection = []
  39. for char in pronunciation:
  40. dissection.append(char)
  41. for i in range(len(dissection)):
  42. if dissection[i] == 'w':
  43. if dissection[i - 1] in ('\'', ' ', '-'):
  44. if dissection[i - 2] in ('i', 'e'):
  45. dissection[i] = 'v'
  46. elif dissection[i - 2] in ('u', 'o'):
  47. dissection[i] = 'v'
  48. else:
  49. if dissection[i - 1] in ('i', 'e'):
  50. dissection[i] = 'v'
  51. elif dissection[i - 1] in ('u', 'o'):
  52. dissection[i] = 'v'
  53. pronunciation = ''.join(dissection)
  54.  
  55.  
  56. str_list = pronunciation.split(' ')
  57. final = ''
  58.  
  59. for str in str_list:
  60. final += str.capitalize()
  61. final += ' '
  62.  
  63. return final
  64.  
  65.  
  66. print(pronunciate('E komo mai'))
  67. print(pronunciate('hoaloha'))
  68. print(pronunciate('humuhumunukunukuapua\'a'))
  69. print(pronunciate('Mahalo wahine'))
  70. print(pronunciate('maika\'i mahalo'))
  71. print(pronunciate('iwa'))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement