From ffe96f7c8745d03dc85a39fabff84a919744c7fe Mon Sep 17 00:00:00 2001 From: Judith Jeong Date: Sun, 27 Jun 2021 18:45:19 +0900 Subject: [PATCH] Fix several lines to make working in Windows --- wikiextractor/WikiExtractor.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/wikiextractor/WikiExtractor.py b/wikiextractor/WikiExtractor.py index 509158a0..c8c05b92 100755 --- a/wikiextractor/WikiExtractor.py +++ b/wikiextractor/WikiExtractor.py @@ -160,6 +160,9 @@ def __init__(self, nextFile, max_file_size=0, compress=True): self.nextFile = nextFile self.compress = compress self.max_file_size = max_file_size + self.file = None + + def open_file(self): self.file = self.open(self.nextFile.next()) def reserve(self, size): @@ -181,7 +184,7 @@ def open(self, filename): if self.compress: return bz2.BZ2File(filename + '.bz2', 'w') else: - return open(filename, 'w') + return open(filename, 'w', encoding='utf-8') # ---------------------------------------------------------------------- @@ -445,8 +448,6 @@ def process_dump(input_file, template_file, out_file, file_size, file_compress, # wait for it to finish reduce.join() - if output != sys.stdout: - output.close() extract_duration = default_timer() - extract_start extract_rate = ordinal / extract_duration logging.info("Finished %d-process extraction of %d articles in %.1fs (%.1f art/s)", @@ -481,6 +482,9 @@ def reduce_process(output_queue, output): :param output: file object where to print. """ + if isinstance(output, OutputSplitter): + output.open_file() + interval_start = default_timer() period = 100000 # FIXME: use a heap @@ -504,6 +508,9 @@ def reduce_process(output_queue, output): ordinal, text = pair ordering_buffer[ordinal] = text + if isinstance(output, OutputSplitter): + output.close() + # ----------------------------------------------------------------------