-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtatfile.py
66 lines (55 loc) · 2.01 KB
/
tatfile.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
#!/usr/bin/env python
#-*- coding:utf8 -*-
""" This code reads alphabet characters from certain files and fills up
an array so it can be used for generating test images.
"""
import os
def combine(frest, fc_cont, fpresv, fpostsv):
""" Creates all possible combinations of consonant + vowel """
all_comb = []
for rest in frest:
rest = rest.strip()
all_comb.append(rest)
for c_val in fc_cont:
c_val = c_val.strip() # Remove special characters
c1_val = c_val + " "
all_comb.append(c1_val)
for prev in fpresv: # Combine consonant+vowel sign
txt = prev.rstrip() + c_val
all_comb.append(txt)
for postv in fpostsv: # Combine vowel sign+consonant
txt = c_val + postv.strip()
txt = txt + " "
all_comb.append(txt)
return all_comb
def read_file(alphabet_dir):
""" Reads input alphabet files from alphabet_dir """
# File containing vowels
if(os.path.exists(alphabet_dir + "consonants")):
file_cc = open(alphabet_dir + "consonants", 'r')
fc_content = file_cc.readlines()
file_cc.close()
else:
fc_content = []
# File containing semivowels of the form consonant_conjunct+semivowel
if(os.path.exists(alphabet_dir + "pre_semivowels")):
file_ps = open(alphabet_dir + "pre_semivowels", 'r')
fpresv = file_ps.readlines()
file_ps.close()
else:
fpresv = []
# File containing semivowels of the form semivowel+consonant_conjunct
if(os.path.exists(alphabet_dir + "post_semivowels")):
file_psv = open(alphabet_dir + "post_semivowels", 'r')
fpostsv = file_psv.readlines()
file_psv.close()
else:
fpostsv = []
# File containing everything else
if(os.path.exists(alphabet_dir + "rest")):
file_rest = open(alphabet_dir + "rest", 'r')
frest = file_rest.readlines()
file_rest.close()
else:
frest = []
return combine(frest, fc_content, fpresv, fpostsv)