Inital commit
This commit contains some basic examples, and the core tool.
This commit is contained in:
parent
0474da4e88
commit
90368c778a
7 changed files with 290 additions and 0 deletions
30
parse_examples.py
Normal file
30
parse_examples.py
Normal file
|
@ -0,0 +1,30 @@
|
|||
#!/usr/bin/env python3
|
||||
import punctCode
|
||||
|
||||
# Given a file name, loop line by line and convert the string of a Key (filename), phonetic word,
|
||||
# plus the pitch accent code to a big list.
|
||||
def parseToneFile(fn):
|
||||
# TODO: Handle empty/invalid lines gracefully
|
||||
print("Parsing file: \"%s\"" % fn)
|
||||
dat = [];
|
||||
for line in open(fn,'r'):
|
||||
[key,w,n]=line.split(':')
|
||||
print(" => importing \"%s\"" % key)
|
||||
pc = punctCode.parseToneString(key,w,n.strip())
|
||||
dat.append(pc)
|
||||
return dat;
|
||||
|
||||
# Parse the list, pucntList is now a list of objects containing grouped mora, and the individual
|
||||
# mora's high/low filled/unfilled graph symbol.
|
||||
punctList = parseToneFile('example_codes.txt')
|
||||
|
||||
print("Saving svgs...")
|
||||
# For each one, dump an SVG
|
||||
for pc in punctList:
|
||||
# using default sizing. Units are in pixels.
|
||||
filename = ('examples/%s.svg' % (pc.key));
|
||||
print(" => saving \"%s\" as \"%s\"" % (pc.key, filename))
|
||||
pc.toSVG(filename, style='font-weight:bold;',\
|
||||
padding_lr=30, padding_tb=15)
|
||||
|
||||
|
Reference in a new issue