Compare commits
2 Commits
a3b6fb2b4c
...
a08efcef9c
Author | SHA1 | Date |
---|---|---|
Silas Vedder | a08efcef9c | 2 years ago |
Silas Vedder | 272b4ba2b7 | 2 years ago |
10 changed files with 150 additions and 114 deletions
@ -1,22 +1,32 @@ |
|||||||
(define-module (bible-tools count-words) |
(define-module (bible-tools count-words) |
||||||
#:use-module (bible-tools) |
#:use-module (bible-tools bible-tools) |
||||||
#:use-module (srfi srfi-1) |
#:use-module (srfi srfi-1) |
||||||
#:use-module (srfi srfi-26) |
#:use-module (srfi srfi-26) |
||||||
|
#:use-module (srfi srfi-171) |
||||||
|
#:use-module (srfi srfi-171 gnu) |
||||||
#:export (count-words)) |
#:export (count-words)) |
||||||
|
|
||||||
(define (split/stuff str) |
(define (split/stuff str) |
||||||
|
(define (mapcan f l) (apply append (map f l))) |
||||||
(define (split-curry char) (cut string-split <> char)) |
(define (split-curry char) (cut string-split <> char)) |
||||||
(let ((splits (map split-curry '(#\, #\: #\. #\! #\? #\; #\< #\>)))) |
(let ((splits (map split-curry '(#\, #\: #\. #\! #\? #\; #\< #\>)))) |
||||||
(clean-strings (fold mapcan (string-split str #\space) splits)))) |
(fold mapcan (string-split str #\space) splits))) |
||||||
|
|
||||||
|
(define (counter . args) |
||||||
|
(cond ((null? args) '()) |
||||||
|
((< (length args) 2) (car args)) |
||||||
|
(else (let ((val (assoc (cadr args) (car args)))) |
||||||
|
(acons (cadr args) |
||||||
|
(1+ (if val (cdr val) 0)) (car args)))))) |
||||||
|
|
||||||
(define (count verse result) |
(define (count verse result) |
||||||
(fold (lambda (word res) |
(list-transduce clean-strings |
||||||
(let ((val (assoc word res))) |
counter |
||||||
(acons word (1+ (if val (cdr val) 0)) res))) |
result (split/stuff verse))) |
||||||
result (split/stuff verse))) |
|
||||||
|
|
||||||
(define (co f g) (lambda (v w) (f (g v) (g w)))) |
(define (co f g) (lambda (v w) (f (g v) (g w)))) |
||||||
|
|
||||||
(define count-words |
(define count-words |
||||||
(compose (cut delete-duplicates <> (co equal? car)) |
(compose (cut sort <> (co > cdr)) |
||||||
(cut sort <> (co > cdr)) |
(cut delete-duplicates <> (co equal? car)) |
||||||
(cut fold count '() <>))) |
(cut fold count '() <>))) |
||||||
|
@ -1,37 +1,36 @@ |
|||||||
#! /usr/bin/env sh |
#! /usr/bin/env sh |
||||||
exec guile -e '(@ (bible2latex) main)' -s "$0" "$@" |
exec guile -e main -s "$0" "$@" |
||||||
!# |
!# |
||||||
|
|
||||||
(define-module (bible2latex) |
(use-modules (bible-tools bible-tools) |
||||||
#:use-module (bible-tools) |
(bible-tools latex-export) |
||||||
#:use-module (bible-tools latex-export) |
(srfi srfi-1) |
||||||
#:use-module (srfi srfi-1) |
(srfi srfi-26)) |
||||||
#:use-module (srfi srfi-26) |
|
||||||
#:export (main)) |
|
||||||
|
|
||||||
(define print-text (compose display as-latex)) |
|
||||||
|
|
||||||
(define (help) |
(define (help) |
||||||
(display "Usage: bible2latex [-b book] [-c chapter] [-h] [-v]\n") |
(display "Usage: bible2latex [-b book] [-c chapter]") |
||||||
|
(display " [-h] [-v] [--bible b]\n") |
||||||
(display "\t-b book\t\texport the book to latex\n") |
(display "\t-b book\t\texport the book to latex\n") |
||||||
(display "\t-c chapter\texport this chapter to latex\n") |
(display "\t-c chapter\texport this chapter to latex\n") |
||||||
(display "\t-h\t\tdisplay this help message\n") |
(display "\t-h\t\tdisplay this help message\n") |
||||||
(display "\t-v\t\tdisplay the current version\n")) |
(display "\t-v\t\tdisplay the current version\n") |
||||||
|
(display "\t--bible b use this bible\n")) |
||||||
(define (version) |
|
||||||
(display "bible2latex v1.0.0\n")) |
|
||||||
|
|
||||||
(define (main args) |
(define (main args) |
||||||
|
(define version "bible2latex v1.0.0\n") |
||||||
|
(define pr (compose display as-latex)) |
||||||
(define flag? (cut member <> args)) |
(define flag? (cut member <> args)) |
||||||
(define get (compose cadr flag?)) |
(define get (compose cadr flag?)) |
||||||
(define-syntax conf |
(let-syntax ((conf |
||||||
(syntax-rules (else) |
(syntax-rules (else) |
||||||
((_ (f e)... (else g)) (cond ((flag? f) e)... (else g))))) |
((_ (f e)... (else g)) (cond ((flag? f) e)... |
||||||
(with-bible "elb1871" |
(else g)))))) |
||||||
(conf ("-h" (help)) |
(let ((bible (if (flag? "--bible") (get "--bible") "elb1871"))) |
||||||
("-v" (version)) |
(with-bible bible |
||||||
("-b" (if (flag? "-c") |
(conf ("-h" (help)) |
||||||
(call-with-chapter (get "-b") (get "-c") |
("-v" (display version)) |
||||||
print-text) |
("-b" (if (flag? "-c") |
||||||
(call-with-book (get "-b") print-text))) |
(call-with-chapter (get "-b") |
||||||
(else print-text)))) |
(get "-c") pr) |
||||||
|
(call-with-book (get "-b") pr))) |
||||||
|
(else pr)))))) |
||||||
|
@ -0,0 +1,39 @@ |
|||||||
|
#! /usr/bin/env sh |
||||||
|
exec guile -e main -s "$0" "$@" |
||||||
|
!# |
||||||
|
|
||||||
|
(use-modules (bible-tools bible-tools) |
||||||
|
(srfi srfi-1) |
||||||
|
(srfi srfi-26)) |
||||||
|
|
||||||
|
(define (search phrase txt) |
||||||
|
(let ((rx (make-regexp phrase regexp/icase))) |
||||||
|
(filter (lambda (v) (regexp-exec rx (text v))) txt))) |
||||||
|
|
||||||
|
(define (help) |
||||||
|
(display "Usage: search-bible search-phrase [-b book] [-c chapter]") |
||||||
|
(display " [-h] [-v] [--bible b]\n") |
||||||
|
(display "\t-b book search in this book\n") |
||||||
|
(display "\t-c chapter search in this chapter\n") |
||||||
|
(display "\t-h display this help message\n") |
||||||
|
(display "\t-v display the current version\n") |
||||||
|
(display "\t--bible b use this bible\n")) |
||||||
|
|
||||||
|
(define (main args) |
||||||
|
(define (pr t) |
||||||
|
(map (lambda (str) (display str) (newline)) |
||||||
|
(map verse->string (search (cadr args) t)))) |
||||||
|
(define version "search-bible v1.0.0\n") |
||||||
|
(define flag? (cut member <> args)) |
||||||
|
(define get (compose cadr flag?)) |
||||||
|
(let-syntax ((conf (syntax-rules (else) |
||||||
|
((_ (f e)... (else g)) (cond ((flag? f) e)... |
||||||
|
(else g)))))) |
||||||
|
(let ((bible (if (flag? "--bible") (get "--bible") "elb1871"))) |
||||||
|
(with-bible bible |
||||||
|
(conf ("-h" (help)) ("-v" (display version)) |
||||||
|
("-b" (if (flag? "-c") |
||||||
|
(call-with-chapter (get "-b") |
||||||
|
(get "-c") pr) |
||||||
|
(call-with-book (get "-b") pr))) |
||||||
|
(else (if (< 1 (length args)) pr (help)))))))) |
@ -1,39 +1,40 @@ |
|||||||
#! /usr/bin/env sh |
#! /usr/bin/env sh |
||||||
exec guile -e '(@ (word-counter) main)' -s "$0" "$@" |
exec guile -e main -s "$0" "$@" |
||||||
!# |
!# |
||||||
|
|
||||||
(define-module (word-counter) |
(use-modules (bible-tools bible-tools) |
||||||
#:use-module (bible-tools) |
(bible-tools count-words) |
||||||
#:use-module (bible-tools count-words) |
(srfi srfi-1) |
||||||
#:use-module (srfi srfi-1) |
(srfi srfi-26)) |
||||||
#:use-module (srfi srfi-26) |
|
||||||
#:export (main)) |
|
||||||
|
|
||||||
(define (show-meta txt) |
(define (show t) |
||||||
(define (tabs w) (if (< (string-length (car w)) 7) "\t\t" "\t")) |
(define (tabs w) (if (< (string-length (car w)) 7) "\t\t" "\t")) |
||||||
(define (to-str w) (string-append (car w) ":" (tabs w) |
(define (to-str w) (string-append (car w) ":" (tabs w) |
||||||
(number->string (cdr w)) "\n")) |
(number->string (cdr w)) "\n")) |
||||||
(for-each (compose display to-str) (count-words (map text txt)))) |
(for-each (compose display to-str) (count-words (map text t)))) |
||||||
|
|
||||||
(define (help) |
(define (help) |
||||||
(display "Usage: count-words [book] [-c chapter] [-h] [-v]\n") |
(display "Usage: word-counter [book] [-c chapter]") |
||||||
|
(display " [-h] [-v] [--bible b]\n") |
||||||
(display "\t-c chapter count the words in this chapter\n") |
(display "\t-c chapter count the words in this chapter\n") |
||||||
(display "\t-h display this help message\n") |
(display "\t-h display this help message\n") |
||||||
(display "\t-v display the current version\n")) |
(display "\t-v display the current version\n") |
||||||
|
(display "\t--bible b use this bible\n")) |
||||||
(define (version) |
|
||||||
(display "count-words v1.0.0\n")) |
|
||||||
|
|
||||||
(define (main args) |
(define (main args) |
||||||
|
(define version "word-counter v1.0.0\n") |
||||||
(define flag? (cut member <> args)) |
(define flag? (cut member <> args)) |
||||||
(define get (compose cadr flag?)) |
(define get (compose cadr flag?)) |
||||||
(define-syntax conf |
(let-syntax ((conf (syntax-rules (else) |
||||||
(syntax-rules (else) |
((_ (f e)... (else g)) (cond ((flag? f) e)... |
||||||
((_ (f e)... (else g)) (cond ((flag? f) e)... (else g))))) |
(else g)))))) |
||||||
(with-bible "elb1871" |
(let ((bible (if (flag? "--bible") (get "--bible") "elb1871"))) |
||||||
(conf ("-h" (help)) |
(with-bible bible |
||||||
("-v" (version)) |
(conf ("-h" (help)) |
||||||
("-c" |
("-v" (display version)) |
||||||
(call-with-chapter (cadr args) (get "-c") show-meta)) |
("-c" |
||||||
(else (if (< (length args) 2) (help) |
(call-with-chapter (cadr args) (get "-c") |
||||||
(call-with-book (cadr args) show-meta)))))) |
show)) |
||||||
|
(else (if (< (length args) 2) (help) |
||||||
|
(call-with-book (cadr args) |
||||||
|
show)))))))) |
||||||
|
Loading…
Reference in new issue