[Tutor] String manipulation: Pig latin translator

Eike Welk eike.welk at gmx.net
Sun Jul 12 14:52:17 CEST 2009


Hello Eddie!

On Sunday 12 July 2009, Eddie wrote:
> Hi guys,
>
> What I have here is more of a logic problem that I can't get my
> head around than a programming problem. I am trying to program an
> English to Pig Latin translator. I've got the English to Pig Latin
> part down and its working great.
>
> The part I am having difficulty with is the Pig Latin to English
> part. Say I have the word ellohay (hello) which I wish to convert
> into English. The first thing I am doing is removing the added ay
> at the end and the new word becomes elloh.
>
> This is where I have the problem. I have to somehow identify which
> letters to remove from the end and add back to the front of the
> word (i.e. h needs to be removed and added back to the front).
> However with a word such as string which translates as ingstray,
> when we remove the ay we are left with ingstr, and need to identify
> that str needs to be removed and added back on the front.
>
> I am lost as to how to identify which characters need to be removed
> to be re-added to the front and can't find a common rule to program
> by. There are translators out there already like this, so it works
> somehow, I just need a push in the right direction i think [image:
> :)]
>
> Thanks

I didn't look up the rules for creating Pig Latin. But from looking at 
your examples: hello --> ellohay, string --> ingstray, I think that 
information loss occurs in the conversion English --> Pig Latin. This 
means that the operation can not be reversed with an algorithm that 
only sees the word in question.

The most easy solution IMHO is to download a big English text from the 
Internet, and translate it to Pig Latin. During the translation you 
create a big reverse mapping: Pig Latin --> English, which for use in 
the reverse translator. 

This method exploits the fact that not each character combination is a 
valid English word. But there may be collisions: two different 
English words that have the same Pig Latin translation. It would be 
interesting to see if such collisions do really occur with English 
source text. 

  
Kind regards,
Eike.



More information about the Tutor mailing list