4 Replies - 6994 Views - Last Post: 13 November 2008 - 03:41 PM Rate Topic: -----

#1 lpicken  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 11-November 08

Pig Latin to English Translator

Posted 11 November 2008 - 03:58 PM

I have been working on Martyr2's pig latin project and I need to write a code to convert the pig latin back to english. And a way to check to see if the word is piglatin at all. I am in need of a little direction. Furthermore, I have trouble writing an isNumeric code for the for the piglatin translator. Meaning I need to be able to enter a number or a word without a,e,i,o,u,y in it such as "sdflkj" be be able to translate it. Is this possible. Here is a copy of Martyr2's piglatin code for VB.NET
Public Class Form1

	Private Sub btnTranslate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTranslate.Click
		' Split the phrase into words
		Dim pieces() As String = txtInput.Text.Split(" ")

		Dim i As Integer
		' Loop through each word for translation
		For i = 0 To pieces.Length - 1
			pigLatin(pieces(i))
		Next
	End Sub


	' Controller function for determining if word starts with vowel, then add "way"
	' Otherwise, pass it on for rotation and add "ay"
	' Piglatin has variations in rules, this is a common form but not only form.
	Private Sub pigLatin(ByVal strWord As String)
		If isVowel(strWord(0)) Then
			txtOutput.Text += strWord + "way "
		Else
			txtOutput.Text += moveLetter(strWord) + "ay "
		End If
	End Sub


	' Recursive function to take off a non vowel letter and put it on the end
	' Recall the function until a vowel is encountered and then return the word.
	Private Function moveLetter(ByVal strWord As String) As String
		Dim chLetter As Char
		If Not isVowel(strWord(0)) Then
			chLetter = Char.ToLower(strWord(0))
			Return moveLetter(strWord.Substring(1) + chLetter)
		Else
			Return strWord
		End If
	End Function


	' Simply checks if letter is a vowel. 
	' For most pig latin variations, Y is considered a vowel.
	Private Function isVowel(ByVal chLetter As Char) As Boolean
		Dim letters() As Char = {"a", "e", "i", "o", "u", "y"}

		Dim i As Integer
		For i = 0 To 5
			If (chLetter = letters(i)) Then
				Return True
			End If
		Next

		Return False
	End Function
End Class



Thanx for ahead for any feedback.

This post has been edited by lpicken: 11 November 2008 - 04:03 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Pig Latin to English Translator

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9224
  • View blog
  • Posts: 34,630
  • Joined: 12-June 08

Re: Pig Latin to English Translator

Posted 12 November 2008 - 02:25 PM

.NET provides good string manipulations you can use for a check. Like

foo.Substring(foo.Length - 4)


would get the last four letters.. if the first is a vowel and the last three are 'way' then it's a good bet that it is piggish.. if not then get the last three and if they are 'ay' proceeded by a concenent then you might have piglatin..

What's wrong with a 'is numeric'? Just take the incoming string.. copy it to a temp variable.. do "isnumeric" on the temp variable after you remove any 'way' or 'ay.
Was This Post Helpful? 0
  • +
  • -

#3 lpicken  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 11-November 08

Re: Pig Latin to English Translator

Posted 13 November 2008 - 11:56 AM

Thanx for the reply. I figured out the numeric part and will be posting some code of the retranslator later this evening.
Was This Post Helpful? 0
  • +
  • -

#4 lpicken  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 11-November 08

Re: Pig Latin to English Translator

Posted 13 November 2008 - 02:42 PM

Here is my code that I came up with for converting Pig Latin into English if the word begins with a vowel. It is easy to strip the "-way" off of the word, but I can't seem to figue out how to strip the -ay and move the consonants to begginning of the word.

Private Sub btnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalc.Click

		Dim pigLatin As String
		pigLatin = txtInput.Text
		If pigLatin.EndsWith("-way") Then
			txtOutput.Text = pigLatin.TrimEnd("-", "w", "a", "y")
		ElseIf pigLatin.EndsWith("") Then
			MsgBox("Word is not pig latin.")
		End If
	End Sub
End Class

Was This Post Helpful? 0
  • +
  • -

#5 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9224
  • View blog
  • Posts: 34,630
  • Joined: 12-June 08

Re: Pig Latin to English Translator

Posted 13 November 2008 - 03:41 PM

Just apply what I said initially.

If you word is dog.. and the piglatin is ogday..

one application of
foo.Substring(foo.Length - 2)

would give you the 'ay' part, right?

set the result from above to a string and get the last character the same way..

string sPLating '-- word that is in pig latin.
string sSuffixRemoved
string sFirstLetterHolder 
string sReturn

sSuffixRemoved=	 foo.Substring(0, foo.Length - 2)
sFirstLetterHolder  = sSuffixRemoved.Substring(sSuffixRemoved.Length - 1)
sReturn = sFirstLetterHolder   + sSuffixRemoved.Substring(sSuffixRemoved.Length - 1)

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1