-
-
Save jsmorph/6053760 to your computer and use it in GitHub Desktop.
Musicbrainz graph access examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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