Datasets:
Size:
10B<n<100B
Download scripts/parse_wikidata.py from recursal/SuperWikiImage-7M: direct link, hf CLI and curl.
- Browser
- Download file 853 Bytes
-
https://huggingface.co/datasets/recursal/SuperWikiImage-7M/resolve/main/scripts/parse_wikidata.py
- Command line
-
hf download hf://datasets/recursal/SuperWikiImage-7M/scripts/parse_wikidata.py
-
curl -L -o parse_wikidata.py https://huggingface.co/datasets/recursal/SuperWikiImage-7M/resolve/main/scripts/parse_wikidata.py
853 Bytes
| import gzip | |
| import msgspec | |
| import pathlib | |
| import tqdm | |
| def read_lines_jsonl(file_name): | |
| with gzip.open(file_name, "rb") as file_handle: | |
| buffer = b"" | |
| while True: | |
| chunk = file_handle.read((2**31) * 2) | |
| if not chunk: | |
| break | |
| lines = (buffer + chunk).split(b"\n") | |
| for line in lines[:-1]: | |
| yield line.strip(), file_handle.tell() | |
| buffer = lines[-1] | |
| decoder = msgspec.json.Decoder() | |
| with gzip.open( | |
| pathlib.Path("v2_SuperWikiFigures/wikidata/latest-all.json.gz"), "rb" | |
| ) as fp: | |
| for line in tqdm.tqdm(fp): | |
| if len(line) <= 2: | |
| continue | |
| if line[-2] == 44: | |
| line = line.rstrip(b",\n") | |
| wkdata: dict = decoder.decode(line) | |
| if wkdata["id"].startswith("M"): | |
| print(wkdata["id"]) | |