DebasishDhal99 commited on
Commit
6f68287
·
1 Parent(s): f9056d5

Adding Serbo-croatian file which can transliterate both latin and Cyrillic forms of language of Former Yugoslavian countries, namely Croatian, Bosnian and Serbian.

Browse files
Files changed (1) hide show
  1. serbo_croatian.py +81 -0
serbo_croatian.py ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ special_combs = {
2
+ 'đ' : 'ъ', 'Đ' : 'Ъ',
3
+ 'ђ' : 'ъ', 'Ђ' : 'Ъ',
4
+ 'dž': 'ъ', 'Dž' : 'Ъ',
5
+ 'dz': 'ъ', 'Dz' : 'Ъ',
6
+ 'џ' : 'ъ', 'Џ' : 'Ъ',
7
+ 'c' : 'ts', 'C' : 'Ts',
8
+ }
9
+
10
+ serbian_dict = {
11
+ 'а': 'a', 'А' : 'A',
12
+ 'б': 'b', 'Б' : 'B',
13
+ 'в': 'v', 'В' : 'V',
14
+ 'г': 'g', 'Г' : 'G',
15
+ 'д': 'd', 'Д' : 'D',
16
+ 'е': 'e', 'Е' : 'E',
17
+ 'ж': 'zh', 'Ж' : 'Zh',
18
+ 'ž': 'zh', 'Ž' : 'Zh',
19
+ 'з': 'z', 'З' : 'Z',
20
+ 'и': 'i', 'И' : 'I',
21
+ 'ј': 'y', 'Ј' : 'Y',
22
+ 'j': 'y', 'J' : 'Y',
23
+ 'к': 'k', 'К' : 'K',
24
+ 'л': 'l', 'Л' : 'L',
25
+ 'љ': 'ly', 'Љ' : 'Ly',
26
+ 'lj': 'ly', 'Lj' : 'Ly',
27
+ 'м': 'm', 'М' : 'M',
28
+ 'н': 'n', 'Н' : 'N',
29
+ 'њ': 'ny', 'Њ' : 'Ny',
30
+ 'nj': 'ny', 'Nj' : 'Ny',
31
+ 'о': 'o', 'О' : 'O',
32
+ 'п': 'p', 'П' : 'P',
33
+ 'р': 'r', 'Р' : 'R',
34
+ 'с': 's', 'С' : 'S',
35
+ 'т': 't', 'Т' : 'T',
36
+ 'ћ': 'ch', 'Ћ' : 'Ch',
37
+ 'ć': 'ch', 'Ć' : 'Ch',
38
+ 'č': 'ch', 'Č' : 'Ch',
39
+ 'у': 'u', 'У' : 'U',
40
+ 'ф': 'f', 'Ф' : 'F',
41
+ 'х': 'h', 'Х' : 'H',
42
+
43
+ 'ч': 'ch', 'Ч' : 'Ch',
44
+ # 'џ': 'dz', 'Џ' : 'Dz',
45
+ 'ш': 'sh', 'Ш' : 'Sh',
46
+ 'š': 'sh', 'Š' : 'Sh',
47
+ }
48
+
49
+ cyrillic_equiv_dict = {
50
+ 'ъ' : 'j', 'Ъ' : 'J',
51
+ 'ц': 'ts', 'Ц' : 'Ts',
52
+ }
53
+
54
+ def check_special_comb(word):
55
+ for comb in special_combs:
56
+ if comb in word:
57
+ word = word.replace(comb,special_combs[comb])
58
+ return word
59
+
60
+ def serbian_letter_to_eng(letter):
61
+ if letter in serbian_dict:
62
+ return serbian_dict[letter]
63
+ else:
64
+ return letter
65
+
66
+ def cyrillic_to_eng(word):
67
+ for cyrillic in cyrillic_equiv_dict:
68
+ if cyrillic in word:
69
+ word = word.replace(cyrillic,cyrillic_equiv_dict[cyrillic])
70
+ return word
71
+
72
+ def serbian_sentence_to_latin(sentence):
73
+ sentence = str(sentence)
74
+ # print("Original word: ", sentence)
75
+ sentence = check_special_comb(sentence)
76
+ # print("Just after special combination replacement: -", sentence)
77
+ sentence = ''.join([serbian_letter_to_eng(letter) for letter in sentence])
78
+ # print("After regular word replacement: -", sentence)
79
+ sentence = cyrillic_to_eng(sentence)
80
+ # print("Simplified pronunciation: -", sentence)
81
+ return sentence