diff options
author | Erich Eckner <git@eckner.net> | 2019-01-10 13:33:13 +0100 |
---|---|---|
committer | Erich Eckner <git@eckner.net> | 2019-01-10 13:33:13 +0100 |
commit | 61c267ac8d0c61f7cf7e9a47cf4bdffbdd0088c2 (patch) | |
tree | 327fba65fd46f755120a37aa362efb531867b1ee | |
parent | 023e6986409ea92689f2a06a12d4f08019928f7b (diff) | |
download | markov-61c267ac8d0c61f7cf7e9a47cf4bdffbdd0088c2.tar.xz |
do not output words which appear in the wordlist
-rw-r--r-- | markov.lpi | 1 | ||||
-rw-r--r-- | markov.lpr | 22 | ||||
-rw-r--r-- | markov.lps | 15 |
3 files changed, 24 insertions, 14 deletions
@@ -51,6 +51,7 @@ </Target> <SearchPaths> <IncludeFiles Value="$(ProjOutDir)"/> + <OtherUnitFiles Value="../units"/> <UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/> </SearchPaths> </CompilerOptions> @@ -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. @@ -7,8 +7,8 @@ <Unit0> <Filename Value="markov.lpr"/> <IsPartOfProject Value="True"/> - <TopLine Value="54"/> - <CursorPos X="37" Y="74"/> + <IsVisibleTab Value="True"/> + <CursorPos X="21" Y="11"/> <UsageCount Value="23"/> <Loaded Value="True"/> </Unit0> @@ -33,7 +33,6 @@ <Unit3> <Filename Value="generate-random-word-from-wikipedia.sh"/> <IsPartOfProject Value="True"/> - <IsVisibleTab Value="True"/> <EditorIndex Value="3"/> <CursorPos X="55" Y="30"/> <UsageCount Value="23"/> @@ -41,7 +40,7 @@ <DefaultSyntaxHighlighter Value="Bash"/> </Unit3> </Units> - <JumpHistory Count="15" HistoryIndex="14"> + <JumpHistory Count="17" HistoryIndex="16"> <Position1> <Filename Value="markov.lpr"/> <Caret Line="19" Column="12"/> @@ -102,6 +101,14 @@ <Filename Value="generate-random-word-from-wikipedia.sh"/> <Caret Line="9"/> </Position15> + <Position16> + <Filename Value="markov.lpr"/> + <Caret Line="18" Column="6" TopLine="4"/> + </Position16> + <Position17> + <Filename Value="markov.lpr"/> + <Caret Line="11" Column="19"/> + </Position17> </JumpHistory> </ProjectSession> </CONFIG> |