There was one last bit of work that needed to be done to the Reciter class, transforming the letters-to-phoneme string back into just phonemes and placing the hyphens in the right place.
Given the input string:
"sup-er-nat-ur-al"
The input string is cleaned of all non-alphabetic characters except for hyphens and apostrophes:
"SUP-ER-NAT-UR-AL"
The string is then prepared to be parsed by removing the hyphens and placing spaces as delimiters before and after the word:
" SUPERNATURAL "
This string is then processed by the Reciter rules to be solved, and it returns a string containing the original letters (in upper case) and the phonemes (in lower case):
" Ss Uuw Pp Eer R Nn Aae Tch Uer R Aah Ll"
The parsed string is walked through character by character, basically:
var out_string:String = "" var clean_string_pos:int = 0 for letter in parsed_string: if letter == " ": if clean_string.substr(clean_string_pos,1) == "-" out_string += "-" clean_string_pos += 1 elif letter == letter.to_upper() if letter != clean_string.substr(clean_string_pos,1): # warning, letters should match clean_string_pos += 1 else: out_string += letter
The result is the phonetic string with hyphen placed as the user indicated:
suwp-er-naech-er-ahl
There's more that needs to be handled, the bare bones code is working.
No comments:
Post a Comment