Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Pig latin


  • Please log in to reply
12 replies to this topic
GeekDude
  • Spam Officer
  • 391 posts
  • Last active: Oct 05 2015 08:13 PM
  • Joined: 23 Nov 2009

I wrote some code to convert normal english to pig latin a few years ago. It was ~110 lines long, very buggy, and couldn't translate back.
A few days ago I rewrote it using regular expressions in just a couple lines, and now I've decided to post it.

 

Just for fun, I decided to do it without regex, also, and made it work just about the same, and still much shorter than my first try.

InputBox, English
MsgBox, % Eng2Pig(English)
return

Eng2Pig(English)
{
	static Consonants := "bcdfghjklmnpqrstvwxyz", Letters := "abcdefghijklmnopqrstuvwxyz"
	Loop, Parse, English
	{
		Letter := A_LoopField
		if (InStr(Consonants, Letter) && !Conss)
			EndOfWord := EndOfWord . Letter
		else if (!InStr(Letters, Letter) || A_Index = StrLen(English))
		{
			if Word
				Word := Word . "-" . EndOfWord . "ay"
			PigLatin .= Word . Letter
			Word :=
			EndOfWord :=
			Conss :=
		}
		else
		{
			Conss := 1
			Word .= Letter
		}
	}
	return PigLatin
}

RegEng2Pig(Eng)
{
	return RegExReplace(Eng, "i)\b([bcdfghjklmnpqrstvwxyz]*)(\w+)\b", "$2-$1ay")
}

Pig2Eng(Pig)
{
	return RegExReplace(Pig, "i)\b(\w+)-([bcdfghjklmnpqrstvwxyz]*)ay\b", "$2$1")
}


Wingfat
  • Members
  • 937 posts
  • Last active: Oct 14 2015 04:20 PM
  • Joined: 23 Aug 2004
Sweet! how fun... now to change it into Horse Latin and I will be supper happy.
----------------------------
Wingfool you fat! I mean, Wingfat you fool!
Line from Woody Allen's movie "What's Up Tiger Lilly?"
-----------------------------

GeekDude
  • Spam Officer
  • 391 posts
  • Last active: Oct 05 2015 08:13 PM
  • Joined: 23 Nov 2009

Sweet! how fun... now to change it into Horse Latin and I will be supper happy.

Horse latin???

InputBox, English
MsgBox, % Eng2Horse(English)
return
; I could not find a good way to do it with regex
Eng2Horse(English)
{
	static Consonants := "bcdfghjklmnpqrstvwxyz", Letters := "abcdefghijklmnopqrstuvwxyz"
	Loop, Parse, English
	{
		Letter := A_LoopField
		if (InStr(Consonants, Letter) && !Conss)
			EndOfWord := EndOfWord . Letter
		else if (!InStr(Letters, Letter) || A_Index = StrLen(English))
		{
			if Word
				Word := Word . "-" . (EndOfWord ? EndOfWord : "n") . "eigh"
			PigLatin .= Word . Letter
			Word :=
			EndOfWord :=
			Conss :=
		}
		else
		{
			Conss := 1
			Word .= Letter
		}
	}
	return PigLatin
}


Wingfat
  • Members
  • 937 posts
  • Last active: Oct 14 2015 04:20 PM
  • Joined: 23 Aug 2004
Yeah i think horse would be too hard, since it is based on the syllables in a word.
in the underground Horse Latin in the US - you put an IB infornt of the first Vowel of each syllable of a word.
that last sentance in Horse Latin is:
yIBou pIBut IBan IBIB IBinfIBornt IBof thIBe fIBrst vIBowel IBof eIBach sIByllIBablIBe IBof IBa wIBord

----------------------------
Wingfool you fat! I mean, Wingfat you fool!
Line from Woody Allen's movie "What's Up Tiger Lilly?"
-----------------------------

GeekDude
  • Spam Officer
  • 391 posts
  • Last active: Oct 05 2015 08:13 PM
  • Joined: 23 Nov 2009
Why would anyone want to use such a strange set of rules masquerading under the word Latin???? that Horse Latin is unreadable.

Wingfat
  • Members
  • 937 posts
  • Last active: Oct 14 2015 04:20 PM
  • Joined: 23 Aug 2004
thats the point i thought.. make it hard for people to read/listen to so they do not know what you and your buddies are talking about.
-my buddy and I were talking about a cute girl while riding BART (Bay Area Rapid Transit) one day coming home from work. when the doors opened up at her stop she turned to us and spoke in Horse latin and said "too bad you guys didnt ask me out".. and she got off. we were shocked that she knew what we were saying ;-)
----------------------------
Wingfool you fat! I mean, Wingfat you fool!
Line from Woody Allen's movie "What's Up Tiger Lilly?"
-----------------------------

GeekDude
  • Spam Officer
  • 391 posts
  • Last active: Oct 05 2015 08:13 PM
  • Joined: 23 Nov 2009
I suppose, but with the invention of texting it seems over complicated to add all those silly rules to the syllables of your words. Unless you are fluent, it must take forever to mentally encode and decode.

Wingfat
  • Members
  • 937 posts
  • Last active: Oct 14 2015 04:20 PM
  • Joined: 23 Aug 2004
so very true.. when i post it on a FaceBook wall with out putting the IBs in caps lock no one gets it but the close circle of friends i have.. about 15 of us are fluent, but I have never been able to get my wife to learn it.. lol
----------------------------
Wingfool you fat! I mean, Wingfat you fool!
Line from Woody Allen's movie "What's Up Tiger Lilly?"
-----------------------------

mario1776
  • Members
  • 18 posts
  • Last active: Nov 08 2015 08:45 PM
  • Joined: 27 Feb 2011
Your RegEng2Pig doesn't know how to handle capitalized letters, and simply ignores them. Adding the capitalized alphabet fixes the problem. It might be bad form to have the original first letter from the first word in a sentence capitalized, instead of the first letter of the first word after translation to pig latin, but it's better than completely ignoring the capitalized letter.
RegEng2Pig(Eng)
{
   return RegExReplace(Eng, "\b([bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ]*)(\w+)\b", "$2-$1ay")
}
Thanks for the code you provided Geekdude! er...
anks-Thay or-fay e-thay ode-cay ou-yay ovided-pray eekdude-Gay!

SoggyDog
  • Members
  • 803 posts
  • Last active: Mar 04 2013 06:27 AM
  • Joined: 02 May 2006
I'm still waiting for an English-to-Yoda translator in AHK.

tidbit
  • Administrators
  • 2709 posts
  • Hates playing Janitor
  • Last active: Jan 15 2016 11:37 PM
  • Joined: 09 Mar 2008
Here you go SoggyDog
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#SingleInstance, force

gui, font, s12, tahoma
Gui, add, edit, xm w400 r3 vinput gupdate, this is a test
Gui, add, edit, xm w400 r3 readonly cgreen vyoda

Gosub, update
gui, show, , Converted to yoda`, this is.
Return

update:
   Gui, Submit, NoHide
   
   ; out1 = first 2 words.
   ; out2 = first letter of the following words.
   ; out3 = everything else.
   blah:=RegExMatch(input, "(\w+\s*\w+)\s+(\w)(.*)", out)
   if (blah==0)
   {
      GuiControl,, yoda,
      Return
   }
   
   StringUpper, out2, out2   
   GuiControl,, yoda, %out2%%out3%`, %out1%.
Return

GuiClose:
GuiEscape:
   ExitApp
Return

rawr. be very afraid
*poke*
. Populate the AutoHotkey city. Pointless but somewhat fun. .


SoggyDog
  • Members
  • 803 posts
  • Last active: Mar 04 2013 06:27 AM
  • Joined: 02 May 2006
Ah, I can always count on tidbit;
"True" Yoda-speak involves a number of grammatical rules that are clearly not covered here;
Boil it down, though, and this is simple and effective;
I love it!

Thanks.

GeekDude
  • Spam Officer
  • 391 posts
  • Last active: Oct 05 2015 08:13 PM
  • Joined: 23 Nov 2009
Adding the capitalized alphabet fixes the problem.

It would be better to use the case insensitive setting "s)" at the beginning of the needle. *updates the first post*

 

Edit: "i)"