Advertisement
abasar

Untitled

Mar 7th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. (defvar *forward-index* (make-hash-table))
  2. (defvar *inverse-index* (make-hash-table))
  3. (defvar *x* nil)
  4.  
  5. ; index a site into *forward-index*
  6. (defun index-site (html doc-id)
  7. (let ((words (split-sequence #\Space html))
  8. (index (make-hash-table)))
  9. (dolist (word words) (if (gethash word index)
  10. (incf (gethash word index))
  11. (setf (gethash word index) 0)))
  12. (setf *x* index)
  13. (setf (gethash doc-id *forward-index*) index)))
  14.  
  15.  
  16. ; generate the inverse index from *forward-index* into *inverse-index*
  17. (defun generate-inverse-index ()
  18. (maphash (lambda (doc-id word-map)
  19. (maphash (lambda (word hits)
  20. (let ((doc-hit-list (list doc-id hits)))
  21. (if (gethash word *inverse-index*)
  22. (push doc-hit-list (gethash word *inverse-index*))
  23. (setf (gethash word *inverse-index*) (list doc-hit-list))))) word-map)) *forward-index*))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement