v2.1: DB restoration (209k entries), cipher fixes & renames, generator tools
- Restore ~64k entries removed by earlier over-aggressive cleanup (alphabet ends A/B/C/X/Y/Z) plus specialty dbs and Thelemic recovery - Fix case-sensitivity bug in precomputed values (Capitals/Alphanumeric Case Sensitive) - Fix bracket-annotation over-counting in digit-aware ciphers - Sort db alphabetically so added entries surface in match lists - Rename Latin->Latin (Jewish), Alphanumeric Satanic->Alphanumeric Case Sensitive - UI: text selection no longer minimizes the modal - Add tools/ generator to rebuild db.json from db.txt
This commit is contained in:
1 parent
210427478f
commit
d5c5cab184
9 files changed
+64176
-7
No files matched your search
@@ -0,0 +1,79 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Generate db.json (HYPER_CYPHERS v2) from a flat db.txt.
|
||||
|
||||
Computes all 69 English-applicable ciphers per entry and emits the JSON shape
|
||||
the calculator's loadPrecomputedDB() expects.
|
||||
|
||||
Usage:
|
||||
python3 generate_db_json.py [input.txt] [output.json]
|
||||
|
||||
Defaults: db_track_a.txt -> db_track_a.json
|
||||
"""
|
||||
import json
|
||||
import re
|
||||
import sys
|
||||
import time
|
||||
from datetime import date
|
||||
from pathlib import Path
|
||||
|
||||
from all_ciphers import get_ciphers, compute_value
|
||||
|
||||
|
||||
def main():
|
||||
in_path = Path(sys.argv[1] if len(sys.argv) > 1 else "db_track_a.txt")
|
||||
out_path = Path(sys.argv[2] if len(sys.argv) > 2 else "db_track_a.json")
|
||||
|
||||
print(f"Input: {in_path}")
|
||||
print(f"Output: {out_path}")
|
||||
|
||||
ciphers = get_ciphers()
|
||||
cipher_order = [c["name"] for c in ciphers]
|
||||
print(f"Computing {len(ciphers)} ciphers per entry...")
|
||||
|
||||
entries = []
|
||||
with open(in_path, encoding="utf-8") as f:
|
||||
for i, line in enumerate(f):
|
||||
if i == 0:
|
||||
continue # skip CREATE_GEMATRO_DB header
|
||||
line = line.rstrip("\r\n").strip()
|
||||
if not line:
|
||||
continue
|
||||
entries.append(line)
|
||||
|
||||
n = len(entries)
|
||||
print(f"Entries to score: {n}")
|
||||
|
||||
t0 = time.time()
|
||||
data = []
|
||||
for idx, phrase in enumerate(entries):
|
||||
# Match the live engine (gematria.js:23, optAllowPhraseComments=true): strip [...]
|
||||
# annotations before computing so digit-counting ciphers (AQ/Synx/etc.) don't count
|
||||
# bracketed display digits. Display text (row[0]) keeps the brackets.
|
||||
compute_text = re.sub(r"\[.+\]", "", phrase).strip() or phrase
|
||||
row = [phrase] + [compute_value(compute_text, c) for c in ciphers]
|
||||
data.append(row)
|
||||
if (idx + 1) % 10000 == 0:
|
||||
elapsed = time.time() - t0
|
||||
rate = (idx + 1) / elapsed
|
||||
eta = (n - idx - 1) / rate
|
||||
print(f" {idx + 1:>7}/{n} ({(idx+1)/n*100:5.1f}%) rate={rate:.0f}/s eta={eta:.0f}s")
|
||||
|
||||
out = {
|
||||
"version": 2,
|
||||
"format": "HYPER_CYPHERS",
|
||||
"generated": date.today().isoformat(),
|
||||
"entries": n,
|
||||
"cipher_order": cipher_order,
|
||||
"data": data,
|
||||
}
|
||||
|
||||
print(f"Writing JSON...")
|
||||
with open(out_path, "w", encoding="utf-8") as f:
|
||||
json.dump(out, f, separators=(",", ":"))
|
||||
|
||||
size_mb = out_path.stat().st_size / 1024 / 1024
|
||||
print(f"Done. {n} entries, {size_mb:.1f} MB, {time.time()-t0:.0f}s total")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in new issue
Block a user