This repository has been archived on 2023-06-17. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
jaPitchPlotter/parse_examples.py
Luke b0a9749559 Updated readme, and examples.
Updated the readme to describe the product.
Added a few examples to show specific mechanics.
2017-08-20 18:14:03 -07:00

30 lines
972 B
Python
Executable file

#!/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)