;;; Utilities ;;; $Id: utils.lisp,v 1.1 2008/10/25 22:09:02 bernd Exp $ (defun write-directories (&optional (n-words *n-words*)) "Create two sorted files from dictionary." (let* ((words (loop for w being the hash-key in n-words collect (cons w (gethash w n-words)))) (swords (sort words #'string< :key #'car))) ;; write a file with alphabetically sorted entries (with-open-file (stream "directory-alphabetically.txt" :direction :output :if-does-not-exist :create :if-exists :supersede) (dolist (w swords) (format stream "~&~A ~D~%" (car w) (cdr w)))) ;; write a file with entries sorted by frequency of occurrence (with-open-file (stream "directory-occurrence.txt" :direction :output :if-does-not-exist :create :if-exists :supersede) (dolist (w (stable-sort swords #'> :key #'cdr)) ; STABLE-SORT retains alphabetically order (format stream "~&~A ~D~%" (car w) (cdr w))))))