summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2019-01-10 13:33:13 +0100
committerErich Eckner <git@eckner.net>2019-01-10 13:33:13 +0100
commit61c267ac8d0c61f7cf7e9a47cf4bdffbdd0088c2 (patch)
tree327fba65fd46f755120a37aa362efb531867b1ee
parent023e6986409ea92689f2a06a12d4f08019928f7b (diff)
downloadmarkov-61c267ac8d0c61f7cf7e9a47cf4bdffbdd0088c2.tar.xz
do not output words which appear in the wordlist
-rw-r--r--markov.lpi1
-rw-r--r--markov.lpr22
-rw-r--r--markov.lps15
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 @@
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
+ <OtherUnitFiles Value="../units"/>
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
</CompilerOptions>
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 @@
<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>