Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defun chunk (n list &optional (acc '()))
- (if (> n (length list))
- acc
- (chunk n
- (subseq list 1)
- (cons (subseq list 0 n)
- acc))))
- (defun hash-set (hash key value)
- (setf (gethash key hash) value))
- (defun hash-count-incr (hash key count)
- (let ( (value (gethash key hash)) )
- (if (not value)
- (hash-set hash key count)
- (hash-set hash key (+ count value)))))
- ;; inifinite loop...?
- (defun file->n-grams (n file-name)
- (let ((n-gram-table (make-hash-table :test #'equal)))
- (with-open-file (stream file-name)
- (loop :for line := (read-line stream nil nil)
- :while line :do
- (mapcar (lambda (c) (hash-count-incr n-gram-table c 1))
- (chunk n (str:split " " (string-downcase (string line)))))))
- n-gram-table))
Advertisement
Add Comment
Please, Sign In to add comment