From 61c267ac8d0c61f7cf7e9a47cf4bdffbdd0088c2 Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Thu, 10 Jan 2019 13:33:13 +0100 Subject: do not output words which appear in the wordlist --- markov.lpi | 1 + markov.lpr | 22 ++++++++++++---------- markov.lps | 15 +++++++++++---- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/markov.lpi b/markov.lpi index 71a6713..c9a492e 100644 --- a/markov.lpi +++ b/markov.lpi @@ -51,6 +51,7 @@ + diff --git a/markov.lpr b/markov.lpr index bdc1e48..adf09db 100644 --- a/markov.lpr +++ b/markov.lpr @@ -8,14 +8,14 @@ uses {$ENDIF}{$ENDIF} Classes { you can add units after this }, - sysutils, math; + sysutils, math, mystringlistunit; var wordFileName,s: string; count: longint; depth,i,j,current: int64; c: char; - f: textFile; + f: tMyStringList; probabilities: array of extended; total: extended; c2i: array[char] of longint; @@ -67,10 +67,9 @@ begin for i:=0 to length(probabilities)-1 do probabilities[i]:=0; - assignFile(f,wordFileName); - reset(f); - while not eof(f) do begin - readln(f,s); + f:=tMyStringList.create; + f.loadFromFile(wordFileName); + while f.readln(s) do begin s:=s+' '; // lf ends a word, too current:=0; // reset current index for i:=1 to length(s) do begin @@ -85,7 +84,6 @@ begin probabilities[current]:=probabilities[current]+1; end; end; - closeFile(f); for i:=0 to length(probabilities) div (length(i2c)+1)-1 do begin total:=0; @@ -115,6 +113,7 @@ begin // generation while count>0 do begin current:=0; + s:=''; repeat current:=current * (length(i2c)+1) mod length(probabilities); total:=random; @@ -126,12 +125,15 @@ begin if current mod (length(i2c)+1) = 0 then break else - write(i2c[current mod (length(i2c)+1)]); + s:=s+i2c[current mod (length(i2c)+1)]; until false; - writeln; - dec(count); + if not f.hatZeile(s,false) then begin; + writeln(s); + dec(count); + end; end; + f.free; setLength(probabilities,0); end. diff --git a/markov.lps b/markov.lps index 4950f82..f9a0deb 100644 --- a/markov.lps +++ b/markov.lps @@ -7,8 +7,8 @@ - - + + @@ -33,7 +33,6 @@ - @@ -41,7 +40,7 @@ - + @@ -102,6 +101,14 @@ + + + + + + + + -- cgit v1.2.3-70-g09d2