-
Notifications
You must be signed in to change notification settings - Fork 0
/
token.py
140 lines (117 loc) · 3.22 KB
/
token.py
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import json
# Load mapping dicts
with open('data/consonants.json') as json_file:
consonantDict = json.load(json_file)
with open('data/vowels.json') as json_file:
vowelDict = json.load(json_file)
with open('data/matras.json') as json_file:
matraDict = json.load(json_file)
class EHConsonant:
"""
Represents a consonant token
:attr: char - English representation of the token
:attr: half (False) - Flag to print the token as a half consonant
"""
def __init__(self, char, half=False):
self.char = char
self.half = half
def toggle(self):
"""
Toggle the flag half
"""
if self.half:
self.half = False
else:
self.half = True
def getChar(self):
"""
Return char
"""
return self.char
def __str__(self):
if(self.half):
return consonantDict[self.char] + "\u094d"
return consonantDict[self.char]
class EHVowel:
"""
Represents a vowel token
:attr: char - English representation of the token
:attr: matra (True) - Flag to print the token as a matra
"""
def __init__(self, char, matra=True):
self.char = char
self.matra = matra
def toggle(self):
"""
Toggle the flag matra
"""
if self.matra:
self.matra = False
else:
self.matra = True
def getChar(self):
"""
Return char
"""
return self.char
def __str__(self):
if(self.matra):
return matraDict[self.char]
return vowelDict[self.char]
with open("data/romanconsonants.json") as json_file:
rconsonantDict = json.load(json_file)
with open("data/romanvowels.json") as json_file:
rvowelDict = json.load(json_file)
with open("data/romanmatras.json") as json_file:
rmatraDict = json.load(json_file)
class HRConsonant:
"""
Represents a consonant token
:attr: char - Roman representation of the token
:attr: half (False) - Flag to print the token as a half consonant
"""
def __init__(self, char, half=True):
self.char = char
self.half = half
def toggle(self):
"""
Toggle the flag half
"""
if self.half:
self.half = False
else:
self.half = True
def getChar(self):
"""
Return char
"""
return self.char
def __str__(self):
if(self.half):
return rconsonantDict[self.char]
return rconsonantDict[self.char]+ "a"
class HRVowel:
"""
Represents a vowel token
:attr: char - Roman representation of the token
"""
def __init__(self, char):
self.char = char
def getChar(self):
"""
Return char
"""
return self.char
def __str__(self):
if self.char in rvowelDict:
return rvowelDict[self.char]
return rmatraDict[self.char]
if __name__=="__main__":
c = EHConsonant("k")
print("Consonant", c.getChar(), "without half", c)
c.toggle()
print("Consonant", c.getChar(), "without half", c)
v = EHVowel("a")
print("Vowel", v.getChar(), "as matra", v)
v.toggle()
print("Vowel", v.getChar(), "as vowel", v)