In: Computer Science
How would you go about writing a MATLAB program to convert a phrase in Pig Latin to English. I have already written a script that converts phrases from English into Pig Latin; however, I am not sure how to reverse the process. Can anyone who know's MATLAB please help me out, thank you?
P.S. I know that this is an unambigious task so it doesn't have to work completely well. With the most minor assumptions made, if it could covert for example ogday -> dog, that would be great. Thank you
Note
PigLatin is not unique in case of ‘ay’ as last character
Example 1: ogday
It can be: dog,gdo
Dog à ogday
Gdo à ogday
Example 2: ootshay
It can be hoots,shoot,tshoo
Hoots à ootshay
Shootàootshay
Tshoo àootshay
Program
str="appleway"; % PigLatin word
len=length(str);
if (str(len-2)=='w') && (str(len-1)=='a') &&
(str(len)=='y')
Translation=str(1:len-3)
end
if (str(len-1)=='a') && (str(len)=='y') &&
(str(len-2)!='w')
i=2;
while (str(len-i)!='a') && (str(len-i)!='e') &&
(str(len-i)!='i') && (str(len-i)!='o') &&
(str(len-i)!='u')
Translation=strcat(str(len-i:len-2),str(1:len-i-1))
i=i+1;
end
end
OUtput
case1 :str="appleway";
Translation = apple
case 2: str="ootshay";
Translation = hoots Translation = shoot Translation = tshoo
case 3:str="ogday";
Translation = dog Translation = gdo