Silas Vedder
2 years ago
9 changed files with 237 additions and 189 deletions
@ -0,0 +1,22 @@ |
|||||||
|
(define-module (count-words) |
||||||
|
#:use-module (bible-tools) |
||||||
|
#:use-module (srfi srfi-1) |
||||||
|
#:use-module (srfi srfi-26) |
||||||
|
#:export (count-words)) |
||||||
|
|
||||||
|
(define (split/stuff str) |
||||||
|
(define (split-curry char) (cut string-split <> char)) |
||||||
|
(let ((splits (map split-curry '(#\, #\: #\. #\! #\? #\; #\< #\>)))) |
||||||
|
(clean-strings (fold mapcan (string-split str #\space) splits)))) |
||||||
|
|
||||||
|
(define (count verse result) |
||||||
|
(fold (lambda (word res) |
||||||
|
(let ((val (assoc word res))) |
||||||
|
(acons word (1+ (if val (cdr val) 0)) res))) |
||||||
|
result (split/stuff verse))) |
||||||
|
|
||||||
|
(define (co f g) (lambda (v w) (f (g v) (g w)))) |
||||||
|
(define count-words |
||||||
|
(compose (cut delete-duplicates <> (co equal? car)) |
||||||
|
(cut sort <> (co > cdr)) |
||||||
|
(cut fold count '() <>))) |
@ -0,0 +1,23 @@ |
|||||||
|
(define-module (latex-export) |
||||||
|
#:use-module (bible-tools) |
||||||
|
#:use-module (srfi srfi-1) |
||||||
|
#:use-module (srfi srfi-26) |
||||||
|
#:export (as-latex)) |
||||||
|
|
||||||
|
(define (verse-to-latex v) |
||||||
|
(define (latex-first c sec b sec-end) |
||||||
|
(if (string=? (c v) "1") (string-append sec (b v) sec-end) "")) |
||||||
|
(let* ((book (latex-first chapter "\\section{" book "}\n")) |
||||||
|
(chapter |
||||||
|
(latex-first verse "\\textbf{\\large{" chapter "}}\n"))) |
||||||
|
(string-append chapter |
||||||
|
"\\textsuperscript{" (verse v) "}" (text v)))) |
||||||
|
|
||||||
|
(define (as-latex text) |
||||||
|
(string-append "\\documentclass{article}\n\n" |
||||||
|
"\\usepackage{fullpage}\n\n" |
||||||
|
"\\begin{document}\n\n" |
||||||
|
(string-join |
||||||
|
(map verse-to-latex text) |
||||||
|
"\n\n") |
||||||
|
"\n\\end{document}\n")) |
@ -0,0 +1,14 @@ |
|||||||
|
#! /usr/bin/env sh |
||||||
|
exec guile -e '(@ (bible-app) main)' -s "$0" "$@" |
||||||
|
!# |
||||||
|
|
||||||
|
(define-module (bible-app) |
||||||
|
#:use-module (bible-tools) |
||||||
|
#:use-module (latex-export) |
||||||
|
#:use-module (count-words) |
||||||
|
#:use-module (srfi srfi-1) |
||||||
|
#:use-module (srfi srfi-26) |
||||||
|
#:export (main)) |
||||||
|
|
||||||
|
(define (main args) |
||||||
|
(display args)) |
@ -0,0 +1,38 @@ |
|||||||
|
#! /usr/bin/env sh |
||||||
|
exec guile -e '(@ (count-words) main)' -s "$0" "$@" |
||||||
|
!# |
||||||
|
|
||||||
|
(define-module (word-counter) |
||||||
|
#:use-module (bible-tools) |
||||||
|
#:use-module (count-words) |
||||||
|
#:use-module (srfi srfi-1) |
||||||
|
#:use-module (srfi srfi-26) |
||||||
|
#:export (main)) |
||||||
|
|
||||||
|
(define (show-meta txt) |
||||||
|
(define (tabs w) (if (< (string-length (car w)) 7) "\t\t" "\t")) |
||||||
|
(define (to-str w) (string-append (car w) ":" (tabs w) |
||||||
|
(number->string (cdr w)) "\n")) |
||||||
|
(for-each (compose display to-str) (count-words (map text txt)))) |
||||||
|
|
||||||
|
(define (help) |
||||||
|
(display "Usage: count-words [book] [-c chapter] [-h] [-v]\n") |
||||||
|
(display "\t-c chapter count the words in this chapter\n") |
||||||
|
(display "\t-h display this help message\n") |
||||||
|
(display "\t-v display the current version\n")) |
||||||
|
|
||||||
|
(define (version) |
||||||
|
(display "count-words v1.0.0\n")) |
||||||
|
|
||||||
|
(define (main args) |
||||||
|
(define flag? (cut member <> args)) |
||||||
|
(define get (compose cadr flag?)) |
||||||
|
(define-syntax conf |
||||||
|
(syntax-rules (else) |
||||||
|
((_ (f e)... (else g)) (cond ((flag? f) e)... (else g))))) |
||||||
|
(with-bible "jantzen" |
||||||
|
(conf ("-h" (help)) |
||||||
|
("-v" (version)) |
||||||
|
("-c" |
||||||
|
(call-with-chapter (cadr args) (get "-c") show-meta)) |
||||||
|
(else (call-with-book (cadr args) show-meta))))) |
Loading…
Reference in new issue