Commit 62fc82e59a9eb5d76499d57175ed1a8475ecf995

Authored by Quillot Mathias
1 parent d6dec28e54
Exists in master

Allow user to generate utt2char file. char2file is in building

Showing 1 changed file with 58 additions and 0 deletions Inline Diff

File was created 1 import argparse
2 import core.data
3 from utils import SubCommandRunner
4
5
6 def utt2char(features: str, outfile: str):
7 """Allow the user to generate utt2char file from masseffect features file.
8
9 TODO: Don't forget to manage two cases: one with old ids, and an other with
10 new ones.
11
12 Args:
13 features (str): [description]
14 outfile (str): [description]
15 """
16 data = core.data.read_features(features)
17 keys = list(data.keys())
18
19 with open(outfile, "w") as f:
20 for key in keys:
21 splited = key.replace("\n", "").split(",")
22 character = splited[1]
23 f.write(",".join(splited) + " " + character + "\n")
24
25
26 def char2utt(features: str, outfile: str):
27 raise Exception("Not implemented yet")
28 pass
29
30
31 if __name__ == '__main__':
32 # Main parser
33 parser = argparse.ArgumentParser(description="...")
34 subparsers = parser.add_subparsers(title="action")
35
36 # utt2char
37 parser_utt2char = subparsers.add_parser("utt2char")
38 parser_utt2char.add_argument("--features", type=str, help="features file")
39 parser_utt2char.add_argument("--outfile", type=str, help="output file")
40 parser_utt2char.set_defaults(which="utt2char")
41
42 # char2utt
43 parser_char2utt = subparsers.add_parser("char2utt")
44 parser_char2utt.add_argument("--features", type=str, help="features file")
45 parser_char2utt.add_argument("--outfile", type=str, help="output file")
46 parser_char2utt.set_defaults(which="char2utt")
47
48
49 # Parse
50 args = parser.parse_args()
51
52 # Run commands
53 runner = SubCommandRunner({
54 "utt2char" : utt2char,
55 "char2utt": char2utt,
56 })
57
58 runner.run(args.which, args.__dict__, remove="which")