Skip to content

Instantly share code, notes, and snippets.

@ckoparkar
Last active January 20, 2018 22:40
Show Gist options
  • Save ckoparkar/6b370b5d875d233ba1f3a2df80ad0d7c to your computer and use it in GitHub Desktop.
Save ckoparkar/6b370b5d875d233ba1f3a2df80ad0d7c to your computer and use it in GitHub Desktop.
Extract see-also information from ClojureDocs
;; depends on monger
;; [com.novemberain/monger "3.1.0"]
(ns cider.nrepl.middleware.see-also
(:require [monger.core :as mg]
[monger.collection :as c]))
(defn extract-see-alsos
[]
(let [conn (mg/connect)
db (mg/get-db conn "clojuredocs")
coll "see-alsos"]
(c/find-maps db coll)))
;; to test things
(def ss (take 10 (extract-see-alsos)))
(defn formatted-see-alsos
[all]
(reduce (fn [acc m]
(let [from-name (get-in m [:from-var :name])
from-ns (get-in m [:from-var :ns])
to-name (get-in m [:to-var :name])
to-ns (get-in m [:to-var :ns])
format (fn [a b] (str a "/" b))]
(update acc (format from-ns from-name) (comp vec conj) (format to-ns to-name))))
{} all))
(def see-also (formatted-see-alsos (extract-see-alsos)))
(defn write-see-alsos
[data]
(with-open [w (clojure.java.io/writer "resources/see-also2.edn")]
(binding [*out* w]
(prn data))))
;; (write-see-alsos see-also)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment