Execute a Markov algorithm: Difference between revisions
Content added Content deleted
(Added zkl) |
(fix bug) |
||
Line 3,565: | Line 3,565: | ||
=={{header|zkl}}== |
=={{header|zkl}}== |
||
<lang zkl> |
<lang zkl>fcn parseRuleSet(lines){ |
||
fcn parseRuleSet(lines){ |
|||
if(vm.numArgs>1) lines=vm.arglist; // lines or object |
if(vm.numArgs>1) lines=vm.arglist; // lines or object |
||
ks:=L(); vs:=L(); |
ks:=L(); vs:=L(); |
||
foreach line in (lines){ |
foreach line in (lines){ |
||
if(line[0]=="#") continue; // nuke <comment> |
if(line[0]=="#") continue; // nuke <comment> |
||
pattern,replacement:=line. |
pattern,replacement:=line.replace("\t"," ") |
||
.split(" -> ",1).apply("strip"); |
|||
ks.append(pattern); vs.append(replacement); |
ks.append(pattern); vs.append(replacement); |
||
} |
} |
||
Line 3,593: | Line 3,593: | ||
<lang zkl>ruleSet:=parseRuleSet("# This rules file is extracted from Wikipedia:", |
<lang zkl>ruleSet:=parseRuleSet("# This rules file is extracted from Wikipedia:", |
||
"# http://en.wikipedia.org/wiki/Markov_Algorithm", |
"# http://en.wikipedia.org/wiki/Markov_Algorithm", |
||
"A |
"A\t->\tapple", "B -> bag", "S -> shop", "T -> the", |
||
"the shop -> my brother", "a never used -> .terminating rule"); |
"the shop -> my brother", "a never used -> .terminating rule"); |
||
ruleSet.println(); |
ruleSet.println(); |