Spintax 实例
理解 spintax 最快的方式,是看着写好的文本变成模板。所以我们拿了一段真实文字——我们自己主页的 About Spintax 段落——按逆向创作指南描述的方式一次一个技巧地拆解了它。下面每个构件的配色与我们的编辑器扩展一致;每一步都链接到对应的完整指南。(示例模板保持英文原文——它的每次渲染都经过引擎验证。)
写好的文本
逆向创作从你已经满意的文字开始,标记最后才加。这是源文本中的一句——与 About Spintax 区块里的字句相同:
Spintax is our own template language for producing many genuinely unique variations of a text from a single source you control.
下面不会发明任何新措辞。我们只标记作者本来就想好的那些选择。
1. 一份选择的词汇表
动句子之前,先把可复用的词声明一次。#set 每次使用都重抽;#def 抽一次并记住(让数字和它的名词保持同步)。在这里改一行,用到它的每个句子都会跟着变。
#set %Unique% = {genuinely unique|truly distinct|non-repeating}
#set %Engine% = {engine|spintax engine|renderer}
#def %pages% = {1|3|48}
2. 替换单词与整个从句
核心操作符是 {a|b|c}。分叉最小的差异片段——一个词——或整个开头从句,始终把共享的尾部留在分叉之外,语法就永远不会失步。
Spintax {(spin syntax)|— "spin syntax" —} is %OwnLang% for
{producing|generating} many %Unique% variations of a text.
只有括号里的插入语不同,所以只分叉它——共享的 Spintax…is 留在花括号外。整句分叉成 {Spintax…is|Spintax…is} 会重复固定部分,请它们各自漂移。
3. 用排列挑选和换序
排列 [<…> a|b|c] 选取随机子集并打乱顺序——比堆同义词的变化多得多。下面的功能列表每次渲染取三到六项。引擎列表保留全部四项、只换序——不带 minsize/maxsize 的排列默认包含所有元素,只有列表需要变长短时才设置尺寸。
It adds [<minsize=3;maxsize=6;sep=", ";lastsep=", and "> permutations|scoped variables|value-driven conditionals|plural agreement|reusable includes|post-processing].
… for [<sep=", ";lastsep=", and "> JavaScript|PHP|Python|Object Pascal]
4. 按值分支
条件 {?VAR?then|else} 按变量的值选择,而不是随机。拨动一个 #def,整个从句一起改变。
#def %ai% = {yes|}
… {?ai?Have an AI draft the template once|Write one template by hand}; the %Engine% then renders unlimited variants.
5. 与数量一致
{plural %n%: one|many} 为数字挑出正确的名词形式。因为 %pages% 是 #def,数字和它的名词永远匹配——复数还可以安然嵌进排列里。
across [<minsize=1;maxsize=3;sep=", ";lastsep=", or "> %pages% {plural %pages%: page|pages}|dozens of sites|many locales]
渲染出 1 page、3 pages、48 pages ——绝不会是 "1 pages"。完整指南:复数 →
6. 按格变位(俄语)
英语一个名词形式就够;屈折语言在每个格里要不同的词尾。技巧是把实体选一次,让每个格都与这一次选择一致——用一个 #def 攥住它,把格变词尾接在词干后面:
#def %e% = {магазин|сайт|проект}
… о %e%е … для %e%а … к %e%у
因为 #def 只抽一次,整个句子停留在同一个实体上——о магазине… для магазина… к магазину。换成每次引用都重抽的 #set,实体就会在句子中途瞬移——о проекте… для магазина… к сайту:语法对,意思乱。这个对比就是 #def 存在的全部理由。(“词干+词尾”的捷径成立是因为这三个名词变位相同;真正不规则的名词要为每个完整形式各留一个 #def。)完整指南:语法安全 →
完整模板
#set %OwnLang% = {our own template language|a markup language we built|our own template syntax}
#set %Unique% = {genuinely unique|truly distinct|non-repeating}
#set %Source% = {a single source you control|one master you own|a single source of truth}
#set %Engine% = {engine|spintax engine|renderer}
#set %N% = {hundreds|thousands|millions}
#def %ai% = {yes|}
#def %pages% = {1|3|48}
<p>Spintax {(spin syntax)|— "spin syntax" —} is %OwnLang% for {producing|generating} many %Unique% variations of a text from %Source%. You write one template that encodes every choice — [<sep=", ";lastsep=", and "> alternatives|orderings|conditions|variables] — and the %Engine% expands it into %N% of %Unique% variants. {Every variation is one you defined|You define every variation}, so the output stays {on-brand and correct|accurate and on-brand} rather than a probabilistic guess.</p>
<p>The {modern|AI-era} workflow {pairs|combines} a {language model|large language model} with that template logic. {?ai?Have an AI draft the richly varied template once|Write one richly varied template by hand}; the %Engine% then renders {unlimited|endless} variants {locally|on your own hardware}, deterministically, and at near-zero cost.</p>
<p>With spintax you {roll out|publish} %Unique% content across [<minsize=1;maxsize=3;sep=", ";lastsep=", or "> %pages% {plural %pages%: page|pages}|dozens of sites|many locales] — unique by construction, not spun gibberish.</p>
<p>Modern spintax is far more than flat alternation. It adds [<minsize=3;maxsize=6;sep=", ";lastsep=", and "> permutations that pick and order a subset|scoped variables|value-driven conditionals|locale-aware plural agreement|reusable includes|a post-processing pass for spacing and capitalisation].</p>
<p>And it {runs wherever you do|works anywhere you deploy}: four {independent|standalone}, open-source implementations — for [<sep=", ";lastsep=", and "> JavaScript|PHP|Python|Object Pascal] — all held to one shared corpus so a template renders identically on every one.</p>
配色方式(与我们编辑器扩展的 scope 一致):
#set指令(#set / #def){a|b}枚举 {a|b}[<…>]排列 [<…> a|b]%VAR%变量 %VAR%{?…}条件 {?…}{plural}复数 {plural …}
打开演练场并载入这个模板——点 Generate 看无穷的现场变体,或者直接改它。(演练场界面为英文。)
在你的编辑器里获得同样的高亮
上面的配色就是我们作为编辑器扩展发布的语法——装上它,你自己的模板也会同样亮起来:VS Code(301st.spintax)或 Sublime Text(Package Control:Spintax)。
接下来去哪
- 打开演练场,贴进你自己写好的文本做逆向拆解。
- 创作指南系列——上面每个技巧的深入版。
- 语法参考与嵌套 spintax。
- 随处运行——四个开源引擎。