Skip to content
Open
Changes from all commits
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
13 changes: 10 additions & 3 deletions wikiextractor/WikiExtractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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')


# ----------------------------------------------------------------------
Expand Down Expand Up @@ -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)",
Expand Down Expand Up @@ -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
Expand All @@ -504,6 +508,9 @@ def reduce_process(output_queue, output):
ordinal, text = pair
ordering_buffer[ordinal] = text

if isinstance(output, OutputSplitter):
output.close()


# ----------------------------------------------------------------------

Expand Down