September 2017 Update

This commit is contained in:
Ingy döt Net 2017-09-23 10:01:46 +02:00
parent bba7bfd280
commit ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions

View file

@ -0,0 +1,26 @@
fcn parseRuleSet(lines){
if(vm.numArgs>1) lines=vm.arglist; // lines or object
ks:=L(); vs:=L();
foreach line in (lines){
if(line[0]=="#") continue; // nuke <comment>
pattern,replacement:=line.replace("\t"," ")
.split(" -> ",1).apply("strip");
ks.append(pattern); vs.append(replacement);
}
return(ks,vs);
}
fcn markov(text,rules){
ks,vs:=rules; eks:=ks.enumerate();
do{ go:=False;
foreach n,k in (eks){
if (Void!=text.find(k)){
if (Void==(v:=vs[n])) return(text);
if (v[0,1]==".") v=v[1,*] else go=True;
text=text.replace(k,v,1);
break; // restart after every rule application, unless terminating
}
}
}while(go);
text
}

View file

@ -0,0 +1,6 @@
ruleSet:=parseRuleSet("# This rules file is extracted from Wikipedia:",
"# http://en.wikipedia.org/wiki/Markov_Algorithm",
"A\t->\tapple", "B -> bag", "S -> shop", "T -> the",
"the shop -> my brother", "a never used -> .terminating rule");
ruleSet.println();
markov("I bought a B of As from T S.",ruleSet).println();

View file

@ -0,0 +1,11 @@
parseRuleSet( // rule set in a list
T("# Slightly modified from the rules on Wikipedia",
"A -> apple", "B -> bag", "S -> .shop", "T -> the",
"the shop -> my brother", "a never used -> .terminating rule")) :
markov("I bought a B of As from T S.",_).println();
parseRuleSet("# 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") :
markov("I bought a B of As W my Bgage from T S.",_).println();

View file

@ -0,0 +1,2 @@
parseRuleSet(File("ruleSet4")) : markov("_1111*11111_",_).println();
parseRuleSet(File("ruleSet5")) : markov("000000A000000",_).println();