Skip to content

Instantly share code, notes, and snippets.

@jsmorph
Last active December 20, 2015 02:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsmorph/6053760 to your computer and use it in GitHub Desktop.
Save jsmorph/6053760 to your computer and use it in GitHub Desktop.
Musicbrainz graph access examples
(defn get-track-artist-names
([track limit]
(into {}
(walk track
[[:out "artist_credit:track"]
[:in "artist_credit:artist_credit_name"]
[:out "artist:artist_credit_name" :id]
[:out "name:artist" "name"]]
limit))))
(defn get-track-releases-texts
([track limit]
(frequencies
(map first
(walk track
[[:out "tracklist:track"]
[:in "tracklist:medium"]
[:out "release:medium"]
[:out "name:release" "name"]]
limit)))))
(defn make-prefix
([id p ^"[B" r strings]
(let [bb (java.nio.ByteBuffer/allocate (if r 9 5))]
(.put bb (get-id-bytes id strings))
(.put bb (byte (if (instance? Byte p) p (tag p))))
(when r (.put bb r))
(.array bb)))
([id p r]
(make-prefix id p r nil))
([id p]
(make-prefix id p nil nil)))
(defn accumulator
([f]
(let [state (ref [])]
(fn g
([] @state)
([x] (dosync (alter state conj x)) x)
([x & more] (g (apply f x more))))))
([]
(accumulator identity)))
(defn get-props*
([^kyotocabinet.DB interned ^kyotocabinet.DB strings ^kyotocabinet.DB ids x]
(let [acc (accumulator #(drop 2 (parse-interned ids %)))]
(do-prefix acc interned (make-prefix x :prop nil strings))
(acc))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment