Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defvar *forward-index* (make-hash-table))
- (defvar *inverse-index* (make-hash-table))
- (defvar *x* nil)
- ; index a site into *forward-index*
- (defun index-site (html doc-id)
- (let ((words (split-sequence #\Space html))
- (index (make-hash-table)))
- (dolist (word words) (if (gethash word index)
- (incf (gethash word index))
- (setf (gethash word index) 0)))
- (setf *x* index)
- (setf (gethash doc-id *forward-index*) index)))
- ; 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*))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement