7 Replies - 3154 Views - Last Post: 19 November 2010 - 12:32 PM Rate Topic: -----

#1 Proplaya23  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 18-November 10

English to PigLatin

Posted 18 November 2010 - 01:41 PM

Hello I would like to explain my problem i currently got Stuck with the Select Case Statement im trying to compare each character in the original english word to check for the first vowel then execute accordingly what must be done based on the position of the vowel(FIRST INSTANCE) then exit the nest. My code so far is this:
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim OriginalWord As String
        Dim PigLatin As String
        Dim Vowels(5) As Char
        Vowels(0) = "A"
        Vowels(1) = "E"
        Vowels(2) = "I"
        Vowels(3) = "O"
        Vowels(4) = "U"
        Vowels(5) = "Y"

        OriginalWord = TxtEnglish.Text.ToUpper

        Select Case Vowels
            Case Is = OriginalWord.Substring(0, 1)
                PigLatin = OriginalWord & "WAY"
                MsgBox(PigLatin)
            Case Is = OriginalWord.Substring(1, 1)
                PigLatin = Mid(OriginalWord, 2, OriginalWord.Length) & Mid(OriginalWord, 1, 1) & "AY"
                MsgBox(PigLatin)
            Case Is = OriginalWord.Substring(2, 1)
                PigLatin = Mid(OriginalWord, 3, OriginalWord.Length) & Mid(OriginalWord, 1, 2) & "AY"
                MsgBox(PigLatin)
        End Select
        



    End Sub
End Class



thanks in advance for anyone who can help me :)

Is This A Good Question/Topic? 0
  • +

Replies To: English to PigLatin

#2 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: English to PigLatin

Posted 18 November 2010 - 02:44 PM

Maybe try
Select Case OriginalWord.Substring(0,1) 'look at first character
  Case "A", "E", "I", "O", "U", "Y"
    PigLatin = OriginalWord & "WAY"
    MsgBox(PigLatin)
  Case Else
    PigLatin = OriginalWord.Substring(1) & OriginalWord.Substring(0, 1) & "AY"
    MsgBox(PigLatin)
End Select


Not sure you can use case Vowels

Anyway, you were backward in your select statement, you select the first letter and if it's a vowel, perform for a leading vowel, otherwise, perform for a consonant.

See if that help you get further.
Was This Post Helpful? 0
  • +
  • -

#3 Proplaya23  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 18-November 10

Re: English to PigLatin

Posted 18 November 2010 - 02:49 PM

Yes i was using this method earlier but was having problems in a string like "eastern" it would give me both message boxes one for the E vowel and one for the A vowel... im sorry if i said something totally dumb.
Was This Post Helpful? 0
  • +
  • -

#4 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: English to PigLatin

Posted 18 November 2010 - 03:22 PM

Well, I'm going to be honest, I would have to re-read up on the rules of Pig Latin as I haven't given it any thought for years. But it does appear that you were looking at the second character and responding to it.

I guess I just thought if the word starts with a consonant, you move the consonant to the end and add "ay" and if it starts with a vowel, you just add "way" to the end.
Was This Post Helpful? 0
  • +
  • -

#5 Proplaya23  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 18-November 10

Re: English to PigLatin

Posted 18 November 2010 - 05:23 PM

I think i figured it out :

 Dim OriginalWord As String
        Dim PigLatin As String
        OriginalWord = TxtEnglish.Text.ToUpper

       
        If OriginalWord.Substring(0, 1) = "A" OrElse OriginalWord.Substring(0, 1) = "E" OrElse OriginalWord.Substring(0, 1) = "I" OrElse OriginalWord.Substring(0, 1) = "O" OrElse OriginalWord.Substring(0, 1) = "U" OrElse OriginalWord.Substring(0, 1) = "Y" Then
            PigLatin = OriginalWord & "WAY"
            MsgBox(PigLatin)
        ElseIf OriginalWord.Substring(1, 1) = "A" OrElse OriginalWord.Substring(1, 1) = "E" OrElse OriginalWord.Substring(1, 1) = "I" OrElse OriginalWord.Substring(1, 1) = "O" OrElse OriginalWord.Substring(1, 1) = "U" OrElse OriginalWord.Substring(1, 1) = "Y" Then
            PigLatin = Mid(OriginalWord, 2, OriginalWord.Length) & Mid(OriginalWord, 1, 1) & "AY"
            MsgBox(PigLatin)
        ElseIf OriginalWord.Substring(2, 1) = "A" OrElse OriginalWord.Substring(2, 1) = "E" OrElse OriginalWord.Substring(2, 1) = "I" OrElse OriginalWord.Substring(2, 1) = "O" OrElse OriginalWord.Substring(2, 1) = "U" OrElse OriginalWord.Substring(2, 1) = "Y" Then
            PigLatin = Mid(OriginalWord, 3, OriginalWord.Length) & Mid(OriginalWord, 1, 2) & "AY"
            MsgBox(PigLatin)
        ElseIf OriginalWord.Substring(3, 1) = "A" OrElse OriginalWord.Substring(3, 1) = "E" OrElse OriginalWord.Substring(3, 1) = "I" OrElse OriginalWord.Substring(3, 1) = "O" OrElse OriginalWord.Substring(3, 1) = "U" OrElse OriginalWord.Substring(3, 1) = "Y" Then
            PigLatin = Mid(OriginalWord, 4, OriginalWord.Length) & Mid(OriginalWord, 1, 3) & "AY"
            MsgBox(PigLatin)
'elseif "continued" "" "" "" "" ""
        End If




its a pretty long way of doing it but i cant figure it out with select case.

This post has been edited by Proplaya23: 18 November 2010 - 05:26 PM

Was This Post Helpful? 0
  • +
  • -

#6 lordofduct  Icon User is online

  • I'm a cheeseburger
  • member icon


Reputation: 2533
  • View blog
  • Posts: 4,633
  • Joined: 24-September 10

Re: English to PigLatin

Posted 19 November 2010 - 08:11 AM

I gave it a shot, to shorten it up and use Regular Expressions...

it will handle a sentence (including punctuation). Though it doesn't know how to handle leading uppercase (see the todo in it). Just got to toss in the one or two lines for that (too lazy right now). -edit- added in uppercase

    ''' <summary>
    ''' Translates a statement to pig-latin
    ''' </summary>
    ''' <param name="sval">A statement of words to translate</param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function TranslateToPigLatin(ByVal sval As String) As String
        Dim wrdX As New Regex("[\w]+")
        Dim conX As New Regex("^(qu|[bcdfghjklmnpqrstvwxyz]+)", RegexOptions.IgnoreCase)
        Dim uppX As New Regex("^[A-Z]")

        Dim wordMat As Match = wrdX.Match(sval)
        Dim conMat As Match
        Dim swrd As String


        While wordMat.Success
            swrd = wordMat.Value
            conMat = conX.Match(swrd)

            If conMat.Success Then
                swrd = swrd.Substring(conMat.Length) & conMat.Value.ToLower() & "ay"
                If uppX.IsMatch(conMat.Value) Then
                    swrd = swrd.Substring(0, 1).ToUpper() & swrd.Substring(1)
                End If

            Else
                swrd &= "way"
            End If

            sval = sval.Substring(0, wordMat.Index) & swrd & sval.Substring(wordMat.Index + wordMat.Length)
            wordMat = wrdX.Match(sval, wordMat.Index + swrd.Length)
        End While

        Return sval

    End Function



NOTE 1: There are varying rules of pig-latin. I used the rule that the OP seemed to be following. Where you take leading consonant clusters and move to the end.

trash -> ash-tray

there are other rules that take only the first consonant, in that case you'd just remove the "+" from the regex.

trash -> rash-tay

NOTE 2: in the regex I search for any cluster of leading consonants OR leading 'qu'. That's because of the special case rule of 'qu' (if there's other special case rules, just | them into the regex). We test the 'qu' first because qu passes the consonant cluster test as well and would come out q. Thusly 'qu' must take precedence.


Example result:

Console.WriteLine(TranslateToPigLatin("Hello world, I have a question about trash."))



writes out:

Quote

Ellohay orldway, Iway avehay away estionquay aboutway ashtray.

This post has been edited by lordofduct: 19 November 2010 - 08:38 AM

Was This Post Helpful? 0
  • +
  • -

#7 Proplaya23  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 18-November 10

Re: English to PigLatin

Posted 19 November 2010 - 11:56 AM

:) Thats Just Genuis. GoodWork. I just wish I understood those terms im still in CIS-130 class and only know VB.net. Unfortunately I will not be using that code because personally I cant except it if i dont understand it. Thanks For all the HElp this site is Great! :)
Was This Post Helpful? 0
  • +
  • -

#8 lordofduct  Icon User is online

  • I'm a cheeseburger
  • member icon


Reputation: 2533
  • View blog
  • Posts: 4,633
  • Joined: 24-September 10

Re: English to PigLatin

Posted 19 November 2010 - 12:32 PM

Well it is all VB... the only part that is more generalized is the 3 regular expressions used. We can break it down to understanding.

First the 3 regular expressions:

"[\w]+" - this expression finds any words. Basically I'm saying find any cluster of characters (w is any alpha character, the + says find multiple)

"^[A-Z]" - this says finds starting with (^) any capital letter ([A-Z])

"^(qu|[bcdfghjklmnpqrstvwxyz]+)" - this says find starting with (^) qu or (|) cluster of consonants (all the letters and the + sign).



For more indepth explanation of Regular Expressions, just google about them.


Then all I do is use the .Net Regex class and Match class to move the strings around based on that. With these 3 expressions I can:

find every word in a statement [\w]+

take each word and find the first few characters that should be moved to the end (the long regex)

if I found starting consonants move it to the end and capitalize the first letter if necessary

otherwise put 'way' on the end

finally stick it back into the supplied statement at the correct index.

This post has been edited by lordofduct: 19 November 2010 - 12:33 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1