diff options
author | Erich Eckner <git@eckner.net> | 2019-01-09 23:48:58 +0100 |
---|---|---|
committer | Erich Eckner <git@eckner.net> | 2019-01-09 23:48:58 +0100 |
commit | 01dc6496d063a8f04f5716cd30098db4d0619481 (patch) | |
tree | 344470e32d9de88fc1ac676fcb4ec1769706a94e /markov.lpr | |
parent | 747d6044dfcad03f2899f8b68cd37925a63ebbf7 (diff) | |
download | markov-01dc6496d063a8f04f5716cd30098db4d0619481.tar.xz |
geht jetzt
Diffstat (limited to 'markov.lpr')
-rw-r--r-- | markov.lpr | 50 |
1 files changed, 32 insertions, 18 deletions
@@ -12,6 +12,7 @@ uses var wordFileName,s: string; + count: longint; depth,i,j,current: int64; c: char; f: textFile; @@ -22,8 +23,8 @@ var begin randomize; - if paramCount<>2 then begin - writeln(stderr,'usage: markov word-file chain-depth'); + if paramCount<>3 then begin + writeln(stderr,'usage: markov word-file chain-depth count'); halt(1); end; wordFileName:=paramStr(1); @@ -41,6 +42,16 @@ begin writeln(stderr,intToStr(depth)+' is not positive'); halt(1); end; + try + count:=strToInt(paramstr(3)); + except + writeln(stderr,''''+paramStr(3)+''' is not a valid integer'); + halt(1); + end; + if count<=0 then begin + writeln(stderr,intToStr(count)+' is not positive'); + halt(1); + end; i2c:='abcdefghijklmnopqrstuvwxyzäöüßABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÜ'; for i:=length(i2c)-1 downto 1 do @@ -64,7 +75,7 @@ begin for i:=1 to length(s) do begin current:=current*(length(i2c)+1) mod length(probabilities); if c2i[s[i]]<0 then begin - if current<>0 then // terminate word + if (current<>0) and (s[i]<>'.') then // terminate word probabilities[current]:=probabilities[current]+1; current:=0; continue; @@ -101,21 +112,24 @@ begin end; *) // generation - current:=0; - repeat - current:=current * (length(i2c)+1) mod length(probabilities); - total:=random; - while total>0 do begin - total:=total - probabilities[current]; - inc(current); - end; - dec(current); - if current mod (length(i2c)+1) = 0 then - break - else - write(i2c[current mod (length(i2c)+1)]); - until false; - writeln; + while count>0 do begin + current:=0; + repeat + current:=current * (length(i2c)+1) mod length(probabilities); + total:=random; + while total>0 do begin + total:=total - probabilities[current]; + inc(current); + end; + dec(current); + if current mod (length(i2c)+1) = 0 then + break + else + write(i2c[current mod (length(i2c)+1)]); + until false; + writeln; + dec(count); + end; setLength(probabilities,0); end. |