-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f364ea8
commit 450e6b1
Showing
9 changed files
with
488 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Utilities for converting wiki's into the dolma format.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
"""Download and extract official wiki dumps.""" | ||
|
||
import argparse | ||
import os | ||
import re | ||
import urllib.parse | ||
|
||
import pyunpack | ||
|
||
from licensed_pile import logs, scrape | ||
|
||
parser = argparse.ArgumentParser( | ||
description="Download and Extract official Wiki dumps." | ||
) | ||
parser.add_argument("--url", help="The url to download a dump from.") | ||
parser.add_argument("--wikimedia", help="") | ||
parser.add_argument( | ||
"--output_dir", default="data/dumps", help="Where to save the downloaded dumps." | ||
) | ||
|
||
|
||
def wikimedia_url(wikimedia): | ||
wikimedia = re.sub(r"^en", "", wikimedia) | ||
return f"https://dumps.wikimedia.org/en{wikimedia}/latest/en{wikimedia}-latest-pages-articles-multistream.xml.bz2" | ||
|
||
|
||
def download_and_extract(url, ident, output_dir): | ||
filename = os.path.basename(urllib.parse.urlparse(url).path) | ||
|
||
|
||
def main(args): | ||
if args.url and args.wikimedia: | ||
raise ValueError( | ||
f"--url={args.url} and --wikimedia={args.wikimedia} cannot be set at the same time." | ||
) | ||
if not (args.url or args.wikimedia): | ||
raise ValueError(f"--url or --wikimedia must be set.") | ||
if not args.url: | ||
args.url = wikimedia_url(args.wikimedia) | ||
|
||
ident = ... | ||
download_and_extract(args.url, ident, args.output_dir) | ||
|
||
|
||
if __name__ == "__main__": | ||
args = parser.parse_args() | ||
logs.configure_logging("wiki/dump") | ||
main(args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/usr/bin/env bash | ||
|
||
DATE=${1} | ||
export_dir=${2:-"data/dumps"} | ||
export_dir=${export_dir%/} | ||
output_dir=${3:-"data/wiki/dump/raw"} | ||
output_dir=${output_dir%/} | ||
|
||
if [ -z ${DATE} ]; then | ||
echo "usage: to_dolma.sh [date] dump/ data/wiki/raw/documents" 2> /dev/null | ||
exit 1 | ||
fi | ||
|
||
declare -a wikis=( | ||
# wiki | ||
wikibooks | ||
wikinews | ||
wikiquote | ||
wikisource | ||
wikiversity | ||
wikivoyage | ||
wiktionary | ||
) | ||
|
||
for wiki in ${wikis[@]}; do | ||
filename="en${wiki}-${DATE}-pages-meta-current.xml" | ||
# Check for output | ||
if [[ ${wiki} == "wiki" ]]; then | ||
url="https://wikipedia.com" | ||
else | ||
url="https://${wiki}.com" | ||
fi | ||
python ../scrape/to_dolma.py --license CC-BY-SA/4.0 --wiki "${url}" --export "${export_dir}/${filename}" --output_dir "${output_dir}" --last_author --source "wiki/dump" | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
{ | ||
"dependencies": { | ||
"commander": "^12.1.0", | ||
"wtf_wikipedia": "^10.3.1" | ||
"wtf_wikipedia": "^10.3.1", | ||
"wtf-plugin-api": "^2.0.0", | ||
"wtf-plugin-latex": "^1.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.