#!/usr/bin/env python3 """Alternative compression approaches beyond DAWG/trie. 1. Compressed page table (sorted entries, zlib pages, binary search) 2. Rule-based reduction (phonetic rules + exception table) 3. MPHF + compressed blob (no random access, decompress per-lookup) 4. Two-level hash (first stroke → bucket → scan) 5. Full compressed blob with LRU page cache 6. Hybrid combos """ import json import struct import sys import zlib import math import os from collections import Counter, defaultdict STENO_KEYS = { '#': 0x00400000, 'S-': 0x00000001, 'T-': 0x00000002, 'K-': 0x00000004, 'P-': 0x00000008, 'W-': 0x00000010, 'H-': 0x00000020, 'R-': 0x00000040, 'A-': 0x00000080, 'O-': 0x00000100, '*': 0x00000200, '-E': 0x00000400, '-U': 0x00000800, '-F': 0x00001000, '-R': 0x00002000, '-P': 0x00004000, '-B': 0x00008000, '-L': 0x00010000, '-G': 0x00020000, '-T': 0x00040000, '-S': 0x00080000, '-D': 0x00100000, '-Z': 0x00200000, } IMPLICIT_HYPHEN = set('AOEU*') def parse_stroke(s): result = 0 if '#' in s: result |= STENO_KEYS['#'] s = s.replace('#', '') has_hyphen = '-' in s s_clean = s.replace('-', '') if not has_hyphen and not any(c in IMPLICIT_HYPHEN for c in s_clean): for c in s_clean: key = c + '-' if key in STENO_KEYS: result |= STENO_KEYS[key] return result past_vowels = False for c in s_clean: if c in 'AO': result |= STENO_KEYS[c + '-'] past_vowels = True elif c in 'EU': result |= STENO_KEYS['-' + c] past_vowels = True elif c == '*': result |= STENO_KEYS['*'] past_vowels = True elif not past_vowels and (c + '-') in STENO_KEYS: result |= STENO_KEYS[c + '-'] elif past_vowels and ('-' + c) in STENO_KEYS: result |= STENO_KEYS['-' + c] elif has_hyphen: if s.index(c) < s.index('-'): result |= STENO_KEYS.get(c + '-', 0) else: result |= STENO_KEYS.get('-' + c, 0) else: if (c + '-') in STENO_KEYS: result |= STENO_KEYS[c + '-'] return result def stroke_to_bytes(stroke_val): """Encode stroke as 3 bytes (23 bits used).""" return struct.pack('