<p>示例文本: </p><p><code>I bought a B of As from T S.</code></p><p>应该生成输出: </p><p><code>I bought a bag of apples from my brother.</code></p>规则集2:<p>终止规则的测试</p>
<pre># Slightly modified from the rules on Wikipedia
A -> apple
B -> bag
S -> .shop
T -> the
the shop -> my brother
a never used -> .terminating rule
</pre>
<p>示例文本: </p><p><code>I bought a B of As from T S.</code></p><p>应该生成: </p><p><code>I bought a bag of apples from T shop.</code></p>规则集3:<p>如果没有转义特殊的正则表达式字符,这将测试正确的替换顺序并可能捕获简单的基于正则表达式的替换例程。 </p>
<pre># BNF Syntax testing rules
A -> apple
WWWW -> with
Bgage -> ->.*
B -> bag
->.* -> money
W -> WW
S -> .shop
T -> the
the shop -> my brother
a never used -> .terminating rule
</pre>
<p>示例文本: </p><p><code>I bought a B of As W my Bgage from T S.</code></p><p>应该生成: </p><p><code>I bought a bag of apples with my money from T shop.</code></p>规则集4:<p>这将测试规则扫描的正确顺序,并可能捕获以错误顺序扫描的替换例程。它实现了一般的一元乘法引擎。 (请注意,在此实现中,输入表达式必须放在下划线中。) </p><pre> ##一元乘法引擎,用于测试马尔可夫算法实现
`markov(["A -> apple","B -> bag","S -> shop","T -> the","the shop -> my brother","a never used -> .terminating rule"],"I bought a B of As from T S.")`应该回复“我从我兄弟那里买了一袋苹果”。
`markov(["A -> apple","B -> bag","S -> .shop","T -> the","the shop -> my brother","a never used -> .terminating rule"],"I bought a B of As from T S.")`应该回来“我从T商店买了一袋苹果。”
`markov(["A -> apple","WWWW -> with","Bgage -> ->.*","B -> bag","->.* -> money","W -> WW","S -> .shop","T -> the","the shop -> my brother","a never used -> .terminating rule"],"I bought a B of As W my Bgage from T S.")`应该返回”我从T商店用我的钱买了一袋苹果。“