| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| import sys, hashlib, shutil |
|
|
| PROSE_START = 96000000 |
| PROSE_END = 96262144 |
|
|
|
|
| def sha256_bytes(b): |
| return hashlib.sha256(b).hexdigest() |
|
|
|
|
| def sha256_file(path): |
| h = hashlib.sha256() |
| with open(path, "rb") as f: |
| for chunk in iter(lambda: f.read(1 << 20), b""): |
| h.update(chunk) |
| return h.hexdigest() |
|
|
|
|
| def main(): |
| if len(sys.argv) != 5: |
| raise SystemExit("usage: extract_corpora.py <enwik8> <rs053_code_corpus> <out_prose> <out_code>") |
| enwik8_path, code_src_path, out_prose, out_code = sys.argv[1:5] |
|
|
| with open(enwik8_path, "rb") as f: |
| f.seek(PROSE_START) |
| prose_bytes = f.read(PROSE_END - PROSE_START) |
| if len(prose_bytes) != (PROSE_END - PROSE_START): |
| raise SystemExit("SHORT READ on enwik8 slice: got %d expected %d" % ( |
| len(prose_bytes), PROSE_END - PROSE_START)) |
| with open(out_prose, "wb") as f: |
| f.write(prose_bytes) |
|
|
| shutil.copyfile(code_src_path, out_code) |
|
|
| prose_sha = sha256_bytes(prose_bytes) |
| code_sha = sha256_file(out_code) |
| import os |
| code_bytes = os.path.getsize(out_code) |
|
|
| print("AC-PROSE path=%s bytes=%d sha256=%s range=[%d,%d)" % ( |
| out_prose, len(prose_bytes), prose_sha, PROSE_START, PROSE_END)) |
| print("AC-CODE path=%s bytes=%d sha256=%s source=%s" % ( |
| out_code, code_bytes, code_sha, code_src_path)) |
|
|
|
|
| if __name__ == "__main__": |
| main() |
|
|