Cache calculated frequency data

This doesn't help that much because it's not streamed data.
This commit is contained in:
Peter McGoron 2024-09-14 12:18:22 -04:00
parent 1fb756d647
commit 9dc8e4bb5e
1 changed files with 16 additions and 4 deletions

View File

@ -1,11 +1,23 @@
(load "markov.chicken.so")
(import markov
(chicken format)
srfi-18)
srfi-18
srfi-69
(chicken file))
(display "Generating table (this may take a while)\n" (current-error-port))
(define table (make-table-from-file "kjv.txt"))
(display "Done generating.\n")
(define table
(if (file-exists? "kjv-data.scm")
(with-input-from-file "kjv-data.scm"
(lambda ()
(display "Reading previously generated data.\n" (current-error-port))
(alist->hash-table (read))))
(with-output-to-file "kjv-data.scm"
(lambda ()
(display "Generating table (this may take a while)\n" (current-error-port))
(let ((table (make-table-from-file "kjv.txt")))
(display "done generating.\n" (current-error-port))
(write (hash-table->alist table))
table)))))
(define (generate-until-word* current collected limits)
(if (member current limits)