Permalink
Browse files

Revert "Use fasl for data."

This reverts commit 4a611ff.
  • Loading branch information...
dchest committed Nov 24, 2010
1 parent 4a611ff commit 8fdd902a8da64be2152592469ba7fa9dfa76c6db
Showing with 26 additions and 12 deletions.
  1. +26 −11 bayes.rkt
  2. +0 −1 data/trained.fasl
View
@@ -2,7 +2,7 @@
(require srfi/1
srfi/13
racket/fasl
racket/serialize
racket/runtime-path)
(define *categories* (make-vector 0))
@@ -118,8 +118,8 @@
(vector-expand! *categories* cat))])
(for-each (lambda (w)
(hash-inc! *totals* idx)
(hash-inc! (hash-ref! *tokens* w (make-hasheqv)) idx))
(get-tokens text)))
(hash-inc! (hash-ref! *tokens* w (make-hasheqv)) idx)))
(get-tokens text))
; Readabilities
(let ([cur-rdb (readability-score text)])
(hash-update! *readabilities* cat (lambda (x) (/ (+ cur-rdb x) 2)) cur-rdb)))
@@ -189,17 +189,32 @@
; Data saving and loading
(define-runtime-path data-file "data/trained.fasl")
(define-runtime-paths
(categories-file
totals-file
tokens-file
readabilities-file)
(values
"data/categories.dat"
"data/totals.dat"
"data/tokens.dat"
"data/readabilities.dat"))
(define (dump-data)
(write-to-file (s-exp->fasl (list *categories*
*totals*
*tokens*
*readabilities*))
data-file #:exists 'replace))
(define (dump-var var file)
(write-to-file (serialize var) file #:exists 'replace))
(dump-var *categories* categories-file)
(dump-var *totals* totals-file)
(dump-var *tokens* tokens-file)
(dump-var *readabilities* readabilities-file))
(define (load-data!)
(set!-values (*categories* *totals* *tokens* *readabilities*)
(apply values (fasl->s-exp (file->value data-file))))
(define (load-var file)
(deserialize (file->value file)))
(set! *categories* (load-var categories-file))
(set! *totals* (load-var totals-file))
(set! *tokens* (load-var tokens-file))
(set! *readabilities* (load-var readabilities-file))
(collect-garbage)
(collect-garbage)) ; collects better when used two times
View

This file was deleted.

Oops, something went wrong.

0 comments on commit 8fdd902

Please sign in to comment.