25 lines
1.3 KiB
Python
Executable File
25 lines
1.3 KiB
Python
Executable File
#! /usr/bin/env python3
|
|
|
|
import argparse
|
|
import phonagen
|
|
|
|
def parseArgs():
|
|
# Define argument parser
|
|
parser = argparse.ArgumentParser(description='Convert a phonology from csv to json.')
|
|
parser.add_argument('file', metavar='csvfile', help='csv file to convert')
|
|
parser.add_argument('--id', metavar='id', help='id of the phonology; guessed from the csv header if not provided', default='')
|
|
parser.add_argument('--description', metavar='description', help='description of the phonology; empty if not provided', default='')
|
|
parser.add_argument('--main', metavar='main-transcription', help='main transcription of the phonology; must correspond to an element of the csv header (outside id and description); guessed from the csv header if not provided.', default='')
|
|
parser.add_argument('--output', metavar='output-file', help='Output file for the phonology. The file is printed to standard output if not given.', default='')
|
|
# Parse arguments
|
|
return parser.parse_args()
|
|
|
|
# Main
|
|
if __name__ == '__main__':
|
|
args = parseArgs()
|
|
phonology = phonagen.Phonology(id = args.id, description = args.description, mainTranscription = args.main)
|
|
phonology.fromCsv(args.file)
|
|
phonagenFile = phonagen.PhonagenFile()
|
|
phonagenFile.addPhonology(phonology)
|
|
phonagenFile.writeTo(args.output)
|