-
Notifications
You must be signed in to change notification settings - Fork 0
/
phonta
executable file
·69 lines (59 loc) · 2.46 KB
/
phonta
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
#!/usr/bin/python
#################################################################################
# @PROJECT: PhonTA - Phonetic Transcription Assistant #
# @VERSION: #
# @AUTHOR: Benjamin Meyers #
# @EMAIL: [email protected] #
# @LICENSE: MIT #
#################################################################################
##### IMPORTS ###################################################################
import sys
from dict.util import upgrade_cmudict, translate, add_to_cmudict
##### GLOBALS ###################################################################
commands = {"upgrade":upgrade_cmudict, "translate":translate, "add":add_to_cmudict}
def display_help_message():
print("USAGE: phonta <command> <options>")
print("\t--help, -h\tDisplay this message.")
print("\t--info, -i\tDiplay program information.")
print("\t--usage, -u\tDisplay usage instructions.")
def display_info_message():
print("\n")
print("#################################################")
print("# PhonTA - Phonetic Transcription Assistant\t#")
print("#\t\t\t\t\t\t#")
print("# Copyright (c) 2016, Benjamin S. Meyers\t#")
print("# \t\t\[email protected]\t#")
print("#################################################")
print("\n")
def display_usage_message():
print("COMMAND\t\tARG\t\tDESCRIPTION")
print("translate\ttext\t\tTranslate the text to ARPABET and IPA.")
print("upgrade\t\tcmudict\t\tUpgrade to the most recent cmudict.")
def run_command(args):
command = args[1]
print(command)
print(args)
if command not in commands.keys():
sys.exit("WARNING: Invalid command. Try '--help' for details.")
elif len(args) == 2:
print(commands[command]())
elif len(args) == 3: # phonta <command> <option(s)>
print(commands[command](args[2]))
def main():
#TODO: Handle translation when term is not in the cmudict.
#TODO: Handle adding new terms to the cmudict.
args = sys.argv
if "python" in args:
args.remove("python")
if len(args) < 2:
display_help_message()
elif len(args) == 2 and args[1] == "--help":
display_help_message()
elif len(args) == 2 and args[1] == "--usage":
display_usage_message()
elif len(args) == 2 and args[1] == "--info":
display_info_message()
else:
run_command(args)
if __name__ == "__main__":
main()