#! /usr/bin/env python3 import argparse import phonagen def parseArgs(): # Define argument parser parser = argparse.ArgumentParser(description='Make a rule generator, from a phonology.') parser.add_argument('--phonologyfile', metavar='phonologyfile', help='File containing the phonology to use an input', required = True) parser.add_argument('--phonology', metavar='phonology', help='Id of the phonology to use an input', required = True) parser.add_argument('--id', metavar='id', help='id of the generator', required = True) parser.add_argument('--description', metavar='description', help='description of the generator; empty if not provided', default='') parser.add_argument('--output', metavar='output-file', help='Output file for the generator. The file is printed to standard output if not given.', default='') parser.add_argument('--minNbSyllables', metavar='min', help='Minimum number of syllables in generated words; 1 by default', default=1, type=int) parser.add_argument('--maxNbSyllables', metavar='max', help='Maximum number of syllables in generated words; 4 by default', default=4, type=int) parser.add_argument('--stressPos', metavar='pos', help='Position of the stress syllable in the word.' 'If position is positive, it indicates the position from the first syllable, with 1 being the first.' 'If position is negative, it indicates the position from the last syllable, with -1 being the last.' 'If position is 0, stress is disabled. By default: -2', default=-2, type=int) parser.add_argument('--distMean', metavar='mean', help='Center of the number of occurences when generating distributions. The occurences are choosen inside the range [mean - range, mean + range]. By default: 20', default=20, type=int) parser.add_argument('--distRange', metavar='range', help='Range from the center of the number of occurences when generating distributions. The occurences are choosen inside the range [mean - range, mean + range]. By default: 5', default=5, type=int) # Parse arguments return parser.parse_args() # Main if __name__ == '__main__': args = parseArgs() # Get the phonology phonologyFile = phonagen.PhonagenFile() phonologyFile.load(args.phonologyfile) phonology = phonologyFile.getPhonology(args.phonology) # Initialize the generator generator = phonagen.RuleGenerator(id = args.id, description = args.description, phonology = args.phonology) # Generate generator.fromPhonology(phonology = phonology, minNumberSyllables = args.minNbSyllables, maxNumberSyllables = args.maxNbSyllables, stressPosition = args.stressPos, distributionMean = args.distMean, distributionRange = args.distRange) # Output phonagenFile = phonagen.PhonagenFile() phonagenFile.addPhonology(phonology) phonagenFile.addGenerator(generator) phonagenFile.writeTo(args.output)