-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeva2laos.cs
More file actions
255 lines (216 loc) · 9.07 KB
/
deva2laos.cs
File metadata and controls
255 lines (216 loc) · 9.07 KB
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
using System;
using System.Collections;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
namespace VRI.CSCD.Conversion
{
class Deva2Laos
{
static void Main(string[] args)
{
try
{
if (args.Length < 2 || args.Length > 3)
{
PrintUsage();
return;
}
// validate args
FileInfo fi = new FileInfo(args[0]);
if (fi.Exists == false)
{
Console.WriteLine("Input file does not exist");
return;
}
DirectoryInfo di = new DirectoryInfo(args[1]);
if (di.Exists == false)
{
Console.Write("Output directory does not exist. Would you like to create it?[y/n] ");
if (Console.ReadLine().ToLower().Substring(0, 1) == "y")
{
di.Create();
}
else
{
return;
}
}
Deva2Laos d2 = new Deva2Laos();
d2.InputFilePath = args[0];
d2.OutputFilePath = di.FullName + "\\" + fi.Name;
d2.Convert();
}
catch (Exception ex)
{
Console.WriteLine("Exception: " + ex);
}
}
static void PrintUsage()
{
Console.WriteLine("Transliterates Unicode Devanagari to Unicode Lao script (Pali)");
Console.WriteLine("syntax:");
Console.WriteLine("deva2laos input [output]");
}
// end static methods
private Hashtable dev2Lao;
public Deva2Laos()
{
dev2Lao = new Hashtable();
// Niggahita (Lao Niggahita)
dev2Lao['\x0902'] = '\x0ECD';
// independent vowels (Using Or O + Vowel sign)
dev2Lao['\x0905'] = '\x0EAD'; // a (Or O)
dev2Lao['\x0906'] = "\x0EAD\x0EB2"; // aa
dev2Lao['\x0907'] = "\x0EAD\x0EB4"; // i
dev2Lao['\x0908'] = "\x0EAD\x0EB5"; // ii
dev2Lao['\x0909'] = "\x0EAD\x0EB8"; // u
dev2Lao['\x090A'] = "\x0EAD\x0EB9"; // uu
dev2Lao['\x090F'] = "\x0EC0\x0EAD"; // e (Sala E + Or O)
dev2Lao['\x0913'] = "\x0EC2\x0EAD"; // o (Sala O + Or O)
// velar stops
dev2Lao['\x0915'] = '\x0E81'; // ka (Ko Kay)
dev2Lao['\x0916'] = '\x0E82'; // kha (Kho Khay)
dev2Lao['\x0917'] = '\x0E84'; // ga (Kho Khouay)
dev2Lao['\x0918'] = '\x0E84'; // gha (Kho Khouay - Lao maps Gh to Kh often in modern types)
dev2Lao['\x0919'] = '\x0E87'; // nga (Ngo Ngu)
// palatal stops
dev2Lao['\x091A'] = '\x0E88'; // ca (Jo Jua)
dev2Lao['\x091B'] = '\x0E29'; // cha (So Seua - used for Pali Cha often, or sometimes So Xang)
dev2Lao['\x091C'] = '\x0E8A'; // ja (Xo Xang)
dev2Lao['\x091D'] = '\x0E8A'; // jha (Xo Xang - Lao maps Jh to X)
dev2Lao['\x091E'] = '\x0E8D'; // ña (Nyo Nyung)
// retroflex stops (Using standard Lao approximate glyphs for Pali)
dev2Lao['\x091F'] = '\x0E8F'; // t underdot a (To Patak - rare but in Unicode)
dev2Lao['\x0920'] = '\x0E90'; // t underdot ha (Tho Than - rare)
dev2Lao['\x0921'] = '\x0E91'; // d underdot a (Do Montho - rare)
dev2Lao['\x0922'] = '\x0E92'; // d underdot ha (Tho Phuthao - rare)
dev2Lao['\x0923'] = '\x0E93'; // n underdot a (No Nen)
// dental stops
dev2Lao['\x0924'] = '\x0E95'; // ta (To Ta)
dev2Lao['\x0925'] = '\x0E96'; // tha (Tho Thung)
dev2Lao['\x0926'] = '\x0E97'; // da (Tho Thung - Pali D)
dev2Lao['\x0927'] = '\x0E98'; // dha (Tho Thong)
dev2Lao['\x0928'] = '\x0E99'; // na (No Nok)
// labial stops
dev2Lao['\x092A'] = '\x0E9B'; // pa (Po Pa)
dev2Lao['\x092B'] = '\x0E9C'; // pha (Pho Pheung)
dev2Lao['\x092C'] = '\x0E9E'; // ba (Pho Phu - Pali B)
dev2Lao['\x092D'] = '\x0E9E'; // bha (Pho Phu - Pali Bh)
dev2Lao['\x092E'] = '\x0EA1'; // ma (Mo Ma)
// liquids, fricatives, etc.
dev2Lao['\x092F'] = '\x0EA2'; // ya (Yo Ya)
dev2Lao['\x0930'] = '\x0EA3'; // ra (Ro Rot - Lo Loot in modern, but Ro for Pali)
dev2Lao['\x0932'] = '\x0EA5'; // la (Lo Ling)
dev2Lao['\x0935'] = '\x0EA7'; // va (Vo Vi)
dev2Lao['\x0938'] = '\x0EAA'; // sa (So Seua)
dev2Lao['\x0939'] = '\x0EAB'; // ha (Ho Han)
dev2Lao['\x0933'] = '\x0EAC'; // l underdot a (Lo Lo)
// dependent vowel signs
dev2Lao['\x093E'] = '\x0EB2'; // aa
dev2Lao['\x093F'] = '\x0EB4'; // i
dev2Lao['\x0940'] = '\x0EB5'; // ii
dev2Lao['\x0941'] = '\x0EB8'; // u
dev2Lao['\x0942'] = '\x0EB9'; // uu
dev2Lao['\x0947'] = '\x0EC0'; // e (Sala E)
dev2Lao['\x094B'] = '\x0EC2'; // o (Sala O)
// Virama (Lao uses Pali Virama - often represented by 0EBA)
dev2Lao['\x094D'] = '\x0EBA';
// numerals (Lao Digits)
dev2Lao['\x0966'] = '\x0ED0';
dev2Lao['\x0967'] = '\x0ED1';
dev2Lao['\x0968'] = '\x0ED2';
dev2Lao['\x0969'] = '\x0ED3';
dev2Lao['\x096A'] = '\x0ED4';
dev2Lao['\x096B'] = '\x0ED5';
dev2Lao['\x096C'] = '\x0ED6';
dev2Lao['\x096D'] = '\x0ED7';
dev2Lao['\x096E'] = '\x0ED8';
dev2Lao['\x096F'] = '\x0ED9';
// other
dev2Lao['\x0970'] = '.'; // Dev. abbreviation sign
dev2Lao['\x200C'] = ""; // ZWNJ (remove)
dev2Lao['\x200D'] = ""; // ZWJ (remove)
}
public string InputFilePath
{
get { return inputFilePath; }
set { inputFilePath = value; }
}
private string inputFilePath;
public string OutputFilePath
{
get { return outputFilePath; }
set { outputFilePath = value; }
}
private string outputFilePath;
public void Convert()
{
StreamReader sr = new StreamReader(InputFilePath);
string devStr = sr.ReadToEnd();
sr.Close();
// change name of stylesheet for Lao
devStr = devStr.Replace("tipitaka-deva.xsl", "tipitaka-lao.xsl");
string str = Convert(devStr);
str = ConvertDandas(str);
str = CleanupPunctuation(str);
StreamWriter sw = new StreamWriter(OutputFilePath, false, Encoding.Unicode);
sw.Write(str);
sw.Flush();
sw.Close();
}
public string Convert(string devStr)
{
// first remove all the ZWJs
devStr = devStr.Replace("\x200D", "");
// pre-processing step for Lao: put the E vowel before its consonants
// Regex for Lao is same logic as Thai (Left-side vowels)
devStr = Regex.Replace(devStr, "([\x0915-\x0939])\x0947", "\x0EC0$1");
// pre-processing step for Lao: put the O vowel before its consonants
devStr = Regex.Replace(devStr, "([\x0915-\x0939])\x094B", "\x0EC2$1");
StringBuilder sb = new StringBuilder();
foreach (char c in devStr.ToCharArray())
{
if (dev2Lao.ContainsKey(c))
sb.Append(dev2Lao[c]);
else
sb.Append(c);
}
return sb.ToString();
}
public string ConvertDandas(string str)
{
// in gathas, single dandas convert to semicolon, double to period
str = Regex.Replace(str, "<p rend=\"gatha[a-z0-9]*\">.+?</p>",
new MatchEvaluator(this.ConvertGathaDandas));
// remove double dandas around namo tassa
str = Regex.Replace(str, "<p rend=\"centre\">.+?</p>",
new MatchEvaluator(this.ConvertNamoTassaDandas));
// convert all others to Lao Ellipsis (Paiyannoi equivalent: \x0EAF)
str = str.Replace("\x0964", "\x0EAF");
str = str.Replace("\x0965", "\x0EAF");
return str;
}
public string ConvertGathaDandas(Match m)
{
string str = m.Value;
str = str.Replace("\x0964", ";");
str = str.Replace("\x0965", "\x0EAF");
return str;
}
public string ConvertNamoTassaDandas(Match m)
{
string str = m.Value;
return str.Replace("\x0965", "\x0EAF");
}
public string CleanupPunctuation(string str)
{
str = str.Replace(" ,", ",");
str = str.Replace(" ?", "?");
str = str.Replace(" !", "!");
str = str.Replace(" ;", ";");
str = str.Replace(" .", ".");
return str;
}
}
}