master
Matthew Butterick 5 years ago
parent 9a7c0cf2b9
commit e4123cac46

@ -23,7 +23,7 @@
(define (word->charidx word) (define (word->charidx word)
(apply bitwise-ior (apply bitwise-ior
(for/list ([c (in-string word)]) (for/list ([c (in-string word)])
(expt 2 (char->bitindex c))))) (expt 2 (char->bitindex c)))))
(define (bitindex->char i) (define (bitindex->char i)
(cond (cond
@ -34,14 +34,14 @@
(define (charidx->chars int) (define (charidx->chars int)
(for/list ([i (in-range 64)] (for/list ([i (in-range 64)]
#:when (bitwise-bit-set? int i)) #:when (bitwise-bit-set? int i))
(bitindex->char i))) (bitindex->char i)))
(define (contains-char? charidx-entry c) (define (contains-char? charidx-entry c)
(bitwise-bit-set? charidx-entry (char->bitindex c))) (bitwise-bit-set? charidx-entry (char->bitindex c)))
(define capitalized-mask (define capitalized-mask
(for/sum ([i (in-range 32 59)]) (for/sum ([i (in-range 32 59)])
(expt 2 i))) (expt 2 i)))
(define (capitalized? charidx-entry) (define (capitalized? charidx-entry)
;; a cap only appears at the beginning of a word, ;; a cap only appears at the beginning of a word,
@ -53,20 +53,20 @@
(require racket/set racket/match) (require racket/set racket/match)
(define (make-word-recs) (define (make-word-recs)
(define words (for/set ([word (in-lines (open-input-file words-file))]) (define words (for/set ([word (in-lines (open-input-file words-file))])
word)) word))
(for/vector ([word (in-set words)]) (for/vector ([word (in-set words)])
(vector word (vector word
(word->charidx word) (word->charidx word)
(string-length word) (string-length word)
(match (regexp-match #rx"^(.+)e?s$" word) (match (regexp-match #rx"^(.+)e?s$" word)
[(list _ prefix) #:when (set-member? words prefix) #true] [(list _ prefix) #:when (set-member? words prefix) #true]
[_ #false])))) [_ #false]))))
(define (regenerate-word-index!) (define (regenerate-word-index!)
(make-parent-directory* wordidx-file) (make-parent-directory* wordidx-file)
(define op (open-output-file wordidx-file #:exists 'replace)) (with-output-to-file wordidx-file
(s-exp->fasl (make-word-recs) op) (λ () (s-exp->fasl (make-word-recs) (current-output-port)))
(flush-output op)) #:exists 'replace))
(define wordrecs (define wordrecs
(fasl->s-exp (open-input-file (and (fasl->s-exp (open-input-file (and

Loading…
Cancel
Save