Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defvar *forward-index* (make-string-hash-table))
- (defvar *inverse-index* (make-string-hash-table))
- (defun make-string-hash-table ()
- "helper function to create a hash table that works with multiple types of keys"
- (make-hash-table :test #'equal))
- ; index a site into *forward-index*
- (defun index-site (html doc-id)
- (let ((words (split-sequence #\Space html))
- (index (make-string-hash-table)))
- (dolist (word words) (if (gethash word index)
- (incf (gethash word index))
- (setf (gethash word index) 1)))
- ; generate the inverse index from *forward-index* into *inverse-index*
- (defun generate-inverse-index ()
- (maphash (lambda (doc-id word-map)
- (maphash (lambda (word hits)
- (let ((doc-hit-list (list doc-id hits)))
- (if (gethash word *inverse-index*)
- (push doc-hit-list (gethash word *inverse-index*))
- (setf (gethash word *inverse-index*) (list doc-hit-list))))) word-map)) *forward-index*)
- (setf *forward-index* (make-string-hash-table))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement