Created
August 29, 2012 06:12
-
-
Save davidjameshumphreys/3507365 to your computer and use it in GitHub Desktop.
Orange (team 3)
This file contains hidden or 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
(ns orange.core | |
(:require [clj-http.client :as client]) | |
) | |
;(client/get "http://www.rhymezone.com/r/rhyme.cgi?Word=egg&typeofrhyme=perfect&org1=syl&org2=l&org3=y") | |
(defn get-url [name] | |
(let [url | |
(str "http://www.rhymezone.com/r/rhyme.cgi?Word=" name "&typeofrhyme=perfect&org1=syl&org2=l&org3=y")] | |
(:body (client/get url)))) | |
;;<A class=d HREF=\"d=begg\"> | |
;;(def BALL (get-url "ball")) | |
(defn get-rhymes [html-file] | |
(let [rhymes (re-seq (re-pattern "<A class=d HREF=.d=([a-z_]+)") html-file)] | |
(map last rhymes) | |
)) | |
(defn rhyme-it [coll] | |
(map (comp rand-nth get-rhymes get-url) (map name coll))) | |
;; Get the rhymes for a single word... | |
;;(get-rhymes (get-url "cat")) | |
;; ("batte" "bhatt" "blatt" "bratt" "catt" "flatt" "glatt" "hatt" "hnat" "jagt" "katt" "klatt" "krat" "kratt" "patt" "pratte" "ratte" "schadt" "shatt" "slaght" "spratt" "arnatt" "biernat" "delatte" "deslatte" "elat" "labatt" "mcnatt" "prevatt" "prevatte" "sarratt" "tvsat" "balyeat" "inmarsat" "rat" "tit" "mortal_combat") | |
;; Get the rhymes for a list... | |
;;(rhyme-it [ :shall :i :compare :thee :to :a :summers :day] ) | |
;;("vidal" "private" "finnair" "jie" "tsu" "aday" "summor" "nej") | |
;;(rhyme-it [:green :eggs :and :ham]) | |
;;("marean" "imreg" "tunde" "kramm") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment