Question

In: Computer Science

How would you go about writing a MATLAB program to convert a phrase in Pig Latin...

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

Solutions

Expert Solution

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

Related Solutions

Write a program that converts an English phrase into pseudo-Pig Latin phrase (that is Pig Latin...
Write a program that converts an English phrase into pseudo-Pig Latin phrase (that is Pig Latin that doesn't allow follow all the Pig Latin Syntax rules.) Use predefined methods of the Array and String classes to do the work. For simplicity in your conversion, place the first letter as the last character in the word and prefix the characters "ay" onto the end. For example, the word "example" would become "xampleay" and "method" would become "ethodmay." Allow the user to...
In Java.This program will translate a word into pig-latin. Pig-latin is a language game in which...
In Java.This program will translate a word into pig-latin. Pig-latin is a language game in which words in English are altered, usually by removing letters from the beginning of a word and arranging them into a suffix. The rules we will use for the pig-latin in this program are as follows: If a word starts with a consonant, split the word at the first instance of a vowel, moving the beginning consonants to the end of the word, following a...
C++ Project 6-2: Pig Latin Translator Create a program that translates English to Pig Latin. Console...
C++ Project 6-2: Pig Latin Translator Create a program that translates English to Pig Latin. Console Pig Latin Translator This program translates a sentence and removes all punctuation from it. Enter a sentence: 'Tis but a scratch. Translation:      Istay utbay away atchscray Specifications Convert the English to lowercase before translating. Remove all punctuation characters before translating. Assume that words are separated from each other by a single space. If the word starts with a vowel, just add way to the...
How do I write a COBOL program that translates a word entered into pig Latin?
How do I write a COBOL program that translates a word entered into pig Latin?
Create a program that translates English into Pig Latin. The function will take the first letter...
Create a program that translates English into Pig Latin. The function will take the first letter of each word in the sentence only if it’s a not a vowel, and place it at the end of the word followed by “ay”. Your program must be case ​ins​ ensitive. You must write the functiontranslate() ​that takes in a single English word and ​returns​ its Pig Latin translation. Remembertranslatemusttake​onlyonewordasinput.​ ############################################################# # translate() takes a single english word translates it to #pig latin...
How would I go about making a simple code for an analog clock using matlab?
How would I go about making a simple code for an analog clock using matlab?
Briefly describe how you would go about normalizing data
Briefly describe how you would go about normalizing data
Language: matlab It is desired to create a mortgage estimator by writing a program containing a...
Language: matlab It is desired to create a mortgage estimator by writing a program containing a function. The user inputs the amount of loan (L), the loan term in number of months (N), and the annual interest rate (I) in the script. The script then makes use of a function that accepts these values as inputs through its argument and calculates and returns the monthly payment and the total payments over the life of the loan. The monthly payment and...
If you were to set-up an informational interview, how would you go about this? What would...
If you were to set-up an informational interview, how would you go about this? What would be your first step? Who would you contact and why? What questions would you ask?
You can turn a word into pig-Latin using the following two rules: If the word starts...
You can turn a word into pig-Latin using the following two rules: If the word starts with a consonant, move that letter to the end and append 'ay'. For example, 'happy' becomes 'appyhay' and 'pencil' becomes 'encilpay'. If the word starts with a vowel, simply append 'way' to the end of the word. For example, 'enter' becomes 'enterway' and 'other' becomes 'otherway'. For our purposes, there are 5 vowels: a, e, i, o, u (we consider y as a consonant)....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT