Spaces:
Sleeping
Sleeping
File size: 2,727 Bytes
c27990f |
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 |
from ipapy import UNICODE_TO_IPA
from ipapy.ipachar import IPAChar
SYMBOLS = {
"r": 1,
"ʝ": 2,
"ã": 3,
"gː": 4,
"t": 5,
"n": 6,
"w": 7,
"u": 8,
"l": 9,
"yː": 10,
"ʎ": 11,
"bʲ": 12,
"ə": 13,
"ʃʲ": 14,
"sː": 15,
"zʲ": 16,
"kː": 17,
"y": 18,
"ɒ": 19,
"fʲ": 20,
"ɑ": 21,
"ʏ": 22,
"ɣ": 23,
"s": 24,
"m": 25,
"tː": 26,
"xʲ": 27,
"vː": 28,
"ø": 29,
"h": 30,
"ɨ": 31,
"dʲ": 32,
"dː": 33,
"bː": 34,
"ɲː": 35,
"ɑː": 36,
"ɪ": 37,
"ɛ": 38,
"i": 39,
"ʔ": 40,
"g": 41,
"ʃ": 42,
"ɜː": 43,
"mː": 44,
"øː": 45,
"fː": 46,
"p": 47,
"iː": 48,
"(...)": 49,
"v": 50,
"ʌ": 51,
"b": 52,
"k": 53,
"x": 54,
"ɲ": 55,
"ʒ": 56,
"rː": 57,
"eː": 58,
"ç": 59,
"ŋ": 60,
"ɔː": 61,
"œ": 62,
"ẽ": 63,
"θ": 64,
"a": 65,
"rʲ": 66,
"vʲ": 67,
"ʃː": 68,
"æ": 69,
"ɶ̃": 70,
"pː": 71,
"nː": 72,
"lʲ": 73,
"õ": 74,
"pʲ": 75,
"ɱ": 76,
"ð": 77,
"f": 78,
"j": 79,
"o": 80,
"nʲ": 81,
"sʲ": 82,
"lː": 83,
"e": 84,
"d": 85,
"ʊ": 86,
"gʲ": 87,
"z": 88,
"ɛː": 89,
"tʲ": 90,
"β": 91,
"mʲ": 92,
"uː": 93,
"ɥ": 94,
"ʀ": 95,
"aː": 96,
"ɐ": 97,
"ɔ": 98,
"oː": 99,
"ʎː": 100,
"kʲ": 101
}
DESCRIPTORS = {}
for s in SYMBOLS:
desc = []
if s == "(...)":
DESCRIPTORS[s] = "silence"
continue
else:
for sym in s:
desc.extend(UNICODE_TO_IPA[sym].descriptors)
if "suprasegmental" in desc:
desc.remove("suprasegmental")
if "diacritic" in desc:
desc.remove("diacritic")
x = IPAChar(desc)
DESCRIPTORS[s] = x.canonical_representation
def to_index(symbol: str, elongations=True) -> int:
if not elongations:
symbol = symbol.replace('ː', '')
return SYMBOLS[symbol]
def to_symbol(index: int, elongations=True) -> str:
idx = list(SYMBOLS.values()).index(index)
symbol = list(SYMBOLS.keys())[idx] if elongations else list(SYMBOLS.keys())[idx].replace('ː', '')
return symbol
def get_class_count() -> int:
return max(SYMBOLS.values())
def symbol_to_descriptor(symbol: str) -> str:
return DESCRIPTORS[symbol]
def index_to_descriptor(index: int) -> str:
return DESCRIPTORS[to_symbol(index)]
if __name__ == "__main__":
print("Running phonetics internal tests")
for s in SYMBOLS:
print(f"{s}: {DESCRIPTORS[s]}")
|