From 9dc8e4bb5e4a81fa5442b9ae4ee07108d20b930e Mon Sep 17 00:00:00 2001 From: Peter McGoron Date: Sat, 14 Sep 2024 12:18:22 -0400 Subject: [PATCH] Cache calculated frequency data This doesn't help that much because it's not streamed data. --- toplevel.scm | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/toplevel.scm b/toplevel.scm index 9fa11bd..d5d6cd0 100644 --- a/toplevel.scm +++ b/toplevel.scm @@ -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)