Skip to content

Instantly share code, notes, and snippets.

@timothyandrew
Created September 26, 2013 07:31
Show Gist options
  • Save timothyandrew/6710926 to your computer and use it in GitHub Desktop.
Save timothyandrew/6710926 to your computer and use it in GitHub Desktop.
(ns antonyms.core
(:gen-class)
(:require [clj-http.client :as client]))
(use 'clojure.java.io)
(defn antonym-for
[word]
(let [api-key "8c1e369f560ac4b0acfff71c674b37d6"
server-url (str "http://words.bighugelabs.com/api/2/" api-key "/" word "/json")
response (client/get server-url {:as :json :throw-exceptions false})]
(get-in response [:body :noun :ant])))
(defn process-file
"Call func once for with each line in filename"
[filename func]
(with-open [rdr (reader filename)]
(doseq [line (line-seq rdr)]
(func line))))
(defn print-with-antonym
[word]
(let [antonym (antonym-for word)]
(if-not (nil? antonym)
(println (str word " " antonym)))))
(defn -main
[filename]
(process-file filename print-with-antonym))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment