关于「繁简口语金额的有限自动机」,《截图不是钱》给出的定量结论是什么?
结论:口语金额不需要靠越写越长的规则堆来解析。一台 15 个状态、9 类记号、45 条转移的有限状态转换器,覆盖了简体、繁体、银行大写、口语省略与阿拉伯数字混写,在 509,498 个文本的穷举往返中零失败;凡是表不许可的说法,一律拒绝。面对听错的近音数字,先让自动机删去不合法的读法,再用待核销池删去不存在的金额,在稠密池中把误读从 0.0092 压到零。可是,读对了金额、对上了末五码,也只说明这张截图「看起来」属于这一单。截图本身只是一个声明。下一章要建立核销的底线:什么证据才能让一单变成「已付」,以及一台核销自动机怎样保证这条底线不被任何事件序列绕过。
数据口径:书中订单、账号末码、金额、截图与哈希均由固定种子合成,参数为示意,全部计算由书中程序生成;本书只讨论核销方如何检出重复或改动过的凭证,不提供任何制作凭证的方法;属非个人化经营方法,不构成法律、财务或理财建议,任何置付与发货都须由主事者人工放行。 第一章用生日问题量化撞单:从 10 单到 100 单,期望撞单配对数增长 110.0 倍,撞单概率只增长 41.3 倍;示意目录的有效金额只有 19.3 种,5.2 单即有对半机会撞单。
对照数据表
下表数字由本章 Python 程序原样打印,可重新运行复现。 程序只用 Python 标准库与结论吻合的打印值: 15, 45
| case | expected yuan | parsed yuan | verdict |
|---|---|---|---|
| 1 | 3200.00 | 3200.00 | ok |
| 2 | 15000.00 | 15000.00 | ok |
| 3 | 250.00 | 250.00 | ok |
| 4 | 1002.00 | 1002.00 | ok |
| 5 | 15.00 | 15.00 | ok |
| 6 | 110.00 | 110.00 | ok |
| 7 | 10.50 | 10.50 | ok |
| 8 | 3.52 | 3.52 | ok |
| 9 | 1.05 | 1.05 | ok |
| 10 | 0.50 | 0.50 | ok |
| 11 | 0.08 | 0.08 | ok |
| 12 | 1200.00 | 1200.00 | ok |
| 13 | 37.50 | 37.50 | ok |
| 14 | 2340.00 | 2340.00 | ok |
| 15 | 10010.00 | 10010.00 | ok |
| 16 | 15000.00 | 15000.00 | ok |
| 17 | 3.50 | 3.50 | ok |
| 18 | 1280.00 | 1280.00 | ok |
| 19 | 299.00 | 299.00 | ok |
| 20 | 200800.00 | 200800.00 | ok |
| 21 | 150000000.00 | 150000000.00 | ok |
| 22 | 456.78 | 456.78 | ok |
| 23 | REJECT | REJECT | ok |
| 24 | REJECT | REJECT | ok |
| 25 | REJECT | REJECT | ok |
| 26 | REJECT | REJECT | ok |
| 27 | REJECT | REJECT | ok |
查看完整验算程序
# Chapter 3. p31: a finite-state transducer for spoken and written
# Chinese amounts (simplified, traditional and banker's capitals)
# Model: each character is mapped to a token class (digit, zero,
# small unit, section unit, yuan, jiao, fen, close mark, Arabic
# number); a transition table over 15 states says which class may
# follow which. Registers hold the running sums; the result is in
# fen (1/100 yuan). Colloquial cut-offs are a rule of the table: a
# digit right after a unit u that ends the integer part counts as
# digit * u/10, so the spoken forms of 3,200, 15,000 and 250 parse as
# people mean them. What the table does not license is rejected,
# never guessed. Chinese characters are written as escapes so the
# code stays ASCII; each line's comment shows them. Test phrases are
# illustrative; only their index and parsed value are printed.
from decimal import Decimal
import re
DIG = {}
for chars, v in (("\u4e00\u58f9\u5e7a", 1), # yi, capital, yao
("\u4e8c\u8d30\u8cb3\u4e24\u5169", 2), # er, liang
("\u4e09\u53c1\u53c3", 3), ("\u56db\u8086", 4),
("\u4e94\u4f0d", 5), ("\u516d\u9646\u9678", 6),
("\u4e03\u67d2", 7), ("\u516b\u634c", 8),
("\u4e5d\u7396", 9)):
for c in chars:
DIG[c] = v
CLS = {c: ("D", v) for c, v in DIG.items()}
for c in "\u96f6\u3007": # ling, circle zero
CLS[c] = ("Z", 0)
for chars, v in (("\u5341\u62fe", 10), ("\u767e\u4f70", 100),
("\u5343\u4edf", 1000)): # shi, bai, qian
for c in chars:
CLS[c] = ("U", v)
for chars, v in (("\u4e07\u842c", 10 ** 4), ("\u4ebf\u5104", 10 ** 8)):
for c in chars: # wan, yi (1e8)
CLS[c] = ("W", v)
for c in "\u5143\u5706\u5713\u5757\u584a": # yuan, kuai
CLS[c] = ("Y", 0)
for c in "\u89d2\u6bdb": # jiao, mao
CLS[c] = ("J", 0)
CLS["\u5206"] = ("F", 0) # fen
for c in "\u6574\u6b63": # zheng (close)
CLS[c] = ("E", 0)
# spaces, commas, currency signs, "renminbi" and "qian" are dropped
FILLER = re.compile("[\\s,\u00a5\uffe5]|\u4eba\u6c11\u5e01|\u94b1")
# state -> token classes it licenses ("$" is the end of input)
TABLE = {
"S": "DZUA", "D": "UWYJF$", "U": "DZWY$", "Z": "DU$", "W": "DZY$",
"A": "UWY$", "AU": "Y$", "Y": "DZE$", "YD": "J$", "YZ": "D",
"YZD": "F$", "J": "DE$", "JD": "F$", "F": "E$", "E": "$",
}
def tokens(text):
text = FILLER.sub("", text)
out, i = [], 0
while i < len(text):
m = re.match(r"[0-9]+(\.[0-9]+)?", text[i:])
if m:
out.append(("A", Decimal(m.group(0))))
i += len(m.group(0))
elif text[i] in CLS:
out.append(CLS[text[i]])
i += 1
else:
return None
return out
def parse(text):
"""Return the amount in fen, or None if the table rejects it."""
toks = tokens(text)
if not toks:
return None
st, big, sec, pend, cut, last = "S", 0, 0, None, 0, 10 ** 9
yuan, jiao, fen = None, 0, 0
for cls, v in toks + [("$", 0)]:
if cls == "A" and st in ("Y", "YZ", "J") and v in range(10):
cls, v = "D", int(v) # an Arabic jiao or fen digit
if cls not in TABLE[st]:
return None
if cls in "YJF$" and yuan is None and st in "DUWZ":
if st == "D" and cls in "JF":
if big or sec:
return None # "11 mao" is ambiguous
yuan = 0 # a bare "5 mao" or "8 fen"
else:
if st == "D":
sec += pend * cut if cut else pend
yuan, pend = big + sec, None
if cls == "D":
if st in ("S", "Z"):
cut = 0
pend = v
st = {"Y": "YD", "YZ": "YZD", "J": "JD"}.get(st, "D")
elif cls == "Z":
st, cut = ("YZ" if st == "Y" else "Z"), 0
elif cls == "U" and st == "A":
val = pend * v
if val != int(val):
return None
yuan, st = int(val), "AU"
elif cls == "U":
if st in ("S", "Z"):
if v != 10:
return None
pend = 1 # a leading "shi" means 10
if v >= last:
return None
sec += pend * v
pend, last, cut, st = None, v, v // 10, "U"
elif cls == "W" and st == "A":
val = pend * v
if val != int(val):
return None
yuan, st = int(val), "AU"
elif cls == "W":
if st == "D":
sec += pend
if sec == 0 and big == 0:
return None
big = (big + sec) * v if v > 10 ** 4 else big + sec * v
sec, pend, last, cut, st = 0, None, 10 ** 9, v // 10, "W"
elif cls == "A":
pend, st = v, "A"
elif cls == "Y":
if st == "A":
yuan = pend
st = "Y"
elif cls == "J":
jiao, st = pend, "J"
elif cls == "F":
fen, st = pend, "F"
elif cls == "E":
st = "E"
elif st == "YD":
jiao = pend
elif st in ("JD", "YZD"):
fen = pend
elif st == "A":
yuan = pend
total = Decimal(yuan or 0) * 100 + jiao * 10 + fen
return int(total) if total == int(total) else None
CASES = [
("\u4e09\u5343\u4e8c", 320000), # san qian er
("\u4e00\u4e07\u4e94", 1500000), # yi wan wu
("\u4e24\u767e\u4e94", 25000), # liang bai wu
("\u4e00\u5343\u96f6\u4e8c", 100200), # yi qian ling er
("\u5341\u4e94\u5757", 1500), # shi wu kuai
("\u4e00\u767e\u4e00", 11000), # yi bai yi
("\u5341\u5757\u4e94", 1050), # shi kuai wu
("\u4e09\u5757\u4e94\u6bdb\u4e8c", 352), # 3 kuai 5 mao 2
("\u4e00\u5757\u96f6\u4e94", 105), # 1 kuai ling 5
("\u4e94\u6bdb", 50), # wu mao
("\u516b\u5206", 8), # ba fen
("\u58f9\u4edf\u8d30\u4f70\u5706\u6574", 120000), # capitals
("\u53c1\u62fe\u67d2\u5713\u4f0d\u89d2", 3750), # traditional
("\u5169\u5343\u4e09\u767e\u56db\u5341\u5143", 234000),
("\u4e00\u4e07\u96f6\u4e00\u5341\u5757", 1001000),
("1.5\u4e07", 1500000), ("3\u57575", 350), # mixed digits
("\uffe51,280", 128000), ("299\u5143", 29900),
("\u4e8c\u5341\u4e07\u96f6\u516b\u767e", 20080000),
("\u4e00\u4ebf\u4e94", 15000000000), # yi yi wu
("\u4eba\u6c11\u5e01\u8086\u4f70\u4f0d\u62fe\u9646"
"\u5143\u67d2\u89d2\u634c\u5206", 45678), # full capitals
("\u4e09\u5757\u4e94\u5757", None), # two yuan marks
("\u4e94\u6bdb\u4e09\u6bdb", None), # two mao marks
("\u767e\u4e94", None), # bai without digit
("\u4e00\u5341\u767e", None), # units rising
("\u4e09\u4e94\u767e", None), # "300 to 500"
("12.345\u5143", None), # beyond the fen
]
ok = 0
print("case expected yuan parsed yuan verdict")
for i, (text, want) in enumerate(CASES, 1):
got = parse(text)
ok += got == want
w = "REJECT" if want is None else "%.2f" % (want / 100)
g = "REJECT" if got is None else "%.2f" % (got / 100)
print("%4d %13s %13s %s" % (i, w, g,
"ok" if got == want else "FAIL"))
print("states %d, token classes 9, licensed transitions %d"
% (len(TABLE), len("".join(TABLE.values()))))
print("cases passed: %d of %d" % (ok, len(CASES)))唯一数据源与引用
范雅福(Fan, Y.). (2026). 《多模态汇款凭证与口语订单容错解析、转账末五码核销自动机与重复截图欺诈阻断母典》第 3 章「繁简口语金额的有限自动机」(版本 1.0.0). 5D Library. DOI 待发布
DOI 待发布 · 专著页正式发布后上线(本站暂无专著页) · 5DL-B-267 · v1.0.0 · CC-BY-NC-ND-4.0
BibTeX
@book{fan2026267,
author = {Fan, Yafu},
title = {Fault-Tolerant Parsing of Payment Receipts and Spoken Orders: Last-Five-Digit Write-Off Automata and Blocking Duplicate-Screenshot Fraud},
year = {2026},
publisher = {5D Library},
edition = {1.0.0},
note = {DOI pending}
}