Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def detokenize_file(language, processes, xml_unescape, encoding, quiet):
moses = MosesDetokenizer(lang=language)
moses_detokenize = partial(moses.detokenize, return_str=True, unescape=xml_unescape)
with click.get_text_stream("stdin", encoding=encoding) as fin:
with click.get_text_stream("stdout", encoding=encoding) as fout:
# If it's single process, joblib parallization is slower,
# so just process line by line normally.
if processes == 1:
for line in tqdm(fin.readlines()):
print(moses_detokenize(str.split(line)), end="\n", file=fout)
else:
document_iterator = map(str.split, fin.readlines())
for outline in parallelize_preprocess(
moses_detokenize, document_iterator, processes, progress_bar=(not quiet)
):
print(outline, end="\n", file=fout)
def detokenize_file(language, processes, xml_unescape, encoding, quiet):
moses = MosesDetokenizer(lang=language)
moses_detokenize = partial(moses.detokenize, return_str=True, unescape=xml_unescape)
with click.get_text_stream("stdin", encoding=encoding) as fin:
with click.get_text_stream("stdout", encoding=encoding) as fout:
# If it's single process, joblib parallization is slower,
# so just process line by line normally.
if processes == 1:
for line in tqdm(fin.readlines()):
print(moses_detokenize(str.split(line)), end="\n", file=fout)
else:
document_iterator = map(str.split, fin.readlines())
for outline in parallelize_preprocess(
moses_detokenize, document_iterator, processes, progress_bar=(not quiet)
):
print(outline, end="\n", file=fout)
def __init__(self, lang="en"):
super(MosesDetokenizer, self).__init__()
self.lang = lang