markov-scm/markov.chicken.scm

40 lines
1.6 KiB
Scheme
Raw Normal View History

2024-09-13 22:48:27 -04:00
(module markov
2024-09-14 11:28:56 -04:00
(make-table-from-file
guess-sentence
generate-next-word
join-verses
seed-from-entropy)
(import scheme (chicken base) srfi-69
(chicken format)
(chicken random))
2024-09-14 11:28:56 -04:00
(define (seed-from-entropy)
(set-pseudo-random-seed! (random-bytes)))
2024-09-14 11:28:56 -04:00
(define (join-verses* lst str book chapter verse)
(if (null? lst)
str
(let* ((cur (car lst))
(first-character (if (= (string-length cur) 0)
#f
(string-ref cur 0)))
(rest (cdr lst)))
(cond
((not (char? first-character)) (join-verses* rest str
book chapter verse))
((equal? cur "startofbook")
(join-verses* rest (sprintf "~A~%~%~%" str) (+ book 1) 1 1))
((equal? cur "startofchapter")
(join-verses* rest (sprintf "~A~%~%" str) book (+ 1 chapter) 1))
((equal? cur "startofverse")
(join-verses* rest (sprintf "~A~%~A:~A:~A"
str book chapter verse)
book chapter (+ 1 verse)))
((or (char-alphabetic? first-character)
(char-numeric? first-character))
(join-verses* rest (string-append str " " cur)
book chapter verse))
(else (join-verses* rest (string-append str cur)
book chapter verse))))))
(define (join-verses lst)
(string-append (join-verses* lst "THE BOOK OF MARKOV" 1 0 1)
"\n"))
2024-09-13 22:48:27 -04:00
(include "markov.impl.scm"))