File size: 2,280 Bytes
370675b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fbbf27f
370675b
 
 
 
 
 
 
 
 
14d74fa
370675b
 
 
 
 
 
 
14d74fa
 
 
 
 
 
370675b
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
alphabet = "abcdefghijklmnopqrstuvwxyz"
vowels = "aeoiu"

def english_to_piglattin( english ):

    piglattin = ""

    in_word = False
    is_first = False
    start = None
    for char in english:
        if not in_word:
            if char in alphabet + alphabet.upper():
                in_word = True

                if char in vowels + vowels.upper():
                    start = None
                    piglattin += char
                else:
                    start = char
                    is_first = True
            else:
                piglattin += char
        else: #if in_word
            if char in alphabet + alphabet.upper():
                if is_first:
                    is_first = False
                    if start in alphabet.upper():
                        piglattin += char.upper()
                    else:
                        piglattin += char
                else:
                    piglattin += char
            else:
                in_word = False
                is_first = False
                if start:
                    piglattin += start.lower() + "ay" + char
                else:
                    piglattin += "yay" + char
    
    #end of sentence needs done as well.
    if in_word:
        if start:
            piglattin += start.lower() + "ay"
        else:
            piglattin += "yay"
    return piglattin


def main():
    used_englishes = []
    with open( "spa.csv", "rt" ) as fin:
        with open( "pig_lattin.csv", "wt" ) as f_out:
            f_out.write( "English,Piglattin\n" )
            for line in fin:
                english = line.split( "\t" )[0]
                english = english.replace( ",", " " )

                if english not in used_englishes:
                    used_englishes.append(english)
                    
                    piglattin = english_to_piglattin( english )

                    f_out.write( f"{english},{piglattin}\n" )

if __name__ == '__main__':
    main()

    # print( english_to_piglattin( "I am not a potato." ) )
    # print( english_to_piglattin( "I am not a potato" ) )
    # print( english_to_piglattin( "I like chicken." ) )
    # print( english_to_piglattin( "Do you know your a b c's?" ) )
    # print( english_to_piglattin( "My name is Joshua." ) )