sae-program-viewer / data /programs /helpers.json
AmiriHayes's picture
SAE program viewer — browse-only static build
0118e4d verified
Raw History Blame Contribute Delete
1.48 kB
{"helpers_source": "def _tok(seq, i):\n \"\"\"The token i positions back; i=1 is the scored position itself.\n None when the offset falls before the start of the sequence, which the\n scored code represents as -1 and which never matches a set.\"\"\"\n return seq[-i] if len(seq) >= i else None\n\ndef _win(seq, k):\n \"\"\"The k tokens immediately before the scored position.\"\"\"\n return seq[max(0, len(seq) - 1 - k):len(seq) - 1]\n\ndef _any_in(toks, s):\n return any(t in s for t in toks)\n\ndef _count_in(toks, s):\n return sum(1 for t in toks if t in s)\n\ndef _suffix(tok, klen):\n \"\"\"The suffix class the scored code uses: the last `klen` characters of the\n token with surrounding whitespace stripped, or '' when it is shorter.\n `_BYTE_TOKENS` maps a `<byte-token N>` literal back to the string the\n scored code actually saw, so these agree on the raw byte tokens too.\"\"\"\n if tok is None:\n return None\n t = _BYTE_TOKENS.get(tok, tok).strip()\n return t[-klen:] if len(t) >= klen else ''\n\ndef _pred(tok, name):\n if tok is None:\n return False\n t = _BYTE_TOKENS.get(tok, tok).strip()\n return {'istitle': t.istitle, 'isupper': t.isupper,\n 'isdigit': t.isdigit}[name]()", "n_byte_tokens": 340, "note": "the 6 helpers every rendered program calls, shown once; _BYTE_TOKENS maps the 340 '<byte-token N>' literals back to the raw string, and is only consulted by _suffix and _pred"}