;; Extension — synonym / query expansion. ;; synmap: car -> automobile, vehicle ; big -> large ;; Corpus: 1 "fast car" 2 "shiny automobile" 3 "big truck" 4 "large house" 5 "vehicle review" (define syn-setup "synmap = [(\"car\", [\"automobile\", \"vehicle\"]), (\"big\", [\"large\"])]\nidx = indexDoc 5 \"vehicle review\" (indexDoc 4 \"large house\" (indexDoc 3 \"big truck\" (indexDoc 2 \"shiny automobile\" (indexDoc 1 \"fast car\" emptyIndex))))\n") (define syn-cases (list (list "expand term with synonyms" "expandTerm synmap \"car\"" (list "car" "automobile" "vehicle")) (list "expand single synonym" "expandTerm synmap \"big\"" (list "big" "large")) (list "expand unknown term" "expandTerm synmap \"banana\"" (list "banana")) (list "syn docs union" "synDocs synmap \"car\" idx" (list 1 2 5)) (list "syn docs single synonym" "synDocs synmap \"big\" idx" (list 3 4)) (list "syn docs no synonyms" "synDocs synmap \"house\" idx" (list 4)) (list "syn docs absent" "synDocs synmap \"plane\" idx" (list)) (list "syn rank expanded" "synRankTfIdf synmap \"car\" idx" (list 1 2 5)) (list "syn rank single" "synRankTfIdf synmap \"big\" idx" (list 3 4)))) (define syn-results (search-batch syn-setup (map (fn (c) (nth c 1)) syn-cases))) (map-indexed (fn (i c) (hk-test (nth c 0) (nth syn-results i) (nth c 2))) syn-cases) {:fail hk-test-fail :pass hk-test-pass :fails hk-test-fails}