Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added flag for running *only* one 1 or more languages #56

Merged
merged 2 commits into from
Jan 28, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/corporacreator/argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ def parse_args(args):
help="Path to the Common Voice tsv for all languages",
dest="tsv_filename",
)
parser.add_argument(
"-l",
"--langs",
required=False,
nargs='+',
help="Which languages you want to make corpora for",
)
parser.add_argument(
"-d",
"--directory",
Expand Down
7 changes: 6 additions & 1 deletion src/corporacreator/corpora.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ def create(self):
corpora_data[["sentence", "up_votes", "down_votes"]] = corpora_data[
["sentence", "up_votes", "down_votes"]
].swifter.apply(func=lambda arg: common_wrapper(*arg), axis=1)
for locale in corpora_data.locale.unique():
if self.args.langs:
locales = self.args.langs
else:
locales = corpora_data.locale.unique()

for locale in locales:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should check that self.args.langs is a subset of corpora_data.locale.unique() and print an error message if it's not and also stop the program.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kdavis-mozilla -- requested changes made to README and catch if entered languages are actually subset of possible languages...

also learned that Python has a x.issubset(y) function:)

_logger.info("Selecting %s corpus data..." % locale)
corpus_data = corpora_data.loc[
lambda df: df.locale == locale,
Expand Down