Execute a Markov algorithm: Difference between revisions
Content added Content deleted
m (→{{header|Python}}: whitespace) |
(Re-word intro and add stretch goal.) |
||
Line 8: | Line 8: | ||
There is one rule per line. If there is a . present before the <replacement>, then this is a terminating rule in which case the interpreter must halt execution. |
There is one rule per line. If there is a . present before the <replacement>, then this is a terminating rule in which case the interpreter must halt execution. |
||
Use the following three tests on entries: |
|||
There are two tests you can make:<pre> |
|||
'''Ruleset 1:'''<pre> |
|||
# This rules file is extracted from Wikipedia: |
# This rules file is extracted from Wikipedia: |
||
# http://en.wikipedia.org/wiki/Markov_Algorithm |
# http://en.wikipedia.org/wiki/Markov_Algorithm |
||
Line 17: | Line 18: | ||
the shop -> my brother |
the shop -> my brother |
||
a never used -> .terminating rule |
a never used -> .terminating rule |
||
</pre> |
|||
</pre>If you input "I bought a B of As from T S." this code should output "I bought a bag of apples from my brother."<br /> |
|||
Sample text of: |
|||
If you use these set of rules:<pre> |
|||
"I bought a B of As from T S." |
|||
Should generate the output: |
|||
"I bought a bag of apples from my brother." |
|||
'''Ruleset 2:'''<br> |
|||
A test of the terminating rule |
|||
<pre> |
|||
# Slightly modified from the rules on Wikipedia |
# Slightly modified from the rules on Wikipedia |
||
A -> apple |
A -> apple |
||
Line 25: | Line 33: | ||
T -> the |
T -> the |
||
the shop -> my brother |
the shop -> my brother |
||
a never used -> .terminating rule</pre> |
a never used -> .terminating rule</pre> |
||
Sample text of: |
|||
"I bought a B of As from T S." |
|||
Should generate: |
|||
"I bought a bag of apples from T shop." |
|||
'''Ruleset 3:'''<br> |
|||
A stretch goal. This tests the for correct substitution order and may trap simple regexp based replacement routines if special regexp characters are not escaped |
|||
<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> |
|||
Sample text of: |
|||
"I bought a B of As W my Bgage from T S."" |
|||
Should generate: |
|||
"I bought a bag of apples with my money from T shop." |
|||
=={{header|J}}== |
=={{header|J}}== |