Skip to content
Open
Show file tree
Hide file tree
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
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ Each file will contains several documents in this [document format](https://gith

```
usage: wikiextractor [-h] [-o OUTPUT] [-b n[KMG]] [-c] [--json] [--html] [-l] [-ns ns1,ns2]
[--templates TEMPLATES] [--no-templates] [--html-safe HTML_SAFE] [--processes PROCESSES]
[-q] [--debug] [-a] [-v]
[--preserve-unicode] [--templates TEMPLATES] [--no-templates] [--html-safe HTML_SAFE] [--processes PROCESSES] [-q] [--debug] [-a] [-v]
input

Wikipedia Extractor:
Expand Down Expand Up @@ -93,6 +92,8 @@ Output:
maximum bytes per output file (default 1M)
-c, --compress compress output files using bzip
--json write output in json format instead of the default <doc> format
--preserve-unicode
Do not convert unicode characters to ascii characters when using JSON output

Processing:
--html produce HTML output, subsumes --links
Expand Down
3 changes: 3 additions & 0 deletions wikiextractor/WikiExtractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,8 @@ def main():
help="compress output files using bzip")
groupO.add_argument("--json", action="store_true",
help="write output in json format instead of the default <doc> format")
groupO.add_argument("--preserve-unicode", action="store_true",
help="Do not convert unicode characters to ascii characters when using JSON output")

groupP = parser.add_argument_group('Processing')
groupP.add_argument("--html", action="store_true",
Expand Down Expand Up @@ -584,6 +586,7 @@ def main():
if args.html:
Extractor.keepLinks = True
Extractor.to_json = args.json
Extractor.preserve_unicode = args.preserve_unicode

try:
power = 'kmg'.find(args.bytes[-1].lower()) + 1
Expand Down
5 changes: 4 additions & 1 deletion wikiextractor/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -982,7 +982,10 @@ def extract(self, out, html_safe=True):
'title': self.title,
'text': "\n".join(text)
}
out_str = json.dumps(json_data)
if self.preserve_unicode:
out_str = json.dumps(json_data, ensure_ascii=False)
else:
out_str = json.dumps(json_data)
out.write(out_str)
out.write('\n')
else:
Expand Down