Advertisement
abasar

Untitled

Mar 9th, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. (defvar *forward-index* (make-string-hash-table))
  2. (defvar *inverse-index* (make-string-hash-table))
  3.  
  4. (defun make-string-hash-table ()
  5. "helper function to create a hash table that works with multiple types of keys"
  6. (make-hash-table :test #'equal))
  7.  
  8. ; index a site into *forward-index*
  9. (defun index-site (html doc-id)
  10. (let ((words (split-sequence #\Space html))
  11. (index (make-string-hash-table)))
  12. (dolist (word words) (if (gethash word index)
  13. (incf (gethash word index))
  14. (setf (gethash word index) 1)))
  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*)
  24. (setf *forward-index* (make-string-hash-table))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement