-
Notifications
You must be signed in to change notification settings - Fork 0
/
syllabics.py
executable file
·92 lines (76 loc) · 2.98 KB
/
syllabics.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
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
# Copyright (C) 2018 Eddie Antonio Santos <easantos@ualberta.ca>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
Hacky script to iterate through the Unicode names database, and find all
syllabics that are used to write nêhiyawêwin.
Generates a either a tab-separated values file with header, or a series of Vim
digraph definitions for each character.
"""
import csv
import sys
from string import printable as ascii_printable
from typing import Set
from libsyllabics.types import Consonant, Syllabic, Syllable, Vowel
from libsyllabics.utils import first
def create_tsv() -> None:
"""
Print all syllabics in order.
"""
any_syllablic = first(plains_cree_syllabics)
fields = any_syllablic.to_dict().keys()
writer = csv.DictWriter(sys.stdout, fieldnames=fields, delimiter="\t")
writer.writeheader()
for syllabic in plains_cree_syllabics:
writer.writerow(syllabic.to_dict())
def create_vim_digraphs() -> None:
"""
Generates a .vim file that defines a bunch of digraphs.
"""
all_digraphs: Set[str] = set()
for syllabic in plains_cree_syllabics:
if not syllabic.in_plains_cree:
continue
digraph = syllabic.vim_digraph
assert len(digraph) == 2, f"not exactly 2 characters: {syllabic}"
assert digraph not in all_digraphs, f"Already saw digraph: {syllabic}"
assert all(
c in ascii_printable for c in digraph
), f"Non-ASCII digraph: {digraph}"
print(
f"digraph {digraph} {syllabic.scalar_value:d}",
f'" {syllabic.character} {syllabic.code_point} {syllabic.name}',
)
all_digraphs.add(digraph)
def print_roster():
for syllabic in roster:
print(syllabic.character)
if __name__ == "__main__":
if "--legacy" in sys.argv[1:]:
from libsyllabics.legacy_roster import plains_cree_syllabics
else:
# I'm not sure what I was thinking. I believe I was going to rewrite this to
# parse the syllabics chart instead of the weird Unicode name parsing done by
# the "legacy_roster". Which is good, because the Unicode names for syllabics
# cannot be trusted!
print("Must specify --legacy in command")
sys.exit(1)
if "--vim" in sys.argv[1:]:
create_vim_digraphs()
elif "--roster" in sys.argv[1:]:
print_roster()
else:
create_tsv()